handle disabled check with fetch_exists

This commit is contained in:
Infinidoge 2024-12-23 00:51:06 -05:00
parent ecf96b427b
commit 1cb36d41ae
Signed by: Infinidoge
SSH key fingerprint: SHA256:GT2StvPQMMfFHyiiFJymQxfTG/z6EWLJ6NWItf5K5sA
2 changed files with 8 additions and 5 deletions

View file

@ -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

View file

@ -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())