lib/chatterbot/config.rb in chatterbot-0.5.1 vs lib/chatterbot/config.rb in chatterbot-0.6.1
- old
+ new
@@ -39,10 +39,17 @@
config[:debug_mode] = d
end
def no_update=(d)
config[:no_update] = d
end
+
+ #
+ # should we reset the since_id for this bot?
+ #
+ def reset_bot?
+ config[:reset_since_id] || false
+ end
#
# are we in debug mode?
def debug_mode?
config[:debug_mode] || false
@@ -103,22 +110,27 @@
#
# update the since_id with either the highest ID of the specified
# tweets, unless it is lower than what we have already
def update_since_id(search)
- unless search.nil?
- tmp_id = case
- # incoming tweets
- when search.has_key?(:id) then search[:id]
-
- # incoming searches
- when search.has_key?("max_id") then search["max_id"]
+ return if search.nil?
+
+ tmp_id = case
+ # Twitter::SearchResults
+ when search.respond_to?(:max_id) then search.max_id
- # other?
- else 1
- end.to_i
- config[:tmp_since_id] = [config[:tmp_since_id].to_i, tmp_id].max
- end
+ # incoming tweets
+ when search.respond_to?(:id) then search.id
+
+ # an enumeration
+ when search.respond_to?(:max) then search.max { |a, b| a.id <=> b.id }.id
+
+ # probably an actual tweet ID at this point,
+ # otherwise it will fail and return 0
+ else search
+ end.to_i
+
+ config[:tmp_since_id] = [config[:tmp_since_id].to_i, tmp_id].max
end
#
# return a hash of the params we need to connect to the Twitter API
def client_params