add bad event reminder functions
This commit is contained in:
15
event_reminders.json
Normal file
15
event_reminders.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"Orga & Finanzen Plenum": {
|
||||
"days": 1,
|
||||
"message": "hey there everyone🦓 hope you are all. okay💖 who is able to attend plenary tomorrow? please give thumbs up or down to know 👎🏽👍🏽"
|
||||
},
|
||||
"Open Library": {
|
||||
"days": 1,
|
||||
"message": "Who is able to attend open library on tuesday? please give thumbs up or down to know 👎🏽👍🏽. Also fill out the pad please <3"
|
||||
},
|
||||
"Malo Gesamtplenum": {
|
||||
"days": 3,
|
||||
"message": "Who is able to attend Gesamtplenum?? please give thumbs up or down to know 👎🏽👍🏽."
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,9 +116,14 @@ class CaldavHandler:
|
||||
if datetime_to_remind not in event_map:
|
||||
return False
|
||||
|
||||
for event_name in event_map[datetime_to_remind]:
|
||||
print("found event!")
|
||||
return True
|
||||
for real_event_name in event_map[datetime_to_remind]:
|
||||
print("real_ev_name:")
|
||||
print(real_event_name)
|
||||
print("ev_name")
|
||||
print(event_name)
|
||||
if event_name in real_event_name:
|
||||
print("found event!")
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import logging
|
||||
import threading
|
||||
import sys
|
||||
from time import sleep
|
||||
|
||||
@@ -16,12 +17,40 @@ from nio import (
|
||||
UnknownEvent,
|
||||
)
|
||||
|
||||
from my_project_name.chat_functions import react_to_event, send_text_to_room
|
||||
from my_project_name.caldav_handler import CaldavHandler
|
||||
|
||||
from my_project_name.callbacks import Callbacks
|
||||
from my_project_name.config import Config
|
||||
from my_project_name.storage import Storage
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
from datetime import datetime, time
|
||||
|
||||
def is_time_between(begin_time, end_time, check_time=None):
|
||||
# If check time is not given, default to current UTC time
|
||||
check_time = check_time or datetime.utcnow().time()
|
||||
if begin_time < end_time:
|
||||
return check_time >= begin_time and check_time <= end_time
|
||||
else: # crosses midnight
|
||||
return check_time >= begin_time or check_time <= end_time
|
||||
|
||||
async def foo(client):
|
||||
ShouldSendReminder = True
|
||||
while True:
|
||||
await client.sync()
|
||||
if is_time_between(time(10,00), time(11,10)):
|
||||
if ShouldSendReminder:
|
||||
handler = CaldavHandler()
|
||||
messages = handler.send_reminders()
|
||||
for message in messages:
|
||||
await send_text_to_room(client, "!aRFGSGKGeaBxiEfDMC:matrix.org", message)
|
||||
ShouldSendReminder = False
|
||||
else:
|
||||
ShouldSendReminder = True
|
||||
sleep(20)
|
||||
|
||||
|
||||
async def main():
|
||||
"""The first function that is run when starting the bot"""
|
||||
@@ -103,6 +132,21 @@ async def main():
|
||||
# Login succeeded!
|
||||
|
||||
logger.info(f"Logged in as {config.user_id}")
|
||||
await client.join("!aRFGSGKGeaBxiEfDMC:matrix.org")
|
||||
print("joined room")
|
||||
sleep(5)
|
||||
await client.sync()
|
||||
print(client.rooms)
|
||||
|
||||
#await client.room_send(
|
||||
# # Watch out! If you join an old room you'll see lots of old messages
|
||||
# room_id="!zKwFlsxXpmVhBMdOBa:matrix.org",
|
||||
# message_type="m.room.message",
|
||||
# content={"msgtype": "m.text", "body": "Hello world!"},
|
||||
# )
|
||||
#t = threading.Thread(target = foo, args =(client, ))
|
||||
#t.start()
|
||||
await foo(client)
|
||||
await client.sync_forever(timeout=30000, full_state=True)
|
||||
|
||||
except (ClientConnectionError, ServerDisconnectedError):
|
||||
|
||||
Reference in New Issue
Block a user