Add /timestamp
This commit is contained in:
parent
46693f2443
commit
3100ea1f62
1 changed files with 33 additions and 0 deletions
|
@ -4,9 +4,11 @@ import platform
|
|||
import re
|
||||
import secrets
|
||||
import string
|
||||
from datetime import timezone
|
||||
from io import BytesIO
|
||||
|
||||
import numpy as np
|
||||
from dateparser import parse
|
||||
from dis_snek import InteractionContext, Scale, Snake, const
|
||||
from dis_snek.models.discord.channel import GuildCategory, GuildText, GuildVoice
|
||||
from dis_snek.models.discord.embed import EmbedField
|
||||
|
@ -23,6 +25,7 @@ from dis_snek.models.snek.application_commands import (
|
|||
from dis_snek.models.snek.command import cooldown
|
||||
from dis_snek.models.snek.cooldowns import Buckets
|
||||
from PIL import Image
|
||||
from tzlocal import get_localzone
|
||||
|
||||
import jarvis
|
||||
from jarvis.data import pigpen
|
||||
|
@ -296,6 +299,7 @@ class UtilCog(Scale):
|
|||
if length > 256:
|
||||
await ctx.send("Please limit password to 256 characters", ephemeral=True)
|
||||
return
|
||||
|
||||
choices = [
|
||||
string.ascii_letters,
|
||||
string.hexdigits,
|
||||
|
@ -329,6 +333,35 @@ class UtilCog(Scale):
|
|||
outp += "`"
|
||||
await ctx.send(outp[:2000])
|
||||
|
||||
@slash_command(
|
||||
name="timestamp", description="Convert a datetime or timestamp into it's counterpart"
|
||||
)
|
||||
@slash_option(
|
||||
name="string", description="String to convert", opt_type=OptionTypes.STRING, required=True
|
||||
)
|
||||
async def _timestamp(self, ctx: InteractionContext, string: str) -> None:
|
||||
timestamp = parse(string)
|
||||
if not timestamp:
|
||||
await ctx.send("Valid time not found, try again", ephemeral=True)
|
||||
return
|
||||
|
||||
if not timestamp.tzinfo:
|
||||
timestamp = timestamp.replace(tzinfo=get_localzone()).astimezone(tz=timezone.utc)
|
||||
|
||||
timestamp_utc = timestamp.astimezone(tz=timezone.utc)
|
||||
|
||||
ts = int(timestamp.timestamp())
|
||||
ts_utc = int(timestamp_utc.timestamp())
|
||||
fields = [
|
||||
EmbedField(name="Unix Epoch", value=f"`{ts}`"),
|
||||
EmbedField(name="Unix Epoch (UTC)", value=f"`{ts_utc}`"),
|
||||
EmbedField(name="Absolute Time", value=f"<t:{ts_utc}:F>\n`<t:{ts_utc}:F>`"),
|
||||
EmbedField(name="Relative Time", value=f"<t:{ts_utc}:R>\n`<t:{ts_utc}:R>`"),
|
||||
EmbedField(name="ISO8601", value=timestamp.isoformat()),
|
||||
]
|
||||
embed = build_embed(title="Converted Time", description="", fields=fields)
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
|
||||
def setup(bot: Snake) -> None:
|
||||
"""Add UtilCog to J.A.R.V.I.S."""
|
||||
|
|
Loading…
Add table
Reference in a new issue