From 86271891a7540a49a360b942c03567605b4ac057 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sat, 1 Jan 2022 16:34:32 +0000 Subject: [PATCH] Fix and simplify dashboard hooks --- handler/agora.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/handler/agora.py b/handler/agora.py index 08fbab2..b758571 100644 --- a/handler/agora.py +++ b/handler/agora.py @@ -41,15 +41,12 @@ class Agora(object): """ Set up the LoopingCall to get all active trades and messages. """ - self.lc_dash = LoopingCall(self.dashboard) + self.lc_dash = LoopingCall(self.loop_check) self.lc_dash.start(int(settings.Agora.RefreshSec)) - def dashboard(self, send_irc=True): + def loop_check(self): """ - Returns a dict for the dashboard. Calls hooks to parse dashboard info and get all contact messages. - :return: dict of dashboard info - :rtype: dict """ dash = self.agora.dashboard_seller() dash_tmp = {} @@ -61,19 +58,25 @@ class Agora(object): contact_id = contact["data"]["contact_id"] dash_tmp[contact_id] = contact - # Call hook function - self.dashboard_hook(dash_tmp, send_irc=send_irc) + # Call dashboard hooks + self.dashboard_hook(dash_tmp) + + # Get recent messages self.get_recent_messages() return dash_tmp - def dashboard_hook(self, dash, send_irc=True): + def get_dashboard(self): + """ + Get dashboard helper for IRC only. + """ + # dash_tmp.append(f"{reference}: {buyer} {amount}{currency} {amount_xmr}XMR") + pass + + def dashboard_hook(self, dash): """ Get information about our open trades. Post new trades to IRC and cache trades for the future. - :return: human readable list of strings about our trades or False - :rtype: list or bool """ - dash_tmp = [] current_trades = [] for contact_id, contact in dash.items(): reference = self.tx.tx_to_ref(contact_id) @@ -90,10 +93,9 @@ class Agora(object): if reference: if reference not in current_trades: current_trades.append(reference) - if send_irc: - self.irc.client.msg(self.irc.client.channel, f"AUTO {reference}: {buyer} {amount}{currency} {amount_xmr}XMR") - - dash_tmp.append(f"{reference}: {buyer} {amount}{currency} {amount_xmr}XMR") + # Let us know there is a new trade + self.irc.client.msg(self.irc.client.channel, f"AUTO {reference}: {buyer} {amount}{currency} {amount_xmr}XMR") + # Note that we have seen this reference self.last_dash.add(reference) # Purge old trades from cache @@ -103,7 +105,6 @@ class Agora(object): if reference and reference not in current_trades: current_trades.append(reference) self.tx.cleanup(current_trades) - return dash_tmp def dashboard_release_urls(self): """