From fac4fec25f07380edd9266d6e0aa01220dee9403 Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Wed, 1 Jan 2025 12:21:43 -0500 Subject: [PATCH 1/3] stop triggering cascade delete when changing settings --- nomen/main.py | 4 ++-- nomen/settings.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/nomen/main.py b/nomen/main.py index ff2d25d..626131f 100644 --- a/nomen/main.py +++ b/nomen/main.py @@ -79,7 +79,7 @@ class Nomen(Bot): return prefix async def set_guild_prefix(self, guild: Guild, prefix): - await self.db.execute("REPLACE INTO guilds (guild_id, prefix) VALUES(?, ?)", (guild.id, prefix)) + await self.db.execute("UPDATE guilds SET prefix = ? WHERE guild_id=?", (prefix, guild.id)) self.prefixes[guild.id] = prefix async def start(self, *args, **kwargs): @@ -94,7 +94,7 @@ class Nomen(Bot): return await self.db.fetch_singleton(f"SELECT {setting} FROM users WHERE user_id=?", (user_id,)) async def set_setting(self, user_id, setting, value: bool): - await self.db.execute(f"REPLACE INTO users (user_id, {setting}) VALUES(?, ?)", (user_id, value)) + await self.db.execute(f"UPDATE users SET {setting} = ? WHERE user_id=?", (value, user_id)) await self.db.commit() diff --git a/nomen/settings.py b/nomen/settings.py index fbe1d3d..3caf544 100644 --- a/nomen/settings.py +++ b/nomen/settings.py @@ -158,7 +158,8 @@ You may want to `{ctx.clean_prefix}nomen export` first""" f"You have now opted-out and will no longer trigger or receive notifications. To opt back in, run `{ctx.clean_prefix}nomen opt-in`" ) - await self.bot.db.execute("REPLACE INTO users (user_id, disabled) VALUES(?, 1)", (ctx.author.id,)) + await self.bot.db.execute("INSERT OR IGNORE INTO users (user_id) VALUES(?)", (ctx.author.id,)) + await self.bot.db.execute("UPDATE users SET disabled=1 WHERE user_id=?", (ctx.author.id,)) await self.bot.db.commit() @nomen.command(name="opt-in") @@ -177,7 +178,8 @@ You may want to `{ctx.clean_prefix}nomen export` first""" f"You have opted back in and will now trigger and receive notifications. To opt out, run `{ctx.clean_prefix}nomen opt-out`" ) - await self.bot.db.execute("REPLACE INTO users (user_id, disabled) VALUES(?, 0)", (ctx.author.id,)) + await self.bot.db.execute("INSERT OR IGNORE INTO users (user_id) VALUES(?)", (ctx.author.id,)) + await self.bot.db.execute("UPDATE users SET disabled=0 WHERE user_id=?", (ctx.author.id,)) await self.bot.db.commit() @group(invoke_without_command=True) From 0093c92a7efa609be864726bc85cb9aec2b3b7f4 Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Wed, 1 Jan 2025 12:22:00 -0500 Subject: [PATCH 2/3] format and paginate return values in admin eval --- nomen/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nomen/main.py b/nomen/main.py index 626131f..03936b7 100644 --- a/nomen/main.py +++ b/nomen/main.py @@ -256,7 +256,7 @@ async def admin_eval(ctx, *, body: str): paginator.add_line(line) paginator.close_page() if ret: - for line in str(ret).split("\n"): + for line in pprint.pformat(ret).split("\n"): paginator.add_line(line) paginator.close_page() From 7f70c2afc86b41783c3fcb776eca9c90c349fff5 Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Wed, 1 Jan 2025 12:22:11 -0500 Subject: [PATCH 3/3] prevent triggering foreign key constraints in import --- nomen/settings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nomen/settings.py b/nomen/settings.py index 3caf544..16eb5e6 100644 --- a/nomen/settings.py +++ b/nomen/settings.py @@ -121,6 +121,8 @@ You may want to `{ctx.clean_prefix}nomen export` first""" } notifications = self.bot.get_cog("Notifications") + await ctx.bot.db.execute("INSERT OR IGNORE INTO users (user_id) VALUES(?)", (ctx.author.id,)) + await ctx.bot.db.commit() try: await self.import_json(ctx, data)