From b871fea0391d1adf14c958b955d0db421ef61bbd Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Tue, 9 Aug 2022 07:20:30 +0100 Subject: [PATCH] Add endpoint to get the bot's nickname --- api/views.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/api/views.py b/api/views.py index 9d2348d..2af0241 100644 --- a/api/views.py +++ b/api/views.py @@ -508,3 +508,18 @@ class API(object): else: main.IRCPool[name].sendmsg(channel, msg) return dumps({"success": True, "message": f"sent message to {channel} on {name}"}) + + @app.route("/irc/nick///", methods=["GET"]) + @login_required + def irc_get_nick(self, request, net, num): + if net not in main.network.keys(): + return dumps({"success": False, "reason": "no such net."}) + if not num.isdigit(): + return dumps({"success": False, "reason": "invalid num: not a number."}) + num = int(num) + if num not in main.network[net].relays.keys(): + return dumps({"success": False, "reason": f"no relay {num} on {net}"}) + name = f"{net}{num}" + if name not in main.IRCPool.keys(): + return dumps({"success": False, "reason": f"relay {num} not on {net}"}) + return dumps({"nickname": main.IRCPool[name].nickname}) \ No newline at end of file