From c27c0b8a488a8676de3b3a94fab514c7517ec764 Mon Sep 17 00:00:00 2001 From: 0x5c Date: Sat, 3 Apr 2021 17:54:38 -0400 Subject: [PATCH] Added ?miltime command Fixes #377 --- exts/time.py | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/exts/time.py b/exts/time.py index 4310ca7..2e4f265 100644 --- a/exts/time.py +++ b/exts/time.py @@ -8,7 +8,7 @@ the GNU General Public License, version 2. """ -from datetime import datetime +from datetime import datetime, timedelta import discord.ext.commands as commands @@ -16,6 +16,34 @@ import common as cmn class TimeCog(commands.Cog): + offsets = [ + ("Y", "", timedelta(hours=-12)), + ("X", "", timedelta(hours=-11)), + ("W", "", timedelta(hours=-10)), + ("V", "", timedelta(hours=-9)), + ("U", "", timedelta(hours=-8)), + ("T", "", timedelta(hours=-7)), + ("S", "", timedelta(hours=-6)), + ("R", "", timedelta(hours=-5)), + ("Q", "", timedelta(hours=-4)), + ("P", "", timedelta(hours=-3)), + ("O", "", timedelta(hours=-2)), + ("N", "", timedelta(hours=-1)), + ("Z", "UTC", timedelta(hours=0)), + ("A", "", timedelta(hours=+1)), + ("B", "", timedelta(hours=+2)), + ("C", "", timedelta(hours=+3)), + ("D", "", timedelta(hours=+4)), + ("E", "", timedelta(hours=+5)), + ("F", "", timedelta(hours=+6)), + ("G", "", timedelta(hours=+7)), + ("H", "", timedelta(hours=+8)), + ("I", "", timedelta(hours=+9)), + ("K", "", timedelta(hours=+10)), + ("L", "", timedelta(hours=+11)), + ("M", "", timedelta(hours=+12)) + ] + def __init__(self, bot): self.bot = bot @@ -30,6 +58,23 @@ class TimeCog(commands.Cog): embed.colour = cmn.colours.good await ctx.send(embed=embed) + @commands.command(name="miltime", category=cmn.Cats.TIME) + async def miltime(self, ctx: commands.Context): + """Prints the current time in all 25 military time zones.""" + time = ctx.message.created_at + embed = cmn.embed_factory(ctx) + embed.title = f"{cmn.emojis.clock} Military Time Zones Now" + embed.colour = cmn.colours.good + embed.description = "```" + embed.description += "\n".join([f"{x}: {time + z :%Y-%m-%d %H:%M} {y}" for x, y, z in self.offsets]) + embed.description += "```" + embed.add_field(name="Notes", value=( + "**J** is not present in the table, and is used for local time.\n" + "The zones are referenced by their letters, using phonetics.\n" + f"You can check the NATO phonetics for a letter using the `{ctx.prefix}phonetics` command." + )) + await ctx.send(embed=embed) + def setup(bot: commands.Bot): bot.add_cog(TimeCog(bot))