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.
This commit is contained in:
derAnfaenger 2017-11-06 13:07:24 +01:00 committed by Tim Abbott
parent 2553cf45a5
commit c6aed00aa1

View file

@ -194,12 +194,14 @@ for status in statuses[::-1][:opts.limit_tweets]:
# https://twitter.com/eatevilpenguins/status/309995853408530432 # https://twitter.com/eatevilpenguins/status/309995853408530432
composed = "%s (%s)" % (status.user.name, status.user.screen_name) composed = "%s (%s)" % (status.user.name, status.user.screen_name)
url = "https://twitter.com/%s/status/%s" % (status.user.screen_name, status.id) 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: if opts.search_terms:
search_term_used = None search_term_used = None
for term in opts.search_terms.split(","): 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 search_term_used = term
break break
# For some reason (perhaps encodings or message tranformations we # For some reason (perhaps encodings or message tranformations we