diff --git a/handler/ux/commands.py b/handler/ux/commands.py index 675f897..66c5b65 100644 --- a/handler/ux/commands.py +++ b/handler/ux/commands.py @@ -13,7 +13,7 @@ class GenericCommands(object): Get details of open trades and post on IRC. """ - trades = caller.get_dashboard() + trades = caller.get_dashboard_irc() if not trades: msg("No open trades.") @@ -770,13 +770,17 @@ class IRCCommands(object): authed = True helptext = "Get a list of acccounts from Nordigen. Usage: naccounts" + @staticmethod + def got_accounts(accounts, msg): + for name, accounts in accounts.items(): + for account in accounts: + msg(dumps(account)) + @staticmethod def run(cmd, spl, length, authed, msg, agora, tx, ux): if length == 1: accounts = tx.sinks.nordigen.get_all_account_info() - for name, accounts in accounts.items(): - for account in accounts: - msg(dumps(account)) + accounts.addCallback(IRCCommands.naccounts.got_accounts, msg) class transactions(object): name = "transactions" @@ -804,21 +808,25 @@ class IRCCommands(object): authed = True helptext = "Get a list of transactions from Nordigen. Usage: ntransactions " + @staticmethod + def got_transactions(transactions, msg): + for transaction in transactions: + if "transaction_id" in transaction: + txid = transaction["transaction_id"] + else: + txid = "not_set" + timestamp = transaction["timestamp"] + amount = transaction["amount"] + currency = transaction["currency"] + reference = transaction["reference"] + msg(f"{timestamp} {txid} {amount}{currency} {reference}") + @staticmethod def run(cmd, spl, length, authed, msg, agora, tx, ux): if length == 2: account_id = spl[1] transactions = tx.sinks.nordigen.get_transactions(account_id) - for transaction in transactions: - if "transaction_id" in transaction: - txid = transaction["transaction_id"] - else: - txid = "not_set" - timestamp = transaction["timestamp"] - amount = transaction["amount"] - currency = transaction["currency"] - reference = transaction["reference"] - msg(f"{timestamp} {txid} {amount}{currency} {reference}") + transactions.addCallback(IRCCommands.ntransactions.got_transactions, msg) class nreqs(object): name = "nreqs" @@ -826,14 +834,18 @@ class IRCCommands(object): helptext = "Get a list of requisitions from Nordigen." @staticmethod - def run(cmd, spl, length, authed, msg, agora, tx, ux): - reqs = tx.sinks.nordigen.get_requisitions() + def got_requisitions(reqs, msg): for req in reqs: id = req["id"] institution_id = req["institution_id"] redirect = req["link"] msg(f"{id} {institution_id} {redirect}") + @staticmethod + def run(cmd, spl, length, authed, msg, agora, tx, ux): + reqs = tx.sinks.nordigen.get_requisitions() + reqs.addCallback(IRCCommands.nreqs.got_requisitions, msg) + class ndelreq(object): name = "ndelreq" authed = True diff --git a/handler/ux/irc.py b/handler/ux/irc.py index 3ef03c1..22afd9f 100644 --- a/handler/ux/irc.py +++ b/handler/ux/irc.py @@ -1,7 +1,6 @@ # Twisted/Klein imports from twisted.words.protocols import irc from twisted.internet import protocol, reactor, ssl -from twisted.internet.task import deferLater # Project imports from settings import settings @@ -116,7 +115,7 @@ class IRCBot(irc.IRCClient): Join our channel. """ self.log.info(f"Signed on as {self.nickname}") - deferLater(reactor, 2, self.join, self.channel) + self.join(self.channel) def joined(self, channel): """