From bd48bf37f503c745bd5a51a189007422abac25e0 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sun, 9 Jan 2022 22:11:39 +0000 Subject: [PATCH] Fix trades command --- handler/agora.py | 30 +++++++++++++++++++++++------- handler/commands.py | 2 +- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/handler/agora.py b/handler/agora.py index 1a8f56f..0997cef 100644 --- a/handler/agora.py +++ b/handler/agora.py @@ -47,10 +47,7 @@ class Agora(object): self.lc_dash = LoopingCall(self.loop_check) self.lc_dash.start(int(settings.Agora.RefreshSec)) - def loop_check(self): - """ - Calls hooks to parse dashboard info and get all contact messages. - """ + def wrap_dashboard(self): try: dash = self.agora.dashboard_seller() except ReadTimeout: @@ -58,11 +55,18 @@ class Agora(object): dash_tmp = {} if "data" not in dash["response"].keys(): self.log.error("Data not in dashboard response: {content}", content=dash) - return False + return dash_tmp if dash["response"]["data"]["contact_count"] > 0: for contact in dash["response"]["data"]["contact_list"]: contact_id = contact["data"]["contact_id"] dash_tmp[contact_id] = contact + return dash_tmp + + def loop_check(self): + """ + Calls hooks to parse dashboard info and get all contact messages. + """ + dash_tmp = self.wrap_dashboard() # Call dashboard hooks self.dashboard_hook(dash_tmp) @@ -78,8 +82,20 @@ class Agora(object): """ Get dashboard helper for IRC only. """ - # dash_tmp.append(f"{reference}: {buyer} {amount}{currency} {amount_xmr}XMR") - pass + dash = self.wrap_dashboard() + rtrn = [] + if not dash.items(): + return + for contact_id, contact in dash.items(): + reference = self.tx.tx_to_ref(contact_id) + buyer = contact["data"]["buyer"]["username"] + amount = contact["data"]["amount"] + amount_xmr = contact["data"]["amount_xmr"] + currency = contact["data"]["currency"] + if not contact["data"]["is_selling"]: + continue + rtrn.append(f"{reference}: {buyer} {amount}{currency} {amount_xmr}XMR") + return rtrn def dashboard_hook(self, dash): """ diff --git a/handler/commands.py b/handler/commands.py index 9895fee..9c3cc08 100644 --- a/handler/commands.py +++ b/handler/commands.py @@ -16,7 +16,7 @@ class IRCCommands(object): # 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.dashboard(send_irc=False) + trades = agora.get_dashboard() if not trades: msg("No open trades.") return