ruboty-haiku_wo_yome 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 598742607727cce56673f535ef56da08dc372e8c
4
- data.tar.gz: e4c17a6a028cd7c1e2c2504fcf57b692b722654c
3
+ metadata.gz: bfd5cdc5131804509972eeca5985b87d139c2a16
4
+ data.tar.gz: c121133f8f556e5e1ec55f7127f079f1fbc7a786
5
5
  SHA512:
6
- metadata.gz: 1a70fe864ad89dbfbac1a0b40db4feb2cc66170dea0124ebb407ef9712200a728c34e926976925fdbd7c98b7d198912bd9e1d77d8d952800c6b4705a7c59c7ce
7
- data.tar.gz: f04240359d3da7f1cc63a5ff7af9023f9568bec19168c67bc46e4efc5bf83ca29eedfc9610f191beadface79018fe86471b59ca4fee37648bf07c6130af8b878
6
+ metadata.gz: 5f57c3c69ed8c3a27d89fb6927b0b96acb65e1ed7a48ff204123b5f6a370e9be42e91c461a9a578a2c004a6a9c7bdd8ac7125de7d068e8f117e653fbe942624a
7
+ data.tar.gz: 258af8ee6e11d39a75105be8d3e0b792f8838d919835cfe62ea3977706dca31f9e0e130d95f70422a6aace8a697d02a99017c38282199c240bb63de84c0f9b0e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.3.0
2
+
3
+ Implements Tanka
4
+
1
5
  # 0.2.0
2
6
 
3
7
  Change required environment variable name
@@ -2,8 +2,14 @@ module Ruboty
2
2
  module HaikuWoYome
3
3
  module Actions
4
4
  class Haiku < Ruboty::Actions::Base
5
- def call
6
- haiku = haiku_list.sample || '「アイエエエエ!?」'
5
+ def call(options = {type: :haiku})
6
+ list = case options[:type]
7
+ when :tanka
8
+ tanka_list
9
+ else
10
+ haiku_list
11
+ end
12
+ haiku = list.sample || '「アイエエエエ!?」'
7
13
  message.reply(haiku)
8
14
  end
9
15
 
@@ -14,13 +20,34 @@ module Ruboty
14
20
  end
15
21
 
16
22
  def haiku_list
17
- haiku_nodes = user_public_messages_text.inject([]) do |acc, message|
18
- haiku = haiku_reviewer.search(message)
19
- acc + haiku
23
+ user_public_messages_text.inject([]) do |acc, message|
24
+ haiku_reviewer.search(message).each do |node|
25
+ acc << node.phrases.join
26
+ end
27
+ acc
20
28
  end
29
+ end
30
+
31
+ def tanka_list
32
+ kaminoku_nodes = user_public_messages_text.inject([]) do |acc, message|
33
+ haiku_reviewer.search(message).each do |node|
34
+ acc << node.phrases.join
35
+ end
36
+ acc
37
+ end
38
+
39
+ reset!
40
+ shimonoku_nodes = user_public_messages_text.inject([]) do |acc, message|
41
+ haiku_reviewer(rule: [7, 7]).search(message).each do |node|
42
+ acc << node.phrases.join
43
+ end
44
+ acc
45
+ end
46
+
47
+ return [] if shimonoku_nodes.empty?
21
48
 
22
- haiku_nodes.map do |haiku_node|
23
- haiku_node.phrases.join
49
+ kaminoku_nodes.map do |kaminoku|
50
+ "#{kaminoku} #{shimonoku_nodes.sample}"
24
51
  end
25
52
  end
26
53
 
@@ -41,8 +68,13 @@ module Ruboty
41
68
  name.start_with?('@') ? name : "@#{name}"
42
69
  end
43
70
 
44
- def haiku_reviewer
45
- @reviewer ||= Ikku::Reviewer.new
71
+ def haiku_reviewer(options = {})
72
+ rule = options[:rule] || [5, 7, 5]
73
+ @reviewer ||= Ikku::Reviewer.new(rule: rule)
74
+ end
75
+
76
+ def reset!
77
+ @reviewer = nil
46
78
  end
47
79
  end
48
80
  end
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module HaikuWoYome
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -6,10 +6,15 @@ module Ruboty
6
6
  env 'SLACK_TOKEN_FOR_SEARCH', "Slack token for search api (important: bot user can't call search api! require human api key"
7
7
 
8
8
  on('(?<user_name>.+) ハイクを詠め', name: :haiku_wo_yome, description: 'カイシャクしてやる', all: true)
9
+ on('(?<user_name>.+) タンカを詠め', name: :tanka_wo_yome, description: 'カイシャクしてやる', all: true)
9
10
 
10
11
  def haiku_wo_yome(message)
11
12
  Ruboty::HaikuWoYome::Actions::Haiku.new(message).call
12
13
  end
14
+
15
+ def tanka_wo_yome(message)
16
+ Ruboty::HaikuWoYome::Actions::Haiku.new(message).call(type: :tanka)
17
+ end
13
18
  end
14
19
  end
15
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-haiku_wo_yome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kinoshita.Yasuhiro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-19 00:00:00.000000000 Z
11
+ date: 2015-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty