From db03faf0420d993553de06af31680871d94f8e14 Mon Sep 17 00:00:00 2001 From: Michael H Date: Thu, 20 Dec 2018 19:43:46 -0500 Subject: [PATCH] Make webhooks automod immune (#2337) Resolves #2336. --- redbot/core/bot.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/redbot/core/bot.py b/redbot/core/bot.py index d09a87a5a..a26fd90f2 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -186,13 +186,23 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): async def is_admin(self, member: discord.Member): """Checks if a member is an admin of their guild.""" admin_role = await self.db.guild(member.guild).admin_role() - return any(role.id == admin_role for role in member.roles) + try: + if any(role.id == admin_role for role in member.roles): + return True + except AttributeError: # someone passed a webhook to this + pass + return False async def is_mod(self, member: discord.Member): """Checks if a member is a mod or admin of their guild.""" mod_role = await self.db.guild(member.guild).mod_role() admin_role = await self.db.guild(member.guild).admin_role() - return any(role.id in (mod_role, admin_role) for role in member.roles) + try: + if any(role.id in (mod_role, admin_role) for role in member.roles): + return True + except AttributeError: # someone passed a webhook to this + pass + return False async def get_context(self, message, *, cls=commands.Context): return await super().get_context(message, cls=cls) @@ -334,8 +344,14 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): ids_to_check = [to_check.id] else: author = getattr(to_check, "author", to_check) - ids_to_check = [r.id for r in author.roles] - ids_to_check.append(author.id) + try: + ids_to_check = [r.id for r in author.roles] + except AttributeError: + # webhook messages are a user not member, + # cheaper than isinstance + return True # webhooks require significant permissions to enable. + else: + ids_to_check.append(author.id) immune_ids = await self.db.guild(guild).autoimmune_ids()