From c3ed4d8f332f889ce947d34df9f2bb965ddc0a2f Mon Sep 17 00:00:00 2001 From: xugro <82907135+xugro@users.noreply.github.com> Date: Thu, 1 Jun 2023 18:07:56 +0300 Subject: [PATCH 01/13] add STARBOARD_THRESHOLD to constants.py --- tle/cogs/starboard.py | 3 +-- tle/constants.py | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tle/cogs/starboard.py b/tle/cogs/starboard.py index 903876be..1d0fa923 100644 --- a/tle/cogs/starboard.py +++ b/tle/cogs/starboard.py @@ -10,7 +10,6 @@ _STAR = '\N{WHITE MEDIUM STAR}' _STAR_ORANGE = 0xffaa10 -_STAR_THRESHOLD = 5 class StarboardCogError(commands.CommandError): @@ -88,7 +87,7 @@ async def check_and_add_to_starboard(self, starboard_channel_id, payload): reaction_count = sum(reaction.count for reaction in message.reactions if str(reaction) == _STAR) - if reaction_count < _STAR_THRESHOLD: + if reaction_count < constants.STARBOARD_THRESHOLD: return lock = self.locks.get(payload.guild_id) if lock is None: diff --git a/tle/constants.py b/tle/constants.py index 6106ef43..2082467c 100644 --- a/tle/constants.py +++ b/tle/constants.py @@ -25,3 +25,5 @@ TLE_ADMIN = os.environ.get('TLE_ADMIN', 'Admin') TLE_MODERATOR = os.environ.get('TLE_MODERATOR', 'Moderator') + +STARBOARD_THRESHOLD = os.environ.get('STARBOARD_THRESHOLD', 5) From 7312007056b66b2282cdd63e88d9ab093fdc8fad Mon Sep 17 00:00:00 2001 From: xugro <82907135+xugro@users.noreply.github.com> Date: Thu, 1 Jun 2023 18:21:47 +0300 Subject: [PATCH 02/13] change constant to be string --- tle/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tle/constants.py b/tle/constants.py index 2082467c..906442e1 100644 --- a/tle/constants.py +++ b/tle/constants.py @@ -26,4 +26,4 @@ TLE_ADMIN = os.environ.get('TLE_ADMIN', 'Admin') TLE_MODERATOR = os.environ.get('TLE_MODERATOR', 'Moderator') -STARBOARD_THRESHOLD = os.environ.get('STARBOARD_THRESHOLD', 5) +STARBOARD_THRESHOLD = os.environ.get('STARBOARD_THRESHOLD', '5') From 7c5ae4f3083134eaf44c6db408ac30e03e6f1c41 Mon Sep 17 00:00:00 2001 From: xugro <82907135+xugro@users.noreply.github.com> Date: Thu, 1 Jun 2023 18:24:14 +0300 Subject: [PATCH 03/13] undo change --- tle/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tle/constants.py b/tle/constants.py index 906442e1..2082467c 100644 --- a/tle/constants.py +++ b/tle/constants.py @@ -26,4 +26,4 @@ TLE_ADMIN = os.environ.get('TLE_ADMIN', 'Admin') TLE_MODERATOR = os.environ.get('TLE_MODERATOR', 'Moderator') -STARBOARD_THRESHOLD = os.environ.get('STARBOARD_THRESHOLD', '5') +STARBOARD_THRESHOLD = os.environ.get('STARBOARD_THRESHOLD', 5) From ec42fde8c55b2c17a53ebced9389040fd92833e6 Mon Sep 17 00:00:00 2001 From: xugro <82907135+xugro@users.noreply.github.com> Date: Thu, 1 Jun 2023 18:44:52 +0300 Subject: [PATCH 04/13] make variable integer --- tle/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tle/constants.py b/tle/constants.py index 2082467c..b20901ce 100644 --- a/tle/constants.py +++ b/tle/constants.py @@ -26,4 +26,4 @@ TLE_ADMIN = os.environ.get('TLE_ADMIN', 'Admin') TLE_MODERATOR = os.environ.get('TLE_MODERATOR', 'Moderator') -STARBOARD_THRESHOLD = os.environ.get('STARBOARD_THRESHOLD', 5) +STARBOARD_THRESHOLD = int(os.environ.get('STARBOARD_THRESHOLD', 5)) From 29090b7ed52c3a1389349982ca46ae2d9838e54d Mon Sep 17 00:00:00 2001 From: xugro <82907135+xugro@users.noreply.github.com> Date: Thu, 15 Jun 2023 19:06:14 +0300 Subject: [PATCH 05/13] add starboard threshold to starboard database --- tle/util/db/user_db_conn.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/tle/util/db/user_db_conn.py b/tle/util/db/user_db_conn.py index 2767c1b2..db22a741 100644 --- a/tle/util/db/user_db_conn.py +++ b/tle/util/db/user_db_conn.py @@ -176,8 +176,9 @@ def create_tables(self): ''') self.conn.execute( 'CREATE TABLE IF NOT EXISTS starboard (' - 'guild_id TEXT PRIMARY KEY,' - 'channel_id TEXT' + 'guild_id TEXT PRIMARY KEY,' + 'channel_id TEXT,' + 'star_threshold INTEGER NOT NULL' ')' ) self.conn.execute( @@ -555,17 +556,23 @@ def clear_reminder_settings(self, guild_id): self.conn.execute(query, (guild_id,)) self.conn.commit() - def get_starboard(self, guild_id): + def get_starboard_channel(self, guild_id): query = ('SELECT channel_id ' 'FROM starboard ' 'WHERE guild_id = ?') return self.conn.execute(query, (guild_id,)).fetchone() + + def get_starboard_threshold(self, guild_id): + query = ('SELECT star_threshold ' + 'FROM starboard ' + 'WHERE guild_id = ?') + return self.conn.execute(query, (guild_id,)).fetchone() - def set_starboard(self, guild_id, channel_id): + def set_starboard(self, guild_id, channel_id, star_threshold): query = ('INSERT OR REPLACE INTO starboard ' - '(guild_id, channel_id) ' + '(guild_id, channel_id, star_threshold) ' 'VALUES (?, ?)') - self.conn.execute(query, (guild_id, channel_id)) + self.conn.execute(query, (guild_id, channel_id, star_threshold)) self.conn.commit() def clear_starboard(self, guild_id): From d6c108f167efb697d9396c0ac179e7ea67d2de1f Mon Sep 17 00:00:00 2001 From: xugro <82907135+xugro@users.noreply.github.com> Date: Thu, 15 Jun 2023 19:06:35 +0300 Subject: [PATCH 06/13] save to and check starboard database for threshold --- tle/cogs/starboard.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tle/cogs/starboard.py b/tle/cogs/starboard.py index 1d0fa923..002ac689 100644 --- a/tle/cogs/starboard.py +++ b/tle/cogs/starboard.py @@ -26,7 +26,7 @@ def __init__(self, bot): async def on_raw_reaction_add(self, payload): if str(payload.emoji) != _STAR or payload.guild_id is None: return - res = cf_common.user_db.get_starboard(payload.guild_id) + res = cf_common.user_db.get_starboard_channel(payload.guild_id) if res is None: return starboard_channel_id = int(res[0]) @@ -39,7 +39,7 @@ async def on_raw_reaction_add(self, payload): async def on_raw_message_delete(self, payload): if payload.guild_id is None: return - res = cf_common.user_db.get_starboard(payload.guild_id) + res = cf_common.user_db.get_starboard_channel(payload.guild_id) if res is None: return starboard_channel_id = int(res[0]) @@ -87,7 +87,8 @@ async def check_and_add_to_starboard(self, starboard_channel_id, payload): reaction_count = sum(reaction.count for reaction in message.reactions if str(reaction) == _STAR) - if reaction_count < constants.STARBOARD_THRESHOLD: + threshold = cf_common.user_db.get_starboard_threshold(payload.guild_id) + if reaction_count < threshold: return lock = self.locks.get(payload.guild_id) if lock is None: @@ -111,11 +112,11 @@ async def starboard(self, ctx): @commands.has_role(constants.TLE_ADMIN) async def here(self, ctx): """Set the current channel as starboard.""" - res = cf_common.user_db.get_starboard(ctx.guild.id) + res = cf_common.user_db.get_starboard_channel(ctx.guild.id) if res is not None: raise StarboardCogError('The starboard channel is already set. Use `clear` before ' 'attempting to set a different channel as starboard.') - cf_common.user_db.set_starboard(ctx.guild.id, ctx.channel.id) + cf_common.user_db.set_starboard(ctx.guild.id, ctx.channel.id, constants.STARBOARD_THRESHOLD) await ctx.send(embed=discord_common.embed_success('Starboard channel set')) @starboard.command(brief='Clear starboard settings') From faa3637526db5b5f6e577a93cf5cd2c0178d1492 Mon Sep 17 00:00:00 2001 From: xugro <82907135+xugro@users.noreply.github.com> Date: Thu, 15 Jun 2023 19:18:50 +0300 Subject: [PATCH 07/13] input threshold from user --- tle/cogs/starboard.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tle/cogs/starboard.py b/tle/cogs/starboard.py index 002ac689..917c3fb5 100644 --- a/tle/cogs/starboard.py +++ b/tle/cogs/starboard.py @@ -110,13 +110,17 @@ async def starboard(self, ctx): @starboard.command(brief='Set starboard to current channel') @commands.has_role(constants.TLE_ADMIN) - async def here(self, ctx): - """Set the current channel as starboard.""" + async def here(self, ctx, threshold: int = constants.STARBOARD_THRESHOLD): + """Set the current channel as starboard. + - Type ;starboard here to set threshold""" res = cf_common.user_db.get_starboard_channel(ctx.guild.id) if res is not None: raise StarboardCogError('The starboard channel is already set. Use `clear` before ' 'attempting to set a different channel as starboard.') - cf_common.user_db.set_starboard(ctx.guild.id, ctx.channel.id, constants.STARBOARD_THRESHOLD) + if( threshold < 1 ) + raise StarboardCogError('Star threshold cannot be lower than 1.') + + cf_common.user_db.set_starboard(ctx.guild.id, ctx.channel.id, threshold) await ctx.send(embed=discord_common.embed_success('Starboard channel set')) @starboard.command(brief='Clear starboard settings') From 79034e56860cbbf6b68e3785ba22a7f6a57dc130 Mon Sep 17 00:00:00 2001 From: xugro <82907135+xugro@users.noreply.github.com> Date: Thu, 15 Jun 2023 19:21:37 +0300 Subject: [PATCH 08/13] fix syntax error --- tle/cogs/starboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tle/cogs/starboard.py b/tle/cogs/starboard.py index 917c3fb5..1b0bb4ae 100644 --- a/tle/cogs/starboard.py +++ b/tle/cogs/starboard.py @@ -117,7 +117,7 @@ async def here(self, ctx, threshold: int = constants.STARBOARD_THRESHOLD): if res is not None: raise StarboardCogError('The starboard channel is already set. Use `clear` before ' 'attempting to set a different channel as starboard.') - if( threshold < 1 ) + if( threshold < 1 ): raise StarboardCogError('Star threshold cannot be lower than 1.') cf_common.user_db.set_starboard(ctx.guild.id, ctx.channel.id, threshold) From a6feaed3e47d5c42434fa4835dcb9877e79dfda5 Mon Sep 17 00:00:00 2001 From: xugro <82907135+xugro@users.noreply.github.com> Date: Thu, 15 Jun 2023 19:24:04 +0300 Subject: [PATCH 09/13] add value for column 3 --- tle/util/db/user_db_conn.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tle/util/db/user_db_conn.py b/tle/util/db/user_db_conn.py index db22a741..fa26356d 100644 --- a/tle/util/db/user_db_conn.py +++ b/tle/util/db/user_db_conn.py @@ -571,7 +571,6 @@ def get_starboard_threshold(self, guild_id): def set_starboard(self, guild_id, channel_id, star_threshold): query = ('INSERT OR REPLACE INTO starboard ' '(guild_id, channel_id, star_threshold) ' - 'VALUES (?, ?)') self.conn.execute(query, (guild_id, channel_id, star_threshold)) self.conn.commit() From 74d1105861b7be143a09cc2262e859625729c4be Mon Sep 17 00:00:00 2001 From: xugro <82907135+xugro@users.noreply.github.com> Date: Thu, 15 Jun 2023 19:26:30 +0300 Subject: [PATCH 10/13] accidentally removed line for some reason bruh --- tle/util/db/user_db_conn.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tle/util/db/user_db_conn.py b/tle/util/db/user_db_conn.py index fa26356d..7421dffb 100644 --- a/tle/util/db/user_db_conn.py +++ b/tle/util/db/user_db_conn.py @@ -571,6 +571,7 @@ def get_starboard_threshold(self, guild_id): def set_starboard(self, guild_id, channel_id, star_threshold): query = ('INSERT OR REPLACE INTO starboard ' '(guild_id, channel_id, star_threshold) ' + 'VALUES (?, ?, ?)') self.conn.execute(query, (guild_id, channel_id, star_threshold)) self.conn.commit() From 008f43e4866f2768c64e6d1ff7130f1eba65d9b6 Mon Sep 17 00:00:00 2001 From: xugro <82907135+xugro@users.noreply.github.com> Date: Thu, 15 Jun 2023 19:32:57 +0300 Subject: [PATCH 11/13] fix comparing between tuple and int --- tle/cogs/starboard.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tle/cogs/starboard.py b/tle/cogs/starboard.py index 1b0bb4ae..65f9d486 100644 --- a/tle/cogs/starboard.py +++ b/tle/cogs/starboard.py @@ -87,7 +87,10 @@ async def check_and_add_to_starboard(self, starboard_channel_id, payload): reaction_count = sum(reaction.count for reaction in message.reactions if str(reaction) == _STAR) - threshold = cf_common.user_db.get_starboard_threshold(payload.guild_id) + res = cf_common.user_db.get_starboard_threshold(payload.guild_id) + if res is None: + raise StarboardCogError('Star threshold not set.') + threshold = res[0] if reaction_count < threshold: return lock = self.locks.get(payload.guild_id) From 1197d63745eaa6577c6559719d1f5d402ad3ee70 Mon Sep 17 00:00:00 2001 From: xugro <82907135+xugro@users.noreply.github.com> Date: Sun, 23 Jul 2023 17:56:17 +0300 Subject: [PATCH 12/13] alter starboard table if database doesn't have star_threshold in starboard --- tle/util/db/user_db_conn.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tle/util/db/user_db_conn.py b/tle/util/db/user_db_conn.py index 7421dffb..c78e819c 100644 --- a/tle/util/db/user_db_conn.py +++ b/tle/util/db/user_db_conn.py @@ -181,6 +181,11 @@ def create_tables(self): 'star_threshold INTEGER NOT NULL' ')' ) + + columns = [i[1] for i in self.conn.execute('PRAGMA table_info(starboard)')] + if 'star_threshold' not in columns: + self.conn.execute('ALTER TABLE starboard ADD COLUMN star_threshold INTEGER NOT NULL') + self.conn.execute( 'CREATE TABLE IF NOT EXISTS starboard_message (' 'original_msg_id TEXT PRIMARY KEY,' From 81f141a57f9c09cda1159db02ad1fd746e707894 Mon Sep 17 00:00:00 2001 From: xugro <82907135+xugro@users.noreply.github.com> Date: Sun, 23 Jul 2023 18:06:40 +0300 Subject: [PATCH 13/13] Use default threshold instead of raising error when no threshold set --- tle/cogs/starboard.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tle/cogs/starboard.py b/tle/cogs/starboard.py index 65f9d486..b3eb548b 100644 --- a/tle/cogs/starboard.py +++ b/tle/cogs/starboard.py @@ -88,9 +88,9 @@ async def check_and_add_to_starboard(self, starboard_channel_id, payload): reaction_count = sum(reaction.count for reaction in message.reactions if str(reaction) == _STAR) res = cf_common.user_db.get_starboard_threshold(payload.guild_id) - if res is None: - raise StarboardCogError('Star threshold not set.') - threshold = res[0] + threshold = constants.STARBOARD_THRESHOLD + if res is not None: + threshold = res[0] if reaction_count < threshold: return lock = self.locks.get(payload.guild_id)