bots: Modify is_private function to take 'id' as parameter.
This is done so that Embedded bot system can also make use of this function directly, as only id is needed in this function. Tweaked by tabbott to have a cleaner interface and simpler documentation.
This commit is contained in:
parent
ae434cd26c
commit
83bfcb6535
|
@ -175,12 +175,17 @@ def extract_query_without_mention(message, client):
|
||||||
query_without_mention = message['content'][len(start_with_mention.group()):]
|
query_without_mention = message['content'][len(start_with_mention.group()):]
|
||||||
return query_without_mention.lstrip()
|
return query_without_mention.lstrip()
|
||||||
|
|
||||||
def is_private(message, client):
|
def is_private_message_from_another_user(message_dict, current_user_id):
|
||||||
# type: (Dict[str, Any], ExternalBotHandler) -> bool
|
# type: (Dict[str, Any], int) -> bool
|
||||||
# bot will not reply if the sender id is the same as the bot id
|
"""
|
||||||
# to prevent infinite loop
|
Checks whether a message dict represents a PM from another user.
|
||||||
if message['type'] == 'private':
|
|
||||||
return client.user_id != message['sender_id']
|
This function is used by the embedded bot system in the
|
||||||
|
zulip/zulip project, so refactor with care. See the comments in
|
||||||
|
extract_query_without_mention.
|
||||||
|
"""
|
||||||
|
if message_dict['type'] == 'private':
|
||||||
|
return current_user_id != message_dict['sender_id']
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name):
|
def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name):
|
||||||
|
@ -212,7 +217,7 @@ def run_message_handler_for_bot(lib_module, quiet, config_file, bot_name):
|
||||||
# is_mentioned is true if the bot is mentioned at ANY position (not necessarily
|
# is_mentioned is true if the bot is mentioned at ANY position (not necessarily
|
||||||
# the first @mention in the message).
|
# the first @mention in the message).
|
||||||
is_mentioned = message['is_mentioned']
|
is_mentioned = message['is_mentioned']
|
||||||
is_private_message = is_private(message, restricted_client)
|
is_private_message = is_private_message_from_another_user(message, restricted_client.user_id)
|
||||||
|
|
||||||
# Strip at-mention botname from the message
|
# Strip at-mention botname from the message
|
||||||
if is_mentioned:
|
if is_mentioned:
|
||||||
|
|
Loading…
Reference in a new issue