-
Notifications
You must be signed in to change notification settings - Fork 4
Description
The handle_text_messages function handles the bot's responses to a given text message, if any. The bot can respond in three different ways: either sending a fox image if the message mentions a fox, sending a random dog picture if the message mentions a sad word or emoji, or sending a random dog picture (possibly of a given breed) if the message otherwise mentions dogs.
Right now, the method checks for all these possibilities and after checking everything, messages back. However, this is doing unnecessary checks at times: for example, if my message contains a fox word or image, I should reply immediately without checking if there are sad words or breed names.
Fixing this issue requires reordering the statements in the handle_text_messages method so that:
- If
has_fox_emojievaluates toTrueright after assigning it, call and return with the methodsend_fox_picture(instead of doing it by the end of the function) - Check for breeds
- Assign
is_sad_messageand if it evaluates toTrueright after assigning it, call and return this instead of doing it by the end of the function - Finally, perform the rest of the checks and if any of them evaluate to True, call and return this