From 87302c58d20cd6d23adad000c613776cc2be8c3d Mon Sep 17 00:00:00 2001 From: John Smith Date: Fri, 6 Sep 2019 09:35:38 +0700 Subject: Change isAppUser method to users.get --- gateway.py | 11 +++++++---- modules/mod_msg_main.py | 4 ++++ modules/mod_msg_xhtml.py | 6 +++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/gateway.py b/gateway.py index 0477db6..a5ba21d 100644 --- a/gateway.py +++ b/gateway.py @@ -194,7 +194,7 @@ def getGatewayRev(): """ Gets gateway revision using git or custom revision number """ - number, hash = 420, 0 + number, hash = 460, 0 shell = os.popen("git describe --always &" "& git log --pretty=format:''").readlines() if shell: @@ -279,8 +279,10 @@ class VK(object): Checks the token """ try: - int(self.engine.method("isAppUser")) - except (api.VkApiError, TypeError, AttributeError): + data = self.engine.method("users.get") + if not data: + raise RuntimeError("Unable to get data for user!") + except api.VkApiError: logger.error("unable to check user's token, error: %s (user: %s)", traceback.format_exc(), self.source) return False @@ -578,7 +580,8 @@ class VK(object): data = self.method("groups.getById", {"group_id": abs(gid), "fields": str.join(",", fields)}) if data: data = data[0] - return data + return data + raise RuntimeError("Unable to get group data") @utils.cache @api.repeat(3, dict, RuntimeError) diff --git a/modules/mod_msg_main.py b/modules/mod_msg_main.py index a1bd57d..7a3410e 100644 --- a/modules/mod_msg_main.py +++ b/modules/mod_msg_main.py @@ -57,6 +57,10 @@ def message_handler(cl, msg): jidTo = msg.getTo() destination = jidTo.getStripped() jidFrom = msg.getFrom() + if isinstance(jidFrom, (str, unicode)): + logger.warning("Received message did not contain a valid jid: %s", msg) + raise xmpp.NodeProcessed() + source = jidFrom.getStripped() if msg.getType() == "chat" and source in Users: diff --git a/modules/mod_msg_xhtml.py b/modules/mod_msg_xhtml.py index fa12a74..8122a61 100644 --- a/modules/mod_msg_xhtml.py +++ b/modules/mod_msg_xhtml.py @@ -9,7 +9,11 @@ import mod_xhtml def xhtml_handler(cl, msg): destination = msg.getTo().getStripped() - source = msg.getFrom().getStripped() + source = msg.getFrom() + if isinstance(source, (str, unicode)): + logger.warning("Received message did not contain a valid jid: %s", msg) + raise xmpp.NodeProcessed() + source = source.getStripped() if source in Users and msg.getType() == "chat": user = Users[source] html = msg.getTag("html") -- cgit v1.2.3