2024-06-06 17:55:29 +00:00
|
|
|
"""Matrix Bot Framework"""
|
|
|
|
import asyncio
|
2024-06-07 22:00:14 +00:00
|
|
|
import nio.exceptions
|
|
|
|
import sys
|
|
|
|
import threading
|
|
|
|
from queue import Queue
|
|
|
|
from loguru import logger
|
2024-06-06 17:59:53 +00:00
|
|
|
from matrix import MatrixBot
|
2024-06-07 22:00:14 +00:00
|
|
|
from monitor import EventMonitor
|
|
|
|
from util import load_config
|
2024-06-06 17:55:29 +00:00
|
|
|
|
|
|
|
|
2024-06-07 22:00:14 +00:00
|
|
|
def init_logger():
|
|
|
|
logger.add(sys.stdout, level="DEBUG")
|
2024-06-06 17:55:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
|
|
|
config = load_config("config.json")
|
2024-06-07 22:00:14 +00:00
|
|
|
queue = Queue()
|
2024-06-06 17:55:29 +00:00
|
|
|
bot = MatrixBot(config['matrix'])
|
2024-06-07 22:00:14 +00:00
|
|
|
monitor = EventMonitor(
|
|
|
|
config={"infura_url": config['infura_url'], "pool_address": config['pool_address']},
|
|
|
|
queue=queue
|
|
|
|
)
|
|
|
|
monitor_thread = threading.Thread(target=monitor.log_loop, args=(15,))
|
|
|
|
monitor_thread.start()
|
|
|
|
|
|
|
|
while True:
|
|
|
|
event = queue.get()
|
|
|
|
try:
|
|
|
|
await bot.send_message(event)
|
|
|
|
await bot.logout()
|
|
|
|
queue.task_done()
|
|
|
|
except nio.exceptions.LocalProtocolError:
|
|
|
|
pass
|
2024-06-06 17:55:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
asyncio.get_event_loop().run_until_complete(main())
|