diff options
author | Dmitrii Morozov <snoopdesigns@gmail.com> | 2024-04-12 13:56:20 +0200 |
---|---|---|
committer | Dmitrii Morozov <snoopdesigns@gmail.com> | 2024-04-12 13:56:20 +0200 |
commit | 45c6a88acee5507215c51cc3529acb285790ebfd (patch) | |
tree | b88db999bd99c6b5bcd4335b6db186d235bde6ca /tgbot.py | |
parent | 9c8fcc8a636ed8c1fa6734e4f5ad6ca346830939 (diff) |
Formatting of online message + exception handler for telebot
Diffstat (limited to 'tgbot.py')
-rwxr-xr-x | tgbot.py | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -1,6 +1,6 @@ #!/usr/bin/python3 -import os, time, telebot, asyncio, telebot.async_telebot, nest_asyncio +import os, time, telebot, asyncio, telebot.async_telebot, nest_asyncio, sys, logging from FortniteStatusNotifier import * from Formatter import * from FortniteClient import * @@ -34,7 +34,15 @@ class FortnitePresenceObserver(PresenceObserver): async def __notifyFriendPlaying(self, display_name: str, party_size: int): await send_message_to_all(formatFriendOnline(display_name, party_size)) -bot = telebot.async_telebot.AsyncTeleBot(os.environ["TELEBOT_BOT_TOKEN"]) +class ExceptionHandler(telebot.ExceptionHandler): + def handle(self, exception): + logging.error('Exception happened: {}'.format(str(exception))) + sys.exit('Exiting with telebot exception') + return True + +bot = telebot.async_telebot.AsyncTeleBot( + token=os.environ["TELEBOT_BOT_TOKEN"], + exception_handler=ExceptionHandler()) userRepository = UserRepository('db.sqlite') fortniteStatusWrapper = FortniteStatusNotifier(FortniteStatusObserver()) fortniteClient = FortniteClient(FortnitePresenceObserver()) |