instanciate the matrix client

This commit is contained in:
histausse 2021-10-05 21:45:35 +02:00
parent 1172db1d95
commit eb8cdefab4
Signed by: histausse
GPG key ID: 67486F107F62E9E9
2 changed files with 21 additions and 1 deletions

3
.gitignore vendored
View file

@ -138,3 +138,6 @@ dmypy.json
# Cython debug symbols # Cython debug symbols
cython_debug/ cython_debug/
# Project specific:
.sync_token
config.yaml

View file

@ -1,14 +1,31 @@
import argparse import argparse
import asyncio import asyncio
from matrix_bot.client import Client
from matrix_bot.invite_policy import WhiteList
from .config import load_config from .config import load_config
async def main(): async def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("-c", "--config", default="config.yaml") parser.add_argument("-c", "--config", default="config.yaml")
args = parser.parse_args() args = parser.parse_args()
config = load_config(args.config) config = load_config(args.config)
print(config) client = await Client(
config.username,
config.homeserver,
config.password
)
invite_policy = await WhiteList(client, config.allert_rooms)
client.set_invite_policy(invite_policy)
# Test:
for room in config.allert_rooms:
await client.send_message(room, f"Hello from {config.username}")
await asyncio.gather(
client.run()
)
if __name__ == "__main__": if __name__ == "__main__":
asyncio.run(main()) asyncio.run(main())