lib/chatterbot/search.rb in chatterbot-0.9.1 vs lib/chatterbot/search.rb in chatterbot-0.9.2
- old
+ new
@@ -2,16 +2,26 @@
#
# handle Twitter searches
module Search
+ @skip_retweets = true
+
#
# modify a query string to exclude retweets from searches
#
- def exclude_retweets(q)
- q.include?("include:retweets") ? q : q += " -include:retweets"
+ def exclude_retweets
+ @skip_retweets = true
end
+
+ def include_retweets
+ @skip_retweets = false
+ end
+
+ def skippable_retweet?(t)
+ @skip_retweets && t.retweeted_status?
+ end
# internal search code
def search(queries, opts = {}, &block)
debug "check for tweets since #{since_id}"
@@ -23,19 +33,18 @@
#
# search twitter
#
queries.each { |query|
debug "search: #{query} #{default_opts.merge(opts)}"
- result = client.search(
- exclude_retweets(query),
- default_opts.merge(opts)
- )
+ result = client.search( query, default_opts.merge(opts) )
update_since_id(result)
@current_tweet = nil
result.each { |s|
debug s.text
- if block_given? && !on_blacklist?(s) && !skip_me?(s)
+ if has_whitelist? && !on_whitelist?(s)
+ debug "skipping because user not on whitelist"
+ elsif block_given? && !on_blacklist?(s) && !skip_me?(s) && !skippable_retweet?(s)
@current_tweet = s
yield s
end
}
@current_tweet = nil