mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
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:
parent
152ca39719
commit
4453b5653a
15
redbot/cogs/cleanup/checks.py
Normal file
15
redbot/cogs/cleanup/checks.py
Normal 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)
|
||||
@ -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.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user