2020-05-27 00:58:53 +02:00
|
|
|
import asyncio
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
import discord
|
2020-05-27 00:58:53 +02:00
|
|
|
from discord.ext import commands, flags
|
|
|
|
|
2019-12-16 19:36:55 +01:00
|
|
|
|
2020-05-24 01:16:08 +02:00
|
|
|
class ContextPlus(commands.Context):
|
|
|
|
async def send(self, content=None, *args, **kwargs):
|
2020-05-31 22:49:04 +02:00
|
|
|
if (hasattr(self.command, 'deletable') and self.command.deletable) \
|
|
|
|
and kwargs.pop('deletable', True):
|
2020-05-27 00:58:53 +02:00
|
|
|
message = await super().send(content, *args, **kwargs)
|
|
|
|
await message.add_reaction('🗑')
|
|
|
|
|
|
|
|
def check(reaction: discord.Reaction, user: discord.User):
|
|
|
|
return user == self.author \
|
|
|
|
and str(reaction.emoji) == '🗑' \
|
|
|
|
and reaction.message.id == message.id
|
|
|
|
|
|
|
|
try:
|
|
|
|
await self.bot.wait_for(
|
|
|
|
'reaction_add',
|
2020-05-31 22:49:04 +02:00
|
|
|
timeout=60.0,
|
2020-05-27 00:58:53 +02:00
|
|
|
check=check
|
|
|
|
)
|
|
|
|
except asyncio.TimeoutError:
|
|
|
|
await message.remove_reaction('🗑', self.bot.user)
|
|
|
|
else:
|
|
|
|
await message.delete()
|
2020-05-31 22:49:04 +02:00
|
|
|
return message
|
2020-05-27 00:58:53 +02:00
|
|
|
else:
|
|
|
|
return await super().send(content, *args, **kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
class CommandPLus(flags.FlagCommand):
|
|
|
|
def __init__(self, function, **kwargs):
|
|
|
|
super().__init__(function, **kwargs)
|
|
|
|
self.deletable = kwargs.pop("deletable", True)
|
|
|
|
|
|
|
|
|
|
|
|
def command_extra(*args, **kwargs):
|
|
|
|
return commands.command(*args, **kwargs, cls=CommandPLus)
|
|
|
|
|
|
|
|
|
|
|
|
class GroupPlus(flags.FlagGroup):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.deletable = kwargs.pop("deletable", True)
|
|
|
|
|
|
|
|
|
|
|
|
def group_extra(*args, **kwargs):
|
|
|
|
return commands.group(*args, **kwargs, cls=GroupPlus)
|