chatterbot 2.0.2 → 2.2.0
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.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +19 -0
- data/Gemfile +9 -17
- data/README.markdown +10 -23
- data/Rakefile +2 -18
- data/chatterbot.gemspec +17 -12
- data/docs/Gemfile +3 -0
- data/docs/README.md +3 -0
- data/docs/_config.yml +37 -0
- data/docs/_includes/footer.html +3 -0
- data/docs/_includes/header.html +4 -0
- data/docs/_includes/navigation.html +23 -0
- data/docs/_layouts/default.html +98 -0
- data/docs/_layouts/page.html +11 -0
- data/docs/_posts/.gitkeep +0 -0
- data/docs/_site/Gemfile +3 -0
- data/docs/_site/advanced.html +465 -0
- data/docs/_site/configuration.html +436 -0
- data/docs/_site/contributing.html +414 -0
- data/docs/_site/css/main.css +58 -0
- data/docs/_site/css/syntax.css +61 -0
- data/docs/_site/deploying.html +451 -0
- data/docs/_site/examples.html +559 -0
- data/docs/_site/features.html +496 -0
- data/docs/_site/images/01-create-application.png +0 -0
- data/docs/_site/images/02-application-permissions.png +0 -0
- data/docs/_site/images/03-mobile-number.png +0 -0
- data/docs/_site/images/04-access-token.png +0 -0
- data/docs/_site/index.html +461 -0
- data/docs/_site/javascripts/main.js +1 -0
- data/docs/_site/other-tools.html +419 -0
- data/docs/_site/params.json +1 -0
- data/docs/_site/rdoc.html +409 -0
- data/docs/_site/setup.html +491 -0
- data/docs/_site/stylesheets/pygment_trac.css +68 -0
- data/docs/_site/stylesheets/stylesheet.css +247 -0
- data/docs/_site/tut.html +402 -0
- data/docs/_site/twitter-docs.html +409 -0
- data/docs/_site/walkthrough.html +447 -0
- data/docs/advanced.md +62 -0
- data/docs/basics.md +12 -0
- data/docs/bin/jekyll-page +109 -0
- data/docs/configuration.md +32 -0
- data/docs/contributing.md +14 -0
- data/docs/css/main.css +58 -0
- data/docs/css/syntax.css +61 -0
- data/docs/deploying.md +47 -0
- data/docs/examples.md +120 -0
- data/docs/features.md +88 -0
- data/docs/images/01-create-application.png +0 -0
- data/docs/images/02-application-permissions.png +0 -0
- data/docs/images/03-mobile-number.png +0 -0
- data/docs/images/04-access-token.png +0 -0
- data/docs/index.md +69 -0
- data/docs/javascripts/main.js +1 -0
- data/docs/other-tools.md +17 -0
- data/docs/params.json +1 -0
- data/docs/rdoc.md +6 -0
- data/docs/setup.md +84 -0
- data/docs/stylesheets/pygment_trac.css +68 -0
- data/docs/stylesheets/stylesheet.css +247 -0
- data/docs/tips.md +22 -0
- data/docs/tut.md +6 -0
- data/docs/twitter-docs.md +6 -0
- data/docs/walkthrough.md +46 -0
- data/lib/chatterbot.rb +0 -1
- data/lib/chatterbot/bot.rb +7 -67
- data/lib/chatterbot/client.rb +2 -9
- data/lib/chatterbot/config.rb +1 -2
- data/lib/chatterbot/dsl.rb +20 -47
- data/lib/chatterbot/home_timeline.rb +1 -1
- data/lib/chatterbot/search.rb +26 -3
- data/lib/chatterbot/skeleton.rb +0 -2
- data/lib/chatterbot/tweet.rb +13 -3
- data/lib/chatterbot/ui.rb +0 -1
- data/lib/chatterbot/version.rb +1 -1
- data/spec/bot_spec.rb +1 -76
- data/spec/client_spec.rb +0 -3
- data/spec/config_manager_spec.rb +6 -5
- data/spec/config_spec.rb +4 -1
- data/spec/dsl_spec.rb +10 -35
- data/spec/fixtures/update_with_media.png +0 -0
- data/spec/search_spec.rb +40 -1
- data/spec/spec_helper.rb +1 -4
- data/spec/tweet_spec.rb +74 -34
- data/templates/skeleton.txt +0 -47
- metadata +81 -135
- data/.document +0 -5
- data/.travis.yml +0 -11
- data/examples/streaming_bot.rb +0 -48
- data/examples/tweet_logger.rb +0 -68
- data/lib/chatterbot/streaming.rb +0 -62
- data/spec/streaming_spec.rb +0 -172
data/lib/chatterbot/streaming.rb
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
module Chatterbot
|
|
2
|
-
|
|
3
|
-
#
|
|
4
|
-
# simple twitter stream handler
|
|
5
|
-
module Streaming
|
|
6
|
-
|
|
7
|
-
def streaming_tweet_handler
|
|
8
|
-
usable_handlers = [:home_timeline, :search]
|
|
9
|
-
name, block = @handlers.find { |k, v| usable_handlers.include?(k) }
|
|
10
|
-
block
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
#
|
|
14
|
-
# Take the passed in object and call the appropriate bot method
|
|
15
|
-
# for it
|
|
16
|
-
# @param [Class] object a streaming API object
|
|
17
|
-
#
|
|
18
|
-
def handle_streaming_object(object)
|
|
19
|
-
debug object
|
|
20
|
-
|
|
21
|
-
case object
|
|
22
|
-
when Twitter::Tweet
|
|
23
|
-
if object.user == authenticated_user
|
|
24
|
-
debug "skipping #{object} because it's from me"
|
|
25
|
-
elsif (h = streaming_tweet_handler) && valid_tweet?(object)
|
|
26
|
-
@current_tweet = object
|
|
27
|
-
update_since_id(object)
|
|
28
|
-
|
|
29
|
-
h.call(object)
|
|
30
|
-
@current_tweet = nil
|
|
31
|
-
end
|
|
32
|
-
when Twitter::Streaming::DeletedTweet
|
|
33
|
-
if (h = @handlers[:deleted])
|
|
34
|
-
h.call(object)
|
|
35
|
-
end
|
|
36
|
-
when Twitter::DirectMessage
|
|
37
|
-
if object.sender == authenticated_user
|
|
38
|
-
debug "skipping DM #{object} because it's from me"
|
|
39
|
-
elsif (h = @handlers[:direct_messages])
|
|
40
|
-
@current_tweet = object
|
|
41
|
-
update_since_id_dm(object)
|
|
42
|
-
h.call(object)
|
|
43
|
-
@current_tweet = nil
|
|
44
|
-
end
|
|
45
|
-
when Twitter::Streaming::Event
|
|
46
|
-
if object.respond_to?(:source) && object.source == authenticated_user
|
|
47
|
-
debug "skipping #{object} because it's from me"
|
|
48
|
-
elsif object.name == :follow && (h = @handlers[:followed])
|
|
49
|
-
h.call(object.source)
|
|
50
|
-
elsif object.name == :favorite && (h = @handlers[:favorited])
|
|
51
|
-
h.call(object.source, object.target_object)
|
|
52
|
-
end
|
|
53
|
-
when Twitter::Streaming::FriendList
|
|
54
|
-
debug "got friend list"
|
|
55
|
-
when Twitter::Streaming::StallWarning
|
|
56
|
-
debug "***** STALL WARNING *****"
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
data/spec/streaming_spec.rb
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
|
2
|
-
|
|
3
|
-
describe "Chatterbot::Streaming" do
|
|
4
|
-
let(:bot) { test_bot }
|
|
5
|
-
let(:user) { fake_user('user', 100) }
|
|
6
|
-
let(:tweet) { fake_tweet(12345) }
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
describe "streaming_tweet_handler" do
|
|
10
|
-
before(:each) do
|
|
11
|
-
bot.skip_run = true
|
|
12
|
-
bot.streaming = true
|
|
13
|
-
allow(bot.client).to receive(:user).and_return(user)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
it "defaults to home_timeline" do
|
|
17
|
-
bot.register_handler(:home_timeline) { @result = :home_timeline }
|
|
18
|
-
bot.register_handler(:search, "foo") { @result = :search }
|
|
19
|
-
|
|
20
|
-
bot.handle_streaming_object(tweet)
|
|
21
|
-
expect(@result).to eql(:home_timeline)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it "will return search" do
|
|
25
|
-
bot.register_handler(:search, "foo") { @result = :search }
|
|
26
|
-
|
|
27
|
-
bot.handle_streaming_object(tweet)
|
|
28
|
-
expect(@result).to eql(:search)
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe "handle_streaming_object" do
|
|
33
|
-
before(:each) {
|
|
34
|
-
bot.skip_run = true
|
|
35
|
-
bot.streaming = true
|
|
36
|
-
allow(bot.client).to receive(:user).and_return(user)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
describe "Twitter::Tweet" do
|
|
40
|
-
it "works if no handler" do
|
|
41
|
-
bot.handle_streaming_object(tweet)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context "with handler" do
|
|
45
|
-
before(:each) do
|
|
46
|
-
bot.register_handler(:home_timeline) { |t| @last_object = t }
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it "ignores tweets from authenticated user" do
|
|
50
|
-
expect(tweet).to receive(:user).and_return(user)
|
|
51
|
-
bot.handle_streaming_object(tweet)
|
|
52
|
-
expect(@last_object).to be_nil
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "passes to handler" do
|
|
56
|
-
bot.handle_streaming_object(tweet)
|
|
57
|
-
expect(@last_object).to eql(tweet)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
it "ignores tweets from blocklist" do
|
|
61
|
-
bot.blocklist = ['chatterbot']
|
|
62
|
-
bot.handle_streaming_object(tweet)
|
|
63
|
-
expect(@last_object).to be_nil
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it "ignores tweets if skip_me is true" do
|
|
67
|
-
bot.exclude = ['tweet']
|
|
68
|
-
bot.handle_streaming_object(tweet)
|
|
69
|
-
expect(@last_object).to be_nil
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
describe "Twitter::Streaming::DeletedTweet" do
|
|
75
|
-
it "works if no handler" do
|
|
76
|
-
obj = Twitter::Streaming::DeletedTweet.new(:id => 1)
|
|
77
|
-
bot.handle_streaming_object(obj)
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it "passes to handler" do
|
|
81
|
-
bot.register_handler(:deleted) { |t| @last_object = t }
|
|
82
|
-
obj = Twitter::Streaming::DeletedTweet.new(:id => 1)
|
|
83
|
-
bot.handle_streaming_object(obj)
|
|
84
|
-
expect(@last_object).to eql(obj)
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
describe "Twitter::DirectMessage" do
|
|
89
|
-
it "works if no handler" do
|
|
90
|
-
obj = Twitter::DirectMessage.new(:id => 1)
|
|
91
|
-
bot.handle_streaming_object(obj)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it "passes to handler" do
|
|
95
|
-
bot.register_handler(:direct_messages) { |t| @last_object = t }
|
|
96
|
-
obj = Twitter::DirectMessage.new(:id => 1)
|
|
97
|
-
bot.handle_streaming_object(obj)
|
|
98
|
-
expect(@last_object).to eql(obj)
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
describe "Twitter::Streaming::Event" do
|
|
103
|
-
it "ignores events generated by authenticated user" do
|
|
104
|
-
event = Twitter::Streaming::Event.new(
|
|
105
|
-
:event => :follow,
|
|
106
|
-
:source => {:id => user.id, :name => 'name', :screen_name => 'name'},
|
|
107
|
-
:target => {:id => user.id, :name => 'name', :screen_name => 'name'})
|
|
108
|
-
|
|
109
|
-
bot.register_handler(:followed) { |t| @last_object = t }
|
|
110
|
-
|
|
111
|
-
bot.handle_streaming_object(event)
|
|
112
|
-
expect(@last_object).to be_nil
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
describe "follow" do
|
|
116
|
-
before(:each) do
|
|
117
|
-
@event = Twitter::Streaming::Event.new(
|
|
118
|
-
:event => :follow,
|
|
119
|
-
:source => {:id => 12345, :name => 'name', :screen_name => 'name'},
|
|
120
|
-
:target => {:id => user.id, :name => 'name', :screen_name => 'name'})
|
|
121
|
-
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
it "works if no handler" do
|
|
125
|
-
bot.handle_streaming_object(@event)
|
|
126
|
-
expect(@last_object).to be_nil
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
it "passes to handler" do
|
|
130
|
-
bot.register_handler(:followed) { |t| @last_object = t }
|
|
131
|
-
bot.handle_streaming_object(@event)
|
|
132
|
-
expect(@last_object.class).to be(Twitter::User)
|
|
133
|
-
expect(@last_object.id).to be(12345)
|
|
134
|
-
end
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
describe "favorite" do
|
|
138
|
-
before(:each) do
|
|
139
|
-
@event = Twitter::Streaming::Event.new(
|
|
140
|
-
:event => :favorite,
|
|
141
|
-
:source => {:id => 12345, :name => 'name', :screen_name => 'name'},
|
|
142
|
-
:target => {:id => user.id, :name => 'name', :screen_name => 'name'},
|
|
143
|
-
:target_object => {
|
|
144
|
-
:from_user => "chatterbot",
|
|
145
|
-
:id => 56789,
|
|
146
|
-
:text => "I am a tweet!",
|
|
147
|
-
:user => { :id => 1, :screen_name => "chatterbot" }
|
|
148
|
-
})
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
it "works if no handler" do
|
|
152
|
-
bot.handle_streaming_object(@event)
|
|
153
|
-
expect(@last_object).to be_nil
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
it "passes to handler" do
|
|
157
|
-
bot.register_handler(:favorited) { |_, t| @last_object = t }
|
|
158
|
-
bot.handle_streaming_object(@event)
|
|
159
|
-
expect(@last_object.class).to be(Twitter::Tweet)
|
|
160
|
-
expect(@last_object.text).to eq("I am a tweet!")
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
describe "Twitter::Streaming::FriendList" do
|
|
166
|
-
it "works if no handler" do
|
|
167
|
-
obj = Twitter::Streaming::FriendList.new
|
|
168
|
-
bot.handle_streaming_object(obj)
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
end
|
|
172
|
-
end
|