lib/twitter_ebooks/bot.rb
def receive_event(ev)
      if ev.is_a? Array # Initial array sent on first connection
        log "Online!"
        return
      end

      if ev.is_a? Twitter::DirectMessage
        return if ev.sender.screen_name.downcase == @username.downcase # Don't reply to self
        log "DM from @#{ev.sender.screen_name}: #{ev.text}"
        fire(:message, ev)

      elsif ev.respond_to?(:name) && ev.name == :follow
        return if ev.source.screen_name.downcase == @username.downcase
        log "Followed by #{ev.source.screen_name}"
        fire(:follow, ev.source)

      elsif ev.is_a? Twitter::Tweet
        return unless ev.text # If it's not a text-containing tweet, ignore it
        return if ev.user.screen_name.downcase == @username.downcase # Ignore our own tweets

        meta = meta(ev)

        if blacklisted?(ev.user.screen_name)
          log "Blocking blacklisted user @#{ev.user.screen_name}"
          @twitter.block(ev.user.screen_name)
        end

        # Avoid responding to duplicate tweets
        if @seen_tweets[ev.id]
          log "Not firing event for duplicate tweet #{ev.id}"
          return
        else
          @seen_tweets[ev.id] = true
        end

        if meta.mentions_bot?
          log "Mention from @#{ev.user.screen_name}: #{ev.text}"
          conversation(ev).add(ev)
          fire(:mention, ev)
        else
          fire(:timeline, ev)
        end

      elsif ev.is_a?(Twitter::Streaming::DeletedTweet) ||
            ev.is_a?(Twitter::Streaming::Event)
        # pass
      else
        log ev
      end
    end
# Receive an event from the twitter stream
# @param ev [Object] Twitter streaming event
Receive an event from the twitter stream
Receive an event from the twitter stream
def receive_event(ev)
      if ev.is_a? Array 
        log "Online!"
        return
      end
      if ev.is_a? Twitter::DirectMessage
        return if ev.sender.screen_name.downcase == @username.downcase 
        log "DM from @#{ev.sender.screen_name}: #{ev.text}"
        fire(:message, ev)
      elsif ev.respond_to?(:name) && ev.name == :follow
        return if ev.source.screen_name.downcase == @username.downcase
        log "Followed by #{ev.source.screen_name}"
        fire(:follow, ev.source)
      elsif ev.is_a? Twitter::Tweet
        return unless ev.text 
        return if ev.user.screen_name.downcase == @username.downcase 
        meta = meta(ev)
        if blacklisted?(ev.user.screen_name)
          log "Blocking blacklisted user @#{ev.user.screen_name}"
          @twitter.block(ev.user.screen_name)
        end
        if @seen_tweets[ev.id]
          log "Not firing event for duplicate tweet #{ev.id}"
          return
        else
          @seen_tweets[ev.id] = true
        end
        if meta.mentions_bot?
          log "Mention from @#{ev.user.screen_name}: #{ev.text}"
          conversation(ev).add(ev)
          fire(:mention, ev)
        else
          fire(:timeline, ev)
        end
      elsif ev.is_a?(Twitter::Streaming::DeletedTweet) ||
            ev.is_a?(Twitter::Streaming::Event)
      else
        log ev
      end
    end
def receive_event ( ev ) if ev . is_a? Array log "Online!" return end if ev . is_a? Twitter :: DirectMessage return if ev . sender . screen_name . downcase == @username . downcase log "DM from @#{ev.sender.screen_name}: #{ev.text}" fire ( :message , ev ) elsif ev . respond_to? ( :name ) && ev . name == :follow return if ev . source . screen_name . downcase == @username . downcase log "Followed by #{ev.source.screen_name}" fire ( :follow , ev . source ) elsif ev . is_a? Twitter :: Tweet return unless ev . text return if ev . user . screen_name . downcase == @username . downcase meta = meta ( ev ) if blacklisted? ( ev . user . screen_name ) log "Blocking blacklisted user @#{ev.user.screen_name}" @twitter . block ( ev . user . screen_name ) end if @seen_tweets [ ev . id ] log "Not firing event for duplicate tweet #{ev.id}" return else @seen_tweets [ ev . id ] = true end if meta . mentions_bot? log "Mention from @#{ev.user.screen_name}: #{ev.text}" conversation ( ev ) . add ( ev ) fire ( :mention , ev ) else fire ( :timeline , ev ) end elsif ev . is_a? ( Twitter :: Streaming :: DeletedTweet ) || ev . is_a? ( Twitter :: Streaming :: Event ) else log ev end end
Receive an event from the twitter stream
Receive an event from the twitter stream
# Initial array sent on first connection # Don't reply to self # If it's not a text-containing tweet, ignore it # Ignore our own tweets # Avoid responding to duplicate tweets # pass
ev
Twitter streaming event
Twitter streaming event