chatterbot 1.0.2 → 2.0.0.pre

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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -2
  3. data/LICENSE.txt +18 -9
  4. data/README.markdown +83 -65
  5. data/bin/chatterbot-register +0 -1
  6. data/chatterbot.gemspec +3 -10
  7. data/examples/class_bot.rb +0 -1
  8. data/examples/echoes_bot.rb +2 -2
  9. data/examples/search_bot.rb +1 -1
  10. data/examples/streaming_bot.rb +21 -15
  11. data/lib/chatterbot.rb +7 -12
  12. data/lib/chatterbot/blocklist.rb +61 -0
  13. data/lib/chatterbot/bot.rb +118 -13
  14. data/lib/chatterbot/client.rb +52 -20
  15. data/lib/chatterbot/config.rb +92 -215
  16. data/lib/chatterbot/config_manager.rb +49 -0
  17. data/lib/chatterbot/direct_messages.rb +46 -0
  18. data/lib/chatterbot/dsl.rb +157 -78
  19. data/lib/chatterbot/followers.rb +4 -0
  20. data/lib/chatterbot/handler.rb +29 -0
  21. data/lib/chatterbot/helpers.rb +14 -3
  22. data/lib/chatterbot/home_timeline.rb +5 -8
  23. data/lib/chatterbot/logging.rb +0 -17
  24. data/lib/chatterbot/profile.rb +0 -1
  25. data/lib/chatterbot/reply.rb +6 -11
  26. data/lib/chatterbot/retweet.rb +2 -6
  27. data/lib/chatterbot/safelist.rb +33 -0
  28. data/lib/chatterbot/search.rb +26 -16
  29. data/lib/chatterbot/skeleton.rb +7 -38
  30. data/lib/chatterbot/streaming.rb +26 -33
  31. data/lib/chatterbot/tweet.rb +0 -1
  32. data/lib/chatterbot/ui.rb +9 -2
  33. data/lib/chatterbot/utils.rb +13 -0
  34. data/lib/chatterbot/version.rb +1 -1
  35. data/spec/blocklist_spec.rb +170 -0
  36. data/spec/bot_spec.rb +83 -8
  37. data/spec/client_spec.rb +61 -7
  38. data/spec/config_manager_spec.rb +59 -0
  39. data/spec/config_spec.rb +33 -158
  40. data/spec/direct_messages_spec.rb +115 -0
  41. data/spec/dsl_spec.rb +95 -53
  42. data/spec/handler_spec.rb +27 -0
  43. data/spec/helpers_spec.rb +7 -11
  44. data/spec/home_timeline_spec.rb +42 -31
  45. data/spec/logging_spec.rb +0 -34
  46. data/spec/reply_spec.rb +10 -34
  47. data/spec/search_spec.rb +65 -6
  48. data/spec/spec_helper.rb +25 -1
  49. data/spec/streaming_spec.rb +56 -58
  50. data/spec/whitelist_spec.rb +10 -10
  51. data/specs.watchr +2 -4
  52. data/templates/skeleton.txt +148 -12
  53. metadata +20 -22
  54. data/bin/chatterbot-blacklist +0 -65
  55. data/bin/chatterbot-status +0 -55
  56. data/examples/loop_bot.rb +0 -44
  57. data/lib/chatterbot/blacklist.rb +0 -61
  58. data/lib/chatterbot/db.rb +0 -79
  59. data/lib/chatterbot/streaming_handler.rb +0 -96
  60. data/lib/chatterbot/whitelist.rb +0 -32
  61. data/spec/blacklist_spec.rb +0 -116
  62. data/spec/db_spec.rb +0 -53
  63. data/spec/streaming_handler_spec.rb +0 -78
data/spec/search_spec.rb CHANGED
@@ -22,8 +22,12 @@ describe "Chatterbot::Search" do
22
22
  bot = test_bot
23
23
 
24
24
  allow(bot).to receive(:client).and_return(fake_search(100, 1))
25
- expect(bot.client).to receive(:search).once.ordered.with("foo", {:result_type=>"recent"})
26
- expect(bot.client).to receive(:search).once.ordered.with("bar", {:result_type=>"recent"})
25
+ expect(bot.client).to receive(:search).once.ordered.
26
+ with("foo OR bar", {
27
+ :result_type=>"recent",
28
+ :since_id => 1,
29
+ :since_id_reply => 1
30
+ })
27
31
 
28
32
  bot.search(["foo", "bar"])
29
33
  end
@@ -32,7 +36,13 @@ describe "Chatterbot::Search" do
32
36
  bot = test_bot
33
37
 
34
38
  allow(bot).to receive(:client).and_return(fake_search(100, 1))
35
- expect(bot.client).to receive(:search).with("foo", {:lang => "en", :result_type=>"recent"})
39
+ expect(bot.client).to receive(:search).
40
+ with("foo", {
41
+ :lang => "en",
42
+ :result_type=>"recent",
43
+ :since_id => 1,
44
+ :since_id_reply => 1
45
+ })
36
46
 
37
47
  bot.search("foo", :lang => "en")
38
48
  end
@@ -41,7 +51,12 @@ describe "Chatterbot::Search" do
41
51
  bot = test_bot
42
52
 
43
53
  allow(bot).to receive(:client).and_return(fake_search(100, 1))
44
- expect(bot.client).to receive(:search).with("foo", {:result_type=>"recent"})
54
+ expect(bot.client).to receive(:search).
55
+ with("foo", {
56
+ :result_type=>"recent",
57
+ :since_id => 1,
58
+ :since_id_reply => 1
59
+ })
45
60
 
46
61
  bot.search("foo")
47
62
  end
@@ -78,11 +93,11 @@ describe "Chatterbot::Search" do
78
93
  expect(indexes).to eq([100, 99, 98])
79
94
  end
80
95
 
81
- it "checks blacklist" do
96
+ it "checks blocklist" do
82
97
  bot = test_bot
83
98
  allow(bot).to receive(:client).and_return(fake_search(100, 3))
84
99
 
85
- allow(bot).to receive(:on_blacklist?).and_return(true, false)
100
+ allow(bot).to receive(:on_blocklist?).and_return(true, false)
86
101
 
87
102
  indexes = []
88
103
  bot.search("foo") do |x|
@@ -92,4 +107,48 @@ describe "Chatterbot::Search" do
92
107
  expect(indexes).to eq([99, 98])
93
108
  end
94
109
 
110
+
111
+ it "checks safelist" do
112
+ bot = test_bot
113
+ allow(bot).to receive(:client).and_return(fake_search(100, 3))
114
+ allow(bot).to receive(:has_safelist?).and_return(true)
115
+ allow(bot).to receive(:on_safelist?).and_return(true, false, false)
116
+
117
+ indexes = []
118
+ bot.search("foo") do |x|
119
+ indexes << x.attrs[:index]
120
+ end
121
+
122
+ expect(indexes).to eq([100])
123
+ end
124
+
125
+
126
+ it "skips retweets" do
127
+ bot = test_bot
128
+ bot.exclude_retweets
129
+ allow(bot).to receive(:client).and_return(fake_search(100, 3))
130
+ allow_any_instance_of(Twitter::Tweet).to receive(:retweeted_status?) do |t|
131
+ (t.id % 2) == 0
132
+ end
133
+
134
+ indexes = []
135
+ bot.search("foo") do |x|
136
+ indexes << x.attrs[:index]
137
+ end
138
+
139
+ expect(indexes).to eq([99])
140
+ end
141
+
142
+ it "includes retweets" do
143
+ bot = test_bot
144
+ bot.include_retweets
145
+ allow(bot).to receive(:client).and_return(fake_search(100, 3))
146
+ indexes = []
147
+ bot.search("foo") do |x|
148
+ indexes << x.attrs[:index]
149
+ end
150
+
151
+ expect(indexes).to eq([100, 99, 98])
152
+ end
153
+
95
154
  end
data/spec/spec_helper.rb CHANGED
@@ -19,14 +19,19 @@ RSpec.configure do |config|
19
19
  # cause any verifying double instantiation for a class that does not
20
20
  # exist to raise, protecting against incorrectly spelt names.
21
21
  mocks.verify_doubled_constant_names = true
22
+ end
22
23
 
24
+ config.after(:each) do
25
+ config_file = File.join(File.dirname($0), "#{File.basename($0, ".*")}.yml")
26
+ if File.exist?(config_file)
27
+ File.delete(config_file) rescue nil
28
+ end
23
29
  end
24
30
  end
25
31
 
26
32
  def test_bot
27
33
  bot = Chatterbot::Bot.new
28
34
  allow(bot).to receive(:load_config).and_return({})
29
- allow(bot).to receive(:update_config_at_exit)
30
35
  bot.reset!
31
36
  bot
32
37
  end
@@ -54,6 +59,12 @@ def fake_replies(result_count = 0, id_base = 0)
54
59
  c
55
60
  end
56
61
 
62
+ def fake_direct_messages(result_count = 0, id_base = 0)
63
+ c = stubbable_client
64
+ allow(c).to receive_messages(:direct_messages_received => 1.upto(result_count).collect { |i| fake_dm(i, id_base)})
65
+ c
66
+ end
67
+
57
68
  def fake_home_timeline(result_count = 0, id_base = 0)
58
69
  c = stubbable_client
59
70
  allow(c).to receive_messages(:home_timeline => 1.upto(result_count).collect { |i| fake_tweet(i, id_base)})
@@ -79,6 +90,19 @@ def fake_tweet(index, id=0)
79
90
  Twitter::Tweet.new(x)
80
91
  end
81
92
 
93
+ def fake_dm(index, id=0)
94
+ id = index if id <= 0
95
+ x = {
96
+ :from_user => "chatterbot",
97
+ :index => index,
98
+ :id => id,
99
+ :text => "I am a direct message",
100
+ :user => { :id => 1, :screen_name => "chatterbot" }
101
+ }
102
+
103
+ Twitter::DirectMessage.new(x)
104
+ end
105
+
82
106
  def fake_follower(index=0)
83
107
  Twitter::User.new(:id => index, :name => "Follower #{index}",
84
108
  :screen_name => "follower#{index}")
@@ -1,66 +1,70 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- class StreamingHandler
4
- attr_accessor :last_object
5
- end
6
-
7
3
  describe "Chatterbot::Streaming" do
8
4
  let(:bot) { test_bot }
9
5
  let(:user) { fake_user('user', 100) }
10
- let(:handler) { StreamingHandler.new(test_bot) }
11
6
  let(:tweet) { fake_tweet(12345) }
12
7
 
13
- def apply_to_handler(&block)
14
- handler.apply block
15
- end
16
8
 
17
- describe "authenticated_user" do
18
- it "should get user from client" do
19
- expect(bot.client).to receive(:user).and_return('user')
20
- expect(bot.authenticated_user).to eql('user')
9
+ describe "streaming_tweet_handler" do
10
+ before(:each) do
11
+ bot.skip_run = true
12
+ allow(bot.client).to receive(:user).and_return(user)
21
13
  end
22
- end
23
14
 
24
- describe "do_streaming" do
15
+ it "defaults to home_timeline" do
16
+ bot.register_handler(:home_timeline) { @result = :home_timeline }
17
+ bot.register_handler(:search, "foo") { @result = :search }
25
18
 
26
- end
19
+ bot.handle_streaming_object(tweet)
20
+ expect(@result).to eql(:home_timeline)
21
+ end
22
+
23
+ it "will return search" do
24
+ bot.register_handler(:search, "foo") { @result = :search }
27
25
 
26
+ bot.handle_streaming_object(tweet)
27
+ expect(@result).to eql(:search)
28
+ end
29
+ end
30
+
28
31
  describe "handle_streaming_object" do
29
32
  before(:each) {
33
+ bot.skip_run = true
30
34
  allow(bot.client).to receive(:user).and_return(user)
31
35
  }
32
36
 
33
37
  describe "Twitter::Tweet" do
34
38
  it "works if no handler" do
35
- bot.handle_streaming_object(tweet, handler)
39
+ bot.handle_streaming_object(tweet)
36
40
  end
37
41
 
38
42
  context "with handler" do
39
43
  before(:each) do
40
- apply_to_handler { replies { |t| @last_object = t } }
44
+ bot.register_handler(:home_timeline) { |t| @last_object = t }
41
45
  end
42
46
 
43
47
  it "ignores tweets from authenticated user" do
44
48
  expect(tweet).to receive(:user).and_return(user)
45
- bot.handle_streaming_object(tweet, handler)
46
- expect(handler.last_object).to be_nil
49
+ bot.handle_streaming_object(tweet)
50
+ expect(@last_object).to be_nil
47
51
  end
48
52
 
49
53
  it "passes to handler" do
50
- bot.handle_streaming_object(tweet, handler)
51
- expect(handler.last_object).to eql(tweet)
54
+ bot.handle_streaming_object(tweet)
55
+ expect(@last_object).to eql(tweet)
52
56
  end
53
57
 
54
- it "ignores tweets from blacklist" do
55
- bot.blacklist = ['chatterbot']
56
- bot.handle_streaming_object(tweet, handler)
57
- expect(handler.last_object).to be_nil
58
+ it "ignores tweets from blocklist" do
59
+ bot.blocklist = ['chatterbot']
60
+ bot.handle_streaming_object(tweet)
61
+ expect(@last_object).to be_nil
58
62
  end
59
63
 
60
64
  it "ignores tweets if skip_me is true" do
61
65
  bot.exclude = ['tweet']
62
- bot.handle_streaming_object(tweet, handler)
63
- expect(handler.last_object).to be_nil
66
+ bot.handle_streaming_object(tweet)
67
+ expect(@last_object).to be_nil
64
68
  end
65
69
  end
66
70
  end
@@ -68,28 +72,28 @@ describe "Chatterbot::Streaming" do
68
72
  describe "Twitter::Streaming::DeletedTweet" do
69
73
  it "works if no handler" do
70
74
  obj = Twitter::Streaming::DeletedTweet.new(:id => 1)
71
- bot.handle_streaming_object(obj, handler)
75
+ bot.handle_streaming_object(obj)
72
76
  end
73
77
 
74
78
  it "passes to handler" do
75
- apply_to_handler { delete { |t| @last_object = t } }
79
+ bot.register_handler(:deleted) { |t| @last_object = t }
76
80
  obj = Twitter::Streaming::DeletedTweet.new(:id => 1)
77
- bot.handle_streaming_object(obj, handler)
78
- expect(handler.last_object).to eql(obj)
81
+ bot.handle_streaming_object(obj)
82
+ expect(@last_object).to eql(obj)
79
83
  end
80
84
  end
81
85
 
82
86
  describe "Twitter::DirectMessage" do
83
87
  it "works if no handler" do
84
88
  obj = Twitter::DirectMessage.new(:id => 1)
85
- bot.handle_streaming_object(obj, handler)
89
+ bot.handle_streaming_object(obj)
86
90
  end
87
91
 
88
92
  it "passes to handler" do
89
- apply_to_handler { direct_message { |t| @last_object = t } }
93
+ bot.register_handler(:direct_messages) { |t| @last_object = t }
90
94
  obj = Twitter::DirectMessage.new(:id => 1)
91
- bot.handle_streaming_object(obj, handler)
92
- expect(handler.last_object).to eql(obj)
95
+ bot.handle_streaming_object(obj)
96
+ expect(@last_object).to eql(obj)
93
97
  end
94
98
  end
95
99
 
@@ -100,9 +104,10 @@ describe "Chatterbot::Streaming" do
100
104
  :source => {:id => user.id, :name => 'name', :screen_name => 'name'},
101
105
  :target => {:id => user.id, :name => 'name', :screen_name => 'name'})
102
106
 
103
- apply_to_handler { followed { |t| @last_object = t } }
104
- bot.handle_streaming_object(event, handler)
105
- expect(handler.last_object).to be_nil
107
+ bot.register_handler(:followed) { |t| @last_object = t }
108
+
109
+ bot.handle_streaming_object(event)
110
+ expect(@last_object).to be_nil
106
111
  end
107
112
 
108
113
  describe "follow" do
@@ -115,15 +120,15 @@ describe "Chatterbot::Streaming" do
115
120
  end
116
121
 
117
122
  it "works if no handler" do
118
- bot.handle_streaming_object(@event, handler)
119
- expect(handler.last_object).to be_nil
123
+ bot.handle_streaming_object(@event)
124
+ expect(@last_object).to be_nil
120
125
  end
121
126
 
122
127
  it "passes to handler" do
123
- apply_to_handler { followed { |t| @last_object = t } }
124
- bot.handle_streaming_object(@event, handler)
125
- expect(handler.last_object.class).to be(Twitter::User)
126
- expect(handler.last_object.id).to be(12345)
128
+ bot.register_handler(:followed) { |t| @last_object = t }
129
+ bot.handle_streaming_object(@event)
130
+ expect(@last_object.class).to be(Twitter::User)
131
+ expect(@last_object.id).to be(12345)
127
132
  end
128
133
  end
129
134
 
@@ -142,15 +147,15 @@ describe "Chatterbot::Streaming" do
142
147
  end
143
148
 
144
149
  it "works if no handler" do
145
- bot.handle_streaming_object(@event, handler)
146
- expect(handler.last_object).to be_nil
150
+ bot.handle_streaming_object(@event)
151
+ expect(@last_object).to be_nil
147
152
  end
148
153
 
149
154
  it "passes to handler" do
150
- apply_to_handler { favorited { |_, t| @last_object = t } }
151
- bot.handle_streaming_object(@event, handler)
152
- expect(handler.last_object.class).to be(Twitter::Tweet)
153
- expect(handler.last_object.text).to eq("I am a tweet!")
155
+ bot.register_handler(:favorited) { |_, t| @last_object = t }
156
+ bot.handle_streaming_object(@event)
157
+ expect(@last_object.class).to be(Twitter::Tweet)
158
+ expect(@last_object.text).to eq("I am a tweet!")
154
159
  end
155
160
  end
156
161
  end
@@ -158,14 +163,7 @@ describe "Chatterbot::Streaming" do
158
163
  describe "Twitter::Streaming::FriendList" do
159
164
  it "works if no handler" do
160
165
  obj = Twitter::Streaming::FriendList.new
161
- bot.handle_streaming_object(obj, handler)
162
- end
163
-
164
- it "passes to handler" do
165
- apply_to_handler { friends { |t| @last_object = t } }
166
- obj = Twitter::Streaming::FriendList.new
167
- bot.handle_streaming_object(obj, handler)
168
- expect(handler.last_object).to eql(obj)
166
+ bot.handle_streaming_object(obj)
169
167
  end
170
168
  end
171
169
  end
@@ -1,30 +1,30 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe "Chatterbot::Whitelist" do
4
- describe "on_whitelist?" do
3
+ describe "Chatterbot::Safelist" do
4
+ describe "on_safelist?" do
5
5
  before(:each) do
6
6
  @bot = test_bot
7
- @bot.whitelist = [fake_user('user', 100), "skippy", "blippy", "dippy"]
7
+ @bot.safelist = [fake_user('user', 100), "skippy", "blippy", "dippy"]
8
8
  end
9
9
 
10
10
  it "includes users we want" do
11
- expect(@bot.on_whitelist?("user")).to eq(true)
12
- expect(@bot.on_whitelist?("skippy")).to eq(true)
11
+ expect(@bot.on_safelist?("user")).to eq(true)
12
+ expect(@bot.on_safelist?("skippy")).to eq(true)
13
13
  end
14
14
 
15
15
  it "excludes users we don't want" do
16
- expect(@bot.on_whitelist?("flippy")).to eq(false)
16
+ expect(@bot.on_safelist?("flippy")).to eq(false)
17
17
  end
18
18
 
19
19
  it "isn't case-specific" do
20
- expect(@bot.on_whitelist?("FLIPPY")).to eq(false)
21
- expect(@bot.on_whitelist?("SKIPPY")).to eq(true)
20
+ expect(@bot.on_safelist?("FLIPPY")).to eq(false)
21
+ expect(@bot.on_safelist?("SKIPPY")).to eq(true)
22
22
  end
23
23
 
24
24
  it "works with result hashes" do
25
- expect(@bot.on_whitelist?(Twitter::Tweet.new(:id => 1,
25
+ expect(@bot.on_safelist?(Twitter::Tweet.new(:id => 1,
26
26
  :user => {:id => 1, :screen_name => "skippy"}))).to eq(true)
27
- expect(@bot.on_whitelist?(Twitter::Tweet.new(:id => 1,
27
+ expect(@bot.on_safelist?(Twitter::Tweet.new(:id => 1,
28
28
  :user => {:id => 1, :screen_name => "flippy"}))).to eq(false)
29
29
  end
30
30
  end
data/specs.watchr CHANGED
@@ -31,11 +31,9 @@ end
31
31
  # --------------------------------------------------
32
32
  # Watchr Rules
33
33
  # --------------------------------------------------
34
- watch('^spec/(.*)_spec\.rb') { |m| run_spec_matching(m[1]) }
35
- #watch('^spec/controllers/(.*)_spec\.rb') { |m| run_spec_matching(m[1]) }
36
-
34
+ watch('^spec/(.*)_spec\.rb') { |m| puts m.inspect; run_spec_matching(m[1]) }
37
35
  watch("^lib/chatterbot/(.*)\.rb") { |m| run_spec_matching(m[1]) }
38
- #watch('^spec/spec_helper\.rb') { run_all_specs }
36
+ watch('^spec/spec_helper\.rb') { run_all_specs }
39
37
 
40
38
  # --------------------------------------------------
41
39
  # Signal Handling
@@ -8,30 +8,166 @@ require 'chatterbot/dsl'
8
8
  # generated on %{timestamp}
9
9
  #
10
10
 
11
- consumer_key '%{consumer_key}'
12
- consumer_secret '%{consumer_secret}'
11
+ #
12
+ # Hello! This is some starter code for your bot. You will need to keep
13
+ # this file and %{name}.yml together to run your bot. The .yml file
14
+ # will hold your authentication credentials and help track certain
15
+ # information about what tweets the bot has seen so far.
16
+ #
17
+ # The code here is a basic starting point for a bot. It shows you the
18
+ # different methods you can use to get tweets, send tweets, etc. It
19
+ # also has a few settings/directives which you will want to read
20
+ # about, and comment or uncomment as you see fit.
21
+ #
22
+
23
+
24
+ #
25
+ # Placing your security credentials right in a script like this is
26
+ # handy, but potentially dangerous, especially if your code is
27
+ # publicly available on github or somewhere else. However, if it is
28
+ # convenient for you to have your authentication data here, you can
29
+ # uncomment the lines below, and copy your configuration data from
30
+ # %{name}.yml into the commands.
31
+ #
32
+ # consumer_key 'consumer_key'
33
+ # consumer_secret 'consumer_secret'
34
+ #
35
+ # secret 'secret'
36
+ # token 'token'
13
37
 
14
- secret '%{secret}'
15
- token '%{token}'
16
38
 
17
- # remove this to send out tweets
39
+ # Enabling **debug_mode** prevents the bot from actually sending
40
+ # tweets. Keep this active while you are developing your bot. Once you
41
+ # are ready to send out tweets, you can remove this line.
18
42
  debug_mode
19
43
 
20
- # remove this to update the db
44
+ # Chatterbot will keep track of the most recent tweets your bot has
45
+ # handled so you don't need to worry about that yourself. While
46
+ # testing, you can use the **no_update** directive to prevent
47
+ # chatterbot from updating those values. This directive can also be
48
+ # handy if you are doing something advanced where you want to track
49
+ # which tweet you saw last on your own.
21
50
  no_update
22
- # remove this to get less output when running
51
+
52
+ # remove this to get less output when running your bot
23
53
  verbose
24
54
 
25
- # here's a list of users to ignore
26
- blacklist "abc", "def"
55
+ # The blocklist is a list of users that your bot will never interact
56
+ # with. Chatterbot will discard any tweets involving these users.
57
+ # Simply add their twitter handle to this list.
58
+ blocklist "abc", "def"
59
+
60
+ # If you want to be even more restrictive, you can specify a
61
+ # 'safelist' of accounts which your bot will *only* interact with. If
62
+ # you uncomment this line, Chatterbot will discard any incoming tweets
63
+ # from a user that is not on this list.
64
+ # safelist "foo", "bar"
27
65
 
28
- # here's a list of things to exclude from searches
66
+ # Here's a list of words to exclude from searches. Use this list to
67
+ # add words which your bot should ignore for whatever reason.
29
68
  exclude "hi", "spammer", "junk"
30
69
 
31
- search "keyword" do |tweet|
32
- reply "Hey #USER# nice to meet you!", tweet
70
+ # Exclude a list of offensive, vulgar, 'bad' words. This list is
71
+ # populated from Darius Kazemi's wordfilter module
72
+ # @see https://github.com/dariusk/wordfilter
73
+ exclude bad_words
74
+
75
+ # This will restrict your bot to tweets that come from accounts that
76
+ # are following your bot. A tweet from an account that isn't following
77
+ # will be rejected
78
+ only_interact_with_followers
79
+
80
+ #
81
+ # Specifying 'streaming true' will cause Chatterbot to use Twitter's
82
+ # Streaming API. Your bot will run constantly, listening for tweets.
83
+ # Alternatively, you can run your bot as a cron/scheduled job. In that
84
+ # case, do not use this line. Every time you run your bot, it will
85
+ # execute once, and then exit.
86
+ #
87
+ streaming true
88
+
89
+ #
90
+ # Here's the fun stuff!
91
+ #
92
+
93
+ # Searches: You can do all sorts of stuff with searches on Twitter.
94
+ # However, please note, interacting with users who don't follow your
95
+ # bot is very possibly:
96
+ # - rude
97
+ # - uncool
98
+ # - likely to get your bot suspended
99
+ #
100
+ # Still here? Hopefully it's because you're going to do something cool
101
+ # with the data that doesn't bother other people. Hooray!
102
+ #
103
+ search "chatterbot" do |tweet|
104
+ # here's the content of a tweet
105
+ puts tweets.text
33
106
  end
34
107
 
108
+ #
109
+ # this block responds to mentions of your bot
110
+ #
35
111
  replies do |tweet|
112
+ # Any time you put the #USER# token in a tweet, Chatterbot will
113
+ # replace it with the handle of the user you are interacting with
36
114
  reply "Yes #USER#, you are very kind to say that!", tweet
37
115
  end
116
+
117
+ #
118
+ # this block handles incoming Direct Messages. if you want to do
119
+ # something with DMs, go for it!
120
+ #
121
+ # direct_messages do |dm|
122
+ # puts "DM received: #{dm.text}"
123
+ # direct_message "HELLO, I GOT YOUR MESSAGE", dm.sender
124
+ # end
125
+
126
+ #
127
+ # Use this block to get tweets that appear on your bot's home timeline
128
+ # (ie, if you were visiting twitter.com) -- using this block might
129
+ # require a little extra work but can be very handy
130
+ #
131
+ # home_timeline do |tweet|
132
+ # puts tweet.inspect
133
+ # end
134
+
135
+ #
136
+ # Use this block if you want to be notified about new followers of
137
+ # your bot. You might do this to follow the user back.
138
+ #
139
+ # NOTE: This block only works with the Streaming API. If you use it,
140
+ # chatterbot will assume you want to use streaming and will
141
+ # automatically activate it for you.
142
+ #
143
+ # followed do |user|
144
+ # puts user.inspect
145
+ # end
146
+
147
+ #
148
+ # Use this block if you want to be notified when one of your tweets is
149
+ # favorited. The object passed in will be a Twitter::Streaming::Event
150
+ # @see http://www.rubydoc.info/gems/twitter/Twitter/Streaming/Event
151
+ #
152
+ # NOTE: This block only works with the Streaming API. If you use it,
153
+ # chatterbot will assume you want to use streaming and will
154
+ # automatically activate it for you.
155
+ #
156
+ # favorited do |event|
157
+ # puts event.inspect
158
+ # end
159
+
160
+ #
161
+ # Use this block if you want to be notified of deleted tweets from
162
+ # your bots home timeline. The object passed in will be a
163
+ # Twitter::Streaming::DeletedTweet
164
+ # @see http://www.rubydoc.info/gems/twitter/Twitter/Streaming/DeletedTweet
165
+ #
166
+ # NOTE: This block only works with the Streaming API. If you use it,
167
+ # chatterbot will assume you want to use streaming and will
168
+ # automatically activate it for you.
169
+ #
170
+ #deleted do |tweet|
171
+ #
172
+ #end
173
+