From c6aed00aa17d9093cd14aeb3a2c9adf6e83dc3e6 Mon Sep 17 00:00:00 2001 From: derAnfaenger Date: Mon, 6 Nov 2017 13:07:24 +0100 Subject: [PATCH] integrations: Make twitter bot handle search terms more intelligently. When invoked with search terms, twitter bot looks for these terms in the content of a message to find out if they match. However, Twitter can return messages that don't directly contain a search term. This commit adds the tweeter user handle and expanded urls to the places to look for a search term. --- zulip/integrations/twitter/twitter-bot | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/zulip/integrations/twitter/twitter-bot b/zulip/integrations/twitter/twitter-bot index 5b3224b..5d69e58 100755 --- a/zulip/integrations/twitter/twitter-bot +++ b/zulip/integrations/twitter/twitter-bot @@ -194,12 +194,14 @@ for status in statuses[::-1][:opts.limit_tweets]: # https://twitter.com/eatevilpenguins/status/309995853408530432 composed = "%s (%s)" % (status.user.name, status.user.screen_name) url = "https://twitter.com/%s/status/%s" % (status.user.screen_name, status.id) - content = status.text + # This contains all strings that could have caused the tweet to match our query. + text_to_check = [status.text, status.user.screen_name] + text_to_check.extend(url.expanded_url for url in status.urls) if opts.search_terms: search_term_used = None for term in opts.search_terms.split(","): - if term.lower() in content.lower(): + if any(term.lower() in text.lower() for text in text_to_check): search_term_used = term break # For some reason (perhaps encodings or message tranformations we