chatterbot 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -0
- data/examples/echoes_bot.rb +6 -1
- data/examples/loop_bot.rb +44 -0
- data/lib/chatterbot/dsl.rb +8 -0
- data/lib/chatterbot/version.rb +1 -1
- data/spec/dsl_spec.rb +16 -2
- data/spec/search_spec.rb +9 -1
- data/spec/spec_helper.rb +8 -6
- metadata +17 -16
data/README.markdown
CHANGED
@@ -183,6 +183,9 @@ to ignore tweets with links, you could do something like this:
|
|
183
183
|
TODO
|
184
184
|
====
|
185
185
|
|
186
|
+
* document DSL methods
|
187
|
+
* document database setup
|
188
|
+
* consider switching to Twitter gem for API
|
186
189
|
* web-based frontend for tracking bot activity
|
187
190
|
* opt-out system that adds people to blacklist if they reply to a bot
|
188
191
|
in the right way
|
data/examples/echoes_bot.rb
CHANGED
@@ -21,7 +21,12 @@ puts "checking for replies to me"
|
|
21
21
|
replies do |tweet|
|
22
22
|
|
23
23
|
# replace the incoming username with the handle of the user who tweeted us
|
24
|
-
src = tweet[:text].gsub(/@echoes_bot/, tweet_user(tweet))
|
24
|
+
# src = tweet[:text].gsub(/@echoes_bot/, tweet_user(tweet))
|
25
|
+
|
26
|
+
# replace the incoming username with #USER#, which will be replaced
|
27
|
+
# with the handle of the user who tweeted us by the
|
28
|
+
# replace_variables helper
|
29
|
+
src = tweet[:text].gsub(/@echoes_bot/, "#USER#")
|
25
30
|
|
26
31
|
# send it back!
|
27
32
|
reply src, tweet
|
@@ -0,0 +1,44 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
# simple example of how to run a bot in a loop. if you want to do
|
5
|
+
# that, you need to call update_config to update the database at the
|
6
|
+
# end of each iteration -- this will keep you from processing the same
|
7
|
+
# tweets multiple times
|
8
|
+
#
|
9
|
+
|
10
|
+
|
11
|
+
#
|
12
|
+
# require the dsl lib to include all the methods you see below.
|
13
|
+
#
|
14
|
+
require 'rubygems'
|
15
|
+
require 'chatterbot/dsl'
|
16
|
+
|
17
|
+
puts "Loading echoes_bot.rb"
|
18
|
+
|
19
|
+
##
|
20
|
+
## If I wanted to exclude some terms from triggering this bot, I would list them here.
|
21
|
+
## For now, we'll block URLs to keep this from being a source of spam
|
22
|
+
##
|
23
|
+
exclude "http://"
|
24
|
+
|
25
|
+
blacklist "mean_user, private_user"
|
26
|
+
|
27
|
+
loop do
|
28
|
+
|
29
|
+
puts "run search #{since_id}"
|
30
|
+
search "twitter" do |tweet|
|
31
|
+
# here you could do something with a tweet
|
32
|
+
end
|
33
|
+
|
34
|
+
puts "checking for replies to me"
|
35
|
+
replies do |tweet|
|
36
|
+
src = "#USER# it is very nice of you to say that!"
|
37
|
+
reply src, tweet
|
38
|
+
end
|
39
|
+
|
40
|
+
# explicitly update our config
|
41
|
+
update_config
|
42
|
+
|
43
|
+
sleep 1
|
44
|
+
end
|
data/lib/chatterbot/dsl.rb
CHANGED
data/lib/chatterbot/version.rb
CHANGED
data/spec/dsl_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe "Chatterbot::DSL" do
|
|
8
8
|
|
9
9
|
Chatterbot::DSL.stub!(:bot).and_return(@bot)
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
describe "blacklist" do
|
13
13
|
it "#blacklist passes along to bot object" do
|
14
14
|
@bot.should_receive(:blacklist=).with(["foo"])
|
@@ -86,7 +86,21 @@ describe "Chatterbot::DSL" do
|
|
86
86
|
it "#reply passes along to bot object" do
|
87
87
|
@bot.should_receive(:reply).with("hello sailor!", { :source => "source "})
|
88
88
|
reply "hello sailor!", { :source => "source "}
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "update_config" do
|
92
|
+
it "should pass to bot object" do
|
93
|
+
@bot.should_receive(:update_config)
|
94
|
+
update_config
|
95
|
+
end
|
89
96
|
end
|
90
|
-
|
97
|
+
|
98
|
+
describe "since_id" do
|
99
|
+
it "should pass to bot object" do
|
100
|
+
@bot.should_receive(:config).and_return({:since_id => 1234})
|
101
|
+
since_id.should == 1234
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
91
105
|
end
|
92
106
|
end
|
data/spec/search_spec.rb
CHANGED
@@ -78,6 +78,15 @@ describe "Chatterbot::Search" do
|
|
78
78
|
|
79
79
|
bot.search("foo")
|
80
80
|
end
|
81
|
+
|
82
|
+
it "updates since_id when complete" do
|
83
|
+
bot = test_bot
|
84
|
+
results = fake_search(100, 1, 1000)
|
85
|
+
|
86
|
+
bot.stub!(:client).and_return(results)
|
87
|
+
|
88
|
+
bot.search("foo")
|
89
|
+
end
|
81
90
|
|
82
91
|
it "iterates results" do
|
83
92
|
bot = test_bot
|
@@ -93,7 +102,6 @@ describe "Chatterbot::Search" do
|
|
93
102
|
|
94
103
|
it "checks blacklist" do
|
95
104
|
bot = test_bot
|
96
|
-
# bot = Chatterbot::Bot.new
|
97
105
|
bot.stub!(:client).and_return(fake_search(100, 3))
|
98
106
|
|
99
107
|
bot.stub!(:on_blacklist?).and_return(true, false)
|
data/spec/spec_helper.rb
CHANGED
@@ -27,28 +27,30 @@ def test_bot
|
|
27
27
|
bot
|
28
28
|
end
|
29
29
|
|
30
|
-
def fake_search(max_id = 100, result_count = 0)
|
30
|
+
def fake_search(max_id = 100, result_count = 0, id_base=0)
|
31
31
|
mock(TwitterOAuth::Client,
|
32
32
|
{
|
33
33
|
:search => {
|
34
34
|
'max_id' => max_id,
|
35
|
-
'results' => 1.upto(result_count).collect { |i| fake_tweet(i) }
|
35
|
+
'results' => 1.upto(result_count).collect { |i| fake_tweet(i, id_base) }
|
36
36
|
}
|
37
37
|
}
|
38
38
|
)
|
39
39
|
end
|
40
40
|
|
41
|
-
def fake_replies(max_id = 100, result_count = 0)
|
41
|
+
def fake_replies(max_id = 100, result_count = 0, id_base = 0)
|
42
42
|
mock(TwitterOAuth::Client,
|
43
43
|
{
|
44
|
-
:replies => 1.upto(result_count).collect { |i| fake_tweet(i) }
|
44
|
+
:replies => 1.upto(result_count).collect { |i| fake_tweet(i, id_base) }
|
45
45
|
}
|
46
46
|
)
|
47
47
|
end
|
48
48
|
|
49
|
-
def fake_tweet(index)
|
49
|
+
def fake_tweet(index, id=0)
|
50
|
+
id = index if id <= 0
|
50
51
|
{
|
51
52
|
:from_user => "chatterbot",
|
52
|
-
:index => index
|
53
|
+
:index => index,
|
54
|
+
:id => id
|
53
55
|
}
|
54
56
|
end
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-09 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: twitter_oauth
|
16
|
-
requirement: &
|
16
|
+
requirement: &24000540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *24000540
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: shoulda
|
27
|
-
requirement: &
|
27
|
+
requirement: &24000040 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *24000040
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &23999560 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *23999560
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rdoc
|
49
|
-
requirement: &
|
49
|
+
requirement: &24048660 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *24048660
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: bundler
|
60
|
-
requirement: &
|
60
|
+
requirement: &24048180 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ~>
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: 1.0.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *24048180
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
|
-
requirement: &
|
71
|
+
requirement: &24047700 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *24047700
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: watchr
|
82
|
-
requirement: &
|
82
|
+
requirement: &24047220 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *24047220
|
91
91
|
description: A framework for writing bots that run on Twitter. Comes with a simple
|
92
92
|
DSL for easy coding.
|
93
93
|
email: colin@muffinlabs.com
|
@@ -112,6 +112,7 @@ files:
|
|
112
112
|
- examples/config.yml.example
|
113
113
|
- examples/dsl_test.rb
|
114
114
|
- examples/echoes_bot.rb
|
115
|
+
- examples/loop_bot.rb
|
115
116
|
- lib/chatterbot.rb
|
116
117
|
- lib/chatterbot/blacklist.rb
|
117
118
|
- lib/chatterbot/bot.rb
|