From 7b992afe70925f244ca6e9746071ae71e497b54e Mon Sep 17 00:00:00 2001 From: Dmitrii Morozov Date: Mon, 8 Apr 2024 23:40:24 +0200 Subject: Observe status of friends --- tgbot.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'tgbot.py') diff --git a/tgbot.py b/tgbot.py index 99d6351..72e7aa9 100755 --- a/tgbot.py +++ b/tgbot.py @@ -3,8 +3,10 @@ import os import time, threading, schedule import telebot -from fortniteStatusWrapper import * -from fortniteStatusFormatter import * +from FortniteStatusWrapper import * +from FortniteStatusFormatter import * +from FortniteClient import * +from FortniteEvents import * from persistence import UserRepository if "TELEBOT_BOT_TOKEN" not in os.environ: @@ -13,6 +15,7 @@ if "TELEBOT_BOT_TOKEN" not in os.environ: bot = telebot.TeleBot(os.environ["TELEBOT_BOT_TOKEN"]) userRepository = UserRepository('db.sqlite') fortniteStatusWrapper = FortniteStatusWrapper() +fortniteClient = FortniteClient() @bot.message_handler(commands = ['start']) def startCommand(message): @@ -28,9 +31,20 @@ class FortniteStatusObserver(Observer): parse_mode='MarkdownV2' ) +class FortnitePresenceObserver(PresenceObserver): + def update(self, display_name: str, playing: bool) -> None: + for user in userRepository.getAllUsers(): + bot.send_message( + user[0], + 'Fortnite observer {}, playing {}'.format(display_name, playing), + parse_mode='MarkdownV2' + ) + if __name__ == '__main__': fortniteStatusWrapper.attach(FortniteStatusObserver()) + fortniteClient.attach(FortnitePresenceObserver()) main_thread = threading.Thread(target=bot.infinity_polling, name='bot_infinity_polling', daemon=True) main_thread.start() - main_thread.join() \ No newline at end of file + #main_thread.join() + fortniteClient.run() \ No newline at end of file -- cgit v1.2.3