🐛 !set-reminder now works!
This commit is contained in:
parent
cf88a8c46f
commit
7d46f4923c
1 changed files with 10 additions and 9 deletions
19
bot.py
19
bot.py
|
@ -1,7 +1,7 @@
|
|||
import simplematrixbotlib as botlib
|
||||
import requests
|
||||
import datetime
|
||||
import threading
|
||||
import asyncio
|
||||
import pytz
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
|
@ -51,11 +51,10 @@ async def times(room, message):
|
|||
async def usage(room, message):
|
||||
match = botlib.MessageMatch(room, message, bot, PREFIX)
|
||||
|
||||
response = """
|
||||
usage:
|
||||
- **!set-location** <City, Country>
|
||||
- **!times**
|
||||
- **!set-reminder** <X> where X is the number of minutes you want to receive the reminder before praying
|
||||
response = """usage:
|
||||
- **!set-location** <City, Country>
|
||||
- **!times**
|
||||
- **!set-reminder** <X> where X is the number of minutes you want to receive the reminder before praying
|
||||
"""
|
||||
|
||||
if match.is_not_from_this_bot() and not match.prefix():
|
||||
|
@ -109,15 +108,17 @@ def get_praying_times(date: datetime.date, username):
|
|||
|
||||
def schedule_reminder(username):
|
||||
times = get_praying_times(datetime.date.today(), username)
|
||||
now = utc.localize(datetime.datetime.now(datetime.UTC))
|
||||
now = datetime.datetime.now(datetime.UTC)
|
||||
for prayer, time in times.items():
|
||||
praying_time = datetime.datetime.fromisoformat(time)
|
||||
if praying_time > now:
|
||||
seconds = int((praying_time - now).total_seconds())
|
||||
threading.Timer(seconds - user_reminders[username] * 60, remind, [username]).start()
|
||||
message = "{} is at {}".format(prayer, praying_time.strftime("%H:%M"))
|
||||
asyncio.ensure_future(remind(username, message, seconds - user_reminders[username] * 60))
|
||||
|
||||
|
||||
async def remind(username, message):
|
||||
async def remind(username, message, seconds):
|
||||
await asyncio.sleep(seconds)
|
||||
await bot.api.send_markdown_message(user_room_ids[username], message)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue