From bf2a3db0697124bd7e2620a501a7181523f03c5e Mon Sep 17 00:00:00 2001 From: John Smith Date: Mon, 7 Sep 2020 20:38:25 +0700 Subject: Add reply plugin; ignore messages from groupchats if creation failed --- extensions/groupchats.py | 4 ++-- extensions/reply.py | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 extensions/reply.py diff --git a/extensions/groupchats.py b/extensions/groupchats.py index 9eaef8c..16bf299 100644 --- a/extensions/groupchats.py +++ b/extensions/groupchats.py @@ -150,7 +150,7 @@ def handleOutgoingChatMessage(user, vkChat): if chatID > 0: # check if the groupchats support enabled in user's settings if not user.settings.groupchats: - return None + return (MSG_SKIP, "") if not hasattr(user, "chats"): user.chats = {} @@ -166,7 +166,7 @@ def handleOutgoingChatMessage(user, vkChat): chat.init(owner, chatID, chatJID, title, time.time(), users) if not chat.created: if chat.creation_failed: - return None + return (MSG_SKIP, "") # we can add user, vkChat to the create() method to prevent losing or messing up the messages chat.create(user) # read the comments above the handleMessage function diff --git a/extensions/reply.py b/extensions/reply.py new file mode 100644 index 0000000..4855164 --- /dev/null +++ b/extensions/reply.py @@ -0,0 +1,26 @@ +# coding: utf-8 +# This file is a part of VK4XMPP transport +# © simpleApps, 2020. + + +def parseReplyMessages(self, msg): + body = "" + result = (MSG_APPEND, "") + if msg.get("reply_message"): + # todo: add date if the message wasn't sent today + reply = msg["reply_message"] + text = escape("", uhtml(reply["text"])) + attachments = parseAttachments(self, reply)[1] + forwarded_messages = parseForwardedMessages(self, reply)[1] + if text: + body += "> " + text + if attachments: + body += "> " + attachments + if forwarded_messages: + body += forwarded_messages.replace("\n", "\n>") + body += "\n" + result = (MSG_PREPEND, body) + return result + + +registerHandler("msg01", parseReplyMessages) \ No newline at end of file -- cgit v1.2.3