Reformat project

This commit is contained in:
2022-07-15 11:09:54 +01:00
parent 933642def6
commit ea81748c0a
29 changed files with 6924 additions and 1009 deletions

View File

@@ -5,9 +5,8 @@
# Project imports
# from settings import settings
import util
import ux.irc
import ux.commands
import ux.irc
import ux.notify
import ux.verify

View File

@@ -1,9 +1,9 @@
# Other library imports
from json import dumps, loads
import db
# Project imports
from settings import settings
import db
class GenericCommands(object):
@@ -27,7 +27,19 @@ class GenericCommands(object):
class create(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux, asset_list, provider_list, caller):
def run(
cmd,
spl,
length,
authed,
msg,
agora,
tx,
ux,
asset_list,
provider_list,
caller,
):
"""
Post an ad on AgoraDesk/LBTC with the given country and currency code.
"""
@@ -47,7 +59,9 @@ class GenericCommands(object):
payment_details=account_info[currency],
)
if posted["success"]:
msg(f"{posted['response']['data']['message']}: {posted['response']['data']['ad_id']}")
msg(
f"{posted['response']['data']['message']}: {posted['response']['data']['ad_id']}"
)
else:
msg(dumps(posted["response"]))
elif length == 5:
@@ -70,7 +84,9 @@ class GenericCommands(object):
payment_details=account_info[currency],
)
if posted["success"]:
msg(f"{posted['response']['data']['message']}: {posted['response']['data']['ad_id']}")
msg(
f"{posted['response']['data']['message']}: {posted['response']['data']['ad_id']}"
)
else:
msg(dumps(posted["response"]))
@@ -106,13 +122,17 @@ class GenericCommands(object):
return
for x in caller.dist_countries(filter_asset=asset):
if x["success"]:
msg(f"{x['response']['data']['message']}: {x['response']['data']['ad_id']}")
msg(
f"{x['response']['data']['message']}: {x['response']['data']['ad_id']}"
)
else:
msg(dumps(x["response"]))
elif length == 1:
for x in caller.dist_countries():
if x["success"]:
msg(f"{x['response']['data']['message']}: {x['response']['data']['ad_id']}")
msg(
f"{x['response']['data']['message']}: {x['response']['data']['ad_id']}"
)
else:
msg(dumps(x["response"]))
@@ -188,7 +208,9 @@ class GenericCommands(object):
return
providers = spl[3].split(",")
currency = spl[2]
c = caller.get_all_public_ads(assets=[asset], currencies=[currency], providers=providers)
c = caller.get_all_public_ads(
assets=[asset], currencies=[currency], providers=providers
)
c.addCallback(GenericCommands.pubads.got_pubads, currency, msg)
class cheat(object):
@@ -268,7 +290,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.trades.run(cmd, spl, length, authed, msg, agora, tx, ux, agora)
GenericCommands.trades.run(
cmd, spl, length, authed, msg, agora, tx, ux, agora
)
class ltrades(object):
authed = True
@@ -277,7 +301,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.trades.run(cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc)
GenericCommands.trades.run(
cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc
)
class acreate(object):
name = "acreate"
@@ -328,7 +354,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.messages.run(cmd, spl, length, authed, msg, agora, tx, ux, agora)
GenericCommands.messages.run(
cmd, spl, length, authed, msg, agora, tx, ux, agora
)
class lmessages(object):
authed = True
@@ -337,7 +365,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.messages.run(cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc)
GenericCommands.messages.run(
cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc
)
class adist(object):
authed = True
@@ -346,7 +376,18 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.dist.run(cmd, spl, length, authed, msg, agora, tx, ux, settings.Agora.AssetList, agora)
GenericCommands.dist.run(
cmd,
spl,
length,
authed,
msg,
agora,
tx,
ux,
settings.Agora.AssetList,
agora,
)
class ldist(object):
authed = True
@@ -356,7 +397,16 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.dist.run(
cmd, spl, length, authed, msg, agora, tx, ux, settings.LocalBitcoins.AssetList, tx.lbtc
cmd,
spl,
length,
authed,
msg,
agora,
tx,
ux,
settings.LocalBitcoins.AssetList,
tx.lbtc,
)
class aredist(object):
@@ -366,7 +416,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.redist.run(cmd, spl, length, authed, msg, agora, tx, ux, agora)
GenericCommands.redist.run(
cmd, spl, length, authed, msg, agora, tx, ux, agora
)
class lredist(object):
authed = True
@@ -375,7 +427,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.redist.run(cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc)
GenericCommands.redist.run(
cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc
)
class astripdupes(object):
authed = True
@@ -384,7 +438,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.stripdupes.run(cmd, spl, length, authed, msg, agora, tx, ux, agora)
GenericCommands.stripdupes.run(
cmd, spl, length, authed, msg, agora, tx, ux, agora
)
class lstripdupes(object):
authed = True
@@ -393,7 +449,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.stripdupes.run(cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc)
GenericCommands.stripdupes.run(
cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc
)
class total(object):
name = "total"
@@ -440,7 +498,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.message.run(cmd, spl, length, authed, msg, agora, tx, ux, agora.agora)
GenericCommands.message.run(
cmd, spl, length, authed, msg, agora, tx, ux, agora.agora
)
class lmessage(object):
authed = True
@@ -449,7 +509,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.message.run(cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc.lbtc)
GenericCommands.message.run(
cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc.lbtc
)
class refs(object):
name = "refs"
@@ -496,7 +558,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.release.run(cmd, spl, length, authed, msg, agora, tx, ux, agora)
GenericCommands.release.run(
cmd, spl, length, authed, msg, agora, tx, ux, agora
)
class lrelease(object):
authed = True
@@ -505,7 +569,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.release.run(cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc)
GenericCommands.release.run(
cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc
)
class map(object):
name = "map"
@@ -535,7 +601,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.nuke.run(cmd, spl, length, authed, msg, agora, tx, ux, agora)
GenericCommands.nuke.run(
cmd, spl, length, authed, msg, agora, tx, ux, agora
)
class lnuke(object):
authed = True
@@ -544,7 +612,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.nuke.run(cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc)
GenericCommands.nuke.run(
cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc
)
class awallet(object):
authed = True
@@ -553,7 +623,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.wallet.run(cmd, spl, length, authed, msg, agora, tx, ux, True, agora.api)
GenericCommands.wallet.run(
cmd, spl, length, authed, msg, agora, tx, ux, True, agora.api
)
class lwallet(object):
authed = True
@@ -562,7 +634,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.wallet.run(cmd, spl, length, authed, msg, agora, tx, ux, False, tx.lbtc.api)
GenericCommands.wallet.run(
cmd, spl, length, authed, msg, agora, tx, ux, False, tx.lbtc.api
)
class apubads(object):
authed = True
@@ -571,7 +645,18 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.pubads.run(cmd, spl, length, authed, msg, agora, tx, ux, settings.Agora.AssetList, agora)
GenericCommands.pubads.run(
cmd,
spl,
length,
authed,
msg,
agora,
tx,
ux,
settings.Agora.AssetList,
agora,
)
class lpubads(object):
authed = True
@@ -581,7 +666,16 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.pubads.run(
cmd, spl, length, authed, msg, agora, tx, ux, settings.LocalBitcoins.AssetList, tx.lbtc
cmd,
spl,
length,
authed,
msg,
agora,
tx,
ux,
settings.LocalBitcoins.AssetList,
tx.lbtc,
)
class acheat(object):
@@ -591,7 +685,18 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.cheat.run(cmd, spl, length, authed, msg, agora, tx, ux, settings.Agora.AssetList, agora)
GenericCommands.cheat.run(
cmd,
spl,
length,
authed,
msg,
agora,
tx,
ux,
settings.Agora.AssetList,
agora,
)
class lcheat(object):
authed = True
@@ -601,7 +706,16 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.cheat.run(
cmd, spl, length, authed, msg, agora, tx, ux, settings.LocalBitcoins.AssetList, tx.lbtc
cmd,
spl,
length,
authed,
msg,
agora,
tx,
ux,
settings.LocalBitcoins.AssetList,
tx.lbtc,
)
class acheatnext(object):
@@ -611,7 +725,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.cheatnext.run(cmd, spl, length, authed, msg, agora, tx, ux, agora)
GenericCommands.cheatnext.run(
cmd, spl, length, authed, msg, agora, tx, ux, agora
)
class lcheatnext(object):
authed = True
@@ -620,7 +736,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.cheatnext.run(cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc)
GenericCommands.cheatnext.run(
cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc
)
class aads(object):
authed = True
@@ -638,7 +756,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.ads.run(cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc)
GenericCommands.ads.run(
cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc
)
class xmr(object):
name = "xmr"
@@ -647,7 +767,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
xmr_prices = agora.money.cg.get_price(ids="monero", vs_currencies=["sek", "usd", "gbp"])
xmr_prices = agora.money.cg.get_price(
ids="monero", vs_currencies=["sek", "usd", "gbp"]
)
price_sek = xmr_prices["monero"]["sek"]
price_usd = xmr_prices["monero"]["usd"]
price_gbp = xmr_prices["monero"]["gbp"]
@@ -660,7 +782,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
xmr_prices = agora.money.cg.get_price(ids="bitcoin", vs_currencies=["sek", "usd", "gbp"])
xmr_prices = agora.money.cg.get_price(
ids="bitcoin", vs_currencies=["sek", "usd", "gbp"]
)
price_sek = xmr_prices["bitcoin"]["sek"]
price_usd = xmr_prices["bitcoin"]["usd"]
price_gbp = xmr_prices["bitcoin"]["gbp"]
@@ -673,7 +797,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.withdraw.run(cmd, spl, length, authed, msg, agora, tx, ux, agora)
GenericCommands.withdraw.run(
cmd, spl, length, authed, msg, agora, tx, ux, agora
)
class lwithdraw(object):
authed = True
@@ -682,7 +808,9 @@ class IRCCommands(object):
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
GenericCommands.withdraw.run(cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc)
GenericCommands.withdraw.run(
cmd, spl, length, authed, msg, agora, tx, ux, tx.lbtc
)
class remaining(object):
name = "r"
@@ -807,7 +935,9 @@ class IRCCommands(object):
account = spl[1]
accounts = tx.sinks.truelayer.get_accounts(account)
for account in accounts["results"]:
msg(f"{account['account_id']} {account['display_name']} {account['currency']}")
msg(
f"{account['account_id']} {account['display_name']} {account['currency']}"
)
class naccounts(object):
name = "naccounts"
@@ -870,7 +1000,9 @@ class IRCCommands(object):
if length == 2:
account_id = spl[1]
transactions = tx.sinks.nordigen.get_transactions(account_id)
transactions.addCallback(IRCCommands.ntransactions.got_transactions, msg)
transactions.addCallback(
IRCCommands.ntransactions.got_transactions, msg
)
class nreqs(object):
name = "nreqs"
@@ -964,7 +1096,9 @@ class IRCCommands(object):
accounts_active.append(account)
accounts_all = tx.sinks.truelayer.get_accounts(bank)
accounts_unmapped = [
x["account_id"] for x in accounts_all["results"] if x["account_id"] not in accounts_active
x["account_id"]
for x in accounts_all["results"]
if x["account_id"] not in accounts_active
]
msg(f"Unmapped accounts: {', '.join(accounts_unmapped)}")
@@ -982,7 +1116,9 @@ class IRCCommands(object):
class authlink(object):
name = "authlink"
authed = True
helptext = "Create a URL for identity verification. Usage: authlink <identifier>"
helptext = (
"Create a URL for identity verification. Usage: authlink <identifier>"
)
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
@@ -994,7 +1130,9 @@ class IRCCommands(object):
class checkauth(object):
name = "checkauth"
authed = True
helptext = "Check the authentication for an identifier. Usage: checkauth <identifier>"
helptext = (
"Check the authentication for an identifier. Usage: checkauth <identifier>"
)
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):
@@ -1013,8 +1151,12 @@ class IRCCommands(object):
if length == 3:
platform = spl[1]
currency = spl[2]
account_info = tx.markets.get_matching_account_details(platform, currency)
bank_details = tx.markets.format_payment_details(currency, account_info, real=True)
account_info = tx.markets.get_matching_account_details(
platform, currency
)
bank_details = tx.markets.format_payment_details(
currency, account_info, real=True
)
if not bank_details:
msg("Could not get bank details.")
return
@@ -1023,7 +1165,9 @@ class IRCCommands(object):
class id(object):
name = "id"
authed = True
helptext = "Get the identity information of a user. Usage: id <platform> <username>"
helptext = (
"Get the identity information of a user. Usage: id <platform> <username>"
)
@staticmethod
def run(cmd, spl, length, authed, msg, agora, tx, ux):

View File

@@ -1,11 +1,10 @@
# Twisted/Klein imports
from twisted.words.protocols import irc
from twisted.internet import protocol, reactor, ssl
import util
# Project imports
from settings import settings
from twisted.internet import protocol, reactor, ssl
from twisted.words.protocols import irc
from ux.commands import IRCCommands
import util
class IRCBot(irc.IRCClient):
@@ -18,7 +17,9 @@ class IRCBot(irc.IRCClient):
self.log = log
self.cmd = IRCCommands()
# Parse the commands into "commandname": "commandclass"
self.cmdhash = {getattr(self.cmd, x).name: x for x in dir(self.cmd) if not x.startswith("_")}
self.cmdhash = {
getattr(self.cmd, x).name: x for x in dir(self.cmd) if not x.startswith("_")
}
self.nickname = settings.IRC.Nick
self.password = settings.IRC.Pass
self.realname = self.nickname

View File

@@ -1,9 +1,8 @@
# Other library imports
import requests
import util
# Project imports
from settings import settings
import util
class Notify(util.Base):

View File

@@ -1,13 +1,13 @@
# Other library imports
import requests
import hashlib
import hmac
import time
import json
import time
import requests
import util
# Project imports
from settings import settings
import util
class Verify(util.Base):
@@ -35,7 +35,9 @@ class Verify(util.Base):
"""
self.antifraud.user_verification_successful(external_user_id)
def update_verification_status(self, external_user_id, review_status, review_answer=None):
def update_verification_status(
self, external_user_id, review_status, review_answer=None
):
"""
Update the authentication status of a external user ID.
"""
@@ -46,7 +48,11 @@ class Verify(util.Base):
if type(content) == str:
content = content.encode("utf-8")
# hmac needs bytes
signature = hmac.new(settings.Verify.WebHookSecret.encode("utf-8"), content, digestmod=hashlib.sha1).hexdigest()
signature = hmac.new(
settings.Verify.WebHookSecret.encode("utf-8"),
content,
digestmod=hashlib.sha1,
).hexdigest()
return signature == payload_digest
@@ -68,7 +74,9 @@ class Verify(util.Base):
if "reviewAnswer" in content_json["reviewResult"]:
review_answer = content_json["reviewResult"]["reviewAnswer"]
self.update_verification_status(external_user_id, review_status, review_answer=review_answer)
self.update_verification_status(
external_user_id, review_status, review_answer=review_answer
)
return True
def handle_callback(self, request):
@@ -137,7 +145,10 @@ class Verify(util.Base):
"""
Get the status of an applicant by the external user ID.
"""
url = settings.Verify.Base + f"/resources/applicants/-;externalUserId={external_user_id}/one"
url = (
settings.Verify.Base
+ f"/resources/applicants/-;externalUserId={external_user_id}/one"
)
resp = self.sign_request(requests.Request("GET", url))
s = requests.Session()
response = s.send(resp)
@@ -173,10 +184,19 @@ class Verify(util.Base):
"""
Get an access token for an external user ID.
"""
params = {"userId": external_user_id, "ttlInSecs": "600", "levelName": level_name}
params = {
"userId": external_user_id,
"ttlInSecs": "600",
"levelName": level_name,
}
headers = {"Content-Type": "application/json", "Content-Encoding": "utf-8"}
resp = self.sign_request(
requests.Request("POST", f"{settings.Verify.Base}/resources/accessTokens", params=params, headers=headers)
requests.Request(
"POST",
f"{settings.Verify.Base}/resources/accessTokens",
params=params,
headers=headers,
)
)
s = requests.Session()
response = s.send(resp)
@@ -196,9 +216,16 @@ class Verify(util.Base):
body = b"" if prepared_request.body is None else prepared_request.body
if type(body) == str:
body = body.encode("utf-8")
data_to_sign = str(now).encode("utf-8") + method.encode("utf-8") + path_url.encode("utf-8") + body
data_to_sign = (
str(now).encode("utf-8")
+ method.encode("utf-8")
+ path_url.encode("utf-8")
+ body
)
# hmac needs bytes
signature = hmac.new(settings.Verify.Key.encode("utf-8"), data_to_sign, digestmod=hashlib.sha256)
signature = hmac.new(
settings.Verify.Key.encode("utf-8"), data_to_sign, digestmod=hashlib.sha256
)
prepared_request.headers["X-App-Token"] = settings.Verify.Token
prepared_request.headers["X-App-Access-Ts"] = str(now)
prepared_request.headers["X-App-Access-Sig"] = signature.hexdigest()