From f4dbf89c15e54e82c7e5a360d8b43d6b6deef253 Mon Sep 17 00:00:00 2001 From: Jaiden Mispy <^_^@mispy.me> Date: Sat, 18 Oct 2014 22:25:39 -0700 Subject: [PATCH] Fix deprecations for twitter gem 5 --- lib/twitter_ebooks/bot.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/twitter_ebooks/bot.rb b/lib/twitter_ebooks/bot.rb index 2506f40..1f5a804 100755 --- a/lib/twitter_ebooks/bot.rb +++ b/lib/twitter_ebooks/bot.rb @@ -46,8 +46,8 @@ module Ebooks @twitter = Twitter::REST::Client.new do |config| config.consumer_key = @consumer_key config.consumer_secret = @consumer_secret - config.oauth_token = @oauth_token - config.oauth_token_secret = @oauth_token_secret + config.access_token = @access_token + config.access_token_secret = @access_token_secret end needs_stream = [@on_follow, @on_message, @on_mention, @on_timeline].any? {|e| !e.nil?} @@ -88,19 +88,19 @@ module Ebooks end @stream.userstream do |ev| - next unless ev[:text] # If it's not a text-containing tweet, ignore it - next if ev[:user][:screen_name] == @username # Ignore our own tweets + next unless ev.text # If it's not a text-containing tweet, ignore it + next if ev.user.screen_name == @username # Ignore our own tweets meta = {} mentions = ev.attrs[:entities][:user_mentions].map { |x| x[:screen_name] } reply_mentions = mentions.reject { |m| m.downcase == @username.downcase } - reply_mentions = [ev[:user][:screen_name]] + reply_mentions + reply_mentions = [ev.user.screen_name] + reply_mentions meta[:reply_prefix] = reply_mentions.uniq.map { |m| '@'+m }.join(' ') + ' ' meta[:limit] = 140 - meta[:reply_prefix].length - mless = ev[:text] + mless = ev.text begin ev.attrs[:entities][:user_mentions].reverse.each do |entity| last = mless[entity[:indices][1]..-1]||'' @@ -108,7 +108,7 @@ module Ebooks end rescue Exception p ev.attrs[:entities][:user_mentions] - p ev[:text] + p ev.text raise end meta[:mentionless] = mless @@ -117,8 +117,8 @@ module Ebooks # - The tweet mentions list contains our username # - The tweet is not being retweeted by somebody else # - Or soft-retweeted by somebody else - if mentions.map(&:downcase).include?(@username.downcase) && !ev[:retweeted_status] && !ev[:text].start_with?('RT ') - log "Mention from @#{ev[:user][:screen_name]}: #{ev[:text]}" + if mentions.map(&:downcase).include?(@username.downcase) && !ev.retweeted_status && !ev.text.start_with?('RT ') + log "Mention from @#{ev.user.screen_name}: #{ev.text}" @on_mention.call(ev, meta) if @on_mention else @on_timeline.call(ev, meta) if @on_timeline @@ -139,11 +139,11 @@ module Ebooks opts = opts.clone if ev.is_a? Twitter::DirectMessage - log "Sending DM to @#{ev[:sender][:screen_name]}: #{text}" - @twitter.direct_message_create(ev[:sender][:screen_name], text, opts) + log "Sending DM to @#{ev.sender.screen_name}: #{text}" + @twitter.direct_message_create(ev.sender.screen_name, text, opts) elsif ev.is_a? Twitter::Tweet - log "Replying to @#{ev[:user][:screen_name]} with: #{text}" - @twitter.update(text, in_reply_to_status_id: ev[:id]) + log "Replying to @#{ev.user.screen_name} with: #{text}" + @twitter.update(text, in_reply_to_status_id: ev.id) else raise Exception("Don't know how to reply to a #{ev.class}") end