Files
GIA/core/modules/router.py

54 lines
1.7 KiB
Python

from core.clients.signal import SignalClient
from core.clients.xmpp import XMPPClient
from core.util import logs
class UnifiedRouter(object):
"""
Unified Router. Contains generic functions for handling XMPP and Signal events.
"""
def __init__(self, loop):
self.loop = loop
self.log = logs.get_logger("router")
self.log.info("Initialised Unified Router Interface.")
self.xmpp = XMPPClient(self, loop, "xmpp")
self.signal = SignalClient(self, loop, "signal")
def _start(self):
print("UR _start")
self.xmpp.start()
self.signal.start()
def run(self):
try:
# self.xmpp.client.client.process()
# self.xmpp.start()
print("IN RUN BEFORE START")
self._start()
self.loop.run_forever()
except (KeyboardInterrupt, SystemExit):
self.log.info("Process terminating")
finally:
self.loop.close()
async def message_received(self, protocol, *args, **kwargs):
self.log.info(f"Message received ({protocol}) {args} {kwargs}")
async def message_read(self, protocol, *args, **kwargs):
self.log.info(f"Message read ({protocol}) {args} {kwargs}")
async def started_typing(self, protocol, *args, **kwargs):
self.log.info(f"Started typing ({protocol}) {args} {kwargs}")
async def stopped_typing(self, protocol, *args, **kwargs):
self.log.info(f"Stopped typing ({protocol}) {args} {kwargs}")
async def reacted(self, protocol, *args, **kwargs):
self.log.info(f"Reacted ({protocol}) {args} {kwargs}")
async def replied(self, protocol, *args, **kwargs):
self.log.info(f"Replied ({protocol}) {args} {kwargs}")