From ed0ad1bea6b80f34e64d1d1823f31f7d8c43e1fd Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Fri, 21 Feb 2025 16:09:49 -0500 Subject: [PATCH 1/5] change default prefix to >> --- nomen/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nomen/main.py b/nomen/main.py index 03936b7..2b8db78 100644 --- a/nomen/main.py +++ b/nomen/main.py @@ -36,7 +36,7 @@ else: TOKEN = os.getenv("TOKEN") DB_FILE = os.getenv("DB_FILE") or "nomen.sqlite3" -DEFAULT_PREFIX = os.getenv("DEFAULT_PREFIX") or ">" +DEFAULT_PREFIX = os.getenv("DEFAULT_PREFIX") or ">>" async def get_prefix(the_bot, message: Message): From 69ce9f23b7217e2370270b28c2dfb66305388542 Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Fri, 21 Feb 2025 16:10:03 -0500 Subject: [PATCH 2/5] properly insert and commit prefix changes --- nomen/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nomen/main.py b/nomen/main.py index 2b8db78..fe33fbf 100644 --- a/nomen/main.py +++ b/nomen/main.py @@ -79,7 +79,11 @@ class Nomen(Bot): return prefix async def set_guild_prefix(self, guild: Guild, prefix): - await self.db.execute("UPDATE guilds SET prefix = ? WHERE guild_id=?", (prefix, guild.id)) + await self.db.execute( + "INSERT INTO guilds VALUES(:guild_id, :prefix) ON CONFLICT(guild_id) DO UPDATE SET prefix = :prefix", + {"guild_id": guild.id, "prefix": prefix}, + ) + await self.db.commit() self.prefixes[guild.id] = prefix async def start(self, *args, **kwargs): From b7456dd759b4bdffe62e2a94e8085db879a84466 Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Fri, 21 Feb 2025 16:10:17 -0500 Subject: [PATCH 3/5] fix main notification query --- nomen/notifications.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/nomen/notifications.py b/nomen/notifications.py index 970f5ca..9d9bc89 100644 --- a/nomen/notifications.py +++ b/nomen/notifications.py @@ -132,6 +132,13 @@ async def handle_triggers(ctx, message): db_updates = [] search_query = """ + WITH + pauses AS (SELECT user_id FROM user_pauses WHERE guild_id=:guild), + ignores AS ( + SELECT target, user_id FROM user_ignores WHERE guild_id=:guild + UNION + SELECT target, user_id FROM user_blocks + ) SELECT keyword, user_id, use_embed FROM ( -- Deduplicate notification recipients by user_id SELECT keyword, user_id, use_embed, row_number() over (partition by user_id) n @@ -140,14 +147,11 @@ async def handle_triggers(ctx, message): WHERE likely(disabled IS NOT 1) -- Don't notify users who opted out AND (unlikely(notify_self IS 1) OR user_id IS NOT :author) -- Don't notify author unless wanted AND (unlikely(bots_notify IS 1) OR :is_bot IS NOT 1) -- Don't notify from bots unless wanted - AND likely(NOT EXISTS(SELECT * FROM ( -- Don't notify if... - SELECT target FROM user_ignores -- Author or channel is ignored in this guild - WHERE user_id=user_id AND guild_id=:guild - UNION - SELECT target FROM user_blocks -- Author is blocked - WHERE user_id=user_id - ) WHERE target IN (:author, :channel, :category, :parent))) - AND likely(NOT EXISTS(SELECT * FROM user_pauses WHERE user_id=user_id AND guild_id=:guild)) + AND likely(:author NOT IN (SELECT target FROM ignores WHERE user_id=user_id)) + AND likely(:channel NOT IN (SELECT target FROM ignores WHERE user_id=user_id)) + AND likely(:category NOT IN (SELECT target FROM ignores WHERE user_id=user_id)) + AND likely(:parent NOT IN (SELECT target FROM ignores WHERE user_id=user_id)) + AND likely(user_id NOT IN pauses) AND guild_id=:guild AND unlikely(contains(:content, keyword, regex)) ) WHERE n=1 From c5530c259bdd7f923c37b7c25d885726e1b266d0 Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Fri, 21 Feb 2025 16:10:33 -0500 Subject: [PATCH 4/5] add unpause alias for resume --- nomen/notifications.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nomen/notifications.py b/nomen/notifications.py index 9d9bc89..9cefc2b 100644 --- a/nomen/notifications.py +++ b/nomen/notifications.py @@ -360,7 +360,7 @@ class Notifications(Cog): await ctx.bot.db.commit() await ctx.send(f"Paused notifications in {ctx.guild}") - @keyword.command() + @keyword.command(aliases=["unpause"]) @guild_only() async def resume(self, ctx): """ From bf9afd97920d76d80282f63c2642ccc595e67f8c Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Fri, 21 Feb 2025 16:10:43 -0500 Subject: [PATCH 5/5] properly get guild id for resume --- nomen/notifications.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nomen/notifications.py b/nomen/notifications.py index 9cefc2b..eaeb8fb 100644 --- a/nomen/notifications.py +++ b/nomen/notifications.py @@ -367,7 +367,7 @@ class Notifications(Cog): Resume notifications in this guild """ - params = (ctx.author.id, ctx.guild_id) + params = (ctx.author.id, ctx.guild.id) if await ctx.bot.db.fetch_exists("SELECT * FROM user_pauses WHERE user_id=? AND guild_id=?", params): await ctx.bot.db.execute("DELETE FROM user_pauses WHERE user_id=? AND guild_id=?", params) await ctx.bot.db.commit()