|
|
|
@ -478,3 +478,27 @@ class API(object):
|
|
|
|
|
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}"})
|
|
|
|
|
|
|
|
|
|
@app.route("/irc/msg/<net>/<num>/<channel>/", methods=["PUT"])
|
|
|
|
|
@login_required
|
|
|
|
|
def irc_send_message(self, request, net, num, channel):
|
|
|
|
|
print("IRC SEND", net, num, channel)
|
|
|
|
|
try:
|
|
|
|
|
data = loads(request.content.read())
|
|
|
|
|
except JSONDecodeError:
|
|
|
|
|
return "Invalid JSON"
|
|
|
|
|
if "msg" not in data:
|
|
|
|
|
return dumps({"success": False, "reason": "no msg."})
|
|
|
|
|
msg = data["msg"]
|
|
|
|
|
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}"})
|
|
|
|
|
main.IRCPool[name].sendmsg(channel, msg)
|
|
|
|
|
return dumps({"success": True, "message": f"sent message to {channel} on {name}"})
|
|
|
|
|