From 2a9d2657b111eef9442f66e0afb2656f7fbe97d1 Mon Sep 17 00:00:00 2001 From: "Schimon Jehudah, Adv." Date: Mon, 16 Sep 2024 14:42:55 +0300 Subject: [PATCH] Invoke Slixfeed by its alias in a given group chat. --- slixfeed/version.py | 4 ++-- slixfeed/xmpp/chat.py | 7 +++++-- slixfeed/xmpp/utilities.py | 6 ++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/slixfeed/version.py b/slixfeed/version.py index 5290407..292bfaf 100644 --- a/slixfeed/version.py +++ b/slixfeed/version.py @@ -1,2 +1,2 @@ -__version__ = '0.1.98' -__version_info__ = (0, 1, 98) +__version__ = '0.1.99' +__version_info__ = (0, 1, 99) diff --git a/slixfeed/xmpp/chat.py b/slixfeed/xmpp/chat.py index 18cbcaf..3a2bf31 100644 --- a/slixfeed/xmpp/chat.py +++ b/slixfeed/xmpp/chat.py @@ -102,8 +102,9 @@ class XmppChat: # nick = message['from'][message['from'].index('/')+1:] # nick = str(message['from']) # nick = nick[nick.index('/')+1:] + alias_of_slixfeed = XmppUtilities.get_self_alias(self, jid_bare) if (alias == self.alias or - not message['body'].startswith('!')): + not message['body'].startswith(alias_of_slixfeed)): return # token = await initdb( # jid_bare, @@ -156,7 +157,9 @@ class XmppChat: else: omemo_decrypted = None - if message_type == 'groupchat': command = command[1:] + # Adding one to the length because of assumption that a comma or a dot is added + alias_of_slixfeed_length = len(alias_of_slixfeed) + 1 + if message_type == 'groupchat': command = (command[alias_of_slixfeed_length:]).lstrip() if isinstance(command, Message): command = command['body'] command_lowercase = command.lower() diff --git a/slixfeed/xmpp/utilities.py b/slixfeed/xmpp/utilities.py index 8f983f1..b56a50c 100644 --- a/slixfeed/xmpp/utilities.py +++ b/slixfeed/xmpp/utilities.py @@ -11,6 +11,12 @@ logger = Logger(__name__) class XmppUtilities: + def get_self_alias(self, room): + """Get self alias of a given group chat""" + jid_full = self.plugin['xep_0045'].get_our_jid_in_room(room) + alias = jid_full.split('/')[1] + return alias + async def get_chat_type(self, jid): """ Check chat (i.e. JID) type.