Seems we can't go to twitter 5 yet
This commit is contained in:
parent
224cbd7952
commit
203c20f6f3
3 changed files with 24 additions and 18 deletions
|
@ -31,12 +31,14 @@ module Ebooks
|
|||
end
|
||||
end
|
||||
|
||||
Twitter::REST::Client.new do |config|
|
||||
Twitter.configure do |config|
|
||||
config.consumer_key = @config[:consumer_key]
|
||||
config.consumer_secret = @config[:consumer_secret]
|
||||
config.access_token = @config[:oauth_token]
|
||||
config.access_token_secret = @config[:oauth_token_secret]
|
||||
config.oauth_token = @config[:oauth_token]
|
||||
config.oauth_token_secret = @config[:oauth_token_secret]
|
||||
end
|
||||
|
||||
Twitter::Client.new
|
||||
end
|
||||
|
||||
def initialize(username, path, client=nil)
|
||||
|
|
|
@ -43,13 +43,15 @@ module Ebooks
|
|||
config.oauth_token_secret = @oauth_token_secret
|
||||
end
|
||||
|
||||
@twitter = Twitter::REST::Client.new do |config|
|
||||
Twitter.configure do |config|
|
||||
config.consumer_key = @consumer_key
|
||||
config.consumer_secret = @consumer_secret
|
||||
config.access_token = @access_token
|
||||
config.access_token_secret = @access_token_secret
|
||||
config.oauth_token = @oauth_token
|
||||
config.oauth_token_secret = @oauth_token_secret
|
||||
end
|
||||
|
||||
@twitter = Twitter::Client.new
|
||||
|
||||
needs_stream = [@on_follow, @on_message, @on_mention, @on_timeline].any? {|e| !e.nil?}
|
||||
|
||||
@stream = TweetStream::Client.new if needs_stream
|
||||
|
@ -88,19 +90,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 +110,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 +119,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 +141,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
|
||||
|
|
|
@ -19,7 +19,9 @@ Gem::Specification.new do |gem|
|
|||
gem.add_development_dependency 'memory_profiler'
|
||||
gem.add_development_dependency 'pry-byebug'
|
||||
|
||||
gem.add_runtime_dependency 'twitter', '~> 5.1'
|
||||
|
||||
gem.add_runtime_dependency 'twitter', '~> 4.0'
|
||||
gem.add_runtime_dependency 'simple_oauth'
|
||||
gem.add_runtime_dependency 'tweetstream'
|
||||
gem.add_runtime_dependency 'rufus-scheduler'
|
||||
gem.add_runtime_dependency 'gingerice'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue