From c1b5007d33e09349e9b26da8af448dae0054063c Mon Sep 17 00:00:00 2001 From: osmarks Date: Sun, 30 May 2021 20:11:01 +0100 Subject: [PATCH] miscellaneous fixes --- src/achievement.py | 3 ++- src/esoserver.py | 2 +- src/reminders.py | 3 +++ src/userdata.py | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/achievement.py b/src/achievement.py index 8fcb76c..9fc2c16 100644 --- a/src/achievement.py +++ b/src/achievement.py @@ -22,7 +22,8 @@ achievements = { } async def achieve(bot: commands.Bot, message: discord.Message, achievement): - guild_conf = await bot.database.execute_fetchone("SELECT achievement_messages FROM guild_config WHERE id = ?", (message.guild.id,)) + if message.guild: + guild_conf = await bot.database.execute_fetchone("SELECT achievement_messages FROM guild_config WHERE id = ?", (message.guild.id,)) if guild_conf and guild_conf["achievement_messages"] == 0: return channel = message.channel diff --git a/src/esoserver.py b/src/esoserver.py index 4bdbc60..789fac8 100644 --- a/src/esoserver.py +++ b/src/esoserver.py @@ -11,7 +11,7 @@ role_transfer_lock = asyncio.Lock() def setup(bot): @bot.listen() async def on_message(message): - if message.guild.id == util.config["esoserver"]["id"]: + if message.guild and message.guild.id == util.config["esoserver"]["id"]: async with role_transfer_lock: # prevent concurrency horrors - serialize accesses, probably for role in message.role_mentions: if role.id == util.config["esoserver"]["transfer_role"]: # transfer the role from sender to other pinged person diff --git a/src/reminders.py b/src/reminders.py index 84b6d9d..f083c6b 100644 --- a/src/reminders.py +++ b/src/reminders.py @@ -42,11 +42,14 @@ def setup(bot): async def send_by_dm(info, text): user = bot.get_user(info["author_id"]) + if not user: + user = await bot.fetch_user(info["author_id"]) if not user: raise Exception(f"user {info['author_id']} unavailable/nonexistent") if not user.dm_channel: await user.create_dm() await user.dm_channel.send(text) async def send_to_guild(info, text): + if not "guild_id" in info: raise Exception("Guild unknown") guild = bot.get_guild(info["guild_id"]) member = guild.get_member(info["author_id"]) self = guild.get_member(bot.user.id) diff --git a/src/userdata.py b/src/userdata.py index 63c01dc..96fd0ca 100644 --- a/src/userdata.py +++ b/src/userdata.py @@ -21,7 +21,7 @@ def setup(bot): @userdata.command(name="list", brief="List userdata keys in a given scope matching a query.") async def list_cmd(ctx, query="%", scope="guild", show_values: bool = False): - "Lsit userdata keys in a given scope (guild/global) matching your query (LIKE syntax). Can also show the associated values." + "List userdata keys in a given scope (guild/global) matching your query (LIKE syntax). Can also show the associated values." if scope == "global": rows = await bot.database.execute_fetchall("SELECT * FROM user_data WHERE user_id = ? AND guild_id = '_global' AND key LIKE ?", (ctx.author.id, query)) else: