mirror of
https://github.com/neoarz/Syntrel.git
synced 2025-12-25 03:40:11 +01:00
feat(purge): make it able to purge specific user messages
This commit is contained in:
@@ -51,8 +51,8 @@ class Moderation(commands.GroupCog, name="moderation"):
|
|||||||
await self._invoke_hybrid(context, "kick", user=user, reason=reason)
|
await self._invoke_hybrid(context, "kick", user=user, reason=reason)
|
||||||
|
|
||||||
@moderation_group.command(name="purge")
|
@moderation_group.command(name="purge")
|
||||||
async def moderation_group_purge(self, context: Context, amount: int):
|
async def moderation_group_purge(self, context: Context, amount: int, user: discord.Member = None):
|
||||||
await self._invoke_hybrid(context, "purge", amount=amount)
|
await self._invoke_hybrid(context, "purge", amount=amount, user=user)
|
||||||
|
|
||||||
@moderation_group.command(name="warnings")
|
@moderation_group.command(name="warnings")
|
||||||
async def moderation_group_warnings(self, context: Context):
|
async def moderation_group_warnings(self, context: Context):
|
||||||
@@ -91,8 +91,8 @@ class Moderation(commands.GroupCog, name="moderation"):
|
|||||||
name="purge",
|
name="purge",
|
||||||
description="Delete a number of messages."
|
description="Delete a number of messages."
|
||||||
)
|
)
|
||||||
async def purge(self, context, amount: int):
|
async def purge(self, context, amount: int, user: discord.Member = None):
|
||||||
return await purge_command()(self, context, amount=amount)
|
return await purge_command()(self, context, amount=amount, user=user)
|
||||||
|
|
||||||
@commands.check(_require_group_prefix)
|
@commands.check(_require_group_prefix)
|
||||||
@commands.hybrid_command(
|
@commands.hybrid_command(
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ from discord import app_commands
|
|||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from discord.ext.commands import Context
|
from discord.ext.commands import Context
|
||||||
|
|
||||||
|
|
||||||
def purge_command():
|
def purge_command():
|
||||||
@commands.hybrid_command(
|
@commands.hybrid_command(
|
||||||
name="purge",
|
name="purge",
|
||||||
@@ -11,16 +10,38 @@ def purge_command():
|
|||||||
)
|
)
|
||||||
@commands.has_guild_permissions(manage_messages=True)
|
@commands.has_guild_permissions(manage_messages=True)
|
||||||
@commands.bot_has_permissions(manage_messages=True)
|
@commands.bot_has_permissions(manage_messages=True)
|
||||||
@app_commands.describe(amount="The amount of messages that should be deleted.")
|
@app_commands.describe(
|
||||||
async def purge(self, context, amount: int):
|
amount="The amount of messages that should be deleted.",
|
||||||
await context.send("Deleting messages...")
|
user="The user whose messages should be deleted (optional)."
|
||||||
purged_messages = await context.channel.purge(limit=amount + 1)
|
)
|
||||||
|
async def purge(self, context, amount: int, user: discord.Member = None):
|
||||||
|
if context.interaction:
|
||||||
|
await context.defer(ephemeral=True)
|
||||||
|
|
||||||
|
if user:
|
||||||
|
deleted_count = 0
|
||||||
|
|
||||||
|
def check(message):
|
||||||
|
nonlocal deleted_count
|
||||||
|
if message.author == user and deleted_count < amount:
|
||||||
|
deleted_count += 1
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
purged_messages = await context.channel.purge(limit=300, check=check)
|
||||||
|
else:
|
||||||
|
purged_messages = await context.channel.purge(limit=amount)
|
||||||
|
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
title="Purge",
|
title="Purge",
|
||||||
description=f"**{context.author}** cleared **{len(purged_messages)-1}** messages!",
|
description=f"**{context.author}** cleared **{len(purged_messages)}** messages!" + (f" from **{user}**" if user else ""),
|
||||||
color=0x7289DA,
|
color=0x7289DA,
|
||||||
)
|
)
|
||||||
embed.set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/CPKHQd.png")
|
embed.set_author(name="Moderation", icon_url="https://yes.nighty.works/raw/CPKHQd.png")
|
||||||
await context.channel.send(embed=embed)
|
|
||||||
|
if context.interaction:
|
||||||
|
await context.send(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await context.send(embed=embed, delete_after=10)
|
||||||
|
|
||||||
return purge
|
return purge
|
||||||
Reference in New Issue
Block a user