diff --git a/redbot/cogs/cleanup/checks.py b/redbot/cogs/cleanup/checks.py new file mode 100644 index 000000000..325f564c0 --- /dev/null +++ b/redbot/cogs/cleanup/checks.py @@ -0,0 +1,15 @@ +from redbot.core.commands import Context, permissions_check +from redbot.core.utils.mod import is_mod_or_superior, check_permissions + + +def check_self_permissions(): + async def predicate(ctx: Context): + if not ctx.guild: + return True + if await check_permissions(ctx, {"manage_messages": True}) or await is_mod_or_superior( + ctx.bot, ctx.author + ): + return True + return False + + return permissions_check(predicate) diff --git a/redbot/cogs/cleanup/cleanup.py b/redbot/cogs/cleanup/cleanup.py index 3703b5105..b33d43566 100644 --- a/redbot/cogs/cleanup/cleanup.py +++ b/redbot/cogs/cleanup/cleanup.py @@ -10,6 +10,7 @@ from redbot.core.i18n import Translator, cog_i18n from redbot.core.utils.chat_formatting import humanize_number from redbot.core.utils.mod import slow_deletion, mass_purge from redbot.core.utils.predicates import MessagePredicate +from .checks import check_self_permissions from .converters import PositiveInt, RawMessageIds, positive_int _ = Translator("Cleanup", __file__) @@ -115,13 +116,13 @@ class Cleanup(commands.Cog): return collected @commands.group() - @checks.mod_or_permissions(manage_messages=True) async def cleanup(self, ctx: commands.Context): """Delete messages.""" pass @cleanup.command() @commands.guild_only() + @checks.mod_or_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True) async def text( self, ctx: commands.Context, text: str, number: positive_int, delete_pinned: bool = False @@ -171,6 +172,7 @@ class Cleanup(commands.Cog): @cleanup.command() @commands.guild_only() + @checks.mod_or_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True) async def user( self, ctx: commands.Context, user: str, number: positive_int, delete_pinned: bool = False @@ -234,6 +236,7 @@ class Cleanup(commands.Cog): @cleanup.command() @commands.guild_only() + @checks.mod_or_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True) async def after( self, ctx: commands.Context, message_id: RawMessageIds, delete_pinned: bool = False @@ -269,6 +272,7 @@ class Cleanup(commands.Cog): @cleanup.command() @commands.guild_only() + @checks.mod_or_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True) async def before( self, @@ -309,6 +313,7 @@ class Cleanup(commands.Cog): @cleanup.command() @commands.guild_only() + @checks.mod_or_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True) async def between( self, @@ -354,6 +359,7 @@ class Cleanup(commands.Cog): @cleanup.command() @commands.guild_only() + @checks.mod_or_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True) async def messages( self, ctx: commands.Context, number: positive_int, delete_pinned: bool = False @@ -386,6 +392,7 @@ class Cleanup(commands.Cog): @cleanup.command(name="bot") @commands.guild_only() + @checks.mod_or_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True) async def cleanup_bot( self, ctx: commands.Context, number: positive_int, delete_pinned: bool = False @@ -462,6 +469,7 @@ class Cleanup(commands.Cog): await mass_purge(to_delete, channel) @cleanup.command(name="self") + @check_self_permissions() async def cleanup_self( self, ctx: commands.Context, @@ -537,6 +545,7 @@ class Cleanup(commands.Cog): @cleanup.command(name="spam") @commands.guild_only() + @checks.mod_or_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True) async def cleanup_spam(self, ctx: commands.Context, number: positive_int = PositiveInt(50)): """Deletes duplicate messages in the channel from the last X messages and keeps only one copy.