Skip to content

Commit

Permalink
added start time to repeat reminders
Browse files Browse the repository at this point in the history
  • Loading branch information
Mole1424 committed Jan 10, 2024
1 parent 23d6132 commit aee62bb
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions cogs/commands/reminders.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@ async def add(self, ctx: Context, when: str, *, reminder_content: str):

@reminder.command(help="Add a repeating reminder.")
async def repeat(
self, ctx: Context, repeat: str, until: str, *, reminder_content: str
self,
ctx: Context,
start: str,
repeat: str,
until: str,
*,
reminder_content: str,
):
repeat_time = timeparse(repeat)
if repeat_time is None:
Expand All @@ -99,24 +105,31 @@ async def repeat(
)
repeat_time = timedelta(seconds=repeat_time)
until_time = parse_time(until)
temp_time = datetime.now(timezone("Europe/London"))
if until_time < temp_time:
return ctx.reply("That time is in the past.")
start_time = (
datetime.now(timezone("Europe/London"))
if start is None
else parse_time(start)
)
if start_time is None or until_time is None:
return ctx.reply(
"I just flat out did not understand what you meant with that start time"
)
if until_time < start_time:
return ctx.reply("The until time is before the start time")

display_name = get_name_string(ctx.message)
if user_is_irc_bot(ctx):
author_id, irc_n = 1, display_name
else:
author_id, irc_n = get_database_user(ctx.author).id, None

temp_time += repeat_time
num_reminders = 0
first_reminder = None
while temp_time < until_time:
while start_time <= until_time:
new_reminder = Reminder(
user_id=author_id,
reminder_content=reminder_content,
trigger_at=temp_time,
trigger_at=start_time,
triggered=False,
playback_channel_id=ctx.message.channel.id,
irc_name=irc_n,
Expand All @@ -125,7 +138,7 @@ async def repeat(
num_reminders += 1
if not first_reminder:
first_reminder = int(new_reminder.trigger_at.timestamp())
temp_time += repeat_time
start_time += repeat_time
await ctx.reply(
f"Added {num_reminders} reminders, first one at <t:{first_reminder}:R>, last one at <t:{int(new_reminder.trigger_at.timestamp())}:R>"
)
Expand Down

0 comments on commit aee62bb

Please sign in to comment.