Skip to content

Commit 3559b98

Browse files
committed
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.
1 parent e175894 commit 3559b98

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

zulip_bots/zulip_bots/lib.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def __init__(self, client, root_dir):
7979
self._client = client
8080
self._root_dir = root_dir
8181
try:
82+
self.id = user_profile['id']
8283
self.full_name = user_profile['full_name']
8384
self.email = user_profile['email']
8485
except KeyError:
@@ -176,10 +177,10 @@ def extract_query_without_mention(message, client):
176177

177178
def is_private(message, client):
178179
# type: (Dict[str, Any], ExternalBotHandler) -> bool
179-
# bot will not reply if the sender name is the same as the bot name
180+
# bot will not reply if the sender id is the same as the bot id
180181
# to prevent infinite loop
181182
if message['type'] == 'private':
182-
return client.full_name != message['sender_full_name']
183+
return client.id != message['sender_id']
183184
return False
184185

185186
def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name):

0 commit comments

Comments
 (0)