lita-talk 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +18 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +34 -0
- data/Rakefile +6 -0
- data/lib/lita/handlers/talk.rb +50 -0
- data/lib/lita-talk.rb +12 -0
- data/lita-talk.gemspec +25 -0
- data/locales/en.yml +4 -0
- data/spec/lita/handlers/talk_spec.rb +4 -0
- data/spec/spec_helper.rb +6 -0
- data/templates/.gitkeep +0 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eb568b171531d5c5039bab11ae8ac2b7077a41c6
|
4
|
+
data.tar.gz: d1bb0bb1d8d215c52f7e0ca149562fc856477920
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e44aa45be00837cf6147857fed67f109c837c1a6645921477cdeb90bd8f25f18cfe0347ec7ab60ee200c74f49eec29318d095df2c92a777cda0688a5183dc6c3
|
7
|
+
data.tar.gz: 46c210ed7511c11038c6460d444c5b2563bc5e2c385ad04dbcad8a1edf024abf7dd37a85494b8eac3116ece755c24ca95fe6d3a70f76320abcc50e15491673e6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2015 fukayatsu
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# lita-talk
|
2
|
+
|
3
|
+
Talk with you if given message didn't match any other handlers.
|
4
|
+
|
5
|
+
Inspired by [r7kamura/ruboty-talk](https://github.com/r7kamura/ruboty-talk).
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add lita-talk to your Lita instance's Gemfile:
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
gem "lita-talk"
|
13
|
+
```
|
14
|
+
|
15
|
+
## Configuration
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
# lita_config.rb
|
19
|
+
Lita.configure do |config|
|
20
|
+
...
|
21
|
+
# required
|
22
|
+
Lita.config.handlers.talk.docomo_api_key = 'xxx'
|
23
|
+
|
24
|
+
# optional (https://dev.smt.docomo.ne.jp/?p=docs.api.page&api_name=dialogue&p_name=api_1#tag01)
|
25
|
+
# 20 : 関西弁キャラ
|
26
|
+
# 30 : 赤ちゃんキャラ
|
27
|
+
# 指定なし : デフォルトキャラ
|
28
|
+
Lita.config.handlers.talk.docomo_character_id = 20
|
29
|
+
end
|
30
|
+
```
|
31
|
+
|
32
|
+
## Usage
|
33
|
+
|
34
|
+
![ss 2015-04-15 at 16 24 51](https://cloud.githubusercontent.com/assets/1041857/7153973/25f15966-e38c-11e4-9c26-3aef61e4e7fa.png)
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'docomoru'
|
2
|
+
|
3
|
+
module Lita
|
4
|
+
module Handlers
|
5
|
+
class Talk < Handler
|
6
|
+
config :docomo_api_key, type: String, required: true
|
7
|
+
config :docomo_character_id, type: Integer, required: false
|
8
|
+
|
9
|
+
route(/^(.+)/, :talk, command: true, help: {
|
10
|
+
"talk" => "Talk with you if given message didn't match any other handlers."
|
11
|
+
})
|
12
|
+
def talk(response)
|
13
|
+
@robot.handlers.map do |handler|
|
14
|
+
next nil if handler == self.class
|
15
|
+
next nil unless handler.respond_to?(:routes)
|
16
|
+
handler.routes
|
17
|
+
end.flatten.compact.each do |route|
|
18
|
+
next unless route.command
|
19
|
+
return if response.message.body.match(route.pattern)
|
20
|
+
end
|
21
|
+
|
22
|
+
context = Lita.redis.get context_key(response)
|
23
|
+
api_response = client.create_dialogue(response.message.body, params(context))
|
24
|
+
Lita.redis.set context_key(response), api_response.body["context"]
|
25
|
+
response.reply api_response.body["utt"]
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def client
|
31
|
+
@client ||= Docomoru::Client.new(api_key: config.docomo_api_key)
|
32
|
+
end
|
33
|
+
|
34
|
+
def context_key(response)
|
35
|
+
"lita-talk:#{response.message.source.room}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def params(context)
|
39
|
+
{
|
40
|
+
context: context,
|
41
|
+
t: config.docomo_character_id,
|
42
|
+
}.reject do |key, value|
|
43
|
+
value.nil?
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
Lita.register_handler(Talk)
|
49
|
+
end
|
50
|
+
end
|
data/lib/lita-talk.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require "lita"
|
2
|
+
|
3
|
+
Lita.load_locales Dir[File.expand_path(
|
4
|
+
File.join("..", "..", "locales", "*.yml"), __FILE__
|
5
|
+
)]
|
6
|
+
|
7
|
+
require "lita/handlers/talk"
|
8
|
+
|
9
|
+
Lita::Handlers::Talk.template_root File.expand_path(
|
10
|
+
File.join("..", "..", "templates"),
|
11
|
+
__FILE__
|
12
|
+
)
|
data/lita-talk.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-talk"
|
3
|
+
spec.version = "0.1.0"
|
4
|
+
spec.authors = ["fukayatsu"]
|
5
|
+
spec.email = ["fukayatsu@gmail.com"]
|
6
|
+
spec.description = "Talk with you if given message didn't match any other handlers."
|
7
|
+
spec.summary = "Talk with you if given message didn't match any other handlers."
|
8
|
+
spec.homepage = "https://github.com/fukayatsu/lita-talk"
|
9
|
+
spec.license = "MIT License"
|
10
|
+
spec.metadata = { "lita_plugin_type" => "handler" }
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($/)
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
|
17
|
+
spec.add_runtime_dependency "lita", "~> 4.3"
|
18
|
+
spec.add_runtime_dependency "docomoru", "~> 0.1.3 "
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
21
|
+
spec.add_development_dependency "pry-byebug"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rack-test"
|
24
|
+
spec.add_development_dependency "rspec", ">= 3.0.0"
|
25
|
+
end
|
data/locales/en.yml
ADDED
data/spec/spec_helper.rb
ADDED
data/templates/.gitkeep
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-talk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- fukayatsu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lita
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: docomoru
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.3
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rack-test
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 3.0.0
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 3.0.0
|
111
|
+
description: Talk with you if given message didn't match any other handlers.
|
112
|
+
email:
|
113
|
+
- fukayatsu@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- Gemfile
|
120
|
+
- LICENSE
|
121
|
+
- README.md
|
122
|
+
- Rakefile
|
123
|
+
- lib/lita-talk.rb
|
124
|
+
- lib/lita/handlers/talk.rb
|
125
|
+
- lita-talk.gemspec
|
126
|
+
- locales/en.yml
|
127
|
+
- spec/lita/handlers/talk_spec.rb
|
128
|
+
- spec/spec_helper.rb
|
129
|
+
- templates/.gitkeep
|
130
|
+
homepage: https://github.com/fukayatsu/lita-talk
|
131
|
+
licenses:
|
132
|
+
- MIT License
|
133
|
+
metadata:
|
134
|
+
lita_plugin_type: handler
|
135
|
+
post_install_message:
|
136
|
+
rdoc_options: []
|
137
|
+
require_paths:
|
138
|
+
- lib
|
139
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 2.4.5
|
152
|
+
signing_key:
|
153
|
+
specification_version: 4
|
154
|
+
summary: Talk with you if given message didn't match any other handlers.
|
155
|
+
test_files:
|
156
|
+
- spec/lita/handlers/talk_spec.rb
|
157
|
+
- spec/spec_helper.rb
|
158
|
+
has_rdoc:
|