lib/twitter_ebooks/bot.rb
def reply(ev, text, opts={})
      opts = opts.clone

      if ev.is_a? Twitter::DirectMessage
        log "Sending DM to @#{ev.sender.screen_name}: #{text}"
        twitter.create_direct_message(ev.sender.screen_name, text, opts)
      elsif ev.is_a? Twitter::Tweet
        meta = meta(ev)

        if conversation(ev).is_bot?(ev.user.screen_name)
          log "Not replying to suspected bot @#{ev.user.screen_name}"
          return false
        end

        text = meta.reply_prefix + text unless text.match /@#{Regexp.escape ev.user.screen_name}/i
        log "Replying to @#{ev.user.screen_name} with: #{text}"
        tweet = twitter.update(text, opts.merge(in_reply_to_status_id: ev.id))
        conversation(tweet).add(tweet)
        tweet
      else
        raise Exception("Don't know how to reply to a #{ev.class}")
      end
    end
# Reply to a tweet or a DM.
# @param ev [Twitter::Tweet, Twitter::DirectMessage]
# @param text [String] contents of reply excluding reply_prefix
# @param opts [Hash] additional params to pass to twitter gem
Reply to a tweet or a DM.
Reply to a tweet or a DM .
def reply(ev, text, opts={})
      opts = opts.clone
      if ev.is_a? Twitter::DirectMessage
        log "Sending DM to @#{ev.sender.screen_name}: #{text}"
        twitter.create_direct_message(ev.sender.screen_name, text, opts)
      elsif ev.is_a? Twitter::Tweet
        meta = meta(ev)
        if conversation(ev).is_bot?(ev.user.screen_name)
          log "Not replying to suspected bot @#{ev.user.screen_name}"
          return false
        end
        text = meta.reply_prefix + text unless text.match /@#{Regexp.escape ev.user.screen_name}/i
        log "Replying to @#{ev.user.screen_name} with: #{text}"
        tweet = twitter.update(text, opts.merge(in_reply_to_status_id: ev.id))
        conversation(tweet).add(tweet)
        tweet
      else
        raise Exception("Don't know how to reply to a #{ev.class}")
      end
    end
def reply ( ev , text , opts = { } ) opts = opts . clone if ev . is_a? Twitter :: DirectMessage log "Sending DM to @#{ev.sender.screen_name}: #{text}" twitter . create_direct_message ( ev . sender . screen_name , text , opts ) elsif ev . is_a? Twitter :: Tweet meta = meta ( ev ) if conversation ( ev ) . is_bot? ( ev . user . screen_name ) log "Not replying to suspected bot @#{ev.user.screen_name}" return false end text = meta . reply_prefix + text unless text . match / @ #{ Regexp . escape ev . user . screen_name } /i log "Replying to @#{ev.user.screen_name} with: #{text}" tweet = twitter . update ( text , opts . merge ( in_reply_to_status_id : ev . id ) ) conversation ( tweet ) . add ( tweet ) tweet else raise Exception ( "Don't know how to reply to a #{ev.class}" ) end end
Reply to a tweet or a DM.
Reply to a tweet or a DM .
ev
text
contents of reply excluding reply_prefix
contents of reply excluding reply_prefix
opts
additional params to pass to twitter gem
additional params to pass to twitter gem
None