add webhook
This commit is contained in:
parent
eb8cdefab4
commit
80891eeda2
4 changed files with 69 additions and 5 deletions
|
@ -1,9 +1,30 @@
|
|||
import argparse
|
||||
import asyncio
|
||||
|
||||
from typing import (
|
||||
Any,
|
||||
NoReturn
|
||||
)
|
||||
|
||||
from matrix_bot.client import Client
|
||||
from matrix_bot.invite_policy import WhiteList
|
||||
from .config import load_config
|
||||
from .webhook import run_webhook
|
||||
|
||||
async def send_messages(
|
||||
message_queue: asyncio.Queue[dict[str, Any]],
|
||||
bot: Client,
|
||||
rooms: list[str]
|
||||
)->NoReturn:
|
||||
"""
|
||||
Read messages from a queue and send them via the bot.
|
||||
"""
|
||||
while True:
|
||||
message = await message_queue.get()
|
||||
message = str(message)
|
||||
for room in rooms:
|
||||
await bot.send_message(room, message)
|
||||
message_queue.task_done()
|
||||
|
||||
async def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
|
@ -11,20 +32,24 @@ async def main():
|
|||
args = parser.parse_args()
|
||||
|
||||
config = load_config(args.config)
|
||||
alert_queue = asyncio.Queue()
|
||||
|
||||
client = await Client(
|
||||
config.username,
|
||||
config.homeserver,
|
||||
config.password
|
||||
)
|
||||
invite_policy = await WhiteList(client, config.allert_rooms)
|
||||
invite_policy = await WhiteList(client, config.alert_rooms)
|
||||
client.set_invite_policy(invite_policy)
|
||||
|
||||
# Test:
|
||||
for room in config.allert_rooms:
|
||||
for room in config.alert_rooms:
|
||||
await client.send_message(room, f"Hello from {config.username}")
|
||||
|
||||
await asyncio.gather(
|
||||
client.run()
|
||||
client.run(),
|
||||
run_webhook(alert_queue, config.host, config.port),
|
||||
send_messages(alert_queue, client, config.alert_rooms)
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue