From 38dbd5a3f919ebe95752739cbb3028f1eda46a6e Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 14 Jun 2022 08:44:29 +0100 Subject: [PATCH] Make more commands async --- handler/ux/commands.py | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/handler/ux/commands.py b/handler/ux/commands.py index 6ddeee8..f8bfa7f 100644 --- a/handler/ux/commands.py +++ b/handler/ux/commands.py @@ -689,60 +689,84 @@ class IRCCommands(object): authed = True helptext = "Show how much is left before we are able to withdraw funds." + @staticmethod + def got_remaining(data_remaining, msg): + msg(f"Remaining: {data_remaining}USD") + @staticmethod def run(cmd, spl, length, authed, msg, agora, tx, ux): remaining = tx.money.get_remaining() - msg(f"Remaining: {remaining}USD") + remaining.addCallback(IRCCommands.remaining.got_remaining, msg) class total_remaining(object): name = "tr" authed = True helptext = "Show how much is left before we are able to withdraw funds (including open trades)." + @staticmethod + def got_total_remaining(data_remaining, msg): + msg(f"Total remaining: {data_remaining}USD") + @staticmethod def run(cmd, spl, length, authed, msg, agora, tx, ux): remaining = tx.money.get_total_remaining() - msg(f"Total remaining: {remaining}USD") + remaining.addCallback(IRCCommands.total_remaining.got_total_remaining, msg) class tradetotal(object): name = "tradetotal" authed = True helptext = "Get total value of all open trades in USD." + @staticmethod + def got_tradetotal(data_tradetotal, msg): + msg(f"Total trades: {data_tradetotal}USD") + @staticmethod def run(cmd, spl, length, authed, msg, agora, tx, ux): total = tx.money.get_open_trades_usd() - msg(f"Total trades: {total}USD") + total.addCallback(IRCCommands.tradetotal.got_tradetotal, msg) class dollar(object): name = "$" authed = True helptext = "Get total value of everything, including open trades." + @staticmethod + def got_dollar(data_dollar, msg): + msg(f"${data_dollar}") + @staticmethod def run(cmd, spl, length, authed, msg, agora, tx, ux): total = tx.money.get_total_with_trades() - msg(f"${total}") + total.addCallback(IRCCommands.dollar.got_dollar, msg) class profit(object): name = "profit" authed = True helptext = "Get total profit." + @staticmethod + def got_profit(data_profit, msg): + msg(f"Profit: {data_profit}USD") + @staticmethod def run(cmd, spl, length, authed, msg, agora, tx, ux): total = tx.money.get_profit() - msg(f"Profit: {total}USD") + total.addCallback(IRCCommands.profit.got_profit, msg) class tprofit(object): name = "tprofit" authed = True helptext = "Get total profit with open trades." + @staticmethod + def got_tprofit(data_tprofit, msg): + msg(f"Total profit: {data_tprofit}USD") + @staticmethod def run(cmd, spl, length, authed, msg, agora, tx, ux): total = tx.money.get_profit(True) - msg(f"Profit: {total}USD") + total.addCallback(IRCCommands.tprofit.got_tprofit, msg) class signin(object): name = "signin"