Add endpoint to get the bot's nickname

This commit is contained in:
Mark Veidemanis 2022-08-09 07:20:30 +01:00
parent a2b6ebd912
commit 7e51178a10
1 changed files with 15 additions and 0 deletions

View File

@ -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/<net>/<num>/", 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})