From ae434cd26cbee9f053918228d46a6ecbfe4da1f3 Mon Sep 17 00:00:00 2001 From: Abhijeet Kaur Date: Fri, 18 Aug 2017 16:59:55 +0530 Subject: [PATCH] bots: Use user 'id' instead of 'name' in is_private function. Names are not guaranteed to be unique, user ids should be used when comparing if the sender and receiver are the same. --- zulip_bots/zulip_bots/lib.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zulip_bots/zulip_bots/lib.py b/zulip_bots/zulip_bots/lib.py index 11c8dd0..4aec921 100644 --- a/zulip_bots/zulip_bots/lib.py +++ b/zulip_bots/zulip_bots/lib.py @@ -79,6 +79,7 @@ class ExternalBotHandler(object): self._client = client self._root_dir = root_dir try: + self.user_id = user_profile['user_id'] self.full_name = user_profile['full_name'] self.email = user_profile['email'] except KeyError: @@ -176,10 +177,10 @@ def extract_query_without_mention(message, client): def is_private(message, client): # type: (Dict[str, Any], ExternalBotHandler) -> bool - # bot will not reply if the sender name is the same as the bot name + # bot will not reply if the sender id is the same as the bot id # to prevent infinite loop if message['type'] == 'private': - return client.full_name != message['sender_full_name'] + return client.user_id != message['sender_id'] return False def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name):