Initial upload dummy matrix code

This commit is contained in:
Felix Albrigtsen 2023-08-17 21:28:28 +02:00
commit 10ae419d7f
3 changed files with 53 additions and 0 deletions

16
event.py Normal file
View File

@ -0,0 +1,16 @@
import datetime
class Event:
def __init__(self, id: int, start: datetime.datetime, end: datetime.datetime, name: str, location: str, description: str):
self.id = id
self.start = start
self.end = end
self.name = name
self.location = location
self.description = description
def __str__(self):
return f'{self.name} ({self.id})'
def __repr__(self):
return f'Event({self.id}, {self.start}, {self.name})'

1
requirements.txt Normal file
View File

@ -0,0 +1 @@
simplematrixbotlib

36
sendMatrix.py Normal file
View File

@ -0,0 +1,36 @@
from event import Event
from textwrap import dedent
import simplematrixbotlib as botlib
MATRIX_URL="https://matrix.pvv.ntnu.no"
MATRIX_USER="@calbot:pvv.ntnu.no"
MATRIX_PASS="foo"
ANNOUNCEMENT_CHANNEL = "#announcements:pvv.ntnu.no"
creds = botlib.Creds(MATRIX_URL, MATRIX_USER, MATRIX_PASS)
bot = botlib.Bot(creds)
async def sendAnnouncement(event: Event, channel: str = ANNOUNCEMENT_CHANNEL, atEveryone: bool = False) -> None:
url = f'https://www.pvv.ntnu.no/hendelser/info.php?id=${id}'
msgText = '''\
# Dagens arrangement / Todays event: {name}
## 🕒 {start} - {end}
## 📍 {location}
{description}
[Les mer / Read More]({url})
'''.format(name=event.name, start=event.start.strftime('%H:%M'), end=event.end.strftime('%H:%M'), location=event.location, description=event.description, url=url)
msgText = dedent(msgText)
if atEveryone:
msgText = msgText + '\n@room'
botResult = await bot.api.send_markdown_message(
room_id=channel,
message=msgText,
msgtype="m.text")