lita-ai 0.1.0 → 0.1.1
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/lib/lita/handlers/ai.rb +10 -5
- data/lita-ai.gemspec +1 -1
- data/spec/lita/handlers/ai_spec.rb +16 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 962088ee29c13008e2aebcfff430e6afc206bcca
|
4
|
+
data.tar.gz: 361a60ed9bc1b7db0e4b5b69bc1afaf61a9ab66e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e3901a4ff474c95006edd23f5267d517d43a8caeae001101f951ad917e9e7df1d826d8da92a58a95828233b4da949c9275578b0ff90abefef91052494624e2a
|
7
|
+
data.tar.gz: f8ecc9edeb4dd2965cab37bf2b8346b95ca0880ed6e68e0b6e7d4a2fe9abff92c4c0fa87a011eed9db228313e3713bbf3094e60c94950f89441ee29acf377900
|
data/lib/lita/handlers/ai.rb
CHANGED
@@ -8,18 +8,23 @@ module Lita
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def chat(payload)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
robot.send_message(message.source, reply)
|
11
|
+
message = payload[:message]
|
12
|
+
return unless should_reply?(message)
|
13
|
+
robot.send_message(message.source, build_response(message))
|
15
14
|
end
|
16
15
|
|
17
16
|
private
|
18
17
|
|
19
|
-
def
|
18
|
+
def should_reply?(message)
|
20
19
|
message.command? || message.body =~ /#{aliases.join('|')}/i
|
21
20
|
end
|
22
21
|
|
22
|
+
def build_response(message)
|
23
|
+
message = extract_aliases(message)
|
24
|
+
reply = self.class.cleverbot.think(message.body)
|
25
|
+
reply.to_s.gsub(/\|([0-9A-F]{4})/) { ["#{$1}".hex].pack("U") } if reply
|
26
|
+
end
|
27
|
+
|
23
28
|
def extract_aliases(message)
|
24
29
|
body = message.body.sub(/#{aliases.join('|')}/i, '').strip
|
25
30
|
Message.new(robot, body, message.source)
|
data/lita-ai.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Lita::Handlers::Ai, lita_handler: true do
|
4
|
-
describe 'handling unhandled_message' do
|
4
|
+
describe 'handling unhandled_message' do
|
5
5
|
context 'unhandled directed at lita' do
|
6
6
|
it 'uses cleverbot to reply' do
|
7
7
|
allow(subject.class.cleverbot).to receive(:think){ 'Hello' }
|
@@ -21,7 +21,7 @@ describe Lita::Handlers::Ai, lita_handler: true do
|
|
21
21
|
let(:cleverbot){ double(:cleverbot) }
|
22
22
|
let(:source){ double(:source) }
|
23
23
|
context 'commanding lita' do
|
24
|
-
let(:message){ double(:message, body: 'Hello', command?: true, source: source) }
|
24
|
+
let(:message){ double(:message, body: 'Hello', command?: true, source: source) }
|
25
25
|
|
26
26
|
it 'strips out the robot name' do
|
27
27
|
expect(subject.class.cleverbot).to receive(:think).with('Hello')
|
@@ -36,15 +36,22 @@ describe Lita::Handlers::Ai, lita_handler: true do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'sends a message with cleverbot\'s response' do
|
39
|
-
|
40
|
-
expect(subject.
|
41
|
-
expect(subject.robot).to receive(:send_message).with(source, reply)
|
39
|
+
expect(subject.class.cleverbot).to receive(:think).with('Hello'){ 'Hi' }
|
40
|
+
expect(subject.robot).to receive(:send_message).with(source, 'Hi')
|
42
41
|
subject.chat(message: message)
|
43
42
|
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'unicode format reply' do
|
47
|
+
let(:message){ double(:message, body: '中文', command?: true, source: source) }
|
48
|
+
before { allow(described_class.cleverbot).to receive(:think).and_return("|56E0|4E3A|6211|4E0D|61C2...") }
|
49
|
+
|
50
|
+
it { expect(subject.chat(message: message)[0]).to eq "因为我不懂..." }
|
44
51
|
end
|
45
52
|
|
46
53
|
context 'mentioning lita' do
|
47
|
-
let(:message){ double(:message, body: 'Hi lita', command?: false, source: source) }
|
54
|
+
let(:message){ double(:message, body: 'Hi lita', command?: false, source: source) }
|
48
55
|
|
49
56
|
it 'strips out the robot name' do
|
50
57
|
expect(subject.class.cleverbot).to receive(:think).with('Hi')
|
@@ -59,15 +66,14 @@ describe Lita::Handlers::Ai, lita_handler: true do
|
|
59
66
|
end
|
60
67
|
|
61
68
|
it 'sends a message with cleverbot\'s response' do
|
62
|
-
|
63
|
-
expect(subject.
|
64
|
-
expect(subject.robot).to receive(:send_message).with(source, reply)
|
69
|
+
expect(subject.class.cleverbot).to receive(:think).with('Hi'){ 'Hello' }
|
70
|
+
expect(subject.robot).to receive(:send_message).with(source, 'Hello')
|
65
71
|
subject.chat(message: message)
|
66
72
|
end
|
67
73
|
end
|
68
74
|
|
69
75
|
context 'is not chatting' do
|
70
|
-
let(:message){ double(:message, body: 'Not talking to you', command?: false, source: source) }
|
76
|
+
let(:message){ double(:message, body: 'Not talking to you', command?: false, source: source) }
|
71
77
|
|
72
78
|
it 'Doesn\'t call cleverbot' do
|
73
79
|
expect(subject.class.cleverbot).to_not receive(:think)
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Beynon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lita
|