mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Add error handler to TelegramBot
This commit is contained in:
parent
6e89c53835
commit
472da17a7d
1 changed files with 7 additions and 2 deletions
|
@ -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
|
||||||
|
try:
|
||||||
return await self.Call(message.chat, command, *parameters, update=update).run()
|
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
|
||||||
|
|
Loading…
Reference in a new issue