256 lines
8.1 KiB
Python
256 lines
8.1 KiB
Python
# Other library imports
|
|
from json import dumps
|
|
|
|
|
|
class IRCCommands(object):
|
|
class trades(object):
|
|
name = "trades"
|
|
authed = True
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
|
"""
|
|
Get details of open trades and post on IRC.
|
|
"""
|
|
trades = agora.dashboard(send_irc=False, formatted=True)
|
|
if trades is False:
|
|
msg("Error getting trades.")
|
|
return
|
|
if not trades:
|
|
msg("No open trades.")
|
|
return
|
|
for trade_id in trades:
|
|
msg(trade_id)
|
|
|
|
class create(object):
|
|
name = "create"
|
|
authed = True
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
|
"""
|
|
Post an ad on AgoraDesk with the given country and currency code.
|
|
"""
|
|
posted = agora.create_ad(spl[1], spl[2])
|
|
if posted["success"]:
|
|
msg(f"{posted['response']['data']['message']}: {posted['response']['data']['ad_id']}")
|
|
else:
|
|
msg(posted["response"]["data"]["message"])
|
|
|
|
class messages(object):
|
|
name = "messages"
|
|
authed = True
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
|
"""
|
|
Get all messages for all open trades or a given trade.
|
|
"""
|
|
if length == 1:
|
|
messages = agora.get_recent_messages()
|
|
if messages is False:
|
|
msg("Error getting messages.")
|
|
return
|
|
if not messages:
|
|
msg("No messages.")
|
|
return
|
|
for reference in messages:
|
|
for message in messages[reference]:
|
|
msg(f"{reference}: {message[0]} {message[1]}")
|
|
msg("---")
|
|
|
|
elif length == 2:
|
|
tx = tx.ref_to_tx(spl[1])
|
|
if not tx:
|
|
msg(f"No such reference: {spl[1]}")
|
|
return
|
|
messages = agora.get_messages(spl[1], send_irc=False)
|
|
if not messages:
|
|
msg("No messages.")
|
|
for message in messages:
|
|
msg(f"{spl[1]}: {message}")
|
|
|
|
class dist(object):
|
|
name = "dist"
|
|
authed = True
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
|
# Distribute out our ad to all countries in the config
|
|
for x in agora.dist_countries():
|
|
if x["success"]:
|
|
msg(f"{x['response']['data']['message']}: {x['response']['data']['ad_id']}")
|
|
else:
|
|
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):
|
|
name = "find"
|
|
authed = True
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
|
"""
|
|
Find a transaction received by Revolut with the given reference and amount.
|
|
"""
|
|
try:
|
|
int(spl[2])
|
|
except ValueError:
|
|
msg("Amount is not an integer.")
|
|
rtrn = tx.find_tx(spl[1], spl[2])
|
|
if rtrn == "AMOUNT_INVALID":
|
|
msg("Reference found but amount invalid.")
|
|
elif not rtrn:
|
|
msg("Reference not found.")
|
|
else:
|
|
return dumps(rtrn)
|
|
|
|
class accounts(object):
|
|
name = "accounts"
|
|
authed = True
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
|
accounts = revolut.accounts()
|
|
accounts_posted = 0
|
|
if accounts is None:
|
|
msg("Error getting accounts.")
|
|
for account in accounts:
|
|
if account["balance"] > 0:
|
|
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.")
|
|
|
|
class total(object):
|
|
name = "total"
|
|
authed = True
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
|
total_usd = revolut.get_total_usd()
|
|
if total_usd is False:
|
|
msg("Error getting total balance.")
|
|
msg(f"Total: {round(total_usd, 2)}USD")
|
|
|
|
class ping(object):
|
|
name = "ping"
|
|
authed = False
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg):
|
|
msg("Pong!")
|
|
|
|
class release_url(object):
|
|
name = "release_url"
|
|
authed = True
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
|
trades = agora.dashboard_release_urls()
|
|
if not trades:
|
|
msg("No trades.")
|
|
for trade in trades:
|
|
msg(trade)
|
|
|
|
class message(object):
|
|
name = "msg"
|
|
authed = True
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
|
if length > 2:
|
|
full_msg = " ".join(spl[2:])
|
|
reference = tx.ref_to_tx(spl[1])
|
|
if not reference:
|
|
msg(f"No such reference: {spl[1]}")
|
|
return
|
|
rtrn = agora.agora.contact_message_post(reference, full_msg)
|
|
msg(f"Sent {full_msg} to {reference}: {rtrn}")
|
|
|
|
class refs(object):
|
|
name = "refs"
|
|
authed = True
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
|
msg(f"References: {', '.join(tx.get_refs())}")
|
|
|
|
class ref(object):
|
|
name = "ref"
|
|
authed = True
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
|
if length == 2:
|
|
ref_data = tx.get_ref(spl[1])
|
|
if not ref_data:
|
|
msg(f"No such reference: {spl[1]}")
|
|
return
|
|
msg(f"{spl[1]}: {dumps(ref_data)}")
|
|
|
|
class delete(object):
|
|
name = "del"
|
|
authed = True
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
|
if length == 2:
|
|
ref_data = tx.get_ref(spl[1])
|
|
if not ref_data:
|
|
msg(f"No such reference: {spl[1]}")
|
|
return
|
|
tx.del_ref(spl[1])
|
|
msg(f"Deleted reference: {spl[1]}")
|
|
|
|
class release(object):
|
|
name = "release"
|
|
authed = True
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
|
if length == 2:
|
|
tx = tx.ref_to_tx(spl[1])
|
|
if not tx:
|
|
msg(f"No such reference: {spl[1]}")
|
|
return
|
|
rtrn = agora.release_funds(tx)
|
|
msg(dumps(rtrn))
|
|
|
|
class nuke(object):
|
|
name = "nuke"
|
|
authed = True
|
|
|
|
@staticmethod
|
|
def run(cmd, spl, length, authed, msg, agora, revolut, tx):
|
|
rtrn = agora.nuke_ads()
|
|
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")
|