1
0
Fork 0

Switch purge to slash commands

This commit is contained in:
Ethanell 2021-02-03 23:06:45 +01:00
parent 7757847ecb
commit 06b978d800
2 changed files with 16 additions and 27 deletions

View file

@ -2,8 +2,10 @@ from asyncio import sleep
from discord.ext import commands from discord.ext import commands
from discord import Embed, RawReactionActionEvent from discord import Embed, RawReactionActionEvent
from discord_slash import SlashContext, cog_ext
from administrator.check import is_enabled from administrator import slash
from administrator.check import is_enabled, guild_only, has_permissions
from administrator.logger import logger from administrator.logger import logger
from administrator.utils import event_is_enabled from administrator.utils import event_is_enabled
@ -15,34 +17,23 @@ class Purge(commands.Cog):
def __init__(self, bot: commands.Bot): def __init__(self, bot: commands.Bot):
self.bot = bot self.bot = bot
self.purges = {} self.purges = {}
slash.get_cog_commands(self)
def description(self): def description(self):
return "Purge all messages between the command and the next add reaction" return "Purge all messages between the command and the next add reaction"
@commands.group("purge", pass_context=True) @cog_ext.cog_slash(name="purge", description="Purge all message delimited by the command to your next reaction")
@is_enabled() @is_enabled()
@commands.guild_only() @guild_only()
@commands.has_permissions(manage_messages=True) @has_permissions(manage_messages=True)
async def purge(self, ctx: commands.Context): async def purge(self, ctx: SlashContext):
if ctx.invoked_subcommand is None: message = await ctx.channel.send(content="\U0001f44d")
self.purges[ctx.message.author.id] = ctx.message self.purges[ctx.author.id] = message
await ctx.message.add_reaction("\U0001f44d")
await sleep(2*60) await sleep(2*60)
try: if ctx.author.id in self.purges and self.purges[ctx.author.id] == message:
if self.purges[ctx.message.author.id] == ctx.message: await message.delete()
await ctx.message.clear_reactions() del self.purges[ctx.author.id]
del self.purges[ctx.message.author.id]
except:
pass
@purge.group("help", pass_context=True)
@commands.guild_only()
async def purge_help(self, ctx: commands.Context):
embed = Embed(title="Purge help")
embed.add_field(name="purge", value="Purge all message delimited by the command to your next reaction",
inline=False)
await ctx.send(embed=embed)
@commands.Cog.listener() @commands.Cog.listener()
async def on_raw_reaction_add(self, payload: RawReactionActionEvent): async def on_raw_reaction_add(self, payload: RawReactionActionEvent):
@ -55,8 +46,7 @@ class Purge(commands.Cog):
if user.id in self.purges: if user.id in self.purges:
if message.channel == self.purges[user.id].channel: if message.channel == self.purges[user.id].channel:
async with message.channel.typing(): async with message.channel.typing():
await message.channel.purge(before=self.purges[user.id], after=message, await message.channel.purge(before=self.purges[user.id], after=message, limit=None)
limit=None)
await self.purges[user.id].delete() await self.purges[user.id].delete()
await message.delete() await message.delete()
del self.purges[user.id] del self.purges[user.id]

View file

@ -1,5 +1,4 @@
import re from datetime import datetime
from datetime import datetime, timedelta
from discord.ext import commands from discord.ext import commands
from discord import Embed from discord import Embed