From 4f141b976a3c1eea0b5087087379c53ef2c2d5db Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 26 Jul 2022 22:16:35 +0100 Subject: [PATCH] Implement network and channels view --- api/views.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/api/views.py b/api/views.py index 7912a62..38566e0 100644 --- a/api/views.py +++ b/api/views.py @@ -132,7 +132,7 @@ class API(object): if "query" not in data: return "No users provided" if not data["query"]: - warn(f"No chans provided: for online {data}") + warn(f"No chans provided: for num_users {data}") return dumps({}) net = data["net"] results = userinfo.getUserNum(net, data["query"]) @@ -151,7 +151,7 @@ class API(object): if "query" not in data: return "No users provided" if not data["query"]: - warn(f"No users provided: for online {data}") + warn(f"No users provided: for num_chans {data}") return dumps({}) net = data["net"] results = userinfo.getChanNum(net, data["query"]) @@ -190,3 +190,58 @@ class API(object): "records": userinfo.getNumWhoEntries(net), } return dumps(networks) + + @app.route("/irc/network//", methods=["POST"]) + @login_required + def irc_network(self, request, net): + if net not in main.network.keys(): + return dumps(False) + inst = main.network[net] + network = {} + network["net"] = inst.net + network["auth"] = inst.auth + network["host"] = inst.host + network["last"] = inst.last + network["port"] = inst.port + network["security"] = inst.security + network["relays"] = len(inst.relays) + network["channels"] = userinfo.getTotalChanNum(net) + network["records"] = userinfo.getNumWhoEntries(net) + return dumps(network) + + @app.route("/irc/network//relays/", methods=["POST"]) + @login_required + def irc_network_relays(self, request, net): + if net not in main.network.keys(): + return dumps(False) + relays_inst = main.network[net].relays + relays = [] + for num in relays_inst.keys(): + to_append = relays_inst[num] + name = f"{net}{num}" + if name in main.IRCPool.keys(): + to_append["chans"] = len(main.IRCPool[name].channels) + to_append["nick"] = main.IRCPool[name].nickname + else: + to_append["chans"] = 0 + to_append["nick"] = None + relays.append(to_append) + + return dumps({"relays": relays}) + + @app.route("/irc/network//channels/", methods=["POST"]) + @login_required + def irc_network_channels(self, request, net): + if net not in main.network.keys(): + return dumps(False) + relays_inst = main.network[net].relays + channels = {} + for num in relays_inst.keys(): + name = f"{net}{num}" + if name in main.IRCPool.keys(): + net_chans = main.IRCPool[name].channels + channels_annotated = userinfo.getUserNum(net, net_chans) + for channel in net_chans: + channels[channel] = channels_annotated[channel] + + return dumps({"channels": channels})