Reimplement messaging and implement bruteforce
This commit is contained in:
parent
1ee39989af
commit
21fce0e685
108
handler/agora.py
108
handler/agora.py
|
@ -61,7 +61,7 @@ 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
|
||||||
fmt = self.dashboard_hook(dash_tmp)
|
fmt = self.dashboard_hook(dash_tmp)
|
||||||
self.get_all_messages_hook(dash_tmp)
|
self.get_recent_messages()
|
||||||
if formatted:
|
if formatted:
|
||||||
return fmt
|
return fmt
|
||||||
return dash_tmp
|
return dash_tmp
|
||||||
|
@ -134,64 +134,39 @@ class Agora(object):
|
||||||
|
|
||||||
return dash_tmp
|
return dash_tmp
|
||||||
|
|
||||||
def get_messages(self, contact_id, send_irc=True):
|
def get_recent_messages(self, send_irc=True):
|
||||||
"""
|
"""
|
||||||
Get messages for a certain trade ID.
|
Get recent messages.
|
||||||
Post new messages to IRC and cache messages for the future.
|
|
||||||
:param contact_id: trade/contact ID
|
|
||||||
:return: list of messages
|
|
||||||
:rtype: list
|
|
||||||
"""
|
|
||||||
messages = self.agora.contact_messages(contact_id)
|
|
||||||
messages_tmp = []
|
|
||||||
reference = self.tx.tx_to_ref(contact_id)
|
|
||||||
if not reference:
|
|
||||||
reference = "not_set"
|
|
||||||
if "data" not in messages["response"]:
|
|
||||||
self.log.error("Malformed messages: {messages}", messages=messages)
|
|
||||||
return False
|
|
||||||
for message in messages["response"]["data"]["message_list"]:
|
|
||||||
messages_tmp.append(f"({message['sender']['username']}): {message['msg']}")
|
|
||||||
if send_irc:
|
|
||||||
if reference in self.last_messages:
|
|
||||||
if not len(self.last_messages[reference]) == len(messages_tmp):
|
|
||||||
difference = set(messages_tmp) ^ set(self.last_messages[reference])
|
|
||||||
for x in difference:
|
|
||||||
self.irc.client.msg(self.irc.client.channel, f"AUTO {reference}: {x}")
|
|
||||||
self.last_messages[reference] = messages_tmp
|
|
||||||
else:
|
|
||||||
self.last_messages[reference] = messages_tmp
|
|
||||||
for x in messages_tmp:
|
|
||||||
self.irc.client.msg(self.irc.client.channel, f"NEW {reference}: {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()
|
|
||||||
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 = {}
|
messages_tmp = {}
|
||||||
for contact_id in dash:
|
messages = self.agora.recent_messages()
|
||||||
|
if not messages["success"]:
|
||||||
|
return False
|
||||||
|
open_tx = self.tx.get_ref_map().keys()
|
||||||
|
for message in messages["response"]["data"]["message_list"]:
|
||||||
|
contact_id = message["contact_id"]
|
||||||
|
username = message["sender"]["username"]
|
||||||
|
msg = message["msg"]
|
||||||
|
if contact_id not in open_tx:
|
||||||
|
continue
|
||||||
reference = self.tx.tx_to_ref(contact_id)
|
reference = self.tx.tx_to_ref(contact_id)
|
||||||
if not reference:
|
if reference in messages_tmp:
|
||||||
reference = "not_set"
|
messages_tmp[reference].append([username, msg])
|
||||||
messages = self.get_messages(contact_id, send_irc=send_irc)
|
else:
|
||||||
if not messages:
|
messages_tmp[reference] = [[username, msg]]
|
||||||
return False
|
|
||||||
messages_tmp[reference] = messages
|
# Send new messages on IRC
|
||||||
|
if send_irc:
|
||||||
|
for user, message in messages_tmp[reference]:
|
||||||
|
if reference in self.last_messages:
|
||||||
|
if not [user, message] in self.last_messages[reference]:
|
||||||
|
self.irc.client.msg(self.irc.client.channel, f"AUTO {reference}: ({user}) {message}")
|
||||||
|
# Append sent messages to last_messages so we don't send them again
|
||||||
|
self.last_messages[reference].append([user, message])
|
||||||
|
else:
|
||||||
|
self.last_messages[reference] = [[user, message]]
|
||||||
|
for x in messages_tmp[reference]:
|
||||||
|
self.irc.client.msg(self.irc.client.channel, f"NEW {reference}: ({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
|
||||||
|
@ -265,6 +240,8 @@ class Agora(object):
|
||||||
:return: data about created object or error
|
:return: data about created object or error
|
||||||
:rtype: dict
|
:rtype: dict
|
||||||
"""
|
"""
|
||||||
|
ad = settings.Agora.Ad
|
||||||
|
ad = ad.replace("$CURRENCY$", currency)
|
||||||
rates = self.get_rates_all()
|
rates = self.get_rates_all()
|
||||||
if currency == "USD":
|
if currency == "USD":
|
||||||
min_amount = float(settings.Agora.MinUSD)
|
min_amount = float(settings.Agora.MinUSD)
|
||||||
|
@ -298,8 +275,9 @@ class Agora(object):
|
||||||
def dist_countries(self):
|
def dist_countries(self):
|
||||||
"""
|
"""
|
||||||
Distribute our advert into all countries listed in the config.
|
Distribute our advert into all countries listed in the config.
|
||||||
:return: True or False
|
Exits on errors.
|
||||||
:rtype: bool
|
:return: False or dict with response
|
||||||
|
:rtype: bool or dict
|
||||||
"""
|
"""
|
||||||
for currency, countrycode in loads(settings.Agora.DistList):
|
for currency, countrycode in loads(settings.Agora.DistList):
|
||||||
rtrn = self.create_ad(countrycode, currency)
|
rtrn = self.create_ad(countrycode, currency)
|
||||||
|
@ -307,6 +285,22 @@ class Agora(object):
|
||||||
return False
|
return False
|
||||||
yield rtrn
|
yield rtrn
|
||||||
|
|
||||||
|
def dist_bruteforce(self):
|
||||||
|
"""
|
||||||
|
Bruteforce all possible ads from the currencies and countries in the config.
|
||||||
|
Does not exit on errors.
|
||||||
|
:return: False or dict with response
|
||||||
|
:rtype: bool or dict
|
||||||
|
"""
|
||||||
|
currencies = loads(settings.Agora.BruteCurrencies)
|
||||||
|
countries = loads(settings.Agora.BruteCountries)
|
||||||
|
combinations = [[country, currency] for country in countries for currency in currencies]
|
||||||
|
for country, currency in combinations:
|
||||||
|
rtrn = self.create_ad(country, currency)
|
||||||
|
if not rtrn:
|
||||||
|
yield False
|
||||||
|
yield rtrn
|
||||||
|
|
||||||
def release_funds(self, contact_id):
|
def release_funds(self, contact_id):
|
||||||
"""
|
"""
|
||||||
Release funds for a contact_id.
|
Release funds for a contact_id.
|
||||||
|
|
|
@ -47,16 +47,16 @@ class IRCCommands(object):
|
||||||
Get all messages for all open trades or a given trade.
|
Get all messages for all open trades or a given trade.
|
||||||
"""
|
"""
|
||||||
if length == 1:
|
if length == 1:
|
||||||
messages = agora.get_all_messages(send_irc=False)
|
messages = agora.get_recent_messages()
|
||||||
if messages is False:
|
if messages is False:
|
||||||
msg("Error getting messages.")
|
msg("Error getting messages.")
|
||||||
return
|
return
|
||||||
if not messages:
|
if not messages:
|
||||||
msg("No messages.")
|
msg("No messages.")
|
||||||
return
|
return
|
||||||
for message_id in messages:
|
for reference in messages:
|
||||||
for message in messages[message_id]:
|
for message in messages[reference]:
|
||||||
msg(f"{message_id}: {message}")
|
msg(f"{reference}: {message[0]} {message[1]}")
|
||||||
msg("---")
|
msg("---")
|
||||||
|
|
||||||
elif length == 2:
|
elif length == 2:
|
||||||
|
@ -83,6 +83,18 @@ class IRCCommands(object):
|
||||||
else:
|
else:
|
||||||
msg(x["response"]["data"]["message"])
|
msg(x["response"]["data"]["message"])
|
||||||
|
|
||||||
|
class brute(object):
|
||||||
|
name = "brute"
|
||||||
|
authed = True
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
for x in agora.dist_bruteforce():
|
||||||
|
if x["success"]:
|
||||||
|
msg(f"{x['response']['data']['message']}: {x['response']['data']['ad_id']}")
|
||||||
|
else:
|
||||||
|
msg(x["response"]["data"]["message"])
|
||||||
|
|
||||||
class find(object):
|
class find(object):
|
||||||
name = "find"
|
name = "find"
|
||||||
authed = True
|
authed = True
|
||||||
|
@ -228,3 +240,16 @@ class IRCCommands(object):
|
||||||
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
rtrn = agora.nuke_ads()
|
rtrn = agora.nuke_ads()
|
||||||
msg(dumps(rtrn))
|
msg(dumps(rtrn))
|
||||||
|
|
||||||
|
class wallet(object):
|
||||||
|
name = "wallet"
|
||||||
|
authed = True
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
||||||
|
rtrn = agora.agora.wallet_balance_xmr()
|
||||||
|
if not rtrn["success"]:
|
||||||
|
msg("Error getting wallet details.")
|
||||||
|
return
|
||||||
|
balance = rtrn["response"]["data"]["total"]["balance"]
|
||||||
|
msg(f"Wallet balance: {balance}XMR")
|
||||||
|
|
Loading…
Reference in New Issue