Reformat legacy project
This commit is contained in:
@@ -2,12 +2,11 @@ import functools
|
||||
from json import JSONDecodeError, dumps, loads
|
||||
from string import digits
|
||||
|
||||
from klein import Klein
|
||||
from twisted.web.server import Request
|
||||
|
||||
import main
|
||||
from klein import Klein
|
||||
from modules import chankeep, helpers, provision, regproc, userinfo
|
||||
from modules.network import Network
|
||||
from twisted.web.server import Request
|
||||
from utils.logging.log import warn
|
||||
|
||||
|
||||
@@ -217,7 +216,12 @@ class API(object):
|
||||
for net_name in nets:
|
||||
conns = helpers.get_connected_relays(net_name)
|
||||
if not conns:
|
||||
return dumps({"success": False, "reason": f"failed to get instances for {net_name}."})
|
||||
return dumps(
|
||||
{
|
||||
"success": False,
|
||||
"reason": f"failed to get instances for {net_name}.",
|
||||
}
|
||||
)
|
||||
if func == "recheckauth":
|
||||
for conn in conns:
|
||||
conn.regPing(reset=True)
|
||||
@@ -279,18 +283,24 @@ class API(object):
|
||||
elif item == "last":
|
||||
last = data[item][0]
|
||||
if not last.isdigit():
|
||||
return dumps({"success": False, "reason": "invalid last: not a number."})
|
||||
return dumps(
|
||||
{"success": False, "reason": "invalid last: not a number."}
|
||||
)
|
||||
elif item == "port":
|
||||
port = data[item][0]
|
||||
if not port.isdigit():
|
||||
return dumps({"success": False, "reason": "invalid port: not a number."})
|
||||
return dumps(
|
||||
{"success": False, "reason": "invalid port: not a number."}
|
||||
)
|
||||
port = int(port)
|
||||
elif item == "chanlimit":
|
||||
chanlimit = data[item][0]
|
||||
if chanlimit == "None":
|
||||
chanlimit = None
|
||||
elif not chanlimit.isdigit():
|
||||
return dumps({"success": False, "reason": "invalid chanlimit: not a number."})
|
||||
return dumps(
|
||||
{"success": False, "reason": "invalid chanlimit: not a number."}
|
||||
)
|
||||
else:
|
||||
chanlimit = int(chanlimit)
|
||||
online_relays = helpers.get_connected_relays(net)
|
||||
@@ -324,9 +334,16 @@ class API(object):
|
||||
if item == "net":
|
||||
net = data[item]
|
||||
if net in main.network.keys():
|
||||
return dumps({"success": False, "reason": "network already exists."})
|
||||
return dumps(
|
||||
{"success": False, "reason": "network already exists."}
|
||||
)
|
||||
if set(net).intersection(set(digits)):
|
||||
return dumps({"success": False, "reason": "network name cannot contain numbers."})
|
||||
return dumps(
|
||||
{
|
||||
"success": False,
|
||||
"reason": "network name cannot contain numbers.",
|
||||
}
|
||||
)
|
||||
elif item == "auth":
|
||||
auth = data[item]
|
||||
if auth not in ["sasl", "ns", "none"]:
|
||||
@@ -336,7 +353,9 @@ class API(object):
|
||||
elif item == "port":
|
||||
port = data[item]
|
||||
if not port.isdigit():
|
||||
return dumps({"success": False, "reason": "invalid port: not a number."})
|
||||
return dumps(
|
||||
{"success": False, "reason": "invalid port: not a number."}
|
||||
)
|
||||
port = int(port)
|
||||
elif item == "security":
|
||||
security = data[item]
|
||||
@@ -408,7 +427,9 @@ class API(object):
|
||||
num = int(num)
|
||||
net_inst = main.network[net]
|
||||
if num in net_inst.relays:
|
||||
return dumps({"success": False, "reason": "network already has this relay."})
|
||||
return dumps(
|
||||
{"success": False, "reason": "network already has this relay."}
|
||||
)
|
||||
id, alias = net_inst.add_relay(num)
|
||||
main.saveConf("network")
|
||||
return dumps({"success": True, "id": id, "alias": alias})
|
||||
@@ -433,7 +454,9 @@ class API(object):
|
||||
num = int(num)
|
||||
net_inst = main.network[net]
|
||||
if num not in net_inst.relays:
|
||||
return dumps({"success": False, "reason": "network does not have this relay."})
|
||||
return dumps(
|
||||
{"success": False, "reason": "network does not have this relay."}
|
||||
)
|
||||
net_inst.delete_relay(num)
|
||||
main.saveConf("network")
|
||||
return dumps({"success": True})
|
||||
@@ -448,7 +471,9 @@ class API(object):
|
||||
num = int(num)
|
||||
net_inst = main.network[net]
|
||||
if num not in net_inst.relays:
|
||||
return dumps({"success": False, "reason": "network does not have this relay."})
|
||||
return dumps(
|
||||
{"success": False, "reason": "network does not have this relay."}
|
||||
)
|
||||
provision.provisionRelay(num, net)
|
||||
return dumps({"success": True})
|
||||
|
||||
@@ -465,7 +490,11 @@ class API(object):
|
||||
net_chans = main.IRCPool[name].channels
|
||||
channels_annotated = userinfo.getUserNum(net, net_chans)
|
||||
for channel in net_chans:
|
||||
channel_inst = {"name": channel, "users": channels_annotated[channel], "num": num}
|
||||
channel_inst = {
|
||||
"name": channel,
|
||||
"users": channels_annotated[channel],
|
||||
"num": num,
|
||||
}
|
||||
channels.append(channel_inst)
|
||||
# channels[channel] = channels_annotated[channel]
|
||||
|
||||
@@ -504,7 +533,9 @@ class API(object):
|
||||
return dumps({"success": False, "reason": "no such net."})
|
||||
joined = chankeep.joinSingle(net, channel)
|
||||
if not joined:
|
||||
return dumps({"success": False, "reason": "could not allocate channel to relay."})
|
||||
return dumps(
|
||||
{"success": False, "reason": "could not allocate channel to relay."}
|
||||
)
|
||||
return dumps({"success": True, "relays": joined})
|
||||
|
||||
@app.route("/irc/network/<net>/channel/<channel>/", methods=["PUT"])
|
||||
@@ -514,7 +545,9 @@ class API(object):
|
||||
return dumps({"success": False, "reason": "no such net."})
|
||||
joined = chankeep.joinSingle(net, channel)
|
||||
if not joined:
|
||||
return dumps({"success": False, "reason": "could not allocate channel to relay."})
|
||||
return dumps(
|
||||
{"success": False, "reason": "could not allocate channel to relay."}
|
||||
)
|
||||
return dumps({"success": True, "relays": joined})
|
||||
|
||||
@app.route("/aliases/", methods=["GET"])
|
||||
@@ -563,7 +596,12 @@ class API(object):
|
||||
provision.provisionRelay(num, net)
|
||||
main.saveConf("network")
|
||||
|
||||
return dumps({"success": True, "message": f"created relay {num} with alias {alias} on {net}"})
|
||||
return dumps(
|
||||
{
|
||||
"success": True,
|
||||
"message": f"created relay {num} with alias {alias} on {net}",
|
||||
}
|
||||
)
|
||||
|
||||
@app.route("/irc/list/<net>/", methods=["POST"])
|
||||
@login_required
|
||||
@@ -572,9 +610,16 @@ class API(object):
|
||||
return dumps({"success": False, "reason": "no such net."})
|
||||
first_relay = helpers.get_first_relay(net)
|
||||
if not first_relay:
|
||||
return dumps({"success": False, "reason": f"could not get first relay for {net}"})
|
||||
return dumps(
|
||||
{"success": False, "reason": f"could not get first relay for {net}"}
|
||||
)
|
||||
first_relay.list()
|
||||
return dumps({"success": True, "message": f"requested list with instance {first_relay.num} of {net}"})
|
||||
return dumps(
|
||||
{
|
||||
"success": True,
|
||||
"message": f"requested list with instance {first_relay.num} of {net}",
|
||||
}
|
||||
)
|
||||
|
||||
@app.route("/irc/list/<net>/", methods=["GET"])
|
||||
@login_required
|
||||
@@ -623,7 +668,9 @@ class API(object):
|
||||
main.IRCPool[name].sendmsg(nick, msg, in_query=in_query)
|
||||
else:
|
||||
main.IRCPool[name].sendmsg(channel, msg, in_query=in_query)
|
||||
return dumps({"success": True, "message": f"sent message to {channel} on {name}"})
|
||||
return dumps(
|
||||
{"success": True, "message": f"sent message to {channel} on {name}"}
|
||||
)
|
||||
|
||||
@app.route("/irc/nick/<net>/<num>/", methods=["GET"])
|
||||
@login_required
|
||||
|
||||
Reference in New Issue
Block a user