Skip to content

Commit 8ad562d

Browse files
committed
bots: Modify 'extract_query_without_mention' to take bot name as input.
This is done so that Embedded bot system can also make use of this function directly, as only client name is needed in this function, and the type of client need not be ExternalBotHandler. Also, there would be ambiguity as what type of BotHandler is passed in the arguments: EmbeddedBotHandler or ExternalBotHandler.
1 parent c5bb72e commit 8ad562d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

zulip_bots/zulip_bots/lib.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,23 @@ def state(self, default):
162162
yield new_state
163163
self.set_state(new_state)
164164

165-
def extract_query_without_mention(message, client):
166-
# type: (Dict[str, Any], ExternalBotHandler) -> str
165+
def extract_query_without_mention(message, at_mention_bot_name):
166+
# type: (Dict[str, Any], str) -> str
167167
"""
168168
If the bot is the first @mention in the message, then this function returns
169169
the message with the bot's @mention removed. Otherwise, it returns None.
170+
This function is being leveraged by two systems; external bot system and embedded bot system.
171+
This function is being called by:
172+
1. 'run_message_handler_for_bot' function (zulip_bots/lib.py file in zulip/python-zulip-api
173+
repository) that executes/runs/calls external bots.
174+
2. 'consume' function in EmbeddedBotWorker class (zerver/worker/queue_processors.py
175+
file in zulip/zulip repository) that executes/runs/calls embedded bots.
176+
177+
Since, this is a general utility function for any working bot, it is planned to be an independent
178+
function for now. Any refactoring should correctly be reflected in all the bot systems using this
179+
function.
170180
"""
171-
bot_mention = r'^@(\*\*{0}\*\*)'.format(client.full_name)
181+
bot_mention = r'^@(\*\*{0}\*\*)'.format(at_mention_bot_name)
172182
start_with_mention = re.compile(bot_mention).match(message['content'])
173183
if start_with_mention is None:
174184
return None

0 commit comments

Comments
 (0)