From 92e7e111f686c7078e5c6a3720514379d69ce02a Mon Sep 17 00:00:00 2001 From: Suhail Date: Thu, 14 Mar 2019 22:19:53 +0000 Subject: Time Left Adds the cog containing the command --- bot/seasons/halloween/timeleft.py | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 bot/seasons/halloween/timeleft.py (limited to 'bot') diff --git a/bot/seasons/halloween/timeleft.py b/bot/seasons/halloween/timeleft.py new file mode 100644 index 00000000..b28f94f0 --- /dev/null +++ b/bot/seasons/halloween/timeleft.py @@ -0,0 +1,53 @@ +import datetime +import logging + +from discord.ext import commands + +log = logging.getLogger(__name__) + + +class TimeLeft: + """ + A Cog that tells you how long left until Hacktober is over! + """ + + def __init__(self, bot): + self.bot = bot + + @staticmethod + def in_october(): + return datetime.datetime.now().month == 10 + + @staticmethod + def load_date(): + now = datetime.datetime.now() + year = now.year + if now.month > 10: + year += 1 + end = datetime.datetime(year, 10, 31, 11, 59, 59) + return now, end + + @commands.command() + async def timeleft(self, ctx): + """ + Calculates the time left until the end of Hacktober + + Whilst in October, displays the days, hours and minutes left. + Only displays the days left whilst in a different month + """ + + now, end = self.load_date() + diff = end - now + days, seconds = diff.days, diff.seconds + if self.in_october(): + minutes = seconds // 60 + hours, minutes = divmod(minutes, 60) + await ctx.send(f"There is currently only {days} days, {hours} hours and {minutes}" + "minutes left until the end of Hacktober.") + else: + await ctx.send(f"It is not currently Hacktober. However, the next one will finish in {days} days.") + + +def setup(bot): + bot.add_cog(TimeLeft(bot)) + log.info("TimeLeft cog loaded") -- cgit v1.2.3 From f932dbc886ed2e6437baaca7c8cae0379249751f Mon Sep 17 00:00:00 2001 From: Suhail Date: Sun, 24 Mar 2019 13:40:39 +0000 Subject: Time Left - Requested Changes --- bot/seasons/halloween/timeleft.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'bot') diff --git a/bot/seasons/halloween/timeleft.py b/bot/seasons/halloween/timeleft.py index b28f94f0..b920560e 100644 --- a/bot/seasons/halloween/timeleft.py +++ b/bot/seasons/halloween/timeleft.py @@ -1,4 +1,4 @@ -import datetime +from datetime import datetime import logging from discord.ext import commands @@ -16,16 +16,23 @@ class TimeLeft: @staticmethod def in_october(): - return datetime.datetime.now().month == 10 + """ + checks that the current month is October + """ + return datetime.now().month == 10 @staticmethod def load_date(): - now = datetime.datetime.now() + """ + Grabs the current time in additon to the first and last day of the following October + """ + now = datetime.now() year = now.year if now.month > 10: year += 1 - end = datetime.datetime(year, 10, 31, 11, 59, 59) - return now, end + end = datetime(year, 10, 31, 11, 59, 59) + start = datetime(year, 10, 1) + return now, end, start @commands.command() async def timeleft(self, ctx): @@ -33,10 +40,10 @@ class TimeLeft: Calculates the time left until the end of Hacktober Whilst in October, displays the days, hours and minutes left. - Only displays the days left whilst in a different month + Only displays the days left until the beginning and end whilst in a different month """ - now, end = self.load_date() + now, end, start = self.load_date() diff = end - now days, seconds = diff.days, diff.seconds if self.in_october(): @@ -45,7 +52,12 @@ class TimeLeft: await ctx.send(f"There is currently only {days} days, {hours} hours and {minutes}" "minutes left until the end of Hacktober.") else: - await ctx.send(f"It is not currently Hacktober. However, the next one will finish in {days} days.") + start_diff = start - now + start_days = start_diff.days + await ctx.send( + f"It is not currently Hacktober. However, the next one will start in {start_days} days " + f"and will finish in {days} days." + ) def setup(bot): -- cgit v1.2.3 From acc43a7a41848db265e25ff517363e7e21ab2b8a Mon Sep 17 00:00:00 2001 From: Suhail Date: Sun, 24 Mar 2019 13:41:58 +0000 Subject: Time Left - Fixed import order --- bot/seasons/halloween/timeleft.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/halloween/timeleft.py b/bot/seasons/halloween/timeleft.py index b920560e..cfb7ec79 100644 --- a/bot/seasons/halloween/timeleft.py +++ b/bot/seasons/halloween/timeleft.py @@ -1,5 +1,5 @@ -from datetime import datetime import logging +from datetime import datetime from discord.ext import commands -- cgit v1.2.3 From caa0d7673ae2212e0794b3a7349dde2ad58acbfc Mon Sep 17 00:00:00 2001 From: Ava Date: Mon, 25 Mar 2019 14:44:13 +0000 Subject: Time left - requested change Co-Authored-By: Suhail6inkling <38522108+Suhail6inkling@users.noreply.github.com> --- bot/seasons/halloween/timeleft.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/halloween/timeleft.py b/bot/seasons/halloween/timeleft.py index cfb7ec79..2fc0fb76 100644 --- a/bot/seasons/halloween/timeleft.py +++ b/bot/seasons/halloween/timeleft.py @@ -19,7 +19,7 @@ class TimeLeft: """ checks that the current month is October """ - return datetime.now().month == 10 + return datetime.utcnow().month == 10 @staticmethod def load_date(): -- cgit v1.2.3 From 2c4b92f0886062100b9989b85c881bfc4aea7ece Mon Sep 17 00:00:00 2001 From: Suhail Date: Mon, 25 Mar 2019 14:46:13 +0000 Subject: Time Left - Changed `datetime.now()` to `datetime.utcnow()` And previous change also did that --- bot/seasons/halloween/timeleft.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'bot') diff --git a/bot/seasons/halloween/timeleft.py b/bot/seasons/halloween/timeleft.py index 2fc0fb76..9488f660 100644 --- a/bot/seasons/halloween/timeleft.py +++ b/bot/seasons/halloween/timeleft.py @@ -26,7 +26,7 @@ class TimeLeft: """ Grabs the current time in additon to the first and last day of the following October """ - now = datetime.now() + now = datetime.utcnow() year = now.year if now.month > 10: year += 1 -- cgit v1.2.3 From 870fe69a85b7478b0425927e61d2db1bf3abcc35 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 26 Mar 2019 09:45:56 +0000 Subject: Apply suggestions from code review Co-Authored-By: Suhail6inkling <38522108+Suhail6inkling@users.noreply.github.com> --- bot/seasons/halloween/timeleft.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'bot') diff --git a/bot/seasons/halloween/timeleft.py b/bot/seasons/halloween/timeleft.py index 9488f660..af205573 100644 --- a/bot/seasons/halloween/timeleft.py +++ b/bot/seasons/halloween/timeleft.py @@ -17,15 +17,17 @@ class TimeLeft: @staticmethod def in_october(): """ - checks that the current month is October + Return True if the current month is October. """ + return datetime.utcnow().month == 10 @staticmethod def load_date(): """ - Grabs the current time in additon to the first and last day of the following October + Return of a tuple of the current time and the end and start times of the following October. """ + now = datetime.utcnow() year = now.year if now.month > 10: @@ -37,7 +39,7 @@ class TimeLeft: @commands.command() async def timeleft(self, ctx): """ - Calculates the time left until the end of Hacktober + Calculates the time left until the end of Hacktober. Whilst in October, displays the days, hours and minutes left. Only displays the days left until the beginning and end whilst in a different month -- cgit v1.2.3