summaryrefslogtreecommitdiff
path: root/Commands.py
blob: e49d3331840cd5b3b08ff92ad0adaf09c664a2af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import telebot
from TelegramBot import *
from Formatter import *
from persistence import *
from FortniteClient import FortniteClient
from pythonFortniteStatus.FortniteStatus import *

class StartCommand(CommandHandler):

    __telegramBot: TelegramBot
    __userRepository: UserRepository

    def __init__(self, telegramBot: TelegramBot, userRepository: UserRepository):
        self.__telegramBot = telegramBot
        self.__userRepository = userRepository

    async def handle(self, message: telebot.types.Message):
        if message.chat.type == 'private':
            alias = message.chat.username
        else:
            alias = message.chat.title
        self.__userRepository.putUser(message.chat.id, alias)
        await self.__telegramBot.reply(message, 'This chat successfully registered to receive Fortnite updates')

class GetStatusCommand(CommandHandler):

    __telegramBot: TelegramBot
    __fortniteStatus: FortniteStatus

    def __init__(self, telegramBot: TelegramBot):
        self.__telegramBot = telegramBot
        self.__fortniteStatus = FortniteStatus()

    async def handle(self, message: telebot.types.Message):
        await self.__telegramBot.reply(message, formatFortniteStatus(self.__fortniteStatus.getStatus()))

class GetFriendsCommand(CommandHandler):

    __telegramBot: TelegramBot
    __fortniteClient: FortniteClient

    def __init__(self, telegramBot: TelegramBot, fortniteClient: FortniteClient):
        self.__telegramBot = telegramBot
        self.__fortniteClient = fortniteClient

    async def handle(self, message: telebot.types.Message):
        friends = await self.__fortniteClient.get_friends()
        await self.__telegramBot.reply(message, formatUsers(friends))


class GetStatsCommand(CommandHandler):

    __telegramBot: TelegramBot
    __fortniteClient: FortniteClient

    def __init__(self, telegramBot: TelegramBot, fortniteClient: FortniteClient):
        self.__telegramBot = telegramBot
        self.__fortniteClient = fortniteClient

    async def handle(self, message: telebot.types.Message):
        friends = await self.__fortniteClient.get_friends()
        stats = [await friend.fetch_stats() for friend in friends]
        await self.__telegramBot.reply(message, formatUserStatsList(stats))

class GetTodayStatsCommand(CommandHandler):

    __telegramBot: TelegramBot
    __fortniteClient: FortniteClient
    __statsRepository: StatsRepository

    def __init__(self, telegramBot: TelegramBot, fortniteClient: FortniteClient, statsRepository: StatsRepository):
        self.__telegramBot = telegramBot
        self.__fortniteClient = fortniteClient
        self.__statsRepository = statsRepository

    async def handle(self, message: telebot.types.Message):
        persisted_stats = self.__statsRepository.getStats()
        friends = await self.__fortniteClient.get_friends()
        current_stats = [await friend.fetch_stats() for friend in friends]
        await self.__telegramBot.reply(message, formatUserStatsDifference(persisted_stats, current_stats))

class RecordStatsCommand(CommandHandler):

    __fortniteClient: FortniteClient
    __statsRepository: StatsRepository

    def __init__(self, fortniteClient: FortniteClient, statsRepository: StatsRepository):
        self.__fortniteClient = fortniteClient
        self.__statsRepository = statsRepository

    async def handle(self, message: telebot.types.Message):
        friends = await self.__fortniteClient.get_friends()
        for friend in friends:
            await self.__statsRepository.putStats(friend)