ruboty-rhymer 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fad7801e8c92841b63a334837f551765ecac7a85
4
+ data.tar.gz: 2b29e5f4b9d30ef79480c7c36a2db96a20dca419
5
+ SHA512:
6
+ metadata.gz: e5a0c03338b9f78bf04f4f89a6f7770ad890fcef4b4bee46f878a298e5bf1913894547062d237bc802f61c8f7c14427a83ebab9179fe4fed54619933b7b9d6b6
7
+ data.tar.gz: 90da7016e290c5f9d2d3a2489ae10628de269beca82d46023bf280f82bac28ef2f9f34052e21f58d89962931e82c12133d8c03b19cbf99ce37af04023f936fa1
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ AllCops:
2
+ Exclude:
3
+ - tmp/**/*
4
+ - vendor/**/*
5
+
6
+ SpecialGlobalVars:
7
+ Enabled: false
8
+
9
+ AsciiComments:
10
+ Enabled: false
11
+
12
+ ClassLength:
13
+ Max: 200
14
+
15
+ Documentation:
16
+ Enabled: false
17
+
18
+ LineLength:
19
+ Max: 120
20
+
21
+ MethodLength:
22
+ Max: 30
23
+
24
+ TrailingCommaInLiteral:
25
+ EnforcedStyleForMultiline: comma
26
+
data/.travis.yml ADDED
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ cache: bundler
3
+ rvm:
4
+ - 2.3.0
5
+ before_install:
6
+ - gem install bundler
7
+ script:
8
+ - bundle exec rubocop
9
+
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-rhymer.gemspec
4
+ gemspec
5
+
6
+ gem 'rhymer', github: 'suzuki86/rhymer'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 ru_shalm
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,31 @@
1
+ # Ruboty::Rhymer
2
+
3
+ [![Build Status](https://travis-ci.org/rutan/ruboty-rhymer.svg?branch=master)](https://travis-ci.org/rutan/ruboty-rhymer)
4
+
5
+ [rhymer](https://github.com/suzuki86/rhymer) handler for [Ruboty](https://github.com/r7kamura/ruboty).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'rhymer', github: 'suzuki86/rhymer'
13
+ gem 'ruboty-rhymer'
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```
19
+ $ bundle exec ruboty
20
+ Type `exit` or `quit` to end the session.
21
+
22
+ > 今日はとても良い天気ですね。
23
+ > いや、そうでもないか?
24
+ > でも、こんな日は自然に元気になります。
25
+ 今日は良い天気 こんな日は自然に元気
26
+ ```
27
+
28
+ ## License
29
+
30
+ MIT
31
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'ruboty/rhymer'
5
+
6
+ require 'pry'
7
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,47 @@
1
+ require 'rhymer'
2
+
3
+ module Ruboty
4
+ module Actions
5
+ module Rhymer
6
+ class Hearing < ::Ruboty::Actions::Base
7
+ def call(store)
8
+ store.concat split_message(message.original[:body])
9
+ rhyme = try_rhymer(store)
10
+ return unless rhyme
11
+ store.clear
12
+ options = {}
13
+ unless ENV['RHYMER_OVERRIDE_TO'].to_s.empty?
14
+ options[:to] = ENV['RHYMER_OVERRIDE_TO']
15
+ end
16
+ message.reply(generate_reply(rhyme), options)
17
+ end
18
+
19
+ private
20
+
21
+ def split_message(str)
22
+ str
23
+ .split(/[[:space:]。!?\.]+/)
24
+ .select { |n| n.size >= 4 }
25
+ end
26
+
27
+ def generate_reply(rhyme)
28
+ buf = []
29
+ buf.push 'Yo!'
30
+ buf.push rhyme[0]
31
+ buf.push rhyme[1]
32
+ buf.join(' ')
33
+ end
34
+
35
+ def try_rhymer(messages)
36
+ ::Rhymer::Parser.new(messages.join("。\n")).rhymes.select do |rhyme|
37
+ rhyme.last >= score_border
38
+ end.sample
39
+ end
40
+
41
+ def score_border
42
+ (ENV['RHYMER_SCORE'] || 10).to_i
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,23 @@
1
+ module Ruboty
2
+ module Handlers
3
+ class Rhymer < Base
4
+ env :RHYMER_SCORE, 'Rhymer score border', optional: true
5
+ env :RHYMER_OVERRIDE_TO, 'override `to` parameter', optional: true
6
+
7
+ on(/(?:.+)/,
8
+ name: 'hearing',
9
+ all: true,
10
+ hidden: true)
11
+
12
+ def hearing(message)
13
+ ::Ruboty::Actions::Rhymer::Hearing.new(message).call(store)
14
+ end
15
+
16
+ private
17
+
18
+ def store
19
+ @store ||= []
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Rhymer
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require 'ruboty'
2
+ require 'ruboty/rhymer/version'
3
+ require 'ruboty/actions/rhymer/hearing'
4
+ require 'ruboty/handlers/rhymer'
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/rhymer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ruboty-rhymer'
8
+ spec.version = Ruboty::Rhymer::VERSION
9
+ spec.authors = ['ru_shalm']
10
+ spec.email = ['ru_shalm@hazimu.com']
11
+ spec.summary = 'rhymer handler for Ruboty'
12
+ spec.homepage = 'https://github.com/rutan/ruboty-rhymer'
13
+ spec.licenses = ['MIT']
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = 'exe'
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'ruboty'
21
+ spec.add_dependency 'rhymer'
22
+ spec.add_development_dependency 'bundler', '~> 1.12'
23
+ spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rubocop', '0.40.0'
25
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-rhymer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ru_shalm
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
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: rhymer
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.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
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
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.40.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.40.0
83
+ description:
84
+ email:
85
+ - ru_shalm@hazimu.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rubocop.yml"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/ruboty/actions/rhymer/hearing.rb
100
+ - lib/ruboty/handlers/rhymer.rb
101
+ - lib/ruboty/rhymer.rb
102
+ - lib/ruboty/rhymer/version.rb
103
+ - ruboty-rhymer.gemspec
104
+ homepage: https://github.com/rutan/ruboty-rhymer
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.5.1
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: rhymer handler for Ruboty
128
+ test_files: []