Fix dashboard stuff

This commit is contained in:
Mark Veidemanis 2022-05-03 08:50:33 +01:00
parent f8521eced3
commit 2bf05eafa7
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 47 additions and 29 deletions

View File

@ -44,7 +44,6 @@ class Agora(util.Base):
""" """
Set up the LoopingCall to get all active trades and messages. Set up the LoopingCall to get all active trades and messages.
""" """
self.loop_check()
self.log.debug("Setting up loops.") self.log.debug("Setting up loops.")
self.lc_dash = LoopingCall(self.loop_check) self.lc_dash = LoopingCall(self.loop_check)
self.lc_dash.start(int(settings.Agora.RefreshSec)) self.lc_dash.start(int(settings.Agora.RefreshSec))
@ -66,8 +65,8 @@ class Agora(util.Base):
return False return False
if dash is False: if dash is False:
return False return False
if dash["response"] is None: # if dash["response"] is None:
return False # return False
dash_tmp = {} dash_tmp = {}
if not dash.items(): if not dash.items():
return False return False
@ -91,11 +90,12 @@ class Agora(util.Base):
m = self.agora.recent_messages() m = self.agora.recent_messages()
m.addCallback(self.got_recent_messages) m.addCallback(self.got_recent_messages)
@inlineCallbacks
def get_dashboard_irc(self): def get_dashboard_irc(self):
""" """
Get dashboard helper for IRC only. Get dashboard helper for IRC only.
""" """
dash = self.wrap_dashboard() dash = yield self.wrap_dashboard()
rtrn = [] rtrn = []
if dash is False: if dash is False:
return False return False
@ -112,7 +112,12 @@ class Agora(util.Base):
provider = contact["data"]["advertisement"]["payment_method"] provider = contact["data"]["advertisement"]["payment_method"]
if not contact["data"]["is_selling"]: if not contact["data"]["is_selling"]:
continue continue
rtrn.append(f"{reference}: {buyer} {amount}{currency} {provider} {amount_crypto}{asset}") rtrn.append(
(
f"[#] [{reference}] ({self.platform}) <{buyer}>"
f" {amount}{currency} {provider} {amount_crypto}{asset}"
)
)
return rtrn return rtrn
def dashboard_hook(self, dash): def dashboard_hook(self, dash):
@ -142,7 +147,7 @@ class Agora(util.Base):
continue continue
if reference not in self.last_dash: if reference not in self.last_dash:
reference = self.tx.new_trade( reference = self.tx.new_trade(
"agora", self.platform,
asset, asset,
contact_id, contact_id,
buyer, buyer,
@ -155,7 +160,12 @@ class Agora(util.Base):
if reference not in current_trades: if reference not in current_trades:
current_trades.append(reference) current_trades.append(reference)
# Let us know there is a new trade # Let us know there is a new trade
self.irc.sendmsg(f"AUTO {reference}: {buyer} {amount}{currency} {provider} {amount_crypto}{asset}") self.irc.sendmsg(
(
f"[#] [{reference}] ({self.platform}) <{buyer}>"
f" {amount}{currency} {provider} {amount_crypto}{asset}"
)
)
# Note that we have seen this reference # Note that we have seen this reference
self.last_dash.add(reference) self.last_dash.add(reference)
@ -165,7 +175,7 @@ class Agora(util.Base):
self.last_dash.remove(ref) self.last_dash.remove(ref)
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(self.platform, current_trades)
def got_recent_messages(self, messages, send_irc=True): def got_recent_messages(self, messages, send_irc=True):
""" """
@ -194,16 +204,16 @@ class Agora(util.Base):
# Send new messages on IRC # Send new messages on IRC
if send_irc: if send_irc:
for user, message in messages_tmp[reference]: for user, message in messages_tmp[reference][::-1]:
if reference in self.last_messages: if reference in self.last_messages:
if not [user, message] in self.last_messages[reference]: if not [user, message] in self.last_messages[reference]:
self.irc.sendmsg(f"AUTO {reference}: ({user}) {message}") self.irc.sendmsg(f"[{reference}] ({self.platform}) <{user}> {message}")
# Append sent messages to last_messages so we don't send them again # Append sent messages to last_messages so we don't send them again
self.last_messages[reference].append([user, message]) self.last_messages[reference].append([user, message])
else: else:
self.last_messages[reference] = [[user, message]] self.last_messages[reference] = [[user, message]]
for x in messages_tmp[reference]: for x in messages_tmp[reference]:
self.irc.sendmsg(f"NEW {reference}: ({user}) {message}") self.irc.sendmsg(f"[{reference}] ({self.platform}) <{user}> {message}")
# Purge old trades from cache # Purge old trades from cache
for ref in list(self.last_messages): # We're removing from the list on the fly for ref in list(self.last_messages): # We're removing from the list on the fly
@ -349,7 +359,7 @@ class Agora(util.Base):
return False return False
# Get the ads to update # Get the ads to update
to_update = self.markets.get_new_ad_equations("agora", public_ads, assets) to_update = self.markets.get_new_ad_equations(self.platform, public_ads, assets)
self.slow_ad_update(to_update) self.slow_ad_update(to_update)
# TODO: make generic and move to markets # TODO: make generic and move to markets
@ -417,7 +427,7 @@ class Agora(util.Base):
cast["type"] = msgtype cast["type"] = msgtype
cast["ts"] = str(datetime.now().isoformat()) cast["ts"] = str(datetime.now().isoformat())
cast["xtype"] = "platorm" cast["xtype"] = "platorm"
cast["market"] = "agora" cast["market"] = self.platform
self.es.index(index=settings.ES.MetaIndex, document=cast) self.es.index(index=settings.ES.MetaIndex, document=cast)
def slow_ad_update(self, ads): def slow_ad_update(self, ads):

View File

@ -44,8 +44,6 @@ class LBTC(util.Base):
""" """
Set up the LoopingCall to get all active trades and messages. Set up the LoopingCall to get all active trades and messages.
""" """
self.log.debug("Running loop check.")
self.loop_check()
self.log.debug("Setting up loops.") self.log.debug("Setting up loops.")
self.lc_dash = LoopingCall(self.loop_check) self.lc_dash = LoopingCall(self.loop_check)
self.lc_dash.start(int(settings.LocalBitcoins.RefreshSec)) self.lc_dash.start(int(settings.LocalBitcoins.RefreshSec))
@ -59,16 +57,16 @@ class LBTC(util.Base):
dash_tmp = yield self.wrap_dashboard(dash) dash_tmp = yield self.wrap_dashboard(dash)
self.dashboard_hook(dash_tmp) self.dashboard_hook(dash_tmp)
@util.handle_exceptions @inlineCallbacks
def wrap_dashboard(self, dash=None): # backwards compatibility with TX def wrap_dashboard(self, dash=None): # backwards compatibility with TX
if not dash: if not dash:
dash = self.lbtc.dashboard() # no dashboard_seller for lbtc dash = yield self.lbtc.dashboard() # no dashboard_seller for lbtc
if dash is None: if dash is None:
return False return False
if dash is False: if dash is False:
return False return False
if dash["response"] is None: # if dash["response"] is None:
return False # return False
dash_tmp = {} dash_tmp = {}
if not dash.items(): if not dash.items():
return False return False
@ -92,11 +90,12 @@ class LBTC(util.Base):
m = self.lbtc.recent_messages() m = self.lbtc.recent_messages()
m.addCallback(self.got_recent_messages) m.addCallback(self.got_recent_messages)
@inlineCallbacks
def get_dashboard_irc(self): def get_dashboard_irc(self):
""" """
Get dashboard helper for IRC only. Get dashboard helper for IRC only.
""" """
dash = self.wrap_dashboard() dash = yield self.wrap_dashboard()
rtrn = [] rtrn = []
if dash is False: if dash is False:
return False return False
@ -111,7 +110,12 @@ class LBTC(util.Base):
provider = contact["data"]["advertisement"]["payment_method"] provider = contact["data"]["advertisement"]["payment_method"]
if not contact["data"]["is_selling"]: if not contact["data"]["is_selling"]:
continue continue
rtrn.append(f"{reference}: {buyer} {amount}{currency} {provider} {amount_crypto}{asset}") rtrn.append(
(
f"[#] [{reference}] ({self.platform}) <{buyer}>"
f" {amount}{currency} {provider} {amount_crypto}{asset}"
)
)
return rtrn return rtrn
def dashboard_hook(self, dash): def dashboard_hook(self, dash):
@ -139,7 +143,7 @@ class LBTC(util.Base):
continue continue
if reference not in self.last_dash: if reference not in self.last_dash:
reference = self.tx.new_trade( reference = self.tx.new_trade(
"lbtc", self.platform,
asset, asset,
contact_id, contact_id,
buyer, buyer,
@ -152,17 +156,21 @@ class LBTC(util.Base):
if reference not in current_trades: if reference not in current_trades:
current_trades.append(reference) current_trades.append(reference)
# Let us know there is a new trade # Let us know there is a new trade
self.irc.sendmsg(f"AUTO {reference}: {buyer} {amount}{currency} {provider} {amount_crypto}{asset}") self.irc.sendmsg(
(
f"[#] [{reference}] ({self.platform}) <{buyer}>"
f" {amount}{currency} {provider} {amount_crypto}{asset}"
)
)
# Note that we have seen this reference # Note that we have seen this reference
self.last_dash.add(reference) self.last_dash.add(reference)
# Purge old trades from cache # Purge old trades from cache
for ref in list(self.last_dash): # We're removing from the list on the fly for ref in list(self.last_dash): # We're removing from the list on the fly
if ref not in current_trades: if ref not in current_trades:
self.last_dash.remove(ref) self.last_dash.remove(ref)
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(self.platform, current_trades)
@util.handle_exceptions @util.handle_exceptions
def got_recent_messages(self, messages, send_irc=True): def got_recent_messages(self, messages, send_irc=True):
@ -192,16 +200,16 @@ class LBTC(util.Base):
# Send new messages on IRC # Send new messages on IRC
if send_irc: if send_irc:
for user, message in messages_tmp[reference]: for user, message in messages_tmp[reference][::-1]:
if reference in self.last_messages: if reference in self.last_messages:
if not [user, message] in self.last_messages[reference]: if not [user, message] in self.last_messages[reference]:
self.irc.sendmsg(f"AUTO {reference}: ({user}) {message}") self.irc.sendmsg(f"[{reference}] ({self.platform}) <{user}> {message}")
# Append sent messages to last_messages so we don't send them again # Append sent messages to last_messages so we don't send them again
self.last_messages[reference].append([user, message]) self.last_messages[reference].append([user, message])
else: else:
self.last_messages[reference] = [[user, message]] self.last_messages[reference] = [[user, message]]
for x in messages_tmp[reference]: for x in messages_tmp[reference]:
self.irc.sendmsg(f"NEW {reference}: ({user}) {message}") self.irc.sendmsg(f"[{reference}] ({self.platform}) <{user}> {message}")
# Purge old trades from cache # Purge old trades from cache
for ref in list(self.last_messages): # We're removing from the list on the fly for ref in list(self.last_messages): # We're removing from the list on the fly