From 8e05b9e711e71df92113046a90d19a2b235dfb6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Forr=C3=B3?= Date: Wed, 9 Sep 2020 13:37:44 +0200 Subject: [PATCH] Format reminders nicely --- bot.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/bot.py b/bot.py index be7091b..e78df4f 100644 --- a/bot.py +++ b/bot.py @@ -130,6 +130,17 @@ class Bot(discord.Client): for tweet in tweets: await channel.send(embed=self.make_twitter_embed(tweet)) + def format_remainder(self, seconds): + minutes = int(seconds / 60) + hours, minutes = divmod(minutes, 60) + days, hours = divmod(hours, 24) + result = ['{0} minute{1}'.format(minutes, 's' if minutes != 1 else '')] + if hours > 0: + result.append('{0} hour{1}'.format(hours, 's' if hours != 1 else '')) + if days > 0: + result.append('{0} day{1}'.format(days, 's' if days != 1 else '')) + return ', '.join(reversed(result)) + async def process_youtube_event(self, data): import json; print(json.dumps(data)) # FIXME: remove entry = data.get('feed', {}).get('entry', {}) @@ -163,7 +174,7 @@ class Bot(discord.Client): payload = data.copy() payload['feed']['entry']['reminder'] = '{0}m'.format(minutes) Timer.schedule(scheduled_start - datetime.timedelta(minutes=minutes), payload) - note = 'Live in {0} minutes!\n'.format(int(remaining / 60)) + note = 'Live in {0}!\n'.format(self.format_remainder(remaining)) await channel.send('@everyone {note}**{title}**\n{link}'.format(note=note, **video)) def make_youtube_embed(self, playlist):