121 lines
3.7 KiB
Python
121 lines
3.7 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)
|
|
if not trades:
|
|
msg("No open trades.")
|
|
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_all_messages()
|
|
if not messages:
|
|
msg("No messages.")
|
|
for message_id in messages:
|
|
for message in messages[message_id]:
|
|
msg(f"{message_id}: {message}")
|
|
msg("---")
|
|
|
|
elif length == 2:
|
|
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
|
|
rtrn = agora.dist_countries()
|
|
msg(dumps(rtrn))
|
|
|
|
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()
|
|
for account in accounts:
|
|
if account["balance"] > 0:
|
|
msg(f"{account['name']} {account['currency']}: {account['balance']}")
|
|
|
|
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 not total_usd:
|
|
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!")
|