TexLiLy/main.py
2023-06-14 18:24:47 +02:00

50 lines
1.4 KiB
Python

from nio import *
import asyncio
import utils
async def main() -> None:
import callbacks
import router
import yaml
# Load our config file.
config = {}
try:
with open('texlily.yaml', 'r') as conf:
config = yaml.safe_load(conf)
# Retrieve our configuration
homeserver = str(config["homeserver"])
user = str(config["user"])
token = str(config["token"])
path = str(config["data"]) # Unused there, required.
utils.set_config(config)
# if config file does not exist, quit
except FileNotFoundError:
print("No config file found.")
print("Please create a file named `texlily.yaml` and read the README file.")
quit()
except TypeError:
print("Invalid configuration file.")
quit()
client = AsyncClient(homeserver)
client.access_token = token
client.user_id = user
# Add routes.
callbacks.init_routes()
# TODO: Fix this hot mess before merging onto main.
await client.sync(timeout=10000)
# Register all of the callbacks
utils.set_client(client)
client.add_event_callback(callbacks.msg_cb, RoomMessageText)
client.add_event_callback(callbacks.file_cb, RoomMessageFile)
client.add_event_callback(callbacks.invite_cb, InviteEvent)
await client.sync_forever(timeout=10000, full_state=True)
asyncio.run(main())