From 975490e0298d0b63618d68cc717291462e5f108f Mon Sep 17 00:00:00 2001 From: Leander Furumo Date: Wed, 4 Jun 2025 15:08:45 +0200 Subject: [PATCH] add humantime command --- requirements.txt | 1 + src/cogs/misc.py | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/requirements.txt b/requirements.txt index d7ee617..2ba2535 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ asyncio==3.4.* +dateparser==1.2.* discord.py==2.3.* graphviz==0.20.* Japanera==2.1.* diff --git a/src/cogs/misc.py b/src/cogs/misc.py index 4bbd3da..90b7c62 100644 --- a/src/cogs/misc.py +++ b/src/cogs/misc.py @@ -4,6 +4,7 @@ from datetime import datetime from hashlib import md5 from io import BytesIO +import dateparser import discord import requests from discord import app_commands @@ -332,6 +333,29 @@ class Misc(commands.Cog): await interaction.response.send_message(outcome) + @app_commands.checks.cooldown(1, 2) + @app_commands.command(name="mennesketid", description="Konverter tid i menneskelig format til dato og klokkeslett") + async def humantime(self, interaction: discord.Interaction, tekst: str): + """ + Convert human-readable time to date and time + + Parameters + ---------- + interaction (discord.Interaction): Slash command context object + tekst (str): Human-readable time string + """ + + parsed_time = dateparser.parse( + tekst, + languages=["nb", "nn", "en"], + ) + if not parsed_time: + embed = embed_templates.error_warning("Forstod ikke tidspunktet. Prøv å skrive det på en annen måte.") + return await interaction.response.send_message(embed=embed) + + timestamp = discord.utils.format_dt(parsed_time, style="F") + await interaction.response.send_message(timestamp) + @app_commands.checks.cooldown(1, 2) @app_commands.command(name="smellynerds", description="MAKE AN EXE FILE") async def smellynerds(self, interaction: discord.Interaction):