You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
"""
|
|
Not really tests, because I don't know how to test without a whole matrix server.
|
|
"""
|
|
|
|
import asyncio
|
|
import logging
|
|
import os
|
|
from dotenv import load_dotenv
|
|
from matrix_bot.client import Client
|
|
from matrix_bot.invite_policy import (
|
|
AcceptAll,
|
|
DeclineAll,
|
|
WhiteList
|
|
)
|
|
from matrix_bot.utils import ignore_client_message
|
|
from getpass import getpass
|
|
|
|
logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.DEBUG)
|
|
|
|
@ignore_client_message
|
|
async def callback(client, room, event):
|
|
await client.send_message(room.room_id, "Hello!")
|
|
|
|
async def main():
|
|
load_dotenv()
|
|
client = await Client(
|
|
os.environ["MUSER"],
|
|
os.environ["HOMESERVER"],
|
|
os.environ["PASSWD"],
|
|
)
|
|
client.add_message_callback(callback)
|
|
withelisted_room_names = os.environ["ROOMS"].split(",")
|
|
whitelist_policy = await WhiteList(client, withelisted_room_names)
|
|
room_name = withelisted_room_names[0]
|
|
client.set_invite_policy(whitelist_policy)
|
|
await client.send_message(room_name, "Beware of Greeks bearing gifts")
|
|
await asyncio.sleep(1)
|
|
await client.send_formated_message(
|
|
room_name,
|
|
"<b><font color='red'>Beware of Greeks bearing gifts</font></b>",
|
|
"Beware of Greeks bearing gifts"
|
|
)
|
|
await client.run()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|
|
|