Handle dashbord smarter and poll messages
This commit is contained in:
parent
d5c272d3f9
commit
64bf5a77ee
|
@ -39,43 +39,43 @@ class Agora(object):
|
|||
|
||||
def setup_loop(self):
|
||||
"""
|
||||
Set up the LoopingCall to get all active trades.
|
||||
Set up the LoopingCall to get all active trades and messages.
|
||||
"""
|
||||
self.lc = LoopingCall(self.dashboard)
|
||||
self.lc.start(int(settings.Agora.RefreshSec))
|
||||
self.lc_dash = LoopingCall(self.dashboard)
|
||||
self.lc_dash.start(int(settings.Agora.RefreshSec))
|
||||
|
||||
def dashboard_id_only(self):
|
||||
def dashboard(self, send_irc=True, formatted=False):
|
||||
"""
|
||||
Returns a list of the IDs of open trades.
|
||||
:return: list of open trade IDs
|
||||
:rtype: list
|
||||
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 = []
|
||||
dash_tmp = {}
|
||||
if "data" not in dash["response"].keys():
|
||||
self.log.error("Data not in dashboard response: {content}", content=dash)
|
||||
return False
|
||||
if dash["response"]["data"]["contact_count"] > 0:
|
||||
for contact in dash["response"]["data"]["contact_list"]:
|
||||
contact_id = contact["data"]["contact_id"]
|
||||
dash_tmp.append(contact_id)
|
||||
dash_tmp[contact_id] = contact
|
||||
fmt = self.dashboard_hook(dash_tmp)
|
||||
self.get_all_messages_hook(dash_tmp)
|
||||
if formatted:
|
||||
return fmt
|
||||
return dash_tmp
|
||||
|
||||
def dashboard(self, send_irc=True):
|
||||
def dashboard_hook(self, dash, send_irc=True):
|
||||
"""
|
||||
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 = self.agora.dashboard_seller()
|
||||
dash_tmp = []
|
||||
current_trades = []
|
||||
if "data" not in dash["response"]:
|
||||
return False
|
||||
if dash["response"]["data"]["contact_count"] > 0:
|
||||
for contact in dash["response"]["data"]["contact_list"]:
|
||||
contact_id = contact["data"]["contact_id"]
|
||||
for contact_id, contact in dash.items():
|
||||
current_trades.append(contact_id)
|
||||
buyer = contact["data"]["buyer"]["username"]
|
||||
amount = contact["data"]["amount"]
|
||||
|
@ -141,21 +141,31 @@ class Agora(object):
|
|||
if not len(self.last_messages[contact_id]) == len(messages_tmp):
|
||||
difference = set(messages_tmp) ^ self.last_messages[contact_id]
|
||||
for x in difference:
|
||||
self.irc.client.msg(self.irc.client.channel, x)
|
||||
self.irc.client.msg(self.irc.client.channel, f"AUTO {contact_id}: {x}")
|
||||
else:
|
||||
self.last_messages[contact_id] = messages_tmp
|
||||
for x in messages_tmp:
|
||||
self.irc.client.msg(self.irc.client.channel, x)
|
||||
self.irc.client.msg(self.irc.client.channel, f"NEW {contact_id}: {x}")
|
||||
return messages_tmp
|
||||
|
||||
def get_all_messages(self, send_irc=True):
|
||||
"""
|
||||
Get all messages for all open trades.
|
||||
Wrapper for passing in dashboard.
|
||||
:return: dict of lists keyed by trade/contact ID
|
||||
:rtype: dict with lists
|
||||
"""
|
||||
dash = self.dashboard_id_only()
|
||||
dash = self.dashboard()
|
||||
if dash is None:
|
||||
return False
|
||||
return self.get_all_messages_hook(dash, send_irc=send_irc)
|
||||
|
||||
def get_all_messages_hook(self, dash, send_irc=True):
|
||||
"""
|
||||
Get all messages for all open trades.
|
||||
:return: dict of lists keyed by trade/contact ID
|
||||
:rtype: dict with lists
|
||||
"""
|
||||
messages_tmp = {}
|
||||
for contact_id in dash:
|
||||
messages = self.get_messages(contact_id, send_irc=send_irc)
|
||||
|
|
|
@ -12,7 +12,7 @@ class IRCCommands(object):
|
|||
"""
|
||||
Get details of open trades and post on IRC.
|
||||
"""
|
||||
trades = agora.dashboard(send_irc=False)
|
||||
trades = agora.dashboard(send_irc=False, formatted=True)
|
||||
if trades is False:
|
||||
msg("Error getting trades.")
|
||||
return
|
||||
|
@ -109,7 +109,11 @@ class IRCCommands(object):
|
|||
msg("Error getting accounts.")
|
||||
for account in accounts:
|
||||
if account["balance"] > 0:
|
||||
msg(f"{account['name']} {account['currency']}: {account['balance']}")
|
||||
if "name" in account:
|
||||
name = account["name"]
|
||||
else:
|
||||
name = "not_set"
|
||||
msg(f"{name} {account['currency']}: {account['balance']}")
|
||||
accounts_posted += 1
|
||||
if accounts_posted == 0:
|
||||
msg("No accounts with balances.")
|
||||
|
|
Loading…
Reference in New Issue