From 66b138b3249572039688bbdf6d9d7896d0758e91 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Mon, 27 Dec 2021 20:59:24 +0000 Subject: [PATCH] Pass through objects smarter --- handler/agora.py | 6 ++++-- handler/irc.py | 33 +++++++++++++++++++++++++++++++++ handler/revolut.py | 4 +++- handler/transactions.py | 6 +++++- 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/handler/agora.py b/handler/agora.py index 7aa6815..dd3e588 100644 --- a/handler/agora.py +++ b/handler/agora.py @@ -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)) diff --git a/handler/irc.py b/handler/irc.py index d9d9c5a..b815d0e 100644 --- a/handler/irc.py +++ b/handler/irc.py @@ -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() diff --git a/handler/revolut.py b/handler/revolut.py index 1c8d065..159f056 100644 --- a/handler/revolut.py +++ b/handler/revolut.py @@ -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): diff --git a/handler/transactions.py b/handler/transactions.py index d528b0e..a24dc1a 100644 --- a/handler/transactions.py +++ b/handler/transactions.py @@ -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):