feat(automation): add possibility to delete command output

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

View file

@ -3,4 +3,7 @@
<component name="DiscordProjectSettings">
<option name="show" value="true" />
</component>
<component name="ProjectNotificationSettings">
<option name="askShowProject" value="false" />
</component>
</project>

View file

@ -2,68 +2,13 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="6566fca1-2e90-48bb-9e74-dd3badbaca99" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.github/issue_template.md" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/LICENSE" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/README.md" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/bot.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/cogs/API.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/cogs/Admin.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/cogs/Help.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/discord.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/discord.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app.py" beforeDir="false" afterPath="$PROJECT_DIR$/app.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cogs/Images.py" beforeDir="false" afterPath="$PROJECT_DIR$/cogs/Images.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cogs/Logs.py" beforeDir="false" afterPath="$PROJECT_DIR$/cogs/Logs.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/cogs/Monitoring.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/cogs/Poll.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/cogs/Useful.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/cogs/User.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/configs/blacklist.cfg" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/configs/config.cfg.example" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/configs/fallbacks.cfg.example" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/configs/prefixes.cfg" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/database.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/generate_locales.sh" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/requirements.txt" beforeDir="false" afterPath="$PROJECT_DIR$/requirements.txt" afterDir="false" />
<change beforePath="$PROJECT_DIR$/todo" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/__init__.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/fonts/credit_card.ttf" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/functions/__init__.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/functions/config.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/functions/database.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/functions/emotes.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/functions/extra.py" beforeDir="false" afterPath="$PROJECT_DIR$/utils/functions/extra.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/utils/functions/lang.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/functions/paginator.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/functions/version.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/images/blank_credit_card.png" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/images/gnous.png" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/en/LC_MESSAGES/admin.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/en/LC_MESSAGES/admin_help.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/en/LC_MESSAGES/base.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/en/LC_MESSAGES/help.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/en/LC_MESSAGES/logs.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/en/LC_MESSAGES/poll.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/en/LC_MESSAGES/poll_help.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/en/LC_MESSAGES/useful.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/en/LC_MESSAGES/useful_help.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/en/LC_MESSAGES/user.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/en/LC_MESSAGES/user_help.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/en/LC_MESSAGES/utils.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/fr/LC_MESSAGES/admin.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/fr/LC_MESSAGES/admin_help.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/fr/LC_MESSAGES/base.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/fr/LC_MESSAGES/help.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/fr/LC_MESSAGES/logs.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/fr/LC_MESSAGES/logs_help.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/fr/LC_MESSAGES/poll.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/fr/LC_MESSAGES/poll_help.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/fr/LC_MESSAGES/useful.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/fr/LC_MESSAGES/useful_help.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/fr/LC_MESSAGES/user.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/fr/LC_MESSAGES/user_help.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/locales/fr/LC_MESSAGES/utils.po" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/models/__init__.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/models/alias.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/models/poll.py" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/utils/models/warn.py" beforeDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -93,14 +38,14 @@
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/configs/bot" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="node.js.detected.package.eslint" value="true" />
<property name="node.js.detected.package.tslint" value="true" />
<property name="node.js.path.for.package.eslint" value="project" />
<property name="node.js.path.for.package.tslint" value="project" />
<property name="node.js.selected.package.eslint" value="(autodetect)" />
<property name="node.js.selected.package.tslint" value="(autodetect)" />
<property name="settings.editor.selected.configurable" value="reference.settingsdialog.IDE.editor.colors" />
<property name="settings.editor.selected.configurable" value="preferences.keymap" />
</component>
<component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
@ -128,7 +73,14 @@
<workItem from="1590065919217" duration="8090000" />
<workItem from="1590152430112" duration="7500000" />
<workItem from="1590268542625" duration="3535000" />
<workItem from="1590273830049" duration="1288000" />
<workItem from="1590273830049" duration="3172000" />
<workItem from="1590337105277" duration="617000" />
<workItem from="1590352676311" duration="3854000" />
<workItem from="1590358535266" duration="6396000" />
<workItem from="1590434673007" duration="144000" />
<workItem from="1590438254185" duration="4301000" />
<workItem from="1590495843694" duration="35000" />
<workItem from="1590529983649" duration="3721000" />
</task>
<option name="localTasksCounter" value="2" />
<option name="createBranch" value="false" />
@ -151,18 +103,18 @@
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state x="2613" y="304" width="528" height="502" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/1920.0.1920.1080/0.29.1920.1051@1920.0.1920.1080" timestamp="1590160080814" />
<state x="2663" y="313" width="428" height="484" key="FileChooserDialogImpl" timestamp="1590152666732">
<state x="2663" y="313" width="428" height="484" key="FileChooserDialogImpl" timestamp="1590495877197">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state x="2663" y="313" width="428" height="484" key="FileChooserDialogImpl/1920.0.1920.1080/0.29.1920.1051@1920.0.1920.1080" timestamp="1590152666732" />
<state x="2663" y="313" width="428" height="484" key="FileChooserDialogImpl/1920.0.1920.1080/0.29.1920.1051@1920.0.1920.1080" timestamp="1590495877197" />
<state x="2666" y="239" width="421" height="633" key="RollbackChangesDialog" timestamp="1589983513390">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state x="2666" y="239" width="421" height="633" key="RollbackChangesDialog/1920.0.1920.1080/0.29.1920.1051@1920.0.1920.1080" timestamp="1589983513390" />
<state x="2669" y="310" key="SettingsEditor" timestamp="1589983575542">
<state x="2669" y="310" key="SettingsEditor" timestamp="1590440149207">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state x="2669" y="310" key="SettingsEditor/1920.0.1920.1080/0.29.1920.1051@1920.0.1920.1080" timestamp="1589983575542" />
<state x="2669" y="310" key="SettingsEditor/1920.0.1920.1080/0.29.1920.1051@1920.0.1920.1080" timestamp="1590440149207" />
<state x="2656" y="388" key="SimpleOpenTaskDialog" timestamp="1589983150588">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
@ -179,6 +131,10 @@
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state x="2440" y="156" width="873" height="799" key="com.intellij.openapi.editor.actions.MultiplePasteAction$ClipboardContentChooser/1920.0.1920.1080/0.29.1920.1051@1920.0.1920.1080" timestamp="1590155739870" />
<state x="2673" y="469" key="com.intellij.openapi.vcs.update.UpdateOrStatusOptionsDialogupdate-v2" timestamp="1590439153191">
<screen x="1920" y="0" width="1920" height="1080" />
</state>
<state x="2673" y="469" key="com.intellij.openapi.vcs.update.UpdateOrStatusOptionsDialogupdate-v2/1920.0.1920.1080/0.29.1920.1051@1920.0.1920.1080" timestamp="1590439153191" />
<state x="2584" y="164" width="592" height="783" key="find.popup" timestamp="1589983672115">
<screen x="1920" y="0" width="1920" height="1080" />
</state>

10
app.py
View file

@ -19,6 +19,7 @@ l_extensions: List[str] = [
"jishaku",
"cogs.Logs",
"cogs.Images",
"cogs.Useless",
]
@ -48,9 +49,9 @@ class TuxBot(commands.AutoShardedBot):
for extension in l_extensions:
try:
self.load_extension(extension)
print(f"{extension} loaded !")
print(extension, "loaded !")
except Exception as e:
print(f"{type(e).__name__}: {e}")
print(f"{type(e).__name__ }:", e)
print("\n"*2)
@ -69,9 +70,8 @@ class TuxBot(commands.AutoShardedBot):
print(f"\n{'='*118}\n\n")
@staticmethod
async def on_resumed():
print("resumed...")
async def on_resumed(self):
print(f"resumed... {self.uptime}")
async def get_context(self, message: discord.Message, *, cls=None):
return await super().get_context(message, cls=ContextPlus)

View file

@ -5,7 +5,7 @@ import discord
from discord.ext import commands, flags
from app import TuxBot
from utils.functions.extra import ContextPlus
from utils.functions.extra import ContextPlus, command_extra
log = logging.getLogger(__name__)
@ -28,11 +28,11 @@ class Images(commands.Cog, name="Images"):
data = BytesIO(await r.read())
await ctx.send(
file=discord.File(data, "output.png")
)
await ctx.send(
file=discord.File(data, "output.png")
)
@commands.command(name="phcomment")
@command_extra(name="phcomment")
@commands.cooldown(1, 5, commands.BucketType.user)
async def _phcomment(self, ctx: ContextPlus, user: discord.User = None, *, message: commands.clean_content(fix_channel_mentions=True, escape_markdown=True)):
async with ctx.typing():
@ -55,11 +55,11 @@ class Images(commands.Cog, name="Images"):
data = BytesIO(await r.read())
await ctx.send(
file=discord.File(data, "output.png")
)
await ctx.send(
file=discord.File(data, "output.png")
)
@commands.command(name="phvideo")
@command_extra(name="phvideo")
@commands.cooldown(1, 5, commands.BucketType.user)
async def _phvideo(self, ctx: ContextPlus, image: str, author: discord.User, *, title: commands.clean_content(fix_channel_mentions=True, escape_markdown=True)):
async with ctx.typing():
@ -74,14 +74,14 @@ class Images(commands.Cog, name="Images"):
data = BytesIO(await r.read())
await ctx.send(
file=discord.File(data, "output.png")
)
await ctx.send(
file=discord.File(data, "output.png")
)
@flags.add_flag("--text1", type=str)
@flags.add_flag("--text2", type=str)
@flags.add_flag("--text3", type=str)
@flags.command(name="balloon")
@command_extra(name="balloon")
@commands.cooldown(1, 5, commands.BucketType.user)
async def _balloon(self, ctx: ContextPlus, **passed_flags):
passed_flags["text3"] = passed_flags.get("text3")
@ -93,48 +93,48 @@ class Images(commands.Cog, name="Images"):
@flags.add_flag("--text1", type=str)
@flags.add_flag("--text2", type=str)
@flags.add_flag("--text3", type=str)
@flags.command(name="butterfly")
@command_extra(name="butterfly")
@commands.cooldown(1, 5, commands.BucketType.user)
async def _butterfly(self, ctx: ContextPlus, **passed_flags):
await self._send_meme(ctx, 'butterfly', **passed_flags)
@flags.add_flag("--text1", type=str)
@flags.add_flag("--text2", type=str)
@flags.command(name="buttons")
@command_extra(name="buttons")
@commands.cooldown(1, 5, commands.BucketType.user)
async def _buttons(self, ctx: ContextPlus, **passed_flags):
await self._send_meme(ctx, 'buttons', **passed_flags)
@flags.add_flag("--text1", type=str)
@flags.command(name="cmm")
@command_extra(name="cmm")
@commands.cooldown(1, 5, commands.BucketType.user)
async def _cmm(self, ctx: ContextPlus, **passed_flags):
await self._send_meme(ctx, 'change_my_mind', **passed_flags)
@flags.add_flag("--text1", type=str)
@flags.add_flag("--text2", type=str)
@flags.command(name="drake")
@command_extra(name="drake")
@commands.cooldown(1, 5, commands.BucketType.user)
async def _drake(self, ctx: ContextPlus, **passed_flags):
await self._send_meme(ctx, 'drake', **passed_flags)
@flags.add_flag("--text1", type=str)
@flags.add_flag("--text2", type=str, default=False)
@flags.command(name="fry")
@command_extra(name="fry")
@commands.cooldown(1, 5, commands.BucketType.user)
async def _fry(self, ctx: ContextPlus, **passed_flags):
await self._send_meme(ctx, 'fry', **passed_flags)
@flags.add_flag("--text1", type=str)
@flags.add_flag("--text2", type=str, default=False)
@flags.command(name="imagination")
@command_extra(name="imagination")
@commands.cooldown(1, 5, commands.BucketType.user)
async def _imagination(self, ctx: ContextPlus, **passed_flags):
await self._send_meme(ctx, 'imagination', **passed_flags)
@flags.add_flag("--text1", type=str)
@flags.add_flag("--text2", type=str, default=False)
@flags.command(name="everywhere")
@command_extra(name="everywhere")
@commands.cooldown(1, 5, commands.BucketType.user)
async def _everywhere(self, ctx: ContextPlus, **passed_flags):
await self._send_meme(ctx, 'everywhere', **passed_flags)
@ -142,13 +142,13 @@ class Images(commands.Cog, name="Images"):
@flags.add_flag("--text1", type=str)
@flags.add_flag("--text2", type=str)
@flags.add_flag("--text3", type=str)
@flags.command(name="choice")
@command_extra(name="choice")
@commands.cooldown(1, 5, commands.BucketType.user)
async def _choice(self, ctx: ContextPlus, **passed_flags):
await self._send_meme(ctx, 'choice', **passed_flags)
@flags.add_flag("--text1", type=str)
@flags.command(name="pika")
@command_extra(name="pika")
@commands.cooldown(1, 5, commands.BucketType.user)
async def _pika(self, ctx: ContextPlus, **passed_flags):
await self._send_meme(ctx, 'pika', **passed_flags)
@ -156,20 +156,20 @@ class Images(commands.Cog, name="Images"):
@flags.add_flag("--text1", type=str)
@flags.add_flag("--text2", type=str)
@flags.add_flag("--text3", type=str)
@flags.command(name="pkp")
@command_extra(name="pkp")
@commands.cooldown(1, 5, commands.BucketType.user)
async def _pkp(self, ctx: ContextPlus, **passed_flags):
await self._send_meme(ctx, 'pkp', **passed_flags)
@flags.add_flag("--text1", type=str)
@flags.add_flag("--text2", type=str)
@flags.command(name="puppet")
@command_extra(name="puppet")
@commands.cooldown(1, 5, commands.BucketType.user)
async def _puppet(self, ctx: ContextPlus, **passed_flags):
await self._send_meme(ctx, 'puppet', **passed_flags)
@flags.add_flag("--text1", type=str)
@flags.command(name="scroll_of_truth", alias=['sot'])
@command_extra(name="scroll_of_truth", alias=['sot'])
@commands.cooldown(1, 5, commands.BucketType.user)
async def _sot(self, ctx: ContextPlus, **passed_flags):
await self._send_meme(ctx, 'scroll_of_truth', **passed_flags)

View file

@ -19,6 +19,7 @@ import psutil
from discord.ext import commands, tasks
from app import TuxBot
from utils.functions.extra import command_extra
log = logging.getLogger(__name__)
@ -269,7 +270,7 @@ class Logs(commands.Cog):
msg = f'{emoji} `[{dt:%Y-%m-%d %H:%M:%S}] {record.message}`'
await self.logs.get('gateway').send(msg)
@commands.command('commandstats')
@command_extra(name='commandstats')
@commands.is_owner()
async def _commandstats(self, ctx, limit=20):
counter = self.bot.command_stats

33
cogs/Useless.py Normal file
View file

@ -0,0 +1,33 @@
import logging
from discord.ext import commands
from app import TuxBot
from utils.functions.extra import ContextPlus, command_extra
log = logging.getLogger(__name__)
class Useless(commands.Cog, name="Useless"):
def __init__(self, bot):
self.bot = bot
@command_extra(name="space")
@commands.cooldown(1, 5, commands.BucketType.user)
async def _space(self, ctx: ContextPlus):
await ctx.send("""
> ˚              *                      .              .                                         ,   
>
> .             .       .             .
>
>       ,       .                             :sunny:                                      .           .             .                                                              ,           :rocket:        ,                  .           .                                 ˚          ,                            .                .             .               *                                     .                  .       .       .     :new_moon:           .           .            
>
>  ˚                          .               .     :earth_americas: ,                * .                   .                     ˚                                    .              . .                     ˚                                    .              .                                         ,   
>
> .             .       .             .
""")
def setup(bot: TuxBot):
cog = Useless(bot)
bot.add_cog(cog)

View file

@ -3,7 +3,7 @@ aiohttp==3.6.2
aiosqlite==0.13.0
astunparse==1.6.3
async-timeout==3.0.1
asyncpg==0.20.1
# asyncpg==0.20.1
attrs==19.3.0
braceexpand==0.1.5
chardet==3.0.4
@ -20,8 +20,7 @@ Pillow==7.1.2
psutil==5.7.0
PyPika==0.37.6
six==1.14.0
sympy==1.5.1
tortoise-orm==0.16.11
# tortoise-orm==0.16.11
typing-extensions==3.7.4.2
websockets==8.1
yarl==1.4.2

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):