aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Suhail <[email protected]>2019-03-14 22:19:53 +0000
committerGravatar Suhail <[email protected]>2019-03-14 22:19:53 +0000
commit92e7e111f686c7078e5c6a3720514379d69ce02a (patch)
tree83bb509e9675651a9f6b8b92642e82d507fa3e75
parentMerge pull request #138 from python-discord/docker-fix (diff)
Time Left
Adds the cog containing the command
-rw-r--r--bot/seasons/halloween/timeleft.py53
1 files changed, 53 insertions, 0 deletions
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")