feat: Added timestamp command
All checks were successful
Build Docker / Build Docker (push) Successful in 24s
All checks were successful
Build Docker / Build Docker (push) Successful in 24s
This commit is contained in:
parent
80460d2203
commit
26e704e551
16
bot.py
16
bot.py
@ -491,6 +491,22 @@ async def reminders(ctx):
|
|||||||
message += f"{time}: {reminder['text']}\n"
|
message += f"{time}: {reminder['text']}\n"
|
||||||
await ctx.response.send_message(message,ephemeral=True)
|
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)
|
@tasks.loop(seconds=10)
|
||||||
async def check_reminders():
|
async def check_reminders():
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
|
8
tools.py
8
tools.py
@ -67,6 +67,14 @@ def embed(title, description):
|
|||||||
def timestamp_relative(date_time):
|
def timestamp_relative(date_time):
|
||||||
return "<t:"+str(int(date_time.timestamp()))+":R>"
|
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__':
|
if __name__ == '__main__':
|
||||||
print(parse_time('1d'))
|
print(parse_time('1d'))
|
||||||
print(timestamp_relative(datetime.datetime.now()+parse_time('1d')))
|
print(timestamp_relative(datetime.datetime.now()+parse_time('1d')))
|
||||||
|
Loading…
Reference in New Issue
Block a user