Port some commands to async

master
Mark Veidemanis 2 years ago
parent 789e27d627
commit 6bf3daee4c
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -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.")
@ -771,13 +771,17 @@ class IRCCommands(object):
helptext = "Get a list of acccounts from Nordigen. Usage: naccounts"
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
if length == 1:
accounts = tx.sinks.nordigen.get_all_account_info()
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()
accounts.addCallback(IRCCommands.naccounts.got_accounts, msg)
class transactions(object):
name = "transactions"
authed = True
@ -805,10 +809,7 @@ class IRCCommands(object):
helptext = "Get a list of transactions from Nordigen. Usage: ntransactions <account_id>"
@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)
def got_transactions(transactions, msg):
for transaction in transactions:
if "transaction_id" in transaction:
txid = transaction["transaction_id"]
@ -820,20 +821,31 @@ class IRCCommands(object):
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)
transactions.addCallback(IRCCommands.ntransactions.got_transactions, msg)
class nreqs(object):
name = "nreqs"
authed = True
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

@ -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):
"""

Loading…
Cancel
Save