lib/chatterbot/config.rb in chatterbot-0.7.0 vs lib/chatterbot/config.rb in chatterbot-0.7.1

- old
+ new

@@ -36,10 +36,11 @@ end def debug_mode=(d) config[:debug_mode] = d end + def no_update=(d) config[:no_update] = d end # @@ -90,13 +91,26 @@ # # return the ID of the most recent tweet pulled up in searches def since_id config[:since_id] || 0 - end + end # + # store since_id_reply to a different key so that it doesn't actually + # get updated until the bot is done running + def since_id_reply=(x) + config[:tmp_since_id_reply] = x + end + + # + # return the ID of the most recent tweet pulled up in mentions or since_id if since_id_reply is nil + def since_id_reply + config[:since_id_reply] || since_id + end + + # # write out our config file def update_config return if ! update_config? # don't update flat file if we can store to the DB instead @@ -113,10 +127,22 @@ end def max_id_from(s) s.max { |a, b| a.id <=> b.id }.id end + + # + # update the since_id_reply with the id of the given tweet, + # unless it is lower thant what we have already + # + def update_since_id_reply(tweet) + return if tweet.nil? or tweet.class != Twitter::Tweet + + tmp_id = tweet.id + + config[:tmp_since_id_reply] = [config[:tmp_since_id_reply].to_i, tmp_id].max + end # # 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) @@ -266,10 +292,11 @@ tmp.delete(:verbose) # update the since_id now tmp[:since_id] = tmp.delete(:tmp_since_id) unless ! tmp.has_key?(:tmp_since_id) + tmp[:since_id_reply] = tmp.delete(:tmp_since_id_reply) unless ! tmp.has_key?(:tmp_since_id_reply) tmp end @@ -300,9 +327,10 @@ return false if db.nil? configs = db[:config] data = { :since_id => config.has_key?(:tmp_since_id) ? config[:tmp_since_id] : config[:since_id], + :since_id_reply => config.has_key?(:tmp_since_id_reply) ? config[:tmp_since_id_reply] : config[:since_id_reply], :token => config[:token], :secret => config[:secret], :consumer_secret => config[:consumer_secret], :consumer_key => config[:consumer_key], :updated_at => Time.now #:NOW.sql_function