1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

Add delete invoking support

This commit is contained in:
Steffo 2019-09-26 15:11:34 +02:00
parent 5be821097d
commit 44703c9028
4 changed files with 31 additions and 0 deletions

View file

@ -64,6 +64,9 @@ class DiscordBot(GenericBot):
raise UnregisteredError("Author is not registered") raise UnregisteredError("Author is not registered")
return result return result
async def delete_invoking(data, error_if_unavailable=False):
await data.message.delete()
return DiscordData return DiscordData
def _bot_factory(self) -> typing.Type[discord.Client]: def _bot_factory(self) -> typing.Type[discord.Client]:

View file

@ -103,6 +103,10 @@ class TelegramBot(GenericBot):
parse_mode="HTML", parse_mode="HTML",
disable_web_page_preview=True) 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 return TelegramData
def __init__(self, *, def __init__(self, *,

View file

@ -25,3 +25,13 @@ class CommandData:
The function should be passed the :py:class:`CommandData` instance as a argument.""" The function should be passed the :py:class:`CommandData` instance as a argument."""
raise NotImplementedError() 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()

View file

@ -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.")