From 3c4480c834460d0ff10c731c3b7c5094c2ba1350 Mon Sep 17 00:00:00 2001 From: ErrorNoInternet Date: Sun, 5 Jan 2025 19:24:19 -0500 Subject: [PATCH] feat: keep track of message responses for all commands --- core.py | 6 +----- utils.py | 25 +++++++++++++++++++------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/core.py b/core.py index 71f69d9..0831315 100644 --- a/core.py +++ b/core.py @@ -96,11 +96,7 @@ async def on_message(message, edited=False): elif len(output.strip()) == 0: await utils.add_check_reaction(message) else: - if message.id in executed_messages: - await executed_messages[message.id].edit(output) - else: - response = await message.channel.send(output) - executed_messages[message.id] = response + await utils.channel_send(message, output) case C.CLEAR | C.PURGE if message.author.id in constants.OWNERS: await commands.tools.clear(message) case C.JOIN: diff --git a/utils.py b/utils.py index b6bf069..8b109b3 100644 --- a/utils.py +++ b/utils.py @@ -1,6 +1,7 @@ import disnake import constants +from state import message_responses def format_duration(duration: int): @@ -34,15 +35,27 @@ async def add_check_reaction(message): async def reply(message, *args, **kwargs): - await message.reply( - *args, **kwargs, allowed_mentions=disnake.AllowedMentions.none() - ) + if message.id in message_responses: + await message_responses[message.id].edit( + *args, **kwargs, allowed_mentions=disnake.AllowedMentions.none() + ) + else: + response = await message.reply( + *args, **kwargs, allowed_mentions=disnake.AllowedMentions.none() + ) + message_responses[message.id] = response async def channel_send(message, *args, **kwargs): - await message.channel.send( - *args, **kwargs, allowed_mentions=disnake.AllowedMentions.none() - ) + if message.id in message_responses: + await message_responses[message.id].edit( + *args, **kwargs, allowed_mentions=disnake.AllowedMentions.none() + ) + else: + response = await message.channel.send( + *args, **kwargs, allowed_mentions=disnake.AllowedMentions.none() + ) + message_responses[message.id] = response async def invalid_user_handler(interaction):