Fix and simplify dashboard hooks

pull/1/head
Mark Veidemanis 3 years ago
parent 05045c2a8e
commit 86271891a7
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -41,15 +41,12 @@ class Agora(object):
""" """
Set up the LoopingCall to get all active trades and messages. 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)) 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. Calls hooks to parse dashboard info and get all contact messages.
:return: dict of dashboard info
:rtype: dict
""" """
dash = self.agora.dashboard_seller() dash = self.agora.dashboard_seller()
dash_tmp = {} dash_tmp = {}
@ -61,19 +58,25 @@ class Agora(object):
contact_id = contact["data"]["contact_id"] contact_id = contact["data"]["contact_id"]
dash_tmp[contact_id] = contact dash_tmp[contact_id] = contact
# Call hook function # Call dashboard hooks
self.dashboard_hook(dash_tmp, send_irc=send_irc) self.dashboard_hook(dash_tmp)
# Get recent messages
self.get_recent_messages() self.get_recent_messages()
return dash_tmp 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. Get information about our open trades.
Post new trades to IRC and cache trades for the future. 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 = [] current_trades = []
for contact_id, contact in dash.items(): for contact_id, contact in dash.items():
reference = self.tx.tx_to_ref(contact_id) reference = self.tx.tx_to_ref(contact_id)
@ -90,10 +93,9 @@ class Agora(object):
if reference: if reference:
if reference not in current_trades: if reference not in current_trades:
current_trades.append(reference) current_trades.append(reference)
if send_irc: # 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") self.irc.client.msg(self.irc.client.channel, f"AUTO {reference}: {buyer} {amount}{currency} {amount_xmr}XMR")
# Note that we have seen this reference
dash_tmp.append(f"{reference}: {buyer} {amount}{currency} {amount_xmr}XMR")
self.last_dash.add(reference) self.last_dash.add(reference)
# Purge old trades from cache # Purge old trades from cache
@ -103,7 +105,6 @@ class Agora(object):
if reference and reference not in current_trades: if reference and reference not in current_trades:
current_trades.append(reference) current_trades.append(reference)
self.tx.cleanup(current_trades) self.tx.cleanup(current_trades)
return dash_tmp
def dashboard_release_urls(self): def dashboard_release_urls(self):
""" """

Loading…
Cancel
Save