From aabdabf3bc1d0545cc770aa5552acaea97f91280 Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Fri, 27 Dec 2019 23:33:22 +0100 Subject: [PATCH] [Core] Prevent users from locking out themselves or guild owner with localblacklist (#3221) * Update core_commands.py * Update core_commands.py * Create 3207.bugfix.rst * Update core_commands.py * Create 3221.bugfix.rst * Update redbot/core/core_commands.py Co-Authored-By: Michael H * Update bot.py * Rename 3221.bugfix.rst to 3221.bugfix.1.rst * Create 3221.bugfix.2.rst * Update bot.py Co-authored-by: Michael H --- changelog.d/3207.bugfix.rst | 1 + changelog.d/3221.bugfix.1.rst | 1 + changelog.d/3221.bugfix.2.rst | 1 + redbot/core/bot.py | 8 ++++++++ redbot/core/core_commands.py | 13 ++++++++++--- 5 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 changelog.d/3207.bugfix.rst create mode 100644 changelog.d/3221.bugfix.1.rst create mode 100644 changelog.d/3221.bugfix.2.rst diff --git a/changelog.d/3207.bugfix.rst b/changelog.d/3207.bugfix.rst new file mode 100644 index 000000000..951e90adc --- /dev/null +++ b/changelog.d/3207.bugfix.rst @@ -0,0 +1 @@ +Red will now prevent users from locking themselves out with localblacklist. diff --git a/changelog.d/3221.bugfix.1.rst b/changelog.d/3221.bugfix.1.rst new file mode 100644 index 000000000..73bad6df3 --- /dev/null +++ b/changelog.d/3221.bugfix.1.rst @@ -0,0 +1 @@ +Red will now prevent users from locking guild owner out with localblacklist (unless the command caller is bot owner). diff --git a/changelog.d/3221.bugfix.2.rst b/changelog.d/3221.bugfix.2.rst new file mode 100644 index 000000000..9f42f6550 --- /dev/null +++ b/changelog.d/3221.bugfix.2.rst @@ -0,0 +1 @@ +Guild owners are no longer affected by local whitelist and blacklist. diff --git a/redbot/core/bot.py b/redbot/core/bot.py index 18e57055d..858273a94 100644 --- a/redbot/core/bot.py +++ b/redbot/core/bot.py @@ -223,6 +223,11 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): # pylint: d ------ TypeError Did not provide ``who`` or ``who_id`` + + Returns + ------- + bool + `True` if user is allowed to run things, `False` otherwise """ # Contributor Note: # All config calls are delayed until needed in this section @@ -254,6 +259,9 @@ class RedBase(commands.GroupMixin, commands.bot.BotBase, RPCMixin): # pylint: d return False if guild: + if guild.owner_id == who.id: + return True + # The delayed expansion of ids to check saves time in the DM case. # Converting to a set reduces the total lookup time in section if mocked: diff --git a/redbot/core/core_commands.py b/redbot/core/core_commands.py index 2fe864c28..c634db6ec 100644 --- a/redbot/core/core_commands.py +++ b/redbot/core/core_commands.py @@ -1915,9 +1915,16 @@ class Core(commands.Cog, CoreLogic): user_or_role = discord.Object(id=user_or_role) user = True - if user and await ctx.bot.is_owner(user_or_role): - await ctx.send(_("You cannot blacklist an owner!")) - return + if user: + if user_or_role.id == ctx.author.id: + await ctx.send(_("You cannot blacklist yourself!")) + return + if user_or_role.id == ctx.guild.owner_id and not await ctx.bot.is_owner(ctx.author): + await ctx.send(_("You cannot blacklist the guild owner!")) + return + if await ctx.bot.is_owner(user_or_role): + await ctx.send(_("You cannot blacklist a bot owner!")) + return async with ctx.bot._config.guild(ctx.guild).blacklist() as curr_list: if user_or_role.id not in curr_list: