chatterbot 0.6.3 → 0.6.5
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/.travis.yml +7 -0
- data/chatterbot.gemspec +2 -2
- data/examples/dsl_test.rb +1 -0
- data/examples/search_bot.rb +22 -0
- data/lib/chatterbot/bot.rb +2 -2
- data/lib/chatterbot/config.rb +8 -5
- data/lib/chatterbot/helpers.rb +8 -5
- data/lib/chatterbot/search.rb +0 -1
- data/lib/chatterbot/version.rb +1 -1
- data/spec/blacklist_spec.rb +2 -2
- data/spec/client_spec.rb +1 -0
- data/spec/config_spec.rb +13 -2
- data/spec/db_spec.rb +25 -19
- data/spec/helpers_spec.rb +2 -2
- data/spec/spec_helper.rb +5 -11
- metadata +10 -8
data/.travis.yml
ADDED
data/chatterbot.gemspec
CHANGED
@@ -21,13 +21,13 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.licenses = ["WTFDBAL"]
|
22
22
|
|
23
23
|
s.add_runtime_dependency(%q<oauth>, [">= 0"])
|
24
|
-
s.add_runtime_dependency(%q<twitter>, [">=
|
24
|
+
s.add_runtime_dependency(%q<twitter>, [">= 4.4.0"])
|
25
25
|
s.add_runtime_dependency(%q<launchy>, [">= 2.1.2"])
|
26
26
|
s.add_development_dependency(%q<yard>, [">= 0"])
|
27
27
|
s.add_development_dependency(%q<redcarpet>, [">= 0"])
|
28
28
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
29
29
|
s.add_development_dependency(%q<rake>, [">= 0"])
|
30
|
-
s.add_development_dependency(%q<rspec>, [">= 0"])
|
30
|
+
s.add_development_dependency(%q<rspec>, [">= 2.12.0"])
|
31
31
|
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
32
32
|
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
33
33
|
s.add_development_dependency(%q<watchr>, [">= 0"])
|
data/examples/dsl_test.rb
CHANGED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
# require the dsl lib to include all the methods you see below.
|
5
|
+
#
|
6
|
+
require 'rubygems'
|
7
|
+
require 'chatterbot/dsl'
|
8
|
+
|
9
|
+
puts "Loading search_bot.rb"
|
10
|
+
|
11
|
+
##
|
12
|
+
## If I wanted to exclude some terms from triggering this bot, I would list them here.
|
13
|
+
## For now, we'll block URLs to keep this from being a source of spam
|
14
|
+
##
|
15
|
+
exclude "http://"
|
16
|
+
|
17
|
+
blacklist "mean_user, private_user"
|
18
|
+
|
19
|
+
search("twitter", :lang => "en") do |tweet|
|
20
|
+
puts tweet[:text]
|
21
|
+
end
|
22
|
+
|
data/lib/chatterbot/bot.rb
CHANGED
data/lib/chatterbot/config.rb
CHANGED
@@ -108,21 +108,24 @@ module Chatterbot
|
|
108
108
|
end
|
109
109
|
end
|
110
110
|
|
111
|
+
def update_config_at_exit
|
112
|
+
update_config
|
113
|
+
end
|
114
|
+
|
111
115
|
#
|
112
116
|
# update the since_id with either the highest ID of the specified
|
113
117
|
# tweets, unless it is lower than what we have already
|
114
118
|
def update_since_id(search)
|
115
119
|
return if search.nil?
|
116
120
|
|
117
|
-
tmp_id = case
|
118
|
-
|
119
|
-
when search.respond_to?(:max_id) then search.max_id
|
121
|
+
tmp_id = case search
|
122
|
+
when Twitter::SearchResults then search.max_id
|
120
123
|
|
121
124
|
# incoming tweets
|
122
|
-
when
|
125
|
+
when Twitter::Tweet then search.id
|
123
126
|
|
124
127
|
# an enumeration
|
125
|
-
when
|
128
|
+
when Array then search.max { |a, b| a.id <=> b.id }.id
|
126
129
|
|
127
130
|
# probably an actual tweet ID at this point,
|
128
131
|
# otherwise it will fail and return 0
|
data/lib/chatterbot/helpers.rb
CHANGED
@@ -23,11 +23,14 @@ module Chatterbot
|
|
23
23
|
# Pull the username from a tweet hash -- this is different depending on
|
24
24
|
# if we're doing a search, or parsing through replies/mentions.
|
25
25
|
def from_user(s)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
case s
|
27
|
+
when Twitter::Tweet
|
28
|
+
s.from_user
|
29
|
+
when String
|
30
|
+
s
|
31
|
+
else
|
32
|
+
s.has_key?(:from_user) ? s[:from_user] : s[:user][:screen_name]
|
33
|
+
end
|
31
34
|
end
|
32
35
|
|
33
36
|
|
data/lib/chatterbot/search.rb
CHANGED
data/lib/chatterbot/version.rb
CHANGED
data/spec/blacklist_spec.rb
CHANGED
@@ -92,8 +92,8 @@ describe "Chatterbot::Blacklist" do
|
|
92
92
|
|
93
93
|
describe "db interaction" do
|
94
94
|
before(:each) do
|
95
|
-
@db_tmp = Tempfile.new("blacklist.db")
|
96
|
-
@db_uri = "sqlite
|
95
|
+
# @db_tmp = Tempfile.new("blacklist.db")
|
96
|
+
@db_uri = "sqlite:/"
|
97
97
|
|
98
98
|
@bot = Chatterbot::Bot.new
|
99
99
|
@bot.config[:db_uri] = @db_uri
|
data/spec/client_spec.rb
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -134,8 +134,6 @@ describe "Chatterbot::Config" do
|
|
134
134
|
|
135
135
|
describe "update_since_id" do
|
136
136
|
it "works with searches" do
|
137
|
-
# data = [ fake_tweet(1000) ]
|
138
|
-
|
139
137
|
data = fake_search(1000, 1).search
|
140
138
|
|
141
139
|
@bot.config[:tmp_since_id] = 100
|
@@ -151,6 +149,19 @@ describe "Chatterbot::Config" do
|
|
151
149
|
@bot.config[:tmp_since_id].should == 1000
|
152
150
|
end
|
153
151
|
|
152
|
+
it "works with arrays" do
|
153
|
+
@bot.config[:tmp_since_id] = 100
|
154
|
+
|
155
|
+
data = [
|
156
|
+
fake_tweet(500, 1000, true),
|
157
|
+
fake_tweet(1000, 1000, true),
|
158
|
+
fake_tweet(400, 1000, true)
|
159
|
+
]
|
160
|
+
|
161
|
+
@bot.update_since_id(data)
|
162
|
+
@bot.config[:tmp_since_id].should == 1000
|
163
|
+
end
|
164
|
+
|
154
165
|
it "never rolls back" do
|
155
166
|
@bot.config[:tmp_since_id] = 100
|
156
167
|
data = fake_tweet(50, 50, true)
|
data/spec/db_spec.rb
CHANGED
@@ -4,10 +4,11 @@ require 'sequel'
|
|
4
4
|
|
5
5
|
describe "Chatterbot::DB" do
|
6
6
|
before(:each) do
|
7
|
-
@
|
8
|
-
|
9
|
-
|
10
|
-
@bot = Chatterbot::Bot.new
|
7
|
+
@db_uri = "sqlite:/tmp/chatterbot.db"
|
8
|
+
File.delete("/tmp/chatterbot.db") if File.exist?("/tmp/chatterbot.db")
|
9
|
+
|
10
|
+
@bot = Chatterbot::Bot.new
|
11
|
+
@bot.stub!(:update_config_at_exit)
|
11
12
|
@bot.config[:db_uri] = @db_uri
|
12
13
|
end
|
13
14
|
|
@@ -18,24 +19,29 @@ describe "Chatterbot::DB" do
|
|
18
19
|
@bot.db
|
19
20
|
end
|
20
21
|
end
|
22
|
+
|
23
|
+
context "db interactions" do
|
24
|
+
after(:each) do
|
25
|
+
@bot.db.disconnect unless @bot.db.nil?
|
26
|
+
end
|
21
27
|
|
22
|
-
|
23
|
-
|
24
|
-
|
28
|
+
describe "table creation" do
|
29
|
+
[:blacklist, :tweets, :config].each do |table|
|
30
|
+
it "should create table #{table}" do
|
31
|
+
@tmp_conn = @bot.db
|
32
|
+
@tmp_conn.tables.include?(table).should == true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "store_database_config" do
|
38
|
+
it "doesn't fail" do
|
39
|
+
@bot = Chatterbot::Bot.new
|
40
|
+
@bot.config[:db_uri] = @db_uri
|
41
|
+
|
25
42
|
@bot.db
|
26
|
-
@
|
27
|
-
@tmp_conn.tables.include?(table).should == true
|
43
|
+
@bot.store_database_config.should == true
|
28
44
|
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe "store_database_config" do
|
33
|
-
it "doesn't fail" do
|
34
|
-
@bot = Chatterbot::Bot.new
|
35
|
-
@bot.config[:db_uri] = @db_uri
|
36
|
-
|
37
|
-
@bot.db
|
38
|
-
@bot.store_database_config.should == true
|
39
45
|
end
|
40
46
|
end
|
41
47
|
end
|
data/spec/helpers_spec.rb
CHANGED
@@ -28,8 +28,8 @@ describe "Chatterbot::Helpers" do
|
|
28
28
|
@bot.from_user("x").should == "x"
|
29
29
|
end
|
30
30
|
|
31
|
-
it "should accept :from_user" do
|
32
|
-
@bot.from_user(:from_user => "x").should == "x"
|
31
|
+
it "should accept :from_user tweet" do
|
32
|
+
@bot.from_user(Twitter::Tweet.new(:id => 123, :from_user => "x")).should == "x"
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should accept :screen_name" do
|
data/spec/spec_helper.rb
CHANGED
@@ -10,8 +10,8 @@ Bundler.require
|
|
10
10
|
#require "twitter_oauth"
|
11
11
|
require "twitter"
|
12
12
|
|
13
|
-
require 'tempfile'
|
14
|
-
require 'sqlite3'
|
13
|
+
#require 'tempfile'
|
14
|
+
#require 'sqlite3'
|
15
15
|
|
16
16
|
|
17
17
|
# Requires supporting files with custom matchers and macros, etc,
|
@@ -22,22 +22,16 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
|
22
22
|
def test_bot
|
23
23
|
bot = Chatterbot::Bot.new
|
24
24
|
bot.stub!(:load_config).and_return({})
|
25
|
+
bot.stub!(:update_config_at_exit)
|
25
26
|
bot
|
26
27
|
end
|
27
28
|
|
28
29
|
def fake_search(max_id = 100, result_count = 0, id_base=0)
|
29
30
|
mock(Twitter::Client,
|
30
31
|
:credentials? => true,
|
31
|
-
:search => Twitter::SearchResults.new(:max_id => max_id,
|
32
|
-
:
|
32
|
+
:search => Twitter::SearchResults.new(:search_metadata => {:max_id => max_id},
|
33
|
+
:statuses => 1.upto(result_count).collect { |i| fake_tweet(i, id_base) } )
|
33
34
|
)
|
34
|
-
|
35
|
-
# mock(Twitter::Client,
|
36
|
-
# {
|
37
|
-
# :credentials? => true,
|
38
|
-
# :search => 1.upto(result_count).collect { |i| fake_tweet(i, id_base) }
|
39
|
-
# }
|
40
|
-
# )
|
41
35
|
end
|
42
36
|
|
43
37
|
def fake_replies(max_id = 100, result_count = 0, id_base = 0)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chatterbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth
|
@@ -34,7 +34,7 @@ dependencies:
|
|
34
34
|
requirements:
|
35
35
|
- - ! '>='
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version:
|
37
|
+
version: 4.4.0
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -42,7 +42,7 @@ dependencies:
|
|
42
42
|
requirements:
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
version:
|
45
|
+
version: 4.4.0
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
47
|
name: launchy
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,7 +130,7 @@ dependencies:
|
|
130
130
|
requirements:
|
131
131
|
- - ! '>='
|
132
132
|
- !ruby/object:Gem::Version
|
133
|
-
version:
|
133
|
+
version: 2.12.0
|
134
134
|
type: :development
|
135
135
|
prerelease: false
|
136
136
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -138,7 +138,7 @@ dependencies:
|
|
138
138
|
requirements:
|
139
139
|
- - ! '>='
|
140
140
|
- !ruby/object:Gem::Version
|
141
|
-
version:
|
141
|
+
version: 2.12.0
|
142
142
|
- !ruby/object:Gem::Dependency
|
143
143
|
name: rdoc
|
144
144
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,6 +199,7 @@ extra_rdoc_files: []
|
|
199
199
|
files:
|
200
200
|
- .document
|
201
201
|
- .gitignore
|
202
|
+
- .travis.yml
|
202
203
|
- Gemfile
|
203
204
|
- LICENSE.txt
|
204
205
|
- README.markdown
|
@@ -212,6 +213,7 @@ files:
|
|
212
213
|
- examples/dsl_test.rb
|
213
214
|
- examples/echoes_bot.rb
|
214
215
|
- examples/loop_bot.rb
|
216
|
+
- examples/search_bot.rb
|
215
217
|
- examples/tweet_logger.rb
|
216
218
|
- lib/chatterbot.rb
|
217
219
|
- lib/chatterbot/blacklist.rb
|
@@ -257,7 +259,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
257
259
|
version: '0'
|
258
260
|
segments:
|
259
261
|
- 0
|
260
|
-
hash:
|
262
|
+
hash: 1490359172289579377
|
261
263
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
262
264
|
none: false
|
263
265
|
requirements:
|
@@ -266,7 +268,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
266
268
|
version: '0'
|
267
269
|
segments:
|
268
270
|
- 0
|
269
|
-
hash:
|
271
|
+
hash: 1490359172289579377
|
270
272
|
requirements: []
|
271
273
|
rubyforge_project: chatterbot
|
272
274
|
rubygems_version: 1.8.24
|