summaryrefslogtreecommitdiff
path: root/telegram_bot
diff options
context:
space:
mode:
Diffstat (limited to 'telegram_bot')
-rw-r--r--telegram_bot/__init__.py2
-rw-r--r--telegram_bot/commands.py17
2 files changed, 12 insertions, 7 deletions
diff --git a/telegram_bot/__init__.py b/telegram_bot/__init__.py
index ebc8c47..c25af95 100644
--- a/telegram_bot/__init__.py
+++ b/telegram_bot/__init__.py
@@ -32,7 +32,7 @@ class TelegramBot:
await self.__bot.polling(
non_stop=True,
timeout=500
- )
+ )
def register_command_handler(self, command: str, command_handler: CommandHandler):
self.__bot.register_message_handler(
diff --git a/telegram_bot/commands.py b/telegram_bot/commands.py
index c5e02ed..e3f8efa 100644
--- a/telegram_bot/commands.py
+++ b/telegram_bot/commands.py
@@ -5,12 +5,17 @@ from formatter import *
from persistence import *
from fortnite_client import *
from fortnite_status import *
+from app_types import *
__stats_now__ = 'stats_now'
__stats_day__ = 'stats_day'
__stats_week__ = 'stats_week'
__stats_month__ = 'stats_month'
+__duration_day__ = Duration(1, 'day')
+__duration_week__ = Duration(7, 'week')
+__duration_month__ = Duration(30, 'month')
+
class StartCommand(CommandHandler):
__telegram_bot: TelegramBot
@@ -70,11 +75,11 @@ class GetStatsCallbackQueryHandler(CallbackQueryHandler):
if call.data == __stats_now__:
await self.reply_with_today_stats(call.message)
elif call.data == __stats_day__:
- await self.reply_with_stats_days_difference(call.message, 1, 'day')
+ await self.reply_with_stats_days_difference(call.message, __duration_day__)
elif call.data == __stats_week__:
- await self.reply_with_stats_days_difference(call.message, 7, 'week')
+ await self.reply_with_stats_days_difference(call.message, __duration_week__)
elif call.data == __stats_month__:
- await self.reply_with_stats_days_difference(call.message, 30, 'month')
+ await self.reply_with_stats_days_difference(call.message, __duration_month__)
await self.__telegram_bot.answer_callback_query(callback_query_id=call.id)
async def reply_with_today_stats(self, message):
@@ -82,13 +87,13 @@ class GetStatsCallbackQueryHandler(CallbackQueryHandler):
stats = [await friend.fetch_stats() for friend in friends]
await self.__telegram_bot.reply(message, format_user_stats_list(stats))
- async def reply_with_stats_days_difference(self, message, days: int, timeframe_alias: str):
- stats_datetime = datetime.datetime.now() - datetime.timedelta(days = days)
+ async def reply_with_stats_days_difference(self, message, duration: Duration):
+ stats_datetime = datetime.datetime.now() - datetime.timedelta(days = duration.duration_days)
persisted_stats = self.__stats_repository.get_stats(stats_datetime)
if len(persisted_stats) > 0:
friends = await self.__fortnite_client.get_friends()
current_stats = [await friend.fetch_stats() for friend in friends]
- await self.__telegram_bot.reply(message, format_user_stats_difference(persisted_stats, current_stats, timeframe_alias))
+ await self.__telegram_bot.reply(message, format_user_stats_difference(persisted_stats, current_stats, duration.description))
else:
await self.__telegram_bot.reply(message, 'No stats available yet for selected time period')