From dbe909f7b7c53a138543705c6aa179c3b436b8db Mon Sep 17 00:00:00 2001 From: Amelia Cuss Date: Thu, 12 Dec 2013 13:27:48 +0000 Subject: [PATCH 1/2] Use STDOUT, please. It exists for a reason! Otherwise we can't distinguish errors (like from unhandled exceptions). --- lib/twitter_ebooks/bot.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/twitter_ebooks/bot.rb b/lib/twitter_ebooks/bot.rb index 3e6072e..088fd56 100755 --- a/lib/twitter_ebooks/bot.rb +++ b/lib/twitter_ebooks/bot.rb @@ -30,8 +30,8 @@ module Ebooks end def log(*args) - STDERR.puts "@#{@username}: " + args.map(&:to_s).join(' ') - STDERR.flush + STDOUT.puts "@#{@username}: " + args.map(&:to_s).join(' ') + STDOUT.flush end def configure From 437e1edff6c88f10862e55c0b0bc30d234454825 Mon Sep 17 00:00:00 2001 From: Amelia Cuss Date: Thu, 12 Dec 2013 13:28:29 +0000 Subject: [PATCH 2/2] Don't connect a TweetStream if we don't use it. --- lib/twitter_ebooks/bot.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/twitter_ebooks/bot.rb b/lib/twitter_ebooks/bot.rb index 088fd56..1f940ed 100755 --- a/lib/twitter_ebooks/bot.rb +++ b/lib/twitter_ebooks/bot.rb @@ -49,8 +49,10 @@ module Ebooks config.oauth_token_secret = @oauth_token_secret end + needs_stream = [@on_follow, @on_message, @on_mention, @on_timeline].any? {|e| !e.nil?} + @twitter = Twitter::Client.new - @stream = TweetStream::Client.new + @stream = TweetStream::Client.new if needs_stream end # Connects to tweetstream and opens event handlers for this bot @@ -59,6 +61,12 @@ module Ebooks @on_startup.call if @on_startup + if not @stream + log "not bothering with stream for #@username" + return + end + + log "starting stream for #@username" @stream.on_error do |msg| log "ERROR: #{msg}" end