2020-05-27 00:58:53 +02:00
|
|
|
import asyncio
|
2020-05-24 01:16:08 +02:00
|
|
|
|
|
|
|
import discord
|
2020-08-29 01:01:34 +02:00
|
|
|
from discord import Embed
|
2020-05-27 00:58:53 +02:00
|
|
|
from discord.ext import commands, flags
|
|
|
|
|
2020-09-02 00:08:06 +02:00
|
|
|
from rich.console import Console
|
2020-10-19 00:20:58 +02:00
|
|
|
|
2020-09-02 00:08:06 +02:00
|
|
|
console = Console()
|
|
|
|
|
2020-10-19 01:37:12 +02:00
|
|
|
TOKEN_REPLACEMENT = "whoops, leaked token"
|
2020-09-02 00:08:06 +02:00
|
|
|
|
2019-12-16 19:36:55 +01:00
|
|
|
|
2020-05-24 01:16:08 +02:00
|
|
|
class ContextPlus(commands.Context):
|
2020-10-20 23:52:05 +02:00
|
|
|
async def send(self, *args, content=None, **kwargs):
|
2020-08-29 01:01:34 +02:00
|
|
|
if content is not None:
|
2020-10-19 01:37:12 +02:00
|
|
|
content = content.replace(
|
|
|
|
self.bot.config.Core.token, TOKEN_REPLACEMENT
|
|
|
|
)
|
2020-10-19 00:20:58 +02:00
|
|
|
if kwargs.get("embed"):
|
2020-10-19 01:37:12 +02:00
|
|
|
embed = kwargs.get("embed").to_dict()
|
|
|
|
for key, value in embed.items():
|
|
|
|
if isinstance(value, (str, bytes)):
|
|
|
|
embed[key] = value.replace(
|
|
|
|
self.bot.config.Core.token, TOKEN_REPLACEMENT
|
|
|
|
)
|
|
|
|
kwargs["embed"] = Embed.from_dict(embed)
|
2020-08-29 01:01:34 +02:00
|
|
|
|
2020-06-06 18:51:47 +02:00
|
|
|
if (
|
|
|
|
hasattr(self.command, "deletable") and self.command.deletable
|
2020-09-02 00:08:06 +02:00
|
|
|
) or kwargs.pop("deletable", False):
|
2020-05-27 00:58:53 +02:00
|
|
|
message = await super().send(content, *args, **kwargs)
|
2020-06-06 18:51:47 +02:00
|
|
|
await message.add_reaction("🗑")
|
2020-05-27 00:58:53 +02:00
|
|
|
|
|
|
|
def check(reaction: discord.Reaction, user: discord.User):
|
2020-06-06 18:51:47 +02:00
|
|
|
return (
|
|
|
|
user == self.author
|
|
|
|
and str(reaction.emoji) == "🗑"
|
|
|
|
and reaction.message.id == message.id
|
|
|
|
)
|
2020-05-27 00:58:53 +02:00
|
|
|
|
|
|
|
try:
|
2020-09-02 00:08:06 +02:00
|
|
|
await self.bot.wait_for(
|
2020-10-19 00:20:58 +02:00
|
|
|
"reaction_add", timeout=42.0, check=check
|
2020-09-02 00:08:06 +02:00
|
|
|
)
|
2020-05-27 00:58:53 +02:00
|
|
|
except asyncio.TimeoutError:
|
2020-06-06 18:51:47 +02:00
|
|
|
await message.remove_reaction("🗑", self.bot.user)
|
2020-05-27 00:58:53 +02:00
|
|
|
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)
|