twibot 0.1.1 → 0.1.2
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 +6 -0
- data/Readme.rdoc +4 -0
- data/lib/twibot/bot.rb +9 -14
- data/lib/twibot.rb +1 -1
- data/test/test_bot.rb +8 -16
- metadata +2 -2
data/History.txt
CHANGED
data/Readme.rdoc
CHANGED
@@ -132,6 +132,10 @@ As long as Twibot finds any messages and/or tweets, the interval stays the same
|
|
132
132
|
sleep is increased by interval_step configuration option. This happens until it
|
133
133
|
reaches max_interval, where it will stay until Twibot finds anything.
|
134
134
|
|
135
|
+
== CONTRIBUTORS
|
136
|
+
|
137
|
+
* Dan Van Derveer (bug fixes)
|
138
|
+
|
135
139
|
== LICENSE
|
136
140
|
|
137
141
|
(The MIT License)
|
data/lib/twibot/bot.rb
CHANGED
@@ -25,7 +25,7 @@ module Twibot
|
|
25
25
|
:tweet => nil
|
26
26
|
}
|
27
27
|
rescue Exception => krash
|
28
|
-
raise SystemExit.new
|
28
|
+
raise SystemExit.new(krash.message)
|
29
29
|
end
|
30
30
|
|
31
31
|
def prompt?
|
@@ -82,8 +82,8 @@ module Twibot
|
|
82
82
|
def receive_messages
|
83
83
|
type = :message
|
84
84
|
return false unless handlers[type].length > 0
|
85
|
-
|
86
|
-
options
|
85
|
+
options = {}
|
86
|
+
options[:since_id] = @processed[type] if @processed[type]
|
87
87
|
dispatch_messages(type, @twitter.messages(:received, options), %w{message messages})
|
88
88
|
end
|
89
89
|
|
@@ -93,8 +93,8 @@ module Twibot
|
|
93
93
|
def receive_tweets
|
94
94
|
type = :tweet
|
95
95
|
return false unless handlers[type].length > 0
|
96
|
-
|
97
|
-
options =
|
96
|
+
options = {}
|
97
|
+
options[:since_id] = @processed[type] if @processed[type]
|
98
98
|
dispatch_messages(type, @twitter.timeline_for(:me, options), %w{tweet tweets})
|
99
99
|
end
|
100
100
|
|
@@ -104,15 +104,9 @@ module Twibot
|
|
104
104
|
def receive_replies
|
105
105
|
type = :reply
|
106
106
|
return false unless handlers[type].length > 0
|
107
|
-
|
108
|
-
options =
|
109
|
-
|
110
|
-
|
111
|
-
# Pick only messages that start with our name
|
112
|
-
num = dispatch_messages(type, messages.find_all { |t| t.text =~ /^@#{@twitter.send :login}/ }, %w{reply replies})
|
113
|
-
|
114
|
-
# Avoid picking up messages over again
|
115
|
-
@processed[type] = messages.first.id if messages.length > 0
|
107
|
+
options = {}
|
108
|
+
options[:since_id] = @processed[type] if @processed[type]
|
109
|
+
num = dispatch_messages(type, @twitter.status(:replies, options), %w{reply replies})
|
116
110
|
num
|
117
111
|
end
|
118
112
|
|
@@ -121,6 +115,7 @@ module Twibot
|
|
121
115
|
#
|
122
116
|
def dispatch_messages(type, messages, labels)
|
123
117
|
messages.each { |message| dispatch(type, message) }
|
118
|
+
# Avoid picking up messages over again
|
124
119
|
@processed[type] = messages.first.id if messages.length > 0
|
125
120
|
|
126
121
|
num = messages.length
|
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.
|
10
|
+
VERSION = '0.1.2'
|
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
@@ -58,7 +58,7 @@ class TestBot < Test::Unit::TestCase
|
|
58
58
|
test "should receive message" do
|
59
59
|
bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "error"))
|
60
60
|
bot.add_handler(:message, Twibot::Handler.new)
|
61
|
-
Twitter::Client.any_instance.expects(:messages).with(:received,
|
61
|
+
Twitter::Client.any_instance.expects(:messages).with(:received, {}).returns([message("cjno", "Hei der!")])
|
62
62
|
|
63
63
|
assert bot.receive_messages
|
64
64
|
end
|
@@ -66,7 +66,7 @@ class TestBot < Test::Unit::TestCase
|
|
66
66
|
test "should remember last received message" do
|
67
67
|
bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "error"))
|
68
68
|
bot.add_handler(:message, Twibot::Handler.new)
|
69
|
-
Twitter::Client.any_instance.expects(:messages).with(:received,
|
69
|
+
Twitter::Client.any_instance.expects(:messages).with(:received, {}).returns([message("cjno", "Hei der!")])
|
70
70
|
assert_equal 1, bot.receive_messages
|
71
71
|
|
72
72
|
Twitter::Client.any_instance.expects(:messages).with(:received, { :since_id => 1 }).returns([])
|
@@ -76,7 +76,7 @@ class TestBot < Test::Unit::TestCase
|
|
76
76
|
test "should receive tweet" do
|
77
77
|
bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "error"))
|
78
78
|
bot.add_handler(:tweet, Twibot::Handler.new)
|
79
|
-
Twitter::Client.any_instance.expects(:timeline_for).with(:me,
|
79
|
+
Twitter::Client.any_instance.expects(:timeline_for).with(:me, {}).returns([tweet("cjno", "Hei der!")])
|
80
80
|
|
81
81
|
assert_equal 1, bot.receive_tweets
|
82
82
|
end
|
@@ -84,25 +84,17 @@ class TestBot < Test::Unit::TestCase
|
|
84
84
|
test "should remember received tweets" do
|
85
85
|
bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "error"))
|
86
86
|
bot.add_handler(:tweet, Twibot::Handler.new)
|
87
|
-
Twitter::Client.any_instance.expects(:timeline_for).with(:me,
|
87
|
+
Twitter::Client.any_instance.expects(:timeline_for).with(:me, {}).returns([tweet("cjno", "Hei der!")])
|
88
88
|
assert_equal 1, bot.receive_tweets
|
89
89
|
|
90
|
-
Twitter::Client.any_instance.expects(:timeline_for).with(:me, { :
|
90
|
+
Twitter::Client.any_instance.expects(:timeline_for).with(:me, { :since_id => 1 }).returns([])
|
91
91
|
assert_equal 0, bot.receive_tweets
|
92
92
|
end
|
93
93
|
|
94
|
-
test "should not receive reply when tweet does not start with login" do
|
95
|
-
bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "error", :login => "irbno"))
|
96
|
-
bot.add_handler(:reply, Twibot::Handler.new)
|
97
|
-
Twitter::Client.any_instance.expects(:timeline_for).with(:me, nil).returns([tweet("cjno", "Hei der!")])
|
98
|
-
|
99
|
-
assert_equal 0, bot.receive_replies
|
100
|
-
end
|
101
|
-
|
102
94
|
test "should receive reply when tweet starts with login" do
|
103
95
|
bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "error", :login => "irbno"))
|
104
96
|
bot.add_handler(:reply, Twibot::Handler.new)
|
105
|
-
Twitter::Client.any_instance.expects(:
|
97
|
+
Twitter::Client.any_instance.expects(:status).with(:replies, {}).returns([tweet("cjno", "@irbno Hei der!")])
|
106
98
|
|
107
99
|
assert_equal 1, bot.receive_replies
|
108
100
|
end
|
@@ -110,10 +102,10 @@ class TestBot < Test::Unit::TestCase
|
|
110
102
|
test "should remember received replies" do
|
111
103
|
bot = Twibot::Bot.new(Twibot::Config.new(:log_level => "error", :login => "irbno"))
|
112
104
|
bot.add_handler(:reply, Twibot::Handler.new)
|
113
|
-
Twitter::Client.any_instance.expects(:
|
105
|
+
Twitter::Client.any_instance.expects(:status).with(:replies, {}).returns([tweet("cjno", "@irbno Hei der!")])
|
114
106
|
assert_equal 1, bot.receive_replies
|
115
107
|
|
116
|
-
Twitter::Client.any_instance.expects(:
|
108
|
+
Twitter::Client.any_instance.expects(:status).with(:replies, { :since_id => 1 }).returns([])
|
117
109
|
assert_equal 0, bot.receive_replies
|
118
110
|
end
|
119
111
|
end
|
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.
|
4
|
+
version: 0.1.2
|
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-
|
12
|
+
date: 2009-03-18 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|