aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts/utilities/epoch.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot/exts/utilities/epoch.py')
-rw-r--r--bot/exts/utilities/epoch.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/bot/exts/utilities/epoch.py b/bot/exts/utilities/epoch.py
index 6f572640..d1ba98bb 100644
--- a/bot/exts/utilities/epoch.py
+++ b/bot/exts/utilities/epoch.py
@@ -1,4 +1,5 @@
-from typing import Optional, Union
+
+import contextlib
import arrow
import discord
@@ -24,7 +25,7 @@ DROPDOWN_TIMEOUT = 60
class DateString(commands.Converter):
"""Convert a relative or absolute date/time string to an arrow.Arrow object."""
- async def convert(self, ctx: commands.Context, argument: str) -> Union[arrow.Arrow, Optional[tuple]]:
+ async def convert(self, ctx: commands.Context, argument: str) -> arrow.Arrow | tuple | None:
"""
Convert a relative or absolute date/time string to an arrow.Arrow object.
@@ -88,10 +89,8 @@ class Epoch(commands.Cog):
view = TimestampMenuView(ctx, self._format_dates(date_time), epoch)
original = await ctx.send(f"`{epoch}`", view=view)
await view.wait() # wait until expiration before removing the dropdown
- try:
+ with contextlib.suppress(discord.NotFound):
await original.edit(view=None)
- except discord.NotFound: # disregard the error message if the message is deleled
- pass
@staticmethod
def _format_dates(date: arrow.Arrow) -> list[str]:
@@ -100,7 +99,7 @@ class Epoch(commands.Cog):
These are used in the description of each style in the dropdown
"""
- date = date.to('utc')
+ date = date.to("utc")
formatted = [str(int(date.timestamp()))]
formatted += [date.format(format[1]) for format in list(STYLES.values())[1:7]]
formatted.append(date.humanize())
@@ -115,7 +114,7 @@ class TimestampMenuView(discord.ui.View):
self.ctx = ctx
self.epoch = epoch
self.dropdown: discord.ui.Select = self.children[0]
- for label, date_time in zip(STYLES.keys(), formatted_times):
+ for label, date_time in zip(STYLES.keys(), formatted_times, strict=True):
self.dropdown.add_option(label=label, description=date_time)
@discord.ui.select(placeholder="Select the format of your timestamp")