Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor #25

Closed
wants to merge 19 commits into from
Prev Previous commit
Next Next commit
refactor Reminder
  • Loading branch information
A-Phamfam committed Dec 29, 2020
commit bd7ca3f03d32cda58b9f781d68ce1c51271dfd98
32 changes: 16 additions & 16 deletions module/Reminder.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,19 +146,19 @@ async def reminder_loop(self):
"""Process for checking for reminders and sending them out if they are past overdue."""
for user_id in ex.cache.reminders:
reminders = ex.cache.reminders.get(user_id)
if reminders:
for remind_id, remind_reason, remind_time in reminders:
try:
current_time = datetime.datetime.now(remind_time.tzinfo)
if current_time >= remind_time:
dm_channel = await ex.get_dm_channel(user_id=user_id)
if dm_channel:
title_desc = f"This is a reminder to **{remind_reason}**."
embed = await ex.create_embed(title="Reminder", title_desc=title_desc)
await dm_channel.send(embed=embed)
await ex.u_reminder.remove_user_reminder(user_id, remind_id)
except:
# likely forbidden error -> do not have access to dm user
pass


if not reminders:
return None
for remind_id, remind_reason, remind_time in reminders:
try:
current_time = datetime.datetime.now(remind_time.tzinfo)
if current_time < remind_time:
return None
dm_channel = await ex.get_dm_channel(user_id=user_id)
if dm_channel:
title_desc = f"This is a reminder to **{remind_reason}**."
embed = await ex.create_embed(title="Reminder", title_desc=title_desc)
await dm_channel.send(embed=embed)
await ex.u_reminder.remove_user_reminder(user_id, remind_id)
except:
# likely forbidden error -> do not have access to dm user
pass