Use JSON for sending messages
This commit is contained in:
parent
b62200d410
commit
c55a4058b1
|
@ -584,16 +584,19 @@ class API(object):
|
||||||
listinfo = chankeep.getListInfo(net)
|
listinfo = chankeep.getListInfo(net)
|
||||||
return dumps({"success": True, "listinfo": listinfo})
|
return dumps({"success": True, "listinfo": listinfo})
|
||||||
|
|
||||||
@app.route("/irc/msg/<net>/<num>/<channel>/", methods=["PUT"])
|
@app.route("/irc/msg/<net>/<num>/", methods=["PUT"])
|
||||||
@login_required
|
@login_required
|
||||||
def irc_send_message(self, request, net, num, channel):
|
def irc_send_message(self, request, net, num):
|
||||||
try:
|
try:
|
||||||
data = loads(request.content.read())
|
data = loads(request.content.read())
|
||||||
except JSONDecodeError:
|
except JSONDecodeError:
|
||||||
return "Invalid JSON"
|
return "Invalid JSON"
|
||||||
if "msg" not in data:
|
if "msg" not in data:
|
||||||
return dumps({"success": False, "reason": "no msg."})
|
return dumps({"success": False, "reason": "no msg."})
|
||||||
|
if "channel" not in data:
|
||||||
|
return dumps({"success": False, "reason": "no msg."})
|
||||||
msg = data["msg"]
|
msg = data["msg"]
|
||||||
|
channel = data["channel"]
|
||||||
if net not in main.network.keys():
|
if net not in main.network.keys():
|
||||||
return dumps({"success": False, "reason": "no such net."})
|
return dumps({"success": False, "reason": "no such net."})
|
||||||
if not num.isdigit():
|
if not num.isdigit():
|
||||||
|
|
|
@ -258,7 +258,10 @@ class IRCBot(IRCClient):
|
||||||
|
|
||||||
def sendmsg(self, channel, msg, in_query=False):
|
def sendmsg(self, channel, msg, in_query=False):
|
||||||
query = f"{self.nickname}!*@*"
|
query = f"{self.nickname}!*@*"
|
||||||
us = list(userinfo.getWhoSingle(self.net, query))
|
res = userinfo.getWhoSingle(self.net, query)
|
||||||
|
if not res:
|
||||||
|
res = []
|
||||||
|
us = list(res)
|
||||||
if len(us) > 0:
|
if len(us) > 0:
|
||||||
hostmask = us[0]
|
hostmask = us[0]
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue