feat: Added timestamp command
All checks were successful
Build Docker / Build Docker (push) Successful in 24s

This commit is contained in:
Nathan Woodburn 2023-11-18 15:20:30 +11:00
parent 80460d2203
commit 26e704e551
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 24 additions and 0 deletions

16
bot.py
View File

@ -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()

View File

@ -67,6 +67,14 @@ def embed(title, description):
def timestamp_relative(date_time):
return "<t:"+str(int(date_time.timestamp()))+":R>"
def timestamp_all_raw(date_time):
timestamps = ""
options = ['R', 't', 'T', 'd', 'D', 'f', 'F']
for option in options:
timestamps += "<t:"+str(int(date_time.timestamp()))+":"+option+"> "
timestamps += "`<t:"+str(int(date_time.timestamp()))+":"+option+">`\n"
return timestamps
if __name__ == '__main__':
print(parse_time('1d'))
print(timestamp_relative(datetime.datetime.now()+parse_time('1d')))