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
class IRCCommands(object):
class GenericCommands(object):
class trades(object):
name = "trades"
authed = True
helptext = "Get all open trades."
platform = None
name = None
helptext = None
@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.
"""
# 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
# then calling msg() ourselves, and we don't want extra spam in the channel.
trades = agora.get_dashboard()
trades = caller.get_dashboard()
if not trades:
msg("No open trades.")
return
for trade_id in trades:
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):
name = "create"
authed = True
@ -44,7 +64,13 @@ class IRCCommands(object):
msg(f"Not a valid asset: {asset}")
return
_, 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"]:
msg(f"{posted['response']['data']['message']}: {posted['response']['data']['ad_id']}")
else:
@ -61,7 +87,13 @@ class IRCCommands(object):
msg(f"Not a valid provider: {provider}")
return
_, 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"]:
msg(f"{posted['response']['data']['message']}: {posted['response']['data']['ad_id']}")
else:
@ -533,9 +565,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
if length == 3:
if length >= 3:
country = spl[1]
bank_name = spl[2]
bank_name = " ".join(spl[2:])
auth_url = tx.sinks.nordigen.create_auth_url(country, bank_name)
if not auth_url:
msg("Could not find bank.")
@ -690,7 +722,9 @@ class IRCCommands(object):
for account in accounts:
accounts_active.append(account)
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)}")
class distdetails(object):