From 26e704e551995787d95d80714737d0039b24fad3 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Sat, 18 Nov 2023 15:20:30 +1100 Subject: [PATCH] feat: Added timestamp command --- bot.py | 16 ++++++++++++++++ tools.py | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/bot.py b/bot.py index 79b7351..6487b3d 100644 --- a/bot.py +++ b/bot.py @@ -491,6 +491,22 @@ async def reminders(ctx): message += f"{time}: {reminder['text']}\n" await ctx.response.send_message(message,ephemeral=True) +@tree.command(name="timestamp", description="Convert timestamp") +async def timestamp(ctx, when: str): + when = when.strip() + time_delta = parse_time(when) + + if time_delta is not None: + # Schedule the reminder + time = datetime.datetime.now() + time_delta + if when.endswith("ago"): + time = datetime.datetime.now() - time_delta + + time = tools.timestamp_all_raw(time) + await ctx.response.send_message(time,ephemeral=True) + else: + await ctx.response.send_message("Invalid time format. Please use something like `1d 3h` or `4hr`. End with `ago` to convert to past time",ephemeral=True) + @tasks.loop(seconds=10) async def check_reminders(): now = datetime.datetime.now() diff --git a/tools.py b/tools.py index 6bd5085..d322959 100644 --- a/tools.py +++ b/tools.py @@ -67,6 +67,14 @@ def embed(title, description): def timestamp_relative(date_time): return "" +def timestamp_all_raw(date_time): + timestamps = "" + options = ['R', 't', 'T', 'd', 'D', 'f', 'F'] + for option in options: + timestamps += " " + timestamps += "``\n" + return timestamps + if __name__ == '__main__': print(parse_time('1d')) print(timestamp_relative(datetime.datetime.now()+parse_time('1d')))