From 1cb36d41aebb7bb081578f4ae6cbb921a1296de8 Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Mon, 23 Dec 2024 00:51:06 -0500 Subject: [PATCH] handle disabled check with fetch_exists --- nomen/notifications.py | 8 +++----- nomen/utils.py | 5 +++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/nomen/notifications.py b/nomen/notifications.py index 74b7fd8..e046c76 100644 --- a/nomen/notifications.py +++ b/nomen/notifications.py @@ -5,7 +5,7 @@ from textwrap import indent from disnake import Embed from disnake.ext.commands import Cog, group, guild_only -from .utils import can_view, confirm, fetch_unpacked, test_keyword +from .utils import can_view, confirm, fetch_exists, fetch_unpacked, test_keyword log = logging.getLogger("nomen.notifications") log.setLevel(logging.DEBUG) @@ -72,11 +72,9 @@ async def handle_triggers(ctx, message): "is_bot": ctx.author.bot, } - disabled = await ctx.bot.db.execute_fetchall( - "SELECT EXISTS(SELECT * FROM users WHERE user_id=:author AND disabled IS 1)", params - ) + disabled = await fetch_exists(ctx.bot.db, "SELECT * FROM users WHERE user_id=:author AND disabled IS 1", params) - if disabled[0][0]: + if disabled: log.debug(f"User {ctx.author} ({ctx.author.id}) opted out") return diff --git a/nomen/utils.py b/nomen/utils.py index c042c1c..1dd643a 100644 --- a/nomen/utils.py +++ b/nomen/utils.py @@ -118,6 +118,11 @@ async def fetch_unpacked(db, sql, params=None): return await cur.fetchall() +async def fetch_exists(db, sql, params=None): + result = await db.execute_fetchall(f"SELECT EXISTS({sql})", params) + return result[0][0] + + async def in_thread(member, thread): # FIXME: Currently overlooks the situation where a moderator isn't in a thread but has manage threads return any(member.id == thread_member.id for thread_member in await thread.fetch_members())