chatterbot 2.0.2 → 2.0.3
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 +4 -4
- data/README.markdown +3 -2
- data/lib/chatterbot/bot.rb +0 -1
- data/lib/chatterbot/dsl.rb +16 -4
- data/lib/chatterbot/tweet.rb +13 -3
- data/lib/chatterbot/ui.rb +0 -1
- data/lib/chatterbot/version.rb +1 -1
- data/spec/dsl_spec.rb +9 -2
- data/spec/fixtures/update_with_media.png +0 -0
- data/spec/tweet_spec.rb +74 -34
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d88eeab29e199d49fb99f081f90d483263c57d9
|
4
|
+
data.tar.gz: 92dbfd810dc21b7c638bc6ff22903194881734e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f33ae22b7f5ebf4d3e774aa95a9761cb4ec8c8970e670ca89181fdf64507814d034fecd206fc52aa0469f3d6c4c854a69395be31a0de4fcde04bfc4f05f181c4
|
7
|
+
data.tar.gz: 5ab5abed1989ef5963b7d2b7b422b433cb7581aa7cd24ccbaee63fc07b9153aaaf9f3cf9c406ef46568844d4140c048402a0bc4e59dc82ebf0607e09e275b69d
|
data/README.markdown
CHANGED
@@ -79,8 +79,9 @@ Or you can write a bot using more traditional ruby classes, extend it if needed,
|
|
79
79
|
```
|
80
80
|
class MyBot < Chatterbot::Bot
|
81
81
|
def do_stuff
|
82
|
-
|
83
|
-
|
82
|
+
home_timeline do |tweet|
|
83
|
+
puts "I like to favorite things"
|
84
|
+
favorite tweet
|
84
85
|
end
|
85
86
|
end
|
86
87
|
end
|
data/lib/chatterbot/bot.rb
CHANGED
data/lib/chatterbot/dsl.rb
CHANGED
@@ -113,8 +113,13 @@ module Chatterbot
|
|
113
113
|
# send a tweet
|
114
114
|
#
|
115
115
|
# @param [String] txt the text you want to tweet
|
116
|
-
# @param [Hash] params
|
117
|
-
#
|
116
|
+
# @param [Hash] params options for the tweet. You can get an idea
|
117
|
+
# of possible values you can send here from the underlying Twitter
|
118
|
+
# gem docs: http://rdoc.info/gems/twitter/Twitter/API#update-instance_method
|
119
|
+
# @option params [String,File] :media Optional file object to send
|
120
|
+
# with the tweet. Must be an image or video that will be accepted by
|
121
|
+
# Twitter. You can pass a File object, or the path to a file
|
122
|
+
# @see http://rdoc.info/gems/twitter/Twitter/API#update-instance_method
|
118
123
|
# @param [Tweet] original if this is a reply, the original tweet. this will
|
119
124
|
# be used for variable substitution, and for logging
|
120
125
|
def tweet(txt, params = {}, original = nil)
|
@@ -141,8 +146,15 @@ module Chatterbot
|
|
141
146
|
#
|
142
147
|
# @param [String] txt the text you want to tweet
|
143
148
|
# @param [Tweet] source the original tweet you are replying to
|
144
|
-
|
145
|
-
|
149
|
+
# @param [Hash] params options for the tweet. You can get an idea
|
150
|
+
# of possible values you can send here from the underlying Twitter
|
151
|
+
# gem docs: http://rdoc.info/gems/twitter/Twitter/API#update-instance_method
|
152
|
+
# @option params [String,File] :media Optional file object to send with the
|
153
|
+
# tweet. Must be an image or video that will be accepted by
|
154
|
+
# Twitter. You can pass a File object, or the path to a file
|
155
|
+
# @see http://rdoc.info/gems/twitter/Twitter/API#update-instance_method
|
156
|
+
def reply(txt, source, params={})
|
157
|
+
bot.reply(txt, source, params)
|
146
158
|
end
|
147
159
|
|
148
160
|
#
|
data/lib/chatterbot/tweet.rb
CHANGED
@@ -13,7 +13,16 @@ module Chatterbot
|
|
13
13
|
debug "I'm in debug mode, otherwise I would tweet: #{txt}"
|
14
14
|
else
|
15
15
|
debug txt
|
16
|
-
|
16
|
+
if params.has_key?(:media)
|
17
|
+
file = params.delete(:media)
|
18
|
+
if ! file.is_a?(File)
|
19
|
+
file = File.new(file)
|
20
|
+
end
|
21
|
+
|
22
|
+
client.update_with_media txt, file, params
|
23
|
+
else
|
24
|
+
client.update txt, params
|
25
|
+
end
|
17
26
|
end
|
18
27
|
rescue Twitter::Error::Forbidden => e
|
19
28
|
#:nocov:
|
@@ -24,9 +33,10 @@ module Chatterbot
|
|
24
33
|
|
25
34
|
|
26
35
|
# reply to a tweet
|
27
|
-
def reply(txt, source)
|
36
|
+
def reply(txt, source, params = {})
|
28
37
|
debug txt
|
29
|
-
|
38
|
+
params = {:in_reply_to_status_id => source.id}.merge(params)
|
39
|
+
tweet txt, params, source
|
30
40
|
end
|
31
41
|
end
|
32
42
|
end
|
data/lib/chatterbot/ui.rb
CHANGED
data/lib/chatterbot/version.rb
CHANGED
data/spec/dsl_spec.rb
CHANGED
@@ -187,10 +187,17 @@ describe "Chatterbot::DSL" do
|
|
187
187
|
end
|
188
188
|
|
189
189
|
it "#reply passes along to bot object" do
|
190
|
-
|
191
|
-
reply
|
190
|
+
source = double(Twitter::Tweet)
|
191
|
+
expect(@bot).to receive(:reply).with("hello sailor!", source, {})
|
192
|
+
reply "hello sailor!", source
|
192
193
|
end
|
193
194
|
|
195
|
+
it "#reply passes along to bot object with media" do
|
196
|
+
source = double(Twitter::Tweet)
|
197
|
+
expect(@bot).to receive(:reply).with("hello sailor!", source, {media:"/tmp/foo.jpg"})
|
198
|
+
reply "hello sailor!", source, media:"/tmp/foo.jpg"
|
199
|
+
end
|
200
|
+
|
194
201
|
describe "#direct_message" do
|
195
202
|
it "passes along to bot object" do
|
196
203
|
expect(@bot).to receive(:direct_message).with("hello sailor!", nil)
|
Binary file
|
data/spec/tweet_spec.rb
CHANGED
@@ -11,29 +11,48 @@ describe "Chatterbot::Tweet" do
|
|
11
11
|
@bot.tweet "tweet test!"
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
bot
|
14
|
+
context "when authenticated" do
|
15
|
+
let(:bot) { test_bot }
|
16
|
+
before(:each) do
|
17
|
+
expect(bot).to receive(:require_login).and_return(true)
|
18
|
+
allow(bot).to receive(:client).and_return(double(Twitter::Client))
|
19
|
+
end
|
20
|
+
|
21
|
+
it "calls client.update with the right values" do
|
22
|
+
allow(bot).to receive(:debug_mode?).and_return(false)
|
16
23
|
|
17
|
-
|
18
|
-
|
24
|
+
test_str = "test!"
|
25
|
+
expect(bot.client).to receive(:update).with(test_str, {})
|
26
|
+
bot.tweet test_str
|
27
|
+
end
|
19
28
|
|
20
|
-
|
29
|
+
it "calls client.update_with_media if media file is specified" do
|
30
|
+
allow(bot).to receive(:debug_mode?).and_return(false)
|
21
31
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
32
|
+
test_str = "test!"
|
33
|
+
path = File.join(File.dirname(__FILE__), "fixtures", "update_with_media.png")
|
34
|
+
media = File.new(path)
|
35
|
+
expect(bot.client).to receive(:update_with_media).with(test_str, media, {})
|
36
|
+
bot.tweet test_str, media:media
|
37
|
+
end
|
26
38
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
expect(bot).to receive(:require_login).and_return(true)
|
31
|
-
allow(bot).to receive(:client).and_return(double(Twitter::Client))
|
39
|
+
it "calls client.update_with_media if media file path is specified" do
|
40
|
+
allow(bot).to receive(:debug_mode?).and_return(false)
|
32
41
|
|
33
|
-
|
42
|
+
test_str = "test!"
|
43
|
+
path = File.join(File.dirname(__FILE__), "fixtures", "update_with_media.png")
|
34
44
|
|
35
|
-
|
36
|
-
|
45
|
+
expect(bot.client).to receive(:update_with_media).with(test_str, an_instance_of(File), {})
|
46
|
+
bot.tweet test_str, media:path
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
it "doesn't tweet when debug_mode? is set" do
|
51
|
+
allow(bot).to receive(:debug_mode?).and_return(true)
|
52
|
+
|
53
|
+
expect(bot.client).not_to receive(:update)
|
54
|
+
bot.tweet "no tweet!"
|
55
|
+
end
|
37
56
|
end
|
38
57
|
end
|
39
58
|
|
@@ -44,30 +63,51 @@ describe "Chatterbot::Tweet" do
|
|
44
63
|
bot.reply "reply test!", fake_tweet(100)
|
45
64
|
end
|
46
65
|
|
47
|
-
|
48
|
-
bot
|
49
|
-
|
50
|
-
|
66
|
+
context "when authenticated" do
|
67
|
+
let(:bot) { test_bot }
|
68
|
+
before(:each) do
|
69
|
+
expect(bot).to receive(:require_login).and_return(true)
|
70
|
+
allow(bot).to receive(:client).and_return(double(Twitter::Client))
|
71
|
+
end
|
51
72
|
|
52
|
-
|
73
|
+
|
74
|
+
it "calls client.update with the right values" do
|
75
|
+
allow(bot).to receive(:debug_mode?).and_return(false)
|
53
76
|
|
54
|
-
|
77
|
+
test_str = "test!"
|
55
78
|
|
56
|
-
|
57
|
-
|
58
|
-
|
79
|
+
expect(bot.client).to receive(:update).with(test_str, {:in_reply_to_status_id => 100})
|
80
|
+
bot.reply test_str, fake_tweet(100, 100)
|
81
|
+
end
|
59
82
|
|
83
|
+
it "calls client.update_with_media if media file is specified" do
|
84
|
+
allow(bot).to receive(:debug_mode?).and_return(false)
|
60
85
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
86
|
+
test_str = "test!"
|
87
|
+
path = File.join(File.dirname(__FILE__), "fixtures", "update_with_media.png")
|
88
|
+
media = File.new(path)
|
89
|
+
|
90
|
+
expect(bot.client).to receive(:update_with_media).with(test_str, media, {:in_reply_to_status_id => 100})
|
91
|
+
bot.reply test_str, fake_tweet(100, 100), media:media
|
92
|
+
end
|
65
93
|
|
66
|
-
|
94
|
+
it "calls client.update_with_media if media file path is specified" do
|
95
|
+
allow(bot).to receive(:debug_mode?).and_return(false)
|
67
96
|
|
68
|
-
|
69
|
-
|
97
|
+
test_str = "test!"
|
98
|
+
path = File.join(File.dirname(__FILE__), "fixtures", "update_with_media.png")
|
99
|
+
|
100
|
+
expect(bot.client).to receive(:update_with_media).with(test_str, an_instance_of(File), {:in_reply_to_status_id => 100})
|
101
|
+
bot.reply test_str, fake_tweet(100, 100), media:path
|
102
|
+
end
|
103
|
+
|
104
|
+
it "doesn't reply when debug_mode? is set" do
|
105
|
+
allow(bot).to receive(:debug_mode?).and_return(true)
|
106
|
+
|
107
|
+
expect(bot.client).not_to receive(:update_with_media)
|
108
|
+
bot.reply "no reply test!", fake_tweet(100)
|
109
|
+
end
|
70
110
|
end
|
71
111
|
end
|
72
|
-
|
112
|
+
|
73
113
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chatterbot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Colin Mitchell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redcarpet
|
@@ -249,6 +249,7 @@ files:
|
|
249
249
|
- spec/direct_messages_spec.rb
|
250
250
|
- spec/dsl_spec.rb
|
251
251
|
- spec/favorite_spec.rb
|
252
|
+
- spec/fixtures/update_with_media.png
|
252
253
|
- spec/followers_spec.rb
|
253
254
|
- spec/handler_spec.rb
|
254
255
|
- spec/helpers_spec.rb
|
@@ -299,6 +300,7 @@ test_files:
|
|
299
300
|
- spec/direct_messages_spec.rb
|
300
301
|
- spec/dsl_spec.rb
|
301
302
|
- spec/favorite_spec.rb
|
303
|
+
- spec/fixtures/update_with_media.png
|
302
304
|
- spec/followers_spec.rb
|
303
305
|
- spec/handler_spec.rb
|
304
306
|
- spec/helpers_spec.rb
|