chatterbot 0.7.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +7 -5
- data/README.markdown +1 -1
- data/Rakefile +8 -0
- data/bin/chatterbot-blacklist +2 -0
- data/bin/chatterbot-register +2 -0
- data/bin/chatterbot-status +2 -0
- data/chatterbot.gemspec +6 -6
- data/examples/streaming_bot.rb +42 -0
- data/lib/chatterbot.rb +16 -1
- data/lib/chatterbot/blacklist.rb +3 -1
- data/lib/chatterbot/bot.rb +4 -0
- data/lib/chatterbot/client.rb +21 -26
- data/lib/chatterbot/config.rb +26 -30
- data/lib/chatterbot/db.rb +2 -0
- data/lib/chatterbot/dsl.rb +117 -3
- data/lib/chatterbot/favorite.rb +23 -0
- data/lib/chatterbot/followers.rb +9 -0
- data/lib/chatterbot/helpers.rb +3 -1
- data/lib/chatterbot/logging.rb +4 -3
- data/lib/chatterbot/profile.rb +40 -0
- data/lib/chatterbot/reply.rb +10 -2
- data/lib/chatterbot/retweet.rb +10 -4
- data/lib/chatterbot/search.rb +12 -6
- data/lib/chatterbot/skeleton.rb +6 -0
- data/lib/chatterbot/streaming.rb +67 -0
- data/lib/chatterbot/streaming_handler.rb +96 -0
- data/lib/chatterbot/tweet.rb +2 -0
- data/lib/chatterbot/ui.rb +2 -1
- data/lib/chatterbot/utils.rb +11 -0
- data/lib/chatterbot/version.rb +1 -1
- data/spec/blacklist_spec.rb +24 -23
- data/spec/bot_spec.rb +12 -0
- data/spec/client_spec.rb +36 -32
- data/spec/config_spec.rb +135 -85
- data/spec/db_spec.rb +5 -5
- data/spec/dsl_spec.rb +74 -27
- data/spec/favorite_spec.rb +34 -0
- data/spec/followers_spec.rb +32 -11
- data/spec/helpers_spec.rb +25 -20
- data/spec/logging_spec.rb +16 -15
- data/spec/profile_spec.rb +65 -0
- data/spec/reply_spec.rb +24 -24
- data/spec/retweet_spec.rb +17 -9
- data/spec/search_spec.rb +26 -26
- data/spec/skeleton_spec.rb +6 -6
- data/spec/spec_helper.rb +44 -32
- data/spec/streaming_handler_spec.rb +78 -0
- data/spec/streaming_spec.rb +172 -0
- data/spec/tweet_spec.rb +18 -18
- data/spec/utils_spec.rb +29 -0
- data/specs.watchr +1 -13
- metadata +27 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d6cc3315231e205c177354dd5673822215379086
|
4
|
+
data.tar.gz: d4b0c0bb2d9ce6d2aa3d06ab17250a43868f1050
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a8a816511a450286f76f0a7e7650c57fda15d9fcf58492473883402253997817a450e55d586858612acf2cf05741afc76567af25c319c7aea1ba0279f4359de
|
7
|
+
data.tar.gz: a66dc9d98fa5f1b40270ac88231b7849a13861a97b565ed0a40f1e582bbae93ef19daf804ce7ae629bd9f3ab06b2db236fea15e3092d1449014d4106edcd782e
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -8,16 +8,18 @@ gemspec
|
|
8
8
|
# Add dependencies to develop your gem here.
|
9
9
|
# Include everything needed to run rake, tests, features, etc.
|
10
10
|
group :development do
|
11
|
-
gem 'simplecov', :require => false, :group => :test
|
11
|
+
#gem 'simplecov', :require => false, :group => :test
|
12
12
|
|
13
|
-
gem "shoulda", ">= 0"
|
14
|
-
gem "rspec"
|
15
|
-
gem "rake"
|
13
|
+
#gem "shoulda", ">= 0"
|
14
|
+
#gem "rspec"
|
15
|
+
#gem "rake"
|
16
16
|
#gem "twitter", "~> 4.4.0"
|
17
17
|
|
18
|
-
gem "watchr"
|
18
|
+
#gem "watchr"
|
19
19
|
end
|
20
20
|
|
21
|
+
gem "pry"
|
22
|
+
|
21
23
|
#
|
22
24
|
# couple extra gems for testing db connectivity
|
23
25
|
#
|
data/README.markdown
CHANGED
@@ -217,7 +217,7 @@ your bot:
|
|
217
217
|
it with your bots if desired.
|
218
218
|
6. In a database. You can store your configuration in a DB, and then
|
219
219
|
specify the connection string either in one of the global config
|
220
|
-
files
|
220
|
+
files by setting `:db_uri: postgres://username:password@host/database`, or on the command-line by using the `--db="db_uri"`
|
221
221
|
configuration option. Any calls to the database are handled by the
|
222
222
|
Sequel gem, and MySQL and Sqlite should work. The DB URI should
|
223
223
|
be in the form of `mysql://username:password@host/database` -- see
|
data/Rakefile
CHANGED
@@ -24,3 +24,11 @@ Rake::RDocTask.new do |rdoc|
|
|
24
24
|
rdoc.rdoc_dir = 'rdoc'
|
25
25
|
rdoc.title = "'chatterbot #{Chatterbot::VERSION}'"
|
26
26
|
end
|
27
|
+
|
28
|
+
task :console do
|
29
|
+
require 'irb'
|
30
|
+
require 'irb/completion'
|
31
|
+
require 'chatterbot' # You know what to do.
|
32
|
+
ARGV.clear
|
33
|
+
IRB.start
|
34
|
+
end
|
data/bin/chatterbot-blacklist
CHANGED
data/bin/chatterbot-register
CHANGED
data/bin/chatterbot-status
CHANGED
data/chatterbot.gemspec
CHANGED
@@ -27,17 +27,17 @@ Gem::Specification.new do |s|
|
|
27
27
|
else
|
28
28
|
s.add_development_dependency(%q<redcarpet>, [">= 0"])
|
29
29
|
end
|
30
|
-
|
31
|
-
s.add_runtime_dependency(%q<oauth>, [">= 0"])
|
32
|
-
s.add_runtime_dependency(%q<twitter>, ["
|
30
|
+
|
31
|
+
s.add_runtime_dependency(%q<oauth>, [">= 0.4.7"])
|
32
|
+
s.add_runtime_dependency(%q<twitter>, ["5.8.0"])
|
33
33
|
s.add_runtime_dependency(%q<launchy>, [">= 2.1.2"])
|
34
34
|
s.add_development_dependency(%q<yard>, [">= 0"])
|
35
35
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
36
36
|
s.add_development_dependency(%q<rake>, [">= 0"])
|
37
|
-
s.add_development_dependency(%q<rspec>, ["
|
38
|
-
s.add_development_dependency(%q<rspec-mocks>, ["
|
37
|
+
s.add_development_dependency(%q<rspec>, ["~> 3.0.0"])
|
38
|
+
s.add_development_dependency(%q<rspec-mocks>, ["~> 3.0.2"])
|
39
39
|
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
40
40
|
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
41
|
-
s.add_development_dependency(%q<
|
41
|
+
s.add_development_dependency(%q<observr>, [">= 0"])
|
42
42
|
end
|
43
43
|
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
## This is a very simple working example of a bot using the streaming
|
4
|
+
## API. It's basically a copy of echoes_bot.rb, just using streaming.
|
5
|
+
|
6
|
+
#
|
7
|
+
# require the dsl lib to include all the methods you see below.
|
8
|
+
#
|
9
|
+
require 'rubygems'
|
10
|
+
require 'chatterbot/dsl'
|
11
|
+
|
12
|
+
consumer_secret 'foo'
|
13
|
+
secret 'bar'
|
14
|
+
token 'biz'
|
15
|
+
consumer_key 'bam'
|
16
|
+
|
17
|
+
|
18
|
+
puts "Loading echoes_bot.rb using the streaming API"
|
19
|
+
|
20
|
+
exclude "http://", "https://"
|
21
|
+
|
22
|
+
blacklist "mean_user, private_user"
|
23
|
+
|
24
|
+
streaming do
|
25
|
+
favorited do |user, tweet|
|
26
|
+
reply "@#{user.screen_name} thanks for the fave!", tweet
|
27
|
+
end
|
28
|
+
|
29
|
+
followed do |user|
|
30
|
+
tweet "@#{user.screen_name} just followed me!"
|
31
|
+
follow user
|
32
|
+
end
|
33
|
+
|
34
|
+
replies do |tweet|
|
35
|
+
favorite tweet
|
36
|
+
|
37
|
+
puts "It's a tweet!"
|
38
|
+
src = tweet.text.gsub(/@echoes_bot/, "#USER#")
|
39
|
+
reply src, tweet
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
data/lib/chatterbot.rb
CHANGED
@@ -28,6 +28,8 @@ end
|
|
28
28
|
#
|
29
29
|
# the big kahuna!
|
30
30
|
module Chatterbot
|
31
|
+
@@from_helper = false
|
32
|
+
|
31
33
|
#
|
32
34
|
# load in our assorted modules
|
33
35
|
def self.load
|
@@ -40,13 +42,26 @@ module Chatterbot
|
|
40
42
|
require "chatterbot/search"
|
41
43
|
require "chatterbot/tweet"
|
42
44
|
require "chatterbot/retweet"
|
45
|
+
require "chatterbot/favorite"
|
46
|
+
require "chatterbot/profile"
|
43
47
|
require "chatterbot/reply"
|
48
|
+
require "chatterbot/streaming"
|
49
|
+
require "chatterbot/streaming_handler"
|
44
50
|
require "chatterbot/followers"
|
45
|
-
require "chatterbot/helpers"
|
51
|
+
require "chatterbot/helpers"
|
52
|
+
require "chatterbot/utils"
|
46
53
|
|
47
54
|
require "chatterbot/bot"
|
48
55
|
end
|
49
56
|
|
57
|
+
def self.from_helper=(x)
|
58
|
+
@@from_helper = x
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.from_helper
|
62
|
+
@@from_helper
|
63
|
+
end
|
64
|
+
|
50
65
|
require 'chatterbot/version'
|
51
66
|
|
52
67
|
# Return a directory with the project libraries.
|
data/lib/chatterbot/blacklist.rb
CHANGED
@@ -29,6 +29,9 @@ module Chatterbot
|
|
29
29
|
#
|
30
30
|
# Is this tweet from a user on our blacklist?
|
31
31
|
def on_blacklist?(s)
|
32
|
+
puts s.inspect
|
33
|
+
puts blacklist.inspect
|
34
|
+
|
32
35
|
search = (s.respond_to?(:user) ? from_user(s) : s).downcase
|
33
36
|
blacklist.any? { |b| search.include?(b.downcase) } ||
|
34
37
|
on_global_blacklist?(search)
|
@@ -52,7 +55,6 @@ module Chatterbot
|
|
52
55
|
|
53
56
|
# make sure we don't have an @ at the beginning of the username
|
54
57
|
user.gsub!(/^@/, "")
|
55
|
-
|
56
58
|
debug "adding #{user} to blacklist"
|
57
59
|
|
58
60
|
db[:blacklist].insert({ :user => user, :created_at => Time.now }) #
|
data/lib/chatterbot/bot.rb
CHANGED
@@ -3,12 +3,16 @@ module Chatterbot
|
|
3
3
|
#
|
4
4
|
# primary Bot object, includes all the other modules
|
5
5
|
class Bot
|
6
|
+
include Utils
|
6
7
|
include Blacklist
|
8
|
+
include Streaming
|
7
9
|
include Config
|
8
10
|
include Logging
|
9
11
|
include Search
|
10
12
|
include Tweet
|
13
|
+
include Profile
|
11
14
|
include Retweet
|
15
|
+
include Favorite
|
12
16
|
include Reply
|
13
17
|
include Followers
|
14
18
|
include UI
|
data/lib/chatterbot/client.rb
CHANGED
@@ -6,39 +6,34 @@ module Chatterbot
|
|
6
6
|
# routines for connecting to Twitter and validating the bot
|
7
7
|
#
|
8
8
|
module Client
|
9
|
-
attr_accessor :screen_name, :client, :search_client
|
9
|
+
attr_accessor :screen_name, :client, :streaming_client, :search_client
|
10
10
|
|
11
11
|
#
|
12
12
|
# the main interface to the Twitter API
|
13
13
|
#
|
14
14
|
def client
|
15
|
-
@client ||= Twitter::Client.new(
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
)
|
15
|
+
@client ||= Twitter::REST::Client.new(
|
16
|
+
:consumer_key => client_params[:consumer_key],
|
17
|
+
:consumer_secret => client_params[:consumer_secret],
|
18
|
+
:access_token => client_params[:token],
|
19
|
+
:access_token_secret => client_params[:secret]
|
20
|
+
)
|
22
21
|
end
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
# return client
|
32
|
-
|
33
|
-
# @search_client ||= Twitter::Client.new(
|
34
|
-
# :endpoint => base_url,
|
35
|
-
# :consumer_key => client_params[:consumer_key],
|
36
|
-
# :consumer_secret => client_params[:consumer_secret],
|
37
|
-
# :oauth_token => client_params[:token],
|
38
|
-
# :oauth_token_secret => client_params[:secret]
|
39
|
-
# )
|
23
|
+
def streaming_client
|
24
|
+
@streaming_client ||= Twitter::Streaming::Client.new(
|
25
|
+
:consumer_key => client_params[:consumer_key],
|
26
|
+
:consumer_secret => client_params[:consumer_secret],
|
27
|
+
:access_token => client_params[:token],
|
28
|
+
:access_token_secret => client_params[:secret]
|
29
|
+
)
|
40
30
|
end
|
41
31
|
|
32
|
+
def reset!
|
33
|
+
config[:since_id] = 0
|
34
|
+
config[:since_id_reply] = 0
|
35
|
+
end
|
36
|
+
|
42
37
|
#
|
43
38
|
# reset the since_id for this bot to the highest since_id we can
|
44
39
|
# get, by running a really open search and updating config with
|
@@ -55,7 +50,7 @@ module Chatterbot
|
|
55
50
|
#
|
56
51
|
def reset_since_id_reply
|
57
52
|
config[:tmp_since_id_reply] = 0
|
58
|
-
result = client.
|
53
|
+
result = client.mentions_timeline.max_by(&:id)
|
59
54
|
update_since_id_reply(result)
|
60
55
|
end
|
61
56
|
|
@@ -179,7 +174,7 @@ module Chatterbot
|
|
179
174
|
|
180
175
|
rescue OAuth::Unauthorized => e
|
181
176
|
display_oauth_error
|
182
|
-
|
177
|
+
warn e.inspect
|
183
178
|
return false
|
184
179
|
end
|
185
180
|
end
|
data/lib/chatterbot/config.rb
CHANGED
@@ -4,7 +4,9 @@ module Chatterbot
|
|
4
4
|
# routines for storing config information for the bot
|
5
5
|
module Config
|
6
6
|
attr_accessor :config
|
7
|
-
|
7
|
+
|
8
|
+
MAX_TWEET_ID = 9223372036854775807
|
9
|
+
|
8
10
|
#
|
9
11
|
# the entire config for the bot, loaded from YAML files and the DB if applicable
|
10
12
|
def config
|
@@ -75,7 +77,7 @@ module Chatterbot
|
|
75
77
|
def verbose?
|
76
78
|
config[:verbose] || false
|
77
79
|
end
|
78
|
-
|
80
|
+
|
79
81
|
#
|
80
82
|
# destination for log entries
|
81
83
|
def log_dest
|
@@ -127,7 +129,10 @@ module Chatterbot
|
|
127
129
|
end
|
128
130
|
|
129
131
|
def max_id_from(s)
|
130
|
-
|
132
|
+
# don't use max_id if it's this ridiculous number
|
133
|
+
# @see https://dev.twitter.com/issues/1300
|
134
|
+
sorted = s.reject { |t| !t || t.id == MAX_TWEET_ID }.max { |a, b| a.id <=> b.id }
|
135
|
+
sorted && sorted.id
|
131
136
|
end
|
132
137
|
|
133
138
|
#
|
@@ -135,7 +140,7 @@ module Chatterbot
|
|
135
140
|
# unless it is lower thant what we have already
|
136
141
|
#
|
137
142
|
def update_since_id_reply(tweet)
|
138
|
-
return if tweet.nil? or tweet.class != Twitter::Tweet
|
143
|
+
return if tweet.nil? or tweet.class != Twitter::Tweet || tweet.id == MAX_TWEET_ID
|
139
144
|
|
140
145
|
tmp_id = tweet.id
|
141
146
|
|
@@ -147,29 +152,17 @@ module Chatterbot
|
|
147
152
|
# tweets, unless it is lower than what we have already
|
148
153
|
def update_since_id(search)
|
149
154
|
return if search.nil?
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
max_id_from(search)
|
160
|
-
end
|
161
|
-
|
162
|
-
# incoming tweets
|
163
|
-
when Twitter::Tweet then search.id
|
164
|
-
|
165
|
-
# an enumeration
|
166
|
-
when Array then max_id_from(search)
|
167
|
-
|
168
|
-
# probably an actual tweet ID at this point,
|
169
|
-
# otherwise it will fail and return 0
|
170
|
-
else search
|
155
|
+
|
156
|
+
tmp_id = if search.is_a?(Twitter::SearchResults)
|
157
|
+
search.attrs[:search_metadata][:max_id]
|
158
|
+
elsif search.respond_to?(:max)
|
159
|
+
max_id_from(search)
|
160
|
+
elsif search.is_a?(Twitter::Tweet)
|
161
|
+
search.id
|
162
|
+
else
|
163
|
+
search
|
171
164
|
end.to_i
|
172
|
-
|
165
|
+
|
173
166
|
config[:tmp_since_id] = [config[:tmp_since_id].to_i, tmp_id].max
|
174
167
|
end
|
175
168
|
|
@@ -200,7 +193,7 @@ module Chatterbot
|
|
200
193
|
# determine if we're being called by one of our internal scripts
|
201
194
|
#
|
202
195
|
def chatterbot_helper?
|
203
|
-
|
196
|
+
Chatterbot::from_helper == true
|
204
197
|
end
|
205
198
|
|
206
199
|
#
|
@@ -221,7 +214,6 @@ module Chatterbot
|
|
221
214
|
# figure out what config file to load based on the name of the bot
|
222
215
|
def config_file
|
223
216
|
dest = working_dir
|
224
|
-
|
225
217
|
x = File.join(File.expand_path(dest), "#{botname}.yml")
|
226
218
|
end
|
227
219
|
|
@@ -268,7 +260,12 @@ module Chatterbot
|
|
268
260
|
#
|
269
261
|
# bot-specific config settings
|
270
262
|
def bot_config
|
271
|
-
|
263
|
+
{
|
264
|
+
:consumer_key => ENV["chatterbot_consumer_key"],
|
265
|
+
:consumer_secret => ENV["chatterbot_consumer_secret"],
|
266
|
+
:token => ENV["chatterbot_token"],
|
267
|
+
:secret => ENV["chatterbot_secret"]
|
268
|
+
}.merge(slurp_file(config_file) || {})
|
272
269
|
end
|
273
270
|
|
274
271
|
#
|
@@ -299,7 +296,6 @@ module Chatterbot
|
|
299
296
|
tmp
|
300
297
|
end
|
301
298
|
|
302
|
-
|
303
299
|
#
|
304
300
|
# load in the config from the assortment of places it can be specified.
|
305
301
|
def load_config(params={})
|
data/lib/chatterbot/db.rb
CHANGED
data/lib/chatterbot/dsl.rb
CHANGED
@@ -5,6 +5,8 @@ module Chatterbot
|
|
5
5
|
#
|
6
6
|
# very basic DSL to handle the common stuff you would want to do with a bot.
|
7
7
|
module DSL
|
8
|
+
#
|
9
|
+
# @return initialized Twitter::REST::Client
|
8
10
|
def client
|
9
11
|
bot.client
|
10
12
|
end
|
@@ -14,7 +16,7 @@ module Chatterbot
|
|
14
16
|
# the block.
|
15
17
|
# @example
|
16
18
|
# search("chatterbot is cool!") do |tweet|
|
17
|
-
# puts tweet
|
19
|
+
# puts tweet.text # this is the actual tweeted text
|
18
20
|
# reply "I agree!", tweet
|
19
21
|
# end
|
20
22
|
def search(query, opts = {}, &block)
|
@@ -27,13 +29,28 @@ module Chatterbot
|
|
27
29
|
#
|
28
30
|
# @example
|
29
31
|
# replies do |tweet|
|
30
|
-
# puts tweet
|
32
|
+
# puts tweet.text # this is the actual tweeted text
|
31
33
|
# reply "Thanks for the mention!", tweet
|
32
34
|
# end
|
33
35
|
def replies(&block)
|
34
36
|
bot.replies(&block)
|
35
37
|
end
|
36
38
|
|
39
|
+
def streaming(opts = {}, &block)
|
40
|
+
params = {
|
41
|
+
:endpoint => :user
|
42
|
+
}.merge(opts)
|
43
|
+
|
44
|
+
h = StreamingHandler.new(bot, params)
|
45
|
+
h.apply block
|
46
|
+
|
47
|
+
bot.do_streaming(h)
|
48
|
+
end
|
49
|
+
|
50
|
+
def streaming_tweets(opts={}, &block)
|
51
|
+
bot.streaming_tweets(opts, &block)
|
52
|
+
end
|
53
|
+
|
37
54
|
#
|
38
55
|
# send a tweet
|
39
56
|
#
|
@@ -48,11 +65,19 @@ module Chatterbot
|
|
48
65
|
|
49
66
|
#
|
50
67
|
# retweet a tweet
|
51
|
-
# @param [id] id the ID of
|
68
|
+
# @param [id] id A tweet or the ID of a tweet
|
52
69
|
def retweet(id)
|
53
70
|
bot.retweet(id)
|
54
71
|
end
|
55
72
|
|
73
|
+
|
74
|
+
#
|
75
|
+
# favorite a tweet
|
76
|
+
# @param [id] id A tweet or the ID of a tweet
|
77
|
+
def favorite(id)
|
78
|
+
bot.favorite(id)
|
79
|
+
end
|
80
|
+
|
56
81
|
#
|
57
82
|
# reply to a tweet
|
58
83
|
#
|
@@ -62,18 +87,37 @@ module Chatterbot
|
|
62
87
|
bot.reply(txt, source)
|
63
88
|
end
|
64
89
|
|
90
|
+
def profile_text(p=nil)
|
91
|
+
if p.nil?
|
92
|
+
bot.profile_text
|
93
|
+
else
|
94
|
+
bot.profile_text(p)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def profile_website(w=nil)
|
99
|
+
if w.nil?
|
100
|
+
bot.profile_website
|
101
|
+
else
|
102
|
+
bot.profile_website(w)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
65
106
|
|
66
107
|
#
|
67
108
|
# generate a Bot object. if the DSL is being called from a Bot object, just return it
|
68
109
|
# otherwise create a bot and return that
|
69
110
|
def bot
|
111
|
+
puts @bot.inspect
|
70
112
|
return @bot unless @bot.nil?
|
71
113
|
|
114
|
+
|
72
115
|
#
|
73
116
|
# parse any command-line options and use them to initialize the bot
|
74
117
|
#
|
75
118
|
params = {}
|
76
119
|
|
120
|
+
#:nocov:
|
77
121
|
opts = OptionParser.new
|
78
122
|
|
79
123
|
opts.banner = "Usage: #{File.basename($0)} [options]"
|
@@ -81,6 +125,7 @@ module Chatterbot
|
|
81
125
|
opts.separator ""
|
82
126
|
opts.separator "Specific options:"
|
83
127
|
|
128
|
+
|
84
129
|
opts.on('-d', '--db [ARG]', "Specify a DB connection URI") { |d| ENV["chatterbot_db"] = d }
|
85
130
|
opts.on('-c', '--config [ARG]', "Specify a config file to use") { |c| ENV["chatterbot_config"] = c }
|
86
131
|
opts.on('-t', '--test', "Run the bot without actually sending any tweets") { params[:debug_mode] = true }
|
@@ -92,15 +137,47 @@ module Chatterbot
|
|
92
137
|
params[:debug_mode] = true
|
93
138
|
params[:reset_since_id] = true
|
94
139
|
}
|
140
|
+
opts.on('--profile [ARG]', "get/set your bot's profile text") { |p|
|
141
|
+
@handle_profile_text = true
|
142
|
+
@profile_text = p
|
143
|
+
}
|
144
|
+
opts.on('--website [ARG]', "get/set your bot's profile URL") { |u|
|
145
|
+
@handle_profile_website = true
|
146
|
+
@profile_website = u
|
147
|
+
}
|
95
148
|
|
149
|
+
|
96
150
|
opts.on_tail("-h", "--help", "Show this message") do
|
97
151
|
puts opts
|
98
152
|
exit
|
99
153
|
end
|
100
154
|
|
101
155
|
opts.parse!(ARGV)
|
156
|
+
#:nocov:
|
102
157
|
|
103
158
|
@bot = Chatterbot::Bot.new(params)
|
159
|
+
|
160
|
+
if @handle_profile_text == true
|
161
|
+
if !@profile_text.nil?
|
162
|
+
@bot.profile_text @profile_text
|
163
|
+
else
|
164
|
+
puts @bot.profile_text
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
if @handle_profile_website == true
|
169
|
+
if !@profile_website.nil?
|
170
|
+
@bot.profile_website @profile_website
|
171
|
+
else
|
172
|
+
puts @bot.profile_website
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
if @handle_profile_website == true || @handle_profile_text == true
|
177
|
+
exit
|
178
|
+
end
|
179
|
+
|
180
|
+
@bot
|
104
181
|
end
|
105
182
|
|
106
183
|
#
|
@@ -157,6 +234,26 @@ module Chatterbot
|
|
157
234
|
def followers(opts={})
|
158
235
|
bot.followers(opts)
|
159
236
|
end
|
237
|
+
|
238
|
+
#
|
239
|
+
# follow a user
|
240
|
+
#
|
241
|
+
# @param u a Twitter::User or user id
|
242
|
+
def follow(u)
|
243
|
+
bot.follow(u)
|
244
|
+
end
|
245
|
+
|
246
|
+
|
247
|
+
#
|
248
|
+
# a common list of bad words, which you might want to filter out.
|
249
|
+
# lifted from https://github.com/dariusk/wordfilter/blob/master/lib/badwords.json
|
250
|
+
#
|
251
|
+
def bad_words
|
252
|
+
["skank", "wetback", "bitch", "cunt", "dick", "douchebag", "dyke", "fag", "nigger", "tranny", "trannies",
|
253
|
+
"paki", "pussy", "retard", "slut", "titt", "tits", "wop", "whore", "chink", "fatass", "shemale", "daygo",
|
254
|
+
"dego", "dago", "gook", "kike", "kraut", "spic", "twat", "lesbo", "homo", "fatso", "lardass", "jap",
|
255
|
+
"biatch", "tard", "gimp", "gyp", "chinaman", "chinamen", "golliwog", "crip", "raghead" ]
|
256
|
+
end
|
160
257
|
|
161
258
|
#
|
162
259
|
# specify list of strings we will check when deciding to respond
|
@@ -187,25 +284,42 @@ module Chatterbot
|
|
187
284
|
bot.config[:since_id]
|
188
285
|
end
|
189
286
|
|
287
|
+
#
|
288
|
+
# set the consumer secret
|
289
|
+
# @param s [String] the consumer secret
|
190
290
|
def consumer_secret(s)
|
191
291
|
bot.config[:consumer_secret] = s
|
192
292
|
end
|
193
293
|
|
294
|
+
#
|
295
|
+
# set the consumer key
|
296
|
+
# @param k [String] the consumer key
|
194
297
|
def consumer_key(k)
|
195
298
|
bot.config[:consumer_key] = k
|
196
299
|
end
|
197
300
|
|
301
|
+
#
|
302
|
+
# set the secret
|
303
|
+
# @param s [String] the secret
|
198
304
|
def secret(s)
|
199
305
|
bot.config[:secret] = s
|
200
306
|
end
|
307
|
+
|
308
|
+
#
|
309
|
+
# set the token
|
310
|
+
# @param s [String] the token
|
201
311
|
def token(s)
|
202
312
|
bot.config[:token] = s
|
203
313
|
end
|
204
314
|
|
315
|
+
#
|
316
|
+
# get the id of the last tweet the bot replied to
|
317
|
+
# @return tweet id
|
205
318
|
def since_id_reply
|
206
319
|
bot.config[:since_id_reply]
|
207
320
|
end
|
208
321
|
|
322
|
+
|
209
323
|
#
|
210
324
|
# explicitly save the configuration/state of the bot.
|
211
325
|
#
|