Define the /time at command.
build_develop / build (push) Successful in 1m32s

This commit is contained in:
2024-05-31 15:20:59 -04:00
parent 4805f6cd5d
commit fdb04149aa
+75 -8
View File
@@ -1,6 +1,6 @@
"""Contains commands for time commands.""" """Contains commands for time commands."""
from datetime import UTC, datetime from datetime import MAXYEAR, MINYEAR, UTC, datetime
import nextcord import nextcord
from nextcord.ext import commands from nextcord.ext import commands
@@ -15,20 +15,87 @@ class TimeCog(commands.Cog, name="Time Commands"):
async def time(self, interaction: nextcord.Interaction) -> None: async def time(self, interaction: nextcord.Interaction) -> None:
"""Parent slash command. Never called.""" """Parent slash command. Never called."""
@time.subcommand(description="1") @time.subcommand(
async def at(self, interaction: nextcord.Interaction) -> None: description="Get a discord timestamp of the given game time. If date information is left blank, uses current day." # noqa: E501
pass )
async def at( # noqa: PLR0913
self,
interaction: nextcord.Interaction,
hour: int = nextcord.SlashOption(
description="The hour you want a timestamp of. Given in gametime/UTC.",
min_value=0,
max_value=23,
required=True,
),
minute: int = nextcord.SlashOption(
description="The minute you want a timestamp of. Given in gametime/UTC.",
min_value=0,
max_value=59,
required=True,
),
year: int = nextcord.SlashOption(
description="Year to make timestamp of.", required=False, min_value=MINYEAR, max_value=MAXYEAR
),
month: int = nextcord.SlashOption(
description="Month to make timestamp of.", required=False, min_value=1, max_value=12
),
day: int = nextcord.SlashOption(
description="Day to make timestamp of.", required=False, min_value=1, max_value=31
),
ephemeral: bool = nextcord.SlashOption( # noqa: FBT001
description="Whether the replying message will be public or not.", required=False, default=True
),
) -> None:
"""
Replies with a discord timestamp of given UTC time.
@time.subcommand(description="1") Args:
async def at_gametime(self, interaction: nextcord.Interaction) -> None: interaction (nextcord.Interaction): Interaction with the command.
pass hour (int): The hour in UTC to make the timestamp of..
minute (int): The minute in UTC to make the timestamp of..
year (int): The year to make the timestamp of.
month (int): The month to make the timestamp of.
day (int): The day to make the timestamp of.
ephemeral (bool): Whether the response is ephemeral or not.
"""
gametime_today: datetime = datetime.now(tz=UTC).replace(hour=hour, minute=minute)
if year is not None:
gametime_today = gametime_today.replace(year=year)
if month is not None and day is not None:
try:
gametime_today = gametime_today.replace(month=month, day=day)
except ValueError:
await interaction.response.send_message(f"Day {day} is out of range for month {month}.", ephemeral=True)
return
else:
if month is not None:
try:
gametime_today = gametime_today.replace(month=month)
except ValueError:
await interaction.response.send_message(
f"Today ({gametime_today.day}) is out of range for month {month}.", ephemeral=True
)
return
if day is not None:
try:
gametime_today = gametime_today.replace(day=day)
except ValueError:
await interaction.response.send_message(
f"Day {day} is out of range for this month {gametime_today.month}.", ephemeral=True
)
return
await interaction.response.send_message(content=f"<t:{int(gametime_today.timestamp())}:t>", ephemeral=ephemeral)
@time.subcommand(description="Get the current time in game.") @time.subcommand(description="Get the current time in game.")
async def gametime( async def gametime(
self, self,
interaction: nextcord.Interaction, interaction: nextcord.Interaction,
ephemeral: bool = nextcord.SlashOption( # noqa: FBT001 ephemeral: bool = nextcord.SlashOption( # noqa: FBT001
required=False, default=True, description="Whether the replying message will be public or not." description="Whether the replying message will be public or not.", required=False, default=True
), ),
) -> None: ) -> None:
""" """