Sha256: 19f8f9b9eb82f1c17dd3e47a53a01c5e95d3d3c4d568793c7e666dd246b99225
Contents?: true
Size: 1.73 KB
Versions: 1
Compression:
Stored size: 1.73 KB
Contents
module Chatterbot # # simple twitter stream handler module Streaming def streaming_tweet_handler usable_handlers = [:home_timeline, :search] name, block = @handlers.find { |k, v| usable_handlers.include?(k) } block end # # Take the passed in object and call the appropriate bot method # for it # @param [Class] object a streaming API object # def handle_streaming_object(object) debug object case object when Twitter::Tweet if object.user == authenticated_user debug "skipping #{object} because it's from me" elsif (h = streaming_tweet_handler) && valid_tweet?(object) @current_tweet = object update_since_id(object) h.call(object) @current_tweet = nil end when Twitter::Streaming::DeletedTweet if (h = @handlers[:deleted]) h.call(object) end when Twitter::DirectMessage if object.sender == authenticated_user debug "skipping DM #{object} because it's from me" elsif (h = @handlers[:direct_messages]) @current_tweet = object update_since_id_dm(object) h.call(object) @current_tweet = nil end when Twitter::Streaming::Event if object.respond_to?(:source) && object.source == authenticated_user debug "skipping #{object} because it's from me" elsif object.name == :follow && (h = @handlers[:followed]) h.call(object.source) elsif object.name == :favorite && (h = @handlers[:favorited]) h.call(object.source, object.target_object) end when Twitter::Streaming::FriendList debug "got friend list" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
chatterbot-2.0.0.pre | lib/chatterbot/streaming.rb |