@@ -164,6 +164,16 @@ def extract_query_without_mention(message, at_mention_bot_name):
164
164
"""
165
165
If the bot is the first @mention in the message, then this function returns
166
166
the message with the bot's @mention removed. Otherwise, it returns None.
167
+ This function is being leveraged by two systems; external bot system and embedded bot system.
168
+ This function is being called by:
169
+ 1. 'run_message_handler_for_bot' function (zulip_bots/lib.py file in zulip/python-zulip-api
170
+ repository) that executes/runs/calls external bots.
171
+ 2. 'consume' function in EmbeddedBotWorker class (zerver/worker/queue_processors.py
172
+ file in zulip/zulip repository) that executes/runs/calls embedded bots.
173
+
174
+ Since, this is a general utility function for any working bot, it is planned to be an independent
175
+ function for now. Any refactoring should correctly be reflected in all the bot systems using this
176
+ function.
167
177
"""
168
178
bot_mention = r'^@(\*\*{0}\*\*)' .format (at_mention_bot_name )
169
179
start_with_mention = re .compile (bot_mention ).match (message ['content' ])
@@ -174,20 +184,46 @@ def extract_query_without_mention(message, at_mention_bot_name):
174
184
175
185
def is_private (message , at_mention_bot_name ):
176
186
# type: (Dict[str, Any], str) -> bool
177
- # bot will not reply if the sender name is the same as the bot name
178
- # to prevent infinite loop
187
+ """
188
+ This function is to ensure that the bot doesn't go into infinite loop if the sender name is
189
+ the same as the bot name. This function makes the bot not reply to such a sender.
190
+
191
+ This function is being leveraged by two systems; external bot system and embedded bot system,
192
+ any change/modification in the structure of this should be reflected at other places accordingly.
193
+ For details read "extract_query_without_mention" function docstring.
194
+ """
179
195
if message ['type' ] == 'private' :
180
196
return at_mention_bot_name != message ['sender_full_name' ]
181
197
return False
182
198
183
199
def initialize_config_bot (message_handler , bot_handler ):
184
200
# type: (Any) -> None
201
+ """
202
+ If a bot has bot-specific configuration settings (both public or private) to be set, then this
203
+ function calls the 'initialize' function which in turn calls 'get_config_info' for bots.
204
+
205
+ This function is being leveraged by two systems; external bot system and embedded bot system,
206
+ any change/modification in the structure of this should be reflected at other places accordingly.
207
+ For details read "extract_query_without_mention" function docstring.
208
+ """
185
209
if hasattr (message_handler , 'initialize' ):
186
210
message_handler .initialize (bot_handler = bot_handler )
187
211
188
212
def get_message_content_if_bot_is_called (message , at_mention_bot_name ):
189
213
# type: (Dict[str, Any], str) -> Any
190
- #
214
+ """
215
+ Check if the bot is called or not; a bot can be called by 2 ways: @mention-botname or private message
216
+ to the bot. Once it is confirmed if a bot is called or not, then we move to the second part of the
217
+ function.
218
+ If the bot is privately messaged, then the message content need not be modified and the bot can directly
219
+ process the entire message content.
220
+ If the bot is called by @mention-botname, then we need to remove @mention-botname for the bot to
221
+ process the rest of the message content.
222
+
223
+ This function is being leveraged by two systems; external bot system and embedded bot system,
224
+ any change/modification in the structure of this should be reflected at other places accordingly.
225
+ For details read "extract_query_without_mention" function docstring.
226
+ """
191
227
# is_mentioned is true if the bot is mentioned at ANY position (not necessarily
192
228
# the first @mention in the message).
193
229
is_mentioned = message ['is_mentioned' ]
0 commit comments