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")