1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-12-17 23:24:20 +00:00

Add error handler to TelegramBot

This commit is contained in:
Steffo 2019-04-01 11:20:13 +02:00
parent 6e89c53835
commit 472da17a7d

View file

@ -24,11 +24,13 @@ class TelegramBot:
master_server_secret: str, master_server_secret: str,
commands: typing.List[typing.Type[Command]], commands: typing.List[typing.Type[Command]],
database_uri: str, database_uri: str,
missing_command: Command = NullCommand): missing_command: Command = NullCommand,
error_command: Command = NullCommand):
self.bot: telegram.Bot = telegram.Bot(api_key) self.bot: telegram.Bot = telegram.Bot(api_key)
self.should_run: bool = False self.should_run: bool = False
self.offset: int = -100 self.offset: int = -100
self.missing_command = missing_command self.missing_command = missing_command
self.error_command = error_command
self.network: RoyalnetLink = RoyalnetLink(master_server_uri, master_server_secret, "telegram", todo) self.network: RoyalnetLink = RoyalnetLink(master_server_uri, master_server_secret, "telegram", todo)
# Generate commands # Generate commands
self.commands = {} self.commands = {}
@ -90,7 +92,10 @@ class TelegramBot:
# Skip inexistent commands # Skip inexistent commands
command = self.missing_command command = self.missing_command
# Call the command # Call the command
return await self.Call(message.chat, command, *parameters, update=update).run() try:
return await self.Call(message.chat, command, *parameters, update=update).run()
except Exception as exc:
return await self.Call(message.chat, self.error_command, *parameters, update=update).run()
async def handle_net_request(self, message: Message): async def handle_net_request(self, message: Message):
pass pass