lita-ai 0.1.2 → 0.1.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.md +9 -3
- data/lib/lita-ai.rb +1 -1
- data/lib/lita/handlers/ai.rb +12 -2
- data/lita-ai.gemspec +2 -2
- data/spec/lita/handlers/ai_spec.rb +15 -10
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff58dd9f5d803c36b9e59dc242c8ec009025d3bd
|
4
|
+
data.tar.gz: 17f3591b0e677ebac0861f2272a2170228ccafca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9072ae25063ed1d8858d08978cfad79e79a5c735dea4bf54e3544300a9604533139a71ede5b9b883ec03fd6a82334ff027573b4a98775d90be46208513c0267f
|
7
|
+
data.tar.gz: d9152b38bf1fc3880e8c0addf92ca0f630c75cb503bdf3f7de228d789d19912e9dd80fb60bdcbaa1268d4661aa4dc1d20db36e927ff83ec16266a1bb4b7681f7
|
data/README.md
CHANGED
@@ -20,11 +20,17 @@ gem 'lita-ai'
|
|
20
20
|
|
21
21
|
## Configuration
|
22
22
|
|
23
|
-
|
23
|
+
Sign up at [cleverbot.io](http://cleverbot.io) and enter your api user and key into lita_config.rb.
|
24
|
+
|
25
|
+
```
|
26
|
+
config.handlers.ai.api_user = '<redacted>'
|
27
|
+
config.handlers.ai.api_key = '<redacted>'
|
28
|
+
```
|
29
|
+
|
24
30
|
|
25
31
|
## Usage
|
26
32
|
|
27
|
-
Just send a message mentioning your robot by it's name or alias, either directly as a command or anywhere else in the message.
|
33
|
+
Just send a message mentioning your robot by it's name or alias, either directly as a command or anywhere else in the message.
|
28
34
|
|
29
35
|
```
|
30
36
|
> lita what's up?
|
@@ -34,7 +40,7 @@ Just send a message mentioning your robot by it's name or alias, either directly
|
|
34
40
|
#=> Sure, when and where?
|
35
41
|
```
|
36
42
|
|
37
|
-
Your robots name will be stripped from the message we send to Cleverbot.. we don't want to confuse it anymore than it already is.
|
43
|
+
Your robots name will be stripped from the message we send to Cleverbot.. we don't want to confuse it anymore than it already is.
|
38
44
|
|
39
45
|
## License
|
40
46
|
|
data/lib/lita-ai.rb
CHANGED
data/lib/lita/handlers/ai.rb
CHANGED
@@ -2,9 +2,19 @@ module Lita
|
|
2
2
|
module Handlers
|
3
3
|
class Ai < Handler
|
4
4
|
on :unhandled_message, :chat
|
5
|
+
config :api_key, type: String
|
6
|
+
config :api_user, type: String
|
5
7
|
|
6
8
|
def self.cleverbot
|
7
|
-
@cleverbot ||=
|
9
|
+
@cleverbot ||= Cleverbot.new(api_user, api_key)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.api_user
|
13
|
+
Lita.config.handlers.ai.api_user
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.api_key
|
17
|
+
Lita.config.handlers.ai.api_key
|
8
18
|
end
|
9
19
|
|
10
20
|
def chat(payload)
|
@@ -21,7 +31,7 @@ module Lita
|
|
21
31
|
|
22
32
|
def build_response(message)
|
23
33
|
message = extract_aliases(message)
|
24
|
-
reply = self.class.cleverbot.
|
34
|
+
reply = self.class.cleverbot.say(message.body)
|
25
35
|
clean_response(reply.to_s) if reply
|
26
36
|
end
|
27
37
|
|
data/lita-ai.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = "lita-ai"
|
3
|
-
spec.version = "0.1.
|
3
|
+
spec.version = "0.1.3"
|
4
4
|
spec.authors = ["Tom Beynon"]
|
5
5
|
spec.email = ["tom@tombeynon.co.uk"]
|
6
6
|
spec.description = "Makes lita respond to unhandled messages using Cleverbot"
|
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
spec.require_paths = ["lib"]
|
16
16
|
|
17
17
|
spec.add_runtime_dependency "lita", ">= 4.6"
|
18
|
-
spec.add_runtime_dependency "
|
18
|
+
spec.add_runtime_dependency "cleverbot_io", "~> 1.2.2"
|
19
19
|
spec.add_runtime_dependency "htmlentities", "~> 4.3"
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
@@ -1,10 +1,15 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Lita::Handlers::Ai, lita_handler: true do
|
4
|
+
let(:cleverbot){ double(:cleverbot) }
|
5
|
+
before(:each) do
|
6
|
+
allow(subject.class).to receive(:cleverbot){ cleverbot }
|
7
|
+
end
|
8
|
+
|
4
9
|
describe 'handling unhandled_message' do
|
5
10
|
context 'unhandled directed at lita' do
|
6
11
|
it 'uses cleverbot to reply' do
|
7
|
-
allow(subject.class.cleverbot).to receive(:
|
12
|
+
allow(subject.class.cleverbot).to receive(:say){ 'Hello' }
|
8
13
|
send_message('Hi lita')
|
9
14
|
expect(replies.last).to eq('Hello')
|
10
15
|
end
|
@@ -24,19 +29,19 @@ describe Lita::Handlers::Ai, lita_handler: true do
|
|
24
29
|
let(:message){ double(:message, body: 'Hello', command?: true, source: source) }
|
25
30
|
|
26
31
|
it 'strips out the robot name' do
|
27
|
-
expect(subject.class.cleverbot).to receive(:
|
32
|
+
expect(subject.class.cleverbot).to receive(:say).with('Hello')
|
28
33
|
subject.chat(message: message)
|
29
34
|
end
|
30
35
|
|
31
36
|
it 'strips out the robot aliases' do
|
32
37
|
robot.alias = 'bender'
|
33
38
|
allow(message).to receive(:body){ 'Hi bender' }
|
34
|
-
expect(subject.class.cleverbot).to receive(:
|
39
|
+
expect(subject.class.cleverbot).to receive(:say).with('Hi')
|
35
40
|
subject.chat(message: message)
|
36
41
|
end
|
37
42
|
|
38
43
|
it 'sends a message with cleverbot\'s response' do
|
39
|
-
expect(subject.class.cleverbot).to receive(:
|
44
|
+
expect(subject.class.cleverbot).to receive(:say).with('Hello'){ 'Hi' }
|
40
45
|
expect(subject.robot).to receive(:send_message).with(source, 'Hi')
|
41
46
|
subject.chat(message: message)
|
42
47
|
end
|
@@ -45,14 +50,14 @@ describe Lita::Handlers::Ai, lita_handler: true do
|
|
45
50
|
|
46
51
|
context 'unicode decoding' do
|
47
52
|
let(:message){ double(:message, body: '中文', command?: true, source: source) }
|
48
|
-
before { allow(described_class.cleverbot).to receive(:
|
53
|
+
before { allow(described_class.cleverbot).to receive(:say).and_return("|56E0|4E3A|6211|4E0D|61C2...") }
|
49
54
|
|
50
55
|
it { expect(subject.chat(message: message)[0]).to eq "因为我不懂..." }
|
51
56
|
end
|
52
57
|
|
53
58
|
context 'HTML entity decoding' do
|
54
59
|
let(:message){ double(:message, body: 'Foo © bar 𝌆', command?: true, source: source) }
|
55
|
-
before { allow(described_class.cleverbot).to receive(:
|
60
|
+
before { allow(described_class.cleverbot).to receive(:say).and_return("Baz ☃ Bim å") }
|
56
61
|
|
57
62
|
it { expect(subject.chat(message: message)[0]).to eq "Baz ☃ Bim å" }
|
58
63
|
end
|
@@ -61,19 +66,19 @@ describe Lita::Handlers::Ai, lita_handler: true do
|
|
61
66
|
let(:message){ double(:message, body: 'Hi lita', command?: false, source: source) }
|
62
67
|
|
63
68
|
it 'strips out the robot name' do
|
64
|
-
expect(subject.class.cleverbot).to receive(:
|
69
|
+
expect(subject.class.cleverbot).to receive(:say).with('Hi')
|
65
70
|
subject.chat(message: message)
|
66
71
|
end
|
67
72
|
|
68
73
|
it 'strips out the robot aliases' do
|
69
74
|
robot.alias = 'bender'
|
70
75
|
allow(message).to receive(:body){ 'Hello bender' }
|
71
|
-
expect(subject.class.cleverbot).to receive(:
|
76
|
+
expect(subject.class.cleverbot).to receive(:say).with('Hello')
|
72
77
|
subject.chat(message: message)
|
73
78
|
end
|
74
79
|
|
75
80
|
it 'sends a message with cleverbot\'s response' do
|
76
|
-
expect(subject.class.cleverbot).to receive(:
|
81
|
+
expect(subject.class.cleverbot).to receive(:say).with('Hi'){ 'Hello' }
|
77
82
|
expect(subject.robot).to receive(:send_message).with(source, 'Hello')
|
78
83
|
subject.chat(message: message)
|
79
84
|
end
|
@@ -83,7 +88,7 @@ describe Lita::Handlers::Ai, lita_handler: true do
|
|
83
88
|
let(:message){ double(:message, body: 'Not talking to you', command?: false, source: source) }
|
84
89
|
|
85
90
|
it 'Doesn\'t call cleverbot' do
|
86
|
-
expect(subject.class.cleverbot).to_not receive(:
|
91
|
+
expect(subject.class.cleverbot).to_not receive(:say)
|
87
92
|
subject.chat(message: message)
|
88
93
|
end
|
89
94
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-ai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Beynon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|
@@ -25,19 +25,19 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: cleverbot_io
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 1.2.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 1.2.2
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: htmlentities
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|