Skip to content

Commit

Permalink
New command /get-timestamp:
Browse files Browse the repository at this point in the history
- Install git inside a container for install the python packages directly from the git repositories
- The hints for input are changed for being more various
- dateparser uses a current Discord user locale
  • Loading branch information
soksanichenko committed Feb 28, 2024
1 parent 5f425c9 commit 34f4570
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion deploy/roles/deploy_bot_container/templates/Dockerfile.j2
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM almalinux:9
ENV TZ="{{ timezone_output.stdout }}"
RUN dnf install python39 -y
RUN dnf install python39 git -y
RUN mkdir -p /code/sources
WORKDIR /code
COPY req.txt sources/req.txt
Expand Down
19 changes: 15 additions & 4 deletions sources/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,28 @@ async def select_callback(
name='get-timestamp',
description='Get formatted timestamp for any date and/or time',
)
@discord.app_commands.describe(time='HH:MM')
@discord.app_commands.describe(date='dd.mm.YYYY')
async def get_timestamp(interaction, time: str = '', date: str = ''):
@discord.app_commands.describe(
time='Please input a time in any suitable format in your region'
)
@discord.app_commands.describe(
date='Please input a date in any suitable format in your region'
)
async def get_timestamp(
interaction: discord.Interaction,
time: str = '',
date: str = '',
):
"""
Send any text by the bot
:param time: an input time for converting
:param date: an input date for converting
:param interaction: the command's interaction
:return: None
"""
time_date = dateparser.parse(f'{time} {date}')
time_date = dateparser.parse(
f'{time} {date}',
locales=[interaction.locale.value],
)
if time_date is None:
await interaction.response.send_message(
'You sent a date/time in incorrect format',
Expand Down
2 changes: 1 addition & 1 deletion sources/req.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
discord==2.3.2
tldextract==5.1.1
dateparser==1.2.0
git+https://github.com/ZelGray/dateparser.git@master

0 comments on commit 34f4570

Please sign in to comment.