diff --git a/royalnet/bots/discord.py b/royalnet/bots/discord.py index 5b61d92c..fa948795 100644 --- a/royalnet/bots/discord.py +++ b/royalnet/bots/discord.py @@ -64,6 +64,9 @@ class DiscordBot(GenericBot): raise UnregisteredError("Author is not registered") return result + async def delete_invoking(data, error_if_unavailable=False): + await data.message.delete() + return DiscordData def _bot_factory(self) -> typing.Type[discord.Client]: diff --git a/royalnet/bots/telegram.py b/royalnet/bots/telegram.py index 76713fd6..893f539b 100644 --- a/royalnet/bots/telegram.py +++ b/royalnet/bots/telegram.py @@ -103,6 +103,10 @@ class TelegramBot(GenericBot): parse_mode="HTML", disable_web_page_preview=True) + async def delete_invoking(data, error_if_unavailable=False) -> None: + message: telegram.Message = data.update.message + await TelegramBot.safe_api_call(message.delete) + return TelegramData def __init__(self, *, diff --git a/royalnet/commands/commanddata.py b/royalnet/commands/commanddata.py index 99f15ce4..4520d79c 100644 --- a/royalnet/commands/commanddata.py +++ b/royalnet/commands/commanddata.py @@ -25,3 +25,13 @@ class CommandData: The function should be passed the :py:class:`CommandData` instance as a argument.""" raise NotImplementedError() + + async def delete_invoking(self, error_if_unavailable=False): + """Delete the invoking message, if supported by the interface. + + The invoking message is the message send by the user that contains the command. + + Parameters: + error_if_unavailable: if True, raise NotImplementedError() if the message cannot been deleted""" + if error_if_unavailable: + raise NotImplementedError() diff --git a/royalnet/commands/debug/debug_invoking.py b/royalnet/commands/debug/debug_invoking.py new file mode 100644 index 00000000..8b8fa94d --- /dev/null +++ b/royalnet/commands/debug/debug_invoking.py @@ -0,0 +1,14 @@ +import typing +from ..command import Command +from ..commandargs import CommandArgs +from ..commanddata import CommandData + + +class DebugKeyboardCommand(Command): + name: str = "debug_invoking" + + description: str = "Elimina il messaggio di invocazione." + + async def run(self, args: CommandArgs, data: CommandData) -> None: + await data.delete_invoking(error_if_unavailable=True) + await data.reply("🗑 Messaggio eliminato.")