handle disabled check with fetch_exists
This commit is contained in:
parent
ecf96b427b
commit
1cb36d41ae
2 changed files with 8 additions and 5 deletions
|
@ -5,7 +5,7 @@ from textwrap import indent
|
||||||
from disnake import Embed
|
from disnake import Embed
|
||||||
from disnake.ext.commands import Cog, group, guild_only
|
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 = logging.getLogger("nomen.notifications")
|
||||||
log.setLevel(logging.DEBUG)
|
log.setLevel(logging.DEBUG)
|
||||||
|
@ -72,11 +72,9 @@ async def handle_triggers(ctx, message):
|
||||||
"is_bot": ctx.author.bot,
|
"is_bot": ctx.author.bot,
|
||||||
}
|
}
|
||||||
|
|
||||||
disabled = await ctx.bot.db.execute_fetchall(
|
disabled = await fetch_exists(ctx.bot.db, "SELECT * FROM users WHERE user_id=:author AND disabled IS 1", params)
|
||||||
"SELECT EXISTS(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")
|
log.debug(f"User {ctx.author} ({ctx.author.id}) opted out")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,11 @@ async def fetch_unpacked(db, sql, params=None):
|
||||||
return await cur.fetchall()
|
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):
|
async def in_thread(member, thread):
|
||||||
# FIXME: Currently overlooks the situation where a moderator isn't in a thread but has manage threads
|
# 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())
|
return any(member.id == thread_member.id for thread_member in await thread.fetch_members())
|
||||||
|
|
Loading…
Reference in a new issue