Pass through objects smarter

This commit is contained in:
Mark Veidemanis 2021-12-27 20:59:24 +00:00
parent 8139845755
commit 66b138b324
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
4 changed files with 45 additions and 4 deletions

View File

@ -16,13 +16,15 @@ class Agora(object):
AgoraDesk API handler.
"""
def __init__(self, irc):
def __init__(self):
self.log = Logger("agora")
self.agora = AgoraDesk(settings.Agora.Token)
self.cr = CurrencyRates()
self.irc = irc
self.last_dash = set()
def set_irc(self, irc):
self.irc = irc
def setup_loop(self):
self.lc = LoopingCall(self.dashboard)
self.lc.start(int(settings.Agora.RefreshSec))

View File

@ -10,6 +10,16 @@ from json import dumps
from settings import settings
def convert(data):
if isinstance(data, bytes):
return data.decode("ascii")
if isinstance(data, dict):
return dict(map(convert, data.items()))
if isinstance(data, tuple):
return map(convert, data)
return data
class IRCBot(irc.IRCClient):
def __init__(self, log):
self.log = log
@ -22,6 +32,7 @@ class IRCBot(irc.IRCClient):
self.fingerReply = None
self.versionName = None
self.sourceURL = None
self.lineRate = None
self.prefix = settings.IRC.Prefix
self.admins = (settings.IRC.Admins).split("\n")
@ -97,6 +108,28 @@ class IRCBot(irc.IRCClient):
self.msg(channel, "---")
# self.msg(channel, dumps(messages))
elif cmd == "messages" and host in self.admins and len(spl) == 2:
messages = self.agora.get_messages(spl[1])
for message in messages:
self.msg(channel, f"{spl[1]}: {message}")
elif cmd == "dist" and host in self.admins:
rtrn = self.agora.dist_countries()
self.msg(channel, dumps(rtrn))
elif cmd == "find" and host in self.admins and len(spl) == 3:
try:
int(spl[2])
except ValueError:
self.msg(channel, "Amount is not an integer")
rtrn = self.tx.find_tx(spl[1], spl[2])
if rtrn == "AMOUNT_INVALID":
return dumps({"success": False, "msg": "Reference found but amount invalid"})
elif not rtrn:
return dumps({"success": False, "msg": "Reference not found"})
else:
return dumps(convert(rtrn))
def stopcall(self, call):
call.stop()

View File

@ -18,9 +18,11 @@ class Revolut(object):
Class to handle Revolut API calls.
"""
def __init__(self, irc):
def __init__(self):
self.log = Logger("revolut")
self.token = None
def set_irc(self, irc):
self.irc = irc
def setup_auth(self):

View File

@ -13,9 +13,13 @@ class Transactions(object):
Handler class for incoming Revolut transactions.
"""
def __init__(self, agora, irc):
def __init__(self):
self.log = Logger("transactions")
def set_agora(self, agora):
self.agora = agora
def set_irc(self, irc):
self.irc = irc
def transaction(self, data):