From 8b7be6b88686a8be248ea25259e93cbbf64c900e Mon Sep 17 00:00:00 2001 From: RGBCube Date: Sat, 17 Dec 2022 15:07:45 +0300 Subject: [PATCH] Add check for permissions and make it case insensitive --- minearchy_bot/cogs/misc.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/minearchy_bot/cogs/misc.py b/minearchy_bot/cogs/misc.py index 450a83e..8b60b6a 100644 --- a/minearchy_bot/cogs/misc.py +++ b/minearchy_bot/cogs/misc.py @@ -69,17 +69,23 @@ class Miscellaneous( async def on_message(self, message: Message) -> None: name = message.author.display_name - if not name.startswith("[AFK]"): + if not name.lower().startswith("[AFK]"): return - await message.author.edit(nick=name.removeprefix("[AFK]")) - await message.channel.send(f"Welcome back {escape_markdown(message.author.mention)}! I've unset your AFK status.") + await message.author.edit(nick=name[5:]) + await message.channel.send( + f"Welcome back {escape_markdown(message.author.mention)}! I've unset your AFK status.") @command( brief="Sets you as AFK.", help="Sets you as AFK.", ) async def afk(self, ctx: Context) -> None: + if ctx.me.top_role.position <= ctx.author.top_role.position: + await ctx.reply( + "I cannot set you as AFK because my role is lower than yours. You can edit your nickname to set yourself as AFK (Add [AFK] to the start of it.).") + return + await ctx.author.edit(nick=f"[AFK] {ctx.author.display_name}") await ctx.reply("Set your status to AFK. You can now touch grass freely 🌲.")