twibot 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,13 @@
1
+ == 0.1.4 / 2009-03-24
2
+
3
+ * Removed some warnings
4
+ * Added error handling to avoid Twibot crashing when Twitter is down (Ben Vandgrift)
5
+ * Fixed bug: receiving tweets from named users crashed Twibot (Jens Ohlig)
6
+
7
+ == 0.1.3 / 2009-03-19
8
+
9
+ * Ruby 1.9 support
10
+
1
11
  == 0.1.2 / 2009-03-18
2
12
 
3
13
  * Removed some warnings
data/Readme.rdoc CHANGED
@@ -134,6 +134,8 @@ reaches max_interval, where it will stay until Twibot finds anything.
134
134
  == Contributors
135
135
 
136
136
  * Dan Van Derveer (bug fixes) - http://dan.van.derveer.com/
137
+ * Ben Vandgrift (Twitter downtime error handling) - http://neovore.com/
138
+ * Jens Ohlig (warnings)
137
139
 
138
140
  == License
139
141
 
data/lib/twibot/bot.rb CHANGED
@@ -48,7 +48,13 @@ module Twibot
48
48
  @processed[:message] = messages.first.id if messages.length > 0
49
49
 
50
50
  handle_tweets = @handlers[:tweet].length + @handlers[:reply].length > 0
51
- tweets = handle_tweets ? @twitter.timeline_for(:me, { :count => 1 }) : []
51
+ tweets = []
52
+ begin
53
+ tweets = handle_tweets ? @twitter.timeline_for(:me, { :count => 1 }) : []
54
+ rescue Twitter::RESTError => e
55
+ log.error("Failed to connect to Twitter. It's likely down for a bit:")
56
+ log.error(e.to_s)
57
+ end
52
58
  @processed[:tweet] = tweets.first.id if tweets.length > 0
53
59
  @processed[:reply] = tweets.first.id if tweets.length > 0
54
60
 
@@ -84,7 +90,13 @@ module Twibot
84
90
  return false unless handlers[type].length > 0
85
91
  options = {}
86
92
  options[:since_id] = @processed[type] if @processed[type]
87
- dispatch_messages(type, @twitter.messages(:received, options), %w{message messages})
93
+ begin
94
+ dispatch_messages(type, @twitter.messages(:received, options), %w{message messages})
95
+ rescue Twitter::RESTError => e
96
+ log.error("Failed to connect to Twitter. It's likely down for a bit:")
97
+ log.error(e.to_s)
98
+ 0
99
+ end
88
100
  end
89
101
 
90
102
  #
@@ -95,7 +107,15 @@ module Twibot
95
107
  return false unless handlers[type].length > 0
96
108
  options = {}
97
109
  options[:since_id] = @processed[type] if @processed[type]
98
- dispatch_messages(type, @twitter.timeline_for(:me, options), %w{tweet tweets})
110
+ begin
111
+ dispatch_messages(type,
112
+ @twitter.timeline_for(config[:include_friends] ? :friends : :me,
113
+ options), %w{tweet tweets})
114
+ rescue Twitter::RESTError => e
115
+ log.error("Failed to connect to Twitter. It's likely down for a bit:")
116
+ log.error(e.to_s)
117
+ 0
118
+ end
99
119
  end
100
120
 
101
121
  #
@@ -106,8 +126,14 @@ module Twibot
106
126
  return false unless handlers[type].length > 0
107
127
  options = {}
108
128
  options[:since_id] = @processed[type] if @processed[type]
109
- num = dispatch_messages(type, @twitter.status(:replies, options), %w{reply replies})
110
- num
129
+ begin
130
+ dispatch_messages(type, @twitter.status(:replies, options), %w{reply replies})
131
+ rescue Twitter::RESTError => e
132
+ log.error("Failed to connect to Twitter. It's likely down for a bit:")
133
+ log.error(e.to_s)
134
+ 0
135
+ end
136
+
111
137
  end
112
138
 
113
139
  #
@@ -171,13 +197,14 @@ module Twibot
171
197
  @config.password = hl.ask("Twitter password: ") { |q| q.echo = '*' } unless @conf[:password]
172
198
  @conf = @config.to_hash
173
199
  rescue LoadError
174
- raise SystemExit.new <<-HELP
200
+ raise SystemExit.new( <<-HELP
175
201
  Unable to continue without login and password. Do one of the following:
176
202
  1) Install the HighLine gem (gem install highline) to be prompted for credentials
177
203
  2) Create a config/bot.yml with login: and password:
178
204
  3) Put a configure { |conf| conf.login = "..." } block in your bot application
179
205
  4) Run bot with --login and --password options
180
206
  HELP
207
+ )
181
208
  end
182
209
  end
183
210
 
data/lib/twibot/config.rb CHANGED
@@ -28,7 +28,8 @@ module Twibot
28
28
  :login => nil,
29
29
  :password => nil,
30
30
  :prompt => false,
31
- :daemonize => false
31
+ :daemonize => false,
32
+ :include_friends => false
32
33
  }
33
34
 
34
35
  def initialize(settings = {})
@@ -69,7 +69,8 @@ module Twibot
69
69
  return false if @options[:pattern] && message.text !~ @options[:pattern] # Pattern check
70
70
 
71
71
  users = @options[:from] ? @options[:from] : nil
72
- return false if users && !users.include?(message.sender.screen_name) # Check allowed senders
72
+ sender = message.respond_to?(:sender) ? message.sender : message.user
73
+ return false if users && !users.include?(sender.screen_name) # Check allowed senders
73
74
  true
74
75
  end
75
76
 
data/lib/twibot.rb CHANGED
@@ -7,7 +7,7 @@ require File.join(File.dirname(__FILE__), 'hash')
7
7
  module Twibot
8
8
 
9
9
  # :stopdoc:
10
- VERSION = '0.1.3'
10
+ VERSION = '0.1.4'
11
11
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
12
12
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
13
13
  # :startdoc:
data/test/test_bot.rb CHANGED
@@ -81,6 +81,14 @@ class TestBot < Test::Unit::TestCase
81
81
  assert_equal 1, bot.receive_tweets
82
82
  end
83
83
 
84
+ should "receive friend tweets if configured" do
85
+ bot = Twibot::Bot.new(Twibot::Config.new({:log_level => "error", :include_friends => true}))
86
+ bot.add_handler(:tweet, Twibot::Handler.new)
87
+ Twitter::Client.any_instance.expects(:timeline_for).with(:friends, {}).returns([tweet("cjno", "Hei der!")])
88
+
89
+ assert_equal 1, bot.receive_tweets
90
+ end
91
+
84
92
  should "remember received tweets" do
85
93
  bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "error"))
86
94
  bot.add_handler(:tweet, Twibot::Handler.new)
data/test/test_handler.rb CHANGED
@@ -121,6 +121,12 @@ class TestHandler < Test::Unit::TestCase
121
121
  assert handler.recognize?(message)
122
122
  end
123
123
 
124
+ should "recognize tweets from allowed users" do
125
+ handler = Twibot::Handler.new :from => [:cjno, :irbno]
126
+ message = tweet "cjno", "time oslo norway"
127
+ assert handler.recognize?(message)
128
+ end
129
+
124
130
  should "accept options as only argument" do
125
131
  handler = Twibot::Handler.new :from => :cjno
126
132
  assert_equal(:cjno, handler.instance_eval { @options[:from] })
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twibot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Johansen
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-18 00:00:00 +01:00
12
+ date: 2009-03-24 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency