Implement generic command types

This commit is contained in:
Mark Veidemanis 2022-04-12 22:06:45 +01:00
parent be356c2721
commit 1501cd0db3
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 47 additions and 13 deletions

View File

@ -5,27 +5,47 @@ from json import dumps, loads
from settings import settings from settings import settings
class IRCCommands(object): class GenericCommands(object):
class trades(object): class trades(object):
name = "trades"
authed = True authed = True
helptext = "Get all open trades." platform = None
name = None
helptext = None
@staticmethod @staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux): def run(cmd, spl, length, authed, msg, agora, tx, ux, caller):
""" """
Get details of open trades and post on IRC. Get details of open trades and post on IRC.
""" """
# Send IRC - we don't want to automatically send messages on IRC, even though
# this variable seems counter-intuitive here, we are doing something with the result trades = caller.get_dashboard()
# then calling msg() ourselves, and we don't want extra spam in the channel.
trades = agora.get_dashboard()
if not trades: if not trades:
msg("No open trades.") msg("No open trades.")
return return
for trade_id in trades: for trade_id in trades:
msg(trade_id) msg(trade_id)
class IRCCommands(object):
class atrades(object):
authed = True
name = "atrades"
helptext = "Get all open trades for Agora."
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.trades.run(cmd, spl, length, authed, msg, agora, tx, ux, agora)
class ltrades(GenericCommands.trades):
authed = True
name = "ltrades"
helptext = "Get all open trades for LBTC."
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.trades.run(cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc)
class create(object): class create(object):
name = "create" name = "create"
authed = True authed = True
@ -44,7 +64,13 @@ class IRCCommands(object):
msg(f"Not a valid asset: {asset}") msg(f"Not a valid asset: {asset}")
return return
_, account_info = tx.markets.get_valid_account_details() _, account_info = tx.markets.get_valid_account_details()
posted = agora.create_ad(asset, country, currency, "NATIONAL_BANK", payment_details=account_info[currency]) posted = agora.create_ad(
asset,
country,
currency,
"NATIONAL_BANK",
payment_details=account_info[currency],
)
if posted["success"]: if posted["success"]:
msg(f"{posted['response']['data']['message']}: {posted['response']['data']['ad_id']}") msg(f"{posted['response']['data']['message']}: {posted['response']['data']['ad_id']}")
else: else:
@ -61,7 +87,13 @@ class IRCCommands(object):
msg(f"Not a valid provider: {provider}") msg(f"Not a valid provider: {provider}")
return return
_, account_info = tx.markets.get_valid_account_details() _, account_info = tx.markets.get_valid_account_details()
posted = agora.create_ad(asset, country, currency, provider, payment_details=account_info[currency]) posted = agora.create_ad(
asset,
country,
currency,
provider,
payment_details=account_info[currency],
)
if posted["success"]: if posted["success"]:
msg(f"{posted['response']['data']['message']}: {posted['response']['data']['ad_id']}") msg(f"{posted['response']['data']['message']}: {posted['response']['data']['ad_id']}")
else: else:
@ -533,9 +565,9 @@ class IRCCommands(object):
@staticmethod @staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux): def run(cmd, spl, length, authed, msg, agora, tx, ux):
if length == 3: if length >= 3:
country = spl[1] country = spl[1]
bank_name = spl[2] bank_name = " ".join(spl[2:])
auth_url = tx.sinks.nordigen.create_auth_url(country, bank_name) auth_url = tx.sinks.nordigen.create_auth_url(country, bank_name)
if not auth_url: if not auth_url:
msg("Could not find bank.") msg("Could not find bank.")
@ -690,7 +722,9 @@ class IRCCommands(object):
for account in accounts: for account in accounts:
accounts_active.append(account) accounts_active.append(account)
accounts_all = tx.sinks.truelayer.get_accounts(bank) accounts_all = tx.sinks.truelayer.get_accounts(bank)
accounts_unmapped = [x["account_id"] for x in accounts_all["results"] if x["account_id"] not in accounts_active] accounts_unmapped = [
x["account_id"] for x in accounts_all["results"] if x["account_id"] not in accounts_active
]
msg(f"Unmapped accounts: {', '.join(accounts_unmapped)}") msg(f"Unmapped accounts: {', '.join(accounts_unmapped)}")
class distdetails(object): class distdetails(object):