51 lines
1.2 KiB
Python
51 lines
1.2 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()
|
|
|
|
# Send "online message"
|
|
try:
|
|
await bot.send_markdown("**MBOT ONLINE**")
|
|
await bot.logout()
|
|
except nio.exceptions.LocalProtocolError:
|
|
pass
|
|
|
|
while True:
|
|
event = queue.get()
|
|
try:
|
|
await bot.send_markdown(event)
|
|
await bot.logout()
|
|
queue.task_done()
|
|
except nio.exceptions.LocalProtocolError:
|
|
pass
|
|
|
|
|
|
if __name__ == '__main__':
|
|
asyncio.get_event_loop().run_until_complete(main())
|