From 1ce5a8228c0f66f69ec589ff85092f1e12c6da5c Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sun, 14 Aug 2022 16:45:40 +0100 Subject: [PATCH] Use JSON for sending messages --- api/views.py | 7 +++++-- core/bot.py | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/api/views.py b/api/views.py index 643cea1..280fd5b 100644 --- a/api/views.py +++ b/api/views.py @@ -584,16 +584,19 @@ class API(object): listinfo = chankeep.getListInfo(net) return dumps({"success": True, "listinfo": listinfo}) - @app.route("/irc/msg////", methods=["PUT"]) + @app.route("/irc/msg///", methods=["PUT"]) @login_required - def irc_send_message(self, request, net, num, channel): + def irc_send_message(self, request, net, num): try: data = loads(request.content.read()) except JSONDecodeError: return "Invalid JSON" if "msg" not in data: return dumps({"success": False, "reason": "no msg."}) + if "channel" not in data: + return dumps({"success": False, "reason": "no msg."}) msg = data["msg"] + channel = data["channel"] if net not in main.network.keys(): return dumps({"success": False, "reason": "no such net."}) if not num.isdigit(): diff --git a/core/bot.py b/core/bot.py index 5b2b04d..b6c7329 100644 --- a/core/bot.py +++ b/core/bot.py @@ -258,7 +258,10 @@ class IRCBot(IRCClient): def sendmsg(self, channel, msg, in_query=False): 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: hostmask = us[0] else: