Skip to content

Commit

Permalink
imp: Raise error when reminder time is in the past
Browse files Browse the repository at this point in the history
  • Loading branch information
seriaati committed Oct 19, 2024
1 parent e2d0536 commit 3a151ef
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions l10n/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ leap_year_notify_embed_description: On a non-leap year, February 29th doesn't ex
notify_on_mar_1: Notify me on March 1st
notify_on_feb_28: Notify me on February 28th
dont_notify: Don't notify me
not_future_time_error: The reminder time must be in the future
7 changes: 5 additions & 2 deletions lumina/cogs/reminder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from discord.ext import commands

from lumina.components import Modal, Paginator, TextInput
from lumina.exceptions import NoRemindersError, ReminderNotFoundError
from lumina.exceptions import NoRemindersError, NotFutureTimeError, ReminderNotFoundError
from lumina.l10n import LocaleStr
from lumina.models import LuminaUser, Reminder, get_locale, get_timezone
from lumina.utils import get_now, shorten_text, split_list_to_chunks
Expand Down Expand Up @@ -38,7 +38,10 @@ def __init__(self, bot: Lumina) -> None:
def natural_language_to_dt(time: str, timezone: int) -> datetime.datetime:
cal = parsedatetime.Calendar()
time_struct, _ = cal.parse(time, get_now(timezone))
return datetime.datetime(*time_struct[:6]).replace(tzinfo=datetime.timezone(datetime.timedelta(hours=timezone)))
dt = datetime.datetime(*time_struct[:6]).replace(tzinfo=datetime.timezone(datetime.timedelta(hours=timezone)))
if dt < get_now(timezone):
raise NotFutureTimeError
return dt

async def cog_load(self) -> None:
self.bot.tree.add_command(self.set_reminder_ctx_menu)
Expand Down
5 changes: 5 additions & 0 deletions lumina/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ def __init__(self) -> None:
class NoteNotFoundError(LuminaError):
def __init__(self) -> None:
super().__init__(LocaleStr("note_not_found_title"))


class NotFutureTimeError(LuminaError):
def __init__(self) -> None:
super().__init__(LocaleStr("not_future_time_error"))

0 comments on commit 3a151ef

Please sign in to comment.