Pass through objects smarter
This commit is contained in:
parent
8139845755
commit
66b138b324
|
@ -16,13 +16,15 @@ class Agora(object):
|
||||||
AgoraDesk API handler.
|
AgoraDesk API handler.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, irc):
|
def __init__(self):
|
||||||
self.log = Logger("agora")
|
self.log = Logger("agora")
|
||||||
self.agora = AgoraDesk(settings.Agora.Token)
|
self.agora = AgoraDesk(settings.Agora.Token)
|
||||||
self.cr = CurrencyRates()
|
self.cr = CurrencyRates()
|
||||||
self.irc = irc
|
|
||||||
self.last_dash = set()
|
self.last_dash = set()
|
||||||
|
|
||||||
|
def set_irc(self, irc):
|
||||||
|
self.irc = irc
|
||||||
|
|
||||||
def setup_loop(self):
|
def setup_loop(self):
|
||||||
self.lc = LoopingCall(self.dashboard)
|
self.lc = LoopingCall(self.dashboard)
|
||||||
self.lc.start(int(settings.Agora.RefreshSec))
|
self.lc.start(int(settings.Agora.RefreshSec))
|
||||||
|
|
|
@ -10,6 +10,16 @@ from json import dumps
|
||||||
from settings import settings
|
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):
|
class IRCBot(irc.IRCClient):
|
||||||
def __init__(self, log):
|
def __init__(self, log):
|
||||||
self.log = log
|
self.log = log
|
||||||
|
@ -22,6 +32,7 @@ class IRCBot(irc.IRCClient):
|
||||||
self.fingerReply = None
|
self.fingerReply = None
|
||||||
self.versionName = None
|
self.versionName = None
|
||||||
self.sourceURL = None
|
self.sourceURL = None
|
||||||
|
self.lineRate = None
|
||||||
|
|
||||||
self.prefix = settings.IRC.Prefix
|
self.prefix = settings.IRC.Prefix
|
||||||
self.admins = (settings.IRC.Admins).split("\n")
|
self.admins = (settings.IRC.Admins).split("\n")
|
||||||
|
@ -97,6 +108,28 @@ class IRCBot(irc.IRCClient):
|
||||||
self.msg(channel, "---")
|
self.msg(channel, "---")
|
||||||
# self.msg(channel, dumps(messages))
|
# 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):
|
def stopcall(self, call):
|
||||||
call.stop()
|
call.stop()
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,11 @@ class Revolut(object):
|
||||||
Class to handle Revolut API calls.
|
Class to handle Revolut API calls.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, irc):
|
def __init__(self):
|
||||||
self.log = Logger("revolut")
|
self.log = Logger("revolut")
|
||||||
self.token = None
|
self.token = None
|
||||||
|
|
||||||
|
def set_irc(self, irc):
|
||||||
self.irc = irc
|
self.irc = irc
|
||||||
|
|
||||||
def setup_auth(self):
|
def setup_auth(self):
|
||||||
|
|
|
@ -13,9 +13,13 @@ class Transactions(object):
|
||||||
Handler class for incoming Revolut transactions.
|
Handler class for incoming Revolut transactions.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, agora, irc):
|
def __init__(self):
|
||||||
self.log = Logger("transactions")
|
self.log = Logger("transactions")
|
||||||
|
|
||||||
|
def set_agora(self, agora):
|
||||||
self.agora = agora
|
self.agora = agora
|
||||||
|
|
||||||
|
def set_irc(self, irc):
|
||||||
self.irc = irc
|
self.irc = irc
|
||||||
|
|
||||||
def transaction(self, data):
|
def transaction(self, data):
|
||||||
|
|
Loading…
Reference in New Issue