diff --git a/miyu_bot/commands/cogs/music.py b/miyu_bot/commands/cogs/music.py index 7aafc7e..c13638b 100644 --- a/miyu_bot/commands/cogs/music.py +++ b/miyu_bot/commands/cogs/music.py @@ -18,7 +18,7 @@ from miyu_bot.commands.common.asset_paths import get_chart_image_path, get_music from miyu_bot.commands.common.emoji import difficulty_emoji_ids from miyu_bot.commands.common.formatting import format_info from miyu_bot.commands.common.fuzzy_matching import romanize -from miyu_bot.commands.common.reaction_message import run_tabbed_message, run_paged_message +from miyu_bot.commands.common.reaction_message import run_tabbed_message, run_paged_message, run_deletable_message class Music(commands.Cog): @@ -91,7 +91,8 @@ class Music(commands.Cog): value=format_info(music_info), inline=False) - await ctx.send(embed=embed) + message = await ctx.send(embed=embed) + await run_deletable_message(ctx, message) @commands.command(name='chart', aliases=[], diff --git a/miyu_bot/commands/common/reaction_message.py b/miyu_bot/commands/common/reaction_message.py index c98c2b1..9ec98f4 100644 --- a/miyu_bot/commands/common/reaction_message.py +++ b/miyu_bot/commands/common/reaction_message.py @@ -113,8 +113,17 @@ async def run_paged_message(ctx: Context, base_embed: discord.Embed, content: Li await run_reaction_message(ctx, message, arrows, callback, timeout) +async def run_deletable_message(ctx: Context, message: Message, timeout=300): + await run_reaction_message(ctx, message, [], _noop, timeout=timeout) + + +async def _noop(n): + return None + + async def run_reaction_message(ctx: Context, message: Message, emojis: List[AnyEmoji], callback: Callable[[AnyEmoji], Awaitable[None]], timeout=300): + emojis.append('❎') for emoji in emojis: await message.add_reaction(emoji) @@ -124,6 +133,9 @@ async def run_reaction_message(ctx: Context, message: Message, emojis: List[AnyE while True: try: reaction, user = await ctx.bot.wait_for('reaction_add', timeout=timeout, check=check) + if reaction.emoji == '❎': + await message.delete() + return await callback(reaction.emoji) await message.remove_reaction(reaction, user) except asyncio.TimeoutError: