Fix [p]cleanup self not working in DMs for non-owners (#4481)

* Fix cleanup self not working in private.

This fix #4408.

* Apply Jack's logic.

* Obviously Black fault.
AGAIN!

* Apply Jack's trick.

* This is not a converter so let's move this to a different file

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
Predeactor 2020-10-18 02:07:08 +02:00 committed by GitHub
parent 152ca39719
commit 4453b5653a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -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)

View File

@ -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.chat_formatting import humanize_number
from redbot.core.utils.mod import slow_deletion, mass_purge from redbot.core.utils.mod import slow_deletion, mass_purge
from redbot.core.utils.predicates import MessagePredicate from redbot.core.utils.predicates import MessagePredicate
from .checks import check_self_permissions
from .converters import PositiveInt, RawMessageIds, positive_int from .converters import PositiveInt, RawMessageIds, positive_int
_ = Translator("Cleanup", __file__) _ = Translator("Cleanup", __file__)
@ -115,13 +116,13 @@ class Cleanup(commands.Cog):
return collected return collected
@commands.group() @commands.group()
@checks.mod_or_permissions(manage_messages=True)
async def cleanup(self, ctx: commands.Context): async def cleanup(self, ctx: commands.Context):
"""Delete messages.""" """Delete messages."""
pass pass
@cleanup.command() @cleanup.command()
@commands.guild_only() @commands.guild_only()
@checks.mod_or_permissions(manage_messages=True)
@commands.bot_has_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True)
async def text( async def text(
self, ctx: commands.Context, text: str, number: positive_int, delete_pinned: bool = False self, ctx: commands.Context, text: str, number: positive_int, delete_pinned: bool = False
@ -171,6 +172,7 @@ class Cleanup(commands.Cog):
@cleanup.command() @cleanup.command()
@commands.guild_only() @commands.guild_only()
@checks.mod_or_permissions(manage_messages=True)
@commands.bot_has_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True)
async def user( async def user(
self, ctx: commands.Context, user: str, number: positive_int, delete_pinned: bool = False self, ctx: commands.Context, user: str, number: positive_int, delete_pinned: bool = False
@ -234,6 +236,7 @@ class Cleanup(commands.Cog):
@cleanup.command() @cleanup.command()
@commands.guild_only() @commands.guild_only()
@checks.mod_or_permissions(manage_messages=True)
@commands.bot_has_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True)
async def after( async def after(
self, ctx: commands.Context, message_id: RawMessageIds, delete_pinned: bool = False self, ctx: commands.Context, message_id: RawMessageIds, delete_pinned: bool = False
@ -269,6 +272,7 @@ class Cleanup(commands.Cog):
@cleanup.command() @cleanup.command()
@commands.guild_only() @commands.guild_only()
@checks.mod_or_permissions(manage_messages=True)
@commands.bot_has_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True)
async def before( async def before(
self, self,
@ -309,6 +313,7 @@ class Cleanup(commands.Cog):
@cleanup.command() @cleanup.command()
@commands.guild_only() @commands.guild_only()
@checks.mod_or_permissions(manage_messages=True)
@commands.bot_has_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True)
async def between( async def between(
self, self,
@ -354,6 +359,7 @@ class Cleanup(commands.Cog):
@cleanup.command() @cleanup.command()
@commands.guild_only() @commands.guild_only()
@checks.mod_or_permissions(manage_messages=True)
@commands.bot_has_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True)
async def messages( async def messages(
self, ctx: commands.Context, number: positive_int, delete_pinned: bool = False self, ctx: commands.Context, number: positive_int, delete_pinned: bool = False
@ -386,6 +392,7 @@ class Cleanup(commands.Cog):
@cleanup.command(name="bot") @cleanup.command(name="bot")
@commands.guild_only() @commands.guild_only()
@checks.mod_or_permissions(manage_messages=True)
@commands.bot_has_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True)
async def cleanup_bot( async def cleanup_bot(
self, ctx: commands.Context, number: positive_int, delete_pinned: bool = False 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) await mass_purge(to_delete, channel)
@cleanup.command(name="self") @cleanup.command(name="self")
@check_self_permissions()
async def cleanup_self( async def cleanup_self(
self, self,
ctx: commands.Context, ctx: commands.Context,
@ -537,6 +545,7 @@ class Cleanup(commands.Cog):
@cleanup.command(name="spam") @cleanup.command(name="spam")
@commands.guild_only() @commands.guild_only()
@checks.mod_or_permissions(manage_messages=True)
@commands.bot_has_permissions(manage_messages=True) @commands.bot_has_permissions(manage_messages=True)
async def cleanup_spam(self, ctx: commands.Context, number: positive_int = PositiveInt(50)): 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. """Deletes duplicate messages in the channel from the last X messages and keeps only one copy.