mbot/main.py

44 lines
1.0 KiB
Python

"""Matrix Bot Framework"""
import asyncio
import nio.exceptions
import sys
import threading
from queue import Queue
from loguru import logger
from matrix import MatrixBot
from monitor import EventMonitor
from util import load_config
def init_logger():
logger.add(sys.stdout, level="DEBUG")
async def main():
config = load_config("config.json")
queue = Queue()
bot = MatrixBot(config['matrix'])
monitor = EventMonitor(
config={
"infura_url": config['infura_url'],
"pool_address": config['pool_address'],
"etherscan_key": config['etherscan_key']
},
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
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(main())