chewbranca-twibot 0.1.7.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 +50 -0
- data/Rakefile +30 -0
- data/Readme.rdoc +269 -0
- data/lib/hash.rb +8 -0
- data/lib/twibot/bot.rb +422 -0
- data/lib/twibot/config.rb +140 -0
- data/lib/twibot/handlers.rb +122 -0
- data/lib/twibot/macros.rb +101 -0
- data/lib/twibot/tweets.rb +4 -0
- data/lib/twibot.rb +87 -0
- data/test/test_bot.rb +300 -0
- data/test/test_config.rb +89 -0
- data/test/test_handler.rb +191 -0
- data/test/test_hash.rb +34 -0
- data/test/test_helper.rb +44 -0
- data/test/test_twibot.rb +1 -0
- data/twibot.gemspec +38 -0
- metadata +97 -0
data/History.txt
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
== 0.1.7 / 2009-06-01
|
2
|
+
|
3
|
+
* New feature - choose how Twibot processes incoming tweets on startup
|
4
|
+
(process all, process new [old behaviour], or process from a given ID)
|
5
|
+
Bodaniel Jeanes
|
6
|
+
* Substantially improved error handling. Now survives all common network
|
7
|
+
stability issues
|
8
|
+
* Added a host configuration option. The host name is displayed along all
|
9
|
+
output from Twibot. Currently Twitter4R does nothing with this option,
|
10
|
+
Twibot knowing about it should make it easier to put Twibot/Twitter4R on
|
11
|
+
other services like Laconica instances
|
12
|
+
|
13
|
+
== 0.1.6 / 2009-04-13
|
14
|
+
|
15
|
+
* Fixed configure block not actually working for username and password
|
16
|
+
Bodaniel Jeanes
|
17
|
+
* Minor updates in tests
|
18
|
+
|
19
|
+
== 0.1.5 / 2009-04-12
|
20
|
+
|
21
|
+
* Added support for regular expression routes
|
22
|
+
* Make timeline_for option configurable, ie in config: timeline_for: :public
|
23
|
+
* Fixed bug: Users where unlawfully rejected when their screen name started with
|
24
|
+
a capital letter (Wilco)
|
25
|
+
* Fixed bug: Twibot crashed if there were no handlers registered
|
26
|
+
|
27
|
+
== 0.1.4 / 2009-03-24
|
28
|
+
|
29
|
+
* Removed some warnings
|
30
|
+
* Added error handling to avoid Twibot crashing when Twitter is down (Ben Vandgrift)
|
31
|
+
* Fixed bug: receiving tweets from named users crashed Twibot (Jens Ohlig)
|
32
|
+
|
33
|
+
== 0.1.3 / 2009-03-19
|
34
|
+
|
35
|
+
* Ruby 1.9 support
|
36
|
+
|
37
|
+
== 0.1.2 / 2009-03-18
|
38
|
+
|
39
|
+
* Removed some warnings
|
40
|
+
* Applied patch from Dan Van Derveer fixing a few minor bugs related to the
|
41
|
+
options hash sent to Twitter4R
|
42
|
+
|
43
|
+
== 0.1.1 / 2009-03-15
|
44
|
+
|
45
|
+
* Fixed dependency
|
46
|
+
|
47
|
+
== 0.1.0 / 2009-03-15
|
48
|
+
|
49
|
+
* 1 major enhancement
|
50
|
+
* Birthday!
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Look in the tasks/setup.rb file for the various options that can be
|
2
|
+
# configured in this Rakefile. The .rake files in the tasks directory
|
3
|
+
# are where the options are used.
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bones'
|
7
|
+
Bones.setup
|
8
|
+
rescue LoadError
|
9
|
+
begin
|
10
|
+
load 'tasks/setup.rb'
|
11
|
+
rescue LoadError
|
12
|
+
raise RuntimeError, '### please install the "bones" gem ###'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
ensure_in_path 'lib'
|
17
|
+
require 'twibot'
|
18
|
+
|
19
|
+
task :default => 'test:run'
|
20
|
+
|
21
|
+
PROJ.name = 'twibot'
|
22
|
+
PROJ.authors = 'Christian Johansen'
|
23
|
+
PROJ.email = 'christian@cjohansen.no'
|
24
|
+
PROJ.url = 'http://github.com/bjeanes/twibot/'
|
25
|
+
PROJ.version = Twibot::VERSION
|
26
|
+
PROJ.rubyforge.name = 'twibot'
|
27
|
+
PROJ.readme_file = 'Readme.rdoc'
|
28
|
+
PROJ.rdoc.remote_dir = 'twibot'
|
29
|
+
|
30
|
+
depend_on "mbbx6spp-twitter4r", "0.3.1"
|
data/Readme.rdoc
ADDED
@@ -0,0 +1,269 @@
|
|
1
|
+
= Twibot
|
2
|
+
Official URL: http://github.com/cjohansen/twibot/tree/master
|
3
|
+
Christian Johansen (http://www.cjohansen.no)
|
4
|
+
Twitter: @cjno
|
5
|
+
|
6
|
+
== Description
|
7
|
+
|
8
|
+
Twibot (pronounced like "Abbot"), is a Ruby microframework for creating Twitter
|
9
|
+
bots, heavily inspired by Sinatra.
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
=== Simple example
|
14
|
+
|
15
|
+
require 'twibot'
|
16
|
+
|
17
|
+
# Receive messages, and tweet them publicly
|
18
|
+
#
|
19
|
+
message do |message, params|
|
20
|
+
post_tweet message
|
21
|
+
end
|
22
|
+
|
23
|
+
# Respond to @replies if they come from the right crowd
|
24
|
+
#
|
25
|
+
reply :from => [:cjno, :irbno] do |message, params|
|
26
|
+
post_reply message, "I agree"
|
27
|
+
end
|
28
|
+
|
29
|
+
# Listen in and log tweets
|
30
|
+
#
|
31
|
+
tweet do |message, params|
|
32
|
+
MyApp.log_tweet(message)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Search for tweets matching a query. The available search operators
|
36
|
+
# are explained here: <http://search.twitter.com/operators>
|
37
|
+
#
|
38
|
+
search "twibot" do |message, params|
|
39
|
+
# do_something
|
40
|
+
end
|
41
|
+
|
42
|
+
# Search for tweets with a hashtag
|
43
|
+
# see: <http://twitter.pbworks.com/Hashtags>
|
44
|
+
#
|
45
|
+
# Note: hashtag is just a convenience wrapper
|
46
|
+
# around search. It will invoke the search
|
47
|
+
# before and after filters.
|
48
|
+
#
|
49
|
+
hashtag "twibot" do |message, params|
|
50
|
+
# do_something
|
51
|
+
end
|
52
|
+
|
53
|
+
# Search for tweets with one of a number of hashtags
|
54
|
+
# see: <http://twitter.pbworks.com/Hashtags>
|
55
|
+
#
|
56
|
+
# Note: hashtags is just an alias to hashtag
|
57
|
+
#
|
58
|
+
hashtags [:twibot, :ruby, "twitter4r"] do |message, params|
|
59
|
+
# do_something
|
60
|
+
end
|
61
|
+
|
62
|
+
# Process any new followers. user_id will be
|
63
|
+
# the user's Numeric id and params will always
|
64
|
+
# be an empty Hash.
|
65
|
+
#
|
66
|
+
# add_friend!(id) is a convenience wrapper around the
|
67
|
+
# twitter4r friendship method. remove_friend!(id)
|
68
|
+
# is also available.
|
69
|
+
#
|
70
|
+
follower do |user_id, params|
|
71
|
+
# keep out the riff-raff...
|
72
|
+
bot.add_friend!(user_id) unless user_id == 890631
|
73
|
+
end
|
74
|
+
|
75
|
+
# add some set-up code that will be called
|
76
|
+
# before each polling cycle. :all is the
|
77
|
+
# default, so it can safely be omitted
|
78
|
+
#
|
79
|
+
before :all do
|
80
|
+
MyApp.log("Started polling at #{Time.now}")
|
81
|
+
end
|
82
|
+
|
83
|
+
# the after hook for the polling cycle gets
|
84
|
+
# passed the number of messages that were
|
85
|
+
# processed
|
86
|
+
#
|
87
|
+
after :all do |message_count|
|
88
|
+
MyApp.log("Finished polling at #{Time.now}. Got #{message_count} messages.")
|
89
|
+
end
|
90
|
+
|
91
|
+
# each action has before and after hooks available:
|
92
|
+
# - follower
|
93
|
+
# - message
|
94
|
+
# - reply
|
95
|
+
# - search
|
96
|
+
# - tweet
|
97
|
+
#
|
98
|
+
# there can be only one before and one after callback
|
99
|
+
# registered for a given type. the callback block
|
100
|
+
# will be called with no arguments.
|
101
|
+
#
|
102
|
+
# Note: hashtag and hashtags are just wrappers around
|
103
|
+
# search and do not have their own hooks. Use the
|
104
|
+
# search hooks when using hashtag or hashtags.
|
105
|
+
#
|
106
|
+
before :message do
|
107
|
+
MyApp.is_processing_a_message = true
|
108
|
+
end
|
109
|
+
|
110
|
+
after :message do
|
111
|
+
MyApp.is_processing_a_message = false
|
112
|
+
end
|
113
|
+
|
114
|
+
after :follower do
|
115
|
+
MyApp.log("I have another follower!")
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
=== Running the bot
|
120
|
+
|
121
|
+
To run the bot, simply do:
|
122
|
+
|
123
|
+
ruby bot.rb
|
124
|
+
|
125
|
+
=== Configuration
|
126
|
+
|
127
|
+
Twibot looks for a configuration file in ./config/bot.yml. It should contain
|
128
|
+
atleast:
|
129
|
+
|
130
|
+
login: twitter_login
|
131
|
+
password: twitter_password
|
132
|
+
|
133
|
+
You can also pass configuration as command line arguments:
|
134
|
+
|
135
|
+
ruby bot.rb --login myaccount
|
136
|
+
|
137
|
+
...or configure with Ruby:
|
138
|
+
|
139
|
+
configure do |conf|
|
140
|
+
conf.login = "my_account"
|
141
|
+
do
|
142
|
+
|
143
|
+
If you don't specify login and/or password in any of these ways, Twibot will
|
144
|
+
prompt you for those.
|
145
|
+
|
146
|
+
If you want to change how Twibot is configured, you can setup the bot instance
|
147
|
+
manually and give it only the configuration options you want:
|
148
|
+
|
149
|
+
# Create bot only with default configuration
|
150
|
+
require 'twibot'
|
151
|
+
bot = Twibot::Bot.new(Twibot::Config.default)
|
152
|
+
|
153
|
+
# Application here...
|
154
|
+
|
155
|
+
If you want command line arguments you can do:
|
156
|
+
|
157
|
+
require 'twibot'
|
158
|
+
bot = Twibot::Bot.new(Twibot::Config.default << Twibot::CliConfig.new)
|
159
|
+
|
160
|
+
To disable the buffering of the Twibot log file, set the `log_flush` config
|
161
|
+
option to `true`:
|
162
|
+
|
163
|
+
configure do |conf|
|
164
|
+
conf.log_file = File.join(DAEMON_ROOT, 'log', 'twitterd.log')
|
165
|
+
conf.log_level = "info"
|
166
|
+
conf.log_flush = true
|
167
|
+
end
|
168
|
+
|
169
|
+
=== "Routes"
|
170
|
+
|
171
|
+
Like Sinatra, and other web app frameworks, Twibot supports "routes": patterns
|
172
|
+
to match incoming tweets and messages:
|
173
|
+
|
174
|
+
require 'twibot'
|
175
|
+
|
176
|
+
tweet "time :country :city" do |message,params|
|
177
|
+
time = MyTimeService.lookup(params[:country], params[:city])
|
178
|
+
client.message :post, "Time is #{time} in #{params[:city]}, #{params[:country]}"
|
179
|
+
end
|
180
|
+
|
181
|
+
You can have several "tweet" blocks (or "message" or "reply"). The first one to
|
182
|
+
match an incoming tweet/message will handle it.
|
183
|
+
|
184
|
+
As of the upcoming 0.1.5/0.2.0, Twibot also supports regular expressions as routes:
|
185
|
+
|
186
|
+
require 'twibot'
|
187
|
+
|
188
|
+
tweet /^time ([^\s]*) ([^\s]*)/ do |message, params|
|
189
|
+
# params is an array of matches when using regexp routes
|
190
|
+
time = MyTimeService.lookup(params[0], params[1])
|
191
|
+
client.message :post, "Time is #{time} in #{params[:city]}, #{params[:country]}"
|
192
|
+
end
|
193
|
+
|
194
|
+
=== Working with the Twitter API
|
195
|
+
|
196
|
+
The DSL gives you access to your Twitter client instance through "client" (or "twitter"):
|
197
|
+
|
198
|
+
message do
|
199
|
+
twitter.status :post, "Hello world" # Also: client.status :post, "Hello world"
|
200
|
+
end
|
201
|
+
|
202
|
+
== Requirements
|
203
|
+
|
204
|
+
Twitter4r. You'll need atleast 0.3.1, which is currently only available from GitHub.
|
205
|
+
Versions of Twitter4r prior to 0.3.1 does not allow for the since_id parameter to be
|
206
|
+
appended to URLs to the REST API. Twibot needs these to only fetch fresh messages
|
207
|
+
and tweets.
|
208
|
+
|
209
|
+
== Installation
|
210
|
+
|
211
|
+
gem install twibot
|
212
|
+
|
213
|
+
== Is it Ruby 1.9?
|
214
|
+
|
215
|
+
As of Twibot 0.1.3, yes it is! All tests pass, please give feedback from real world
|
216
|
+
usage if you have trouble.
|
217
|
+
|
218
|
+
== Polling
|
219
|
+
|
220
|
+
Twitter pulled the plug on it's xmpp service last year. This means that Twibot backed
|
221
|
+
bots needs to poll the Twitter service to keep up. Twitter has a request limit on 70
|
222
|
+
reqs/hour, so you should configure your bot not to make more than that, else it will
|
223
|
+
fail. You can ask for your bot account to be put on the whitelist which allows you to
|
224
|
+
make 20.000 reqs/hour, and shouldn't be a problem so long as your intentions are good
|
225
|
+
(I think).
|
226
|
+
|
227
|
+
Twibot polls like this:
|
228
|
+
* Poll messages if any message handlers exist
|
229
|
+
* Poll tweets if any tweet or reply handlers exist
|
230
|
+
* Sleep for +interval+ seconds
|
231
|
+
* Go over again
|
232
|
+
|
233
|
+
As long as Twibot finds any messages and/or tweets, the interval stays the same
|
234
|
+
(min_interval configuration switch). If nothing was found however, the interval to
|
235
|
+
sleep is increased by interval_step configuration option. This happens until it
|
236
|
+
reaches max_interval, where it will stay until Twibot finds anything.
|
237
|
+
|
238
|
+
== Contributors
|
239
|
+
|
240
|
+
* Dan Van Derveer (bug fixes) - http://dan.van.derveer.com/
|
241
|
+
* Ben Vandgrift (Twitter downtime error handling) - http://neovore.com/
|
242
|
+
* Jens Ohlig (warnings)
|
243
|
+
* Wilco van Duinkerken (bug fixes) - http://www.sparkboxx.com/
|
244
|
+
* Bodaniel Jeanes (configure block fix) - http://bjeanes.github.com/
|
245
|
+
|
246
|
+
== License
|
247
|
+
|
248
|
+
(The MIT License)
|
249
|
+
|
250
|
+
Copyright (c) 2009 Christian Johansen
|
251
|
+
|
252
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
253
|
+
a copy of this software and associated documentation files (the
|
254
|
+
'Software'), to deal in the Software without restriction, including
|
255
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
256
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
257
|
+
permit persons to whom the Software is furnished to do so, subject to
|
258
|
+
the following conditions:
|
259
|
+
|
260
|
+
The above copyright notice and this permission notice shall be
|
261
|
+
included in all copies or substantial portions of the Software.
|
262
|
+
|
263
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
264
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
265
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
266
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
267
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
268
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
269
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|