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 ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ # uncomment this line if your project needs to run something other than `rake`:
7
+ # script: bundle exec rspec spec
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>, [">= 3.6.0"])
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
@@ -6,3 +6,4 @@ exclude ["bar"]
6
6
  search("foo", :lang => "en") do |tweet|
7
7
  puts tweet.inspect
8
8
  end
9
+
@@ -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
+
@@ -29,11 +29,11 @@ module Chatterbot
29
29
  update_config
30
30
  puts "Reset to #{@config[:since_id]}"
31
31
  exit
32
- else
32
+ else
33
33
  # update config when we exit
34
34
  at_exit do
35
35
  raise $! if $!
36
- update_config
36
+ update_config_at_exit
37
37
  end
38
38
  end
39
39
  end
@@ -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
- # Twitter::SearchResults
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 search.respond_to?(:id) then search.id
125
+ when Twitter::Tweet then search.id
123
126
 
124
127
  # an enumeration
125
- when search.respond_to?(:max) then search.max { |a, b| a.id <=> b.id }.id
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
@@ -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
- return s if s.is_a?(String)
27
- return s.from_user if s.respond_to?(:from_user) #&& ! s.from_user.nil?
28
- # return s.user.screen_name if s.respond_to?(:user)
29
-
30
- s.has_key?(:from_user) ? s[:from_user] : s[:user][:screen_name]
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
 
@@ -28,7 +28,6 @@ module Chatterbot
28
28
  exclude_retweets(query),
29
29
  opts.merge(default_opts)
30
30
  )
31
-
32
31
  update_since_id(result.max_id)
33
32
 
34
33
  result.collection.each { |s|
@@ -1,3 +1,3 @@
1
1
  module Chatterbot
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.5"
3
3
  end
@@ -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://#{@db_tmp.path}"
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
@@ -12,6 +12,7 @@ describe "Chatterbot::Client" do
12
12
 
13
13
  bot.stub!(:search_client).and_return(fake_search(100, 1))
14
14
  bot.search_client.should_receive(:search).with("a")
15
+ bot.search("a")
15
16
  bot.reset_since_id
16
17
 
17
18
  bot.config[:tmp_since_id].should == 100
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
- @db_tmp = Tempfile.new("config.db")
8
- @db_uri = "sqlite://#{@db_tmp.path}"
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
- describe "table creation" do
23
- [:blacklist, :tweets, :config].each do |table|
24
- it "should create table #{table}" do
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
- @tmp_conn = Sequel.connect(@db_uri)
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
- :results => 1.upto(result_count).collect { |i| fake_tweet(i, id_base) } )
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.3
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: 2012-08-23 00:00:00.000000000 Z
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: 3.6.0
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: 3.6.0
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: '0'
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: '0'
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: 3131576310873480670
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: 3131576310873480670
271
+ hash: 1490359172289579377
270
272
  requirements: []
271
273
  rubyforge_project: chatterbot
272
274
  rubygems_version: 1.8.24