ruboty-zatsudan 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +16 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/lib/ruboty/handlers/zatsudan.rb +35 -0
- data/lib/ruboty/zatsudan.rb +8 -0
- data/lib/ruboty/zatsudan/actions/zatsudan.rb +67 -0
- data/lib/ruboty/zatsudan/version.rb +5 -0
- data/ruboty-zatsudan.gemspec +24 -0
- data/screenshot.png +0 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fc0ff62e6c2c4afd7b932ee196c542de98ce6146
|
4
|
+
data.tar.gz: fe0dab2165ae3cadf476926effc79d98600bbbfc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3bbbb185ef143af253e5db6e68f1be4eac765e3a3af89d80e2ec37dcd7c7c7e1dda67db329f3eb8846c5095329d27a4a60ebdcc2c6ed0a6ad00bc090a0bf8eba
|
7
|
+
data.tar.gz: 9f8a537d3aaba040d877e1dbcd0c0bf9674d9c3e353bc3f8dd586e847aa3d23b3616d0d05231fffeac3a6dbbf23c20b8bf5c45c1a92bbb9df0bac7be046add29
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 block_given?
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Ruboty::Zatsudan
|
2
|
+
|
3
|
+
ruboty plugin for 雑談.
|
4
|
+
|
5
|
+
![screenshot](screenshot.png)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'ruboty-zatsudan'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install ruboty-zatsudan
|
22
|
+
|
23
|
+
|
24
|
+
Get docomo api key from:
|
25
|
+
|
26
|
+
https://dev.smt.docomo.ne.jp/?p=docs.api.page&api_docs_id=4
|
27
|
+
|
28
|
+
And set to `DOCOMO_APIKEY` environment variable.
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
@ruboty 雑談しよ
|
33
|
+
@ruboty 雑談もういい
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it ( https://github.com/blockgiven/ruboty-zatsudan/fork )
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
require "ruboty/zatsudan/actions/zatsudan"
|
3
|
+
|
4
|
+
module Ruboty
|
5
|
+
module Handlers
|
6
|
+
class Zatsudan < Base
|
7
|
+
env :DOCOMO_APIKEY, 'Docomo API key'
|
8
|
+
|
9
|
+
on /.*/, name: 'zatsudan', description: 'receive any 雑談', all: true, hidden: true
|
10
|
+
on /雑談しよ/, name: 'zatsudan_start', description: 'start 雑談'
|
11
|
+
on /雑談もういい/, name: 'zatsudan_end', description: 'end 雑談'
|
12
|
+
|
13
|
+
def zatsudan_start(message)
|
14
|
+
message.robot.brain.data[::Ruboty::Zatsudan::NAMESPACE] = {zatsudan: true}
|
15
|
+
message.reply("OK")
|
16
|
+
end
|
17
|
+
|
18
|
+
def zatsudan_end(message)
|
19
|
+
message.robot.brain.data[::Ruboty::Zatsudan::NAMESPACE] = {zatsudan: false}
|
20
|
+
message.reply("BYE")
|
21
|
+
end
|
22
|
+
|
23
|
+
def zatsudan(message)
|
24
|
+
if zatsudan?(robot)
|
25
|
+
Ruboty::Zatsudan::Actions::Zatsudan.new(message).call
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def zatsudan?(robot)
|
30
|
+
zatsudan = robot.brain.data[::Ruboty::Zatsudan::NAMESPACE] || {}
|
31
|
+
zatsudan[:zatsudan]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module Ruboty
|
5
|
+
module Zatsudan
|
6
|
+
module Actions
|
7
|
+
class Zatsudan < Ruboty::Actions::Base
|
8
|
+
def call
|
9
|
+
message.reply(zatsudan(message.body))
|
10
|
+
rescue => e
|
11
|
+
message.reply(e.message)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def zatsudan_api_url
|
17
|
+
'https://api.apigw.smt.docomo.ne.jp'
|
18
|
+
end
|
19
|
+
|
20
|
+
def zatsudan_api_key
|
21
|
+
ENV['DOCOMO_APIKEY']
|
22
|
+
end
|
23
|
+
|
24
|
+
def zatsudan(utt)
|
25
|
+
res = connection.post do |req|
|
26
|
+
req.url "/dialogue/v1/dialogue?APIKEY=#{zatsudan_api_key}"
|
27
|
+
req.headers['Content-Type'] = 'application/json'
|
28
|
+
if context && mode
|
29
|
+
req.body = JSON.generate(utt: utt, nickname: message.from_name, mode: mode, context: context)
|
30
|
+
else
|
31
|
+
req.body = JSON.generate(utt: utt, nickname: message.from_name)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
zatsudan_reply = JSON.parse(res.body)
|
36
|
+
|
37
|
+
self.context = zatsudan_reply['context']
|
38
|
+
self.mode = zatsudan_reply['mode']
|
39
|
+
|
40
|
+
zatsudan_reply['utt']
|
41
|
+
end
|
42
|
+
|
43
|
+
def connection
|
44
|
+
@connection ||= Faraday.new(url: zatsudan_api_url) do |faraday|
|
45
|
+
faraday.adapter Faraday.default_adapter
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def mode=(mode)
|
50
|
+
message.robot.brain.data[::Ruboty::Zatsudan::NAMESPACE][:mode] = mode
|
51
|
+
end
|
52
|
+
|
53
|
+
def mode
|
54
|
+
message.robot.brain.data[::Ruboty::Zatsudan::NAMESPACE][:mode]
|
55
|
+
end
|
56
|
+
|
57
|
+
def context=(context)
|
58
|
+
message.robot.brain.data[::Ruboty::Zatsudan::NAMESPACE][:context] = context
|
59
|
+
end
|
60
|
+
|
61
|
+
def context
|
62
|
+
message.robot.brain.data[::Ruboty::Zatsudan::NAMESPACE][:context]
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruboty/zatsudan/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruboty-zatsudan"
|
8
|
+
spec.version = Ruboty::Zatsudan::VERSION
|
9
|
+
spec.authors = ["block_given?"]
|
10
|
+
spec.email = ["block_given@outlook.com"]
|
11
|
+
spec.summary = %q{ruboty plugin for 雑談.}
|
12
|
+
spec.homepage = "https://github.com/blockgiven/ruboty-zatsudan"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_runtime_dependency "faraday"
|
21
|
+
spec.add_runtime_dependency "ruboty"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
end
|
data/screenshot.png
ADDED
Binary file
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-zatsudan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- block_given?
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ruboty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
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.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- block_given@outlook.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/ruboty/handlers/zatsudan.rb
|
82
|
+
- lib/ruboty/zatsudan.rb
|
83
|
+
- lib/ruboty/zatsudan/actions/zatsudan.rb
|
84
|
+
- lib/ruboty/zatsudan/version.rb
|
85
|
+
- ruboty-zatsudan.gemspec
|
86
|
+
- screenshot.png
|
87
|
+
homepage: https://github.com/blockgiven/ruboty-zatsudan
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.2.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: ruboty plugin for 雑談.
|
111
|
+
test_files: []
|
112
|
+
has_rdoc:
|