feat(automation): add possibility to delete command output

This commit is contained in:
Romain J 2020-05-27 00:58:53 +02:00
commit 45d61fc71d
8 changed files with 136 additions and 102 deletions
utils/functions

View file

@ -1,9 +1,11 @@
import ast
import asyncio
import json
import os
import discord
from discord.ext import commands
from discord.ext import commands, flags
from configs.bot.protected import protected
from configs.bot.settings import prefix
@ -41,7 +43,47 @@ class ContextPlus(commands.Context):
ast.literal_eval(embed)
)
return await super().send(content, *args, **kwargs)
if self.command.deletable:
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',
timeout=120.0,
check=check
)
except asyncio.TimeoutError:
await message.remove_reaction('🗑', self.bot.user)
else:
await message.delete()
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)
async def get_prefix(bot, message):