ruboty-magi 0.4.0 → 0.5.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 +4 -4
- data/README.md +40 -0
- data/lib/ruboty/handlers/magi.rb +29 -5
- data/lib/ruboty/magi/version.rb +1 -1
- 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: 50832c0851d2165a8e009e01bfaec2e01bfcd794
|
4
|
+
data.tar.gz: 5a38a96c1363580586981e45f3f4901e6b3c0d81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4cf70dbbb84e902ee36fbe4b31413bf7c92b7b5d2bb6b851f05c90381406d5c5b82250d5ad89e1ab9f75dea78c68a871965b4d32c19ac6056f893b1a9482316
|
7
|
+
data.tar.gz: 79504dce353bc7959260fe7672656a5b939c1e0f0dee23486865b26e7cd42178434f4827bf5da5fe6234c802e22bbaef58d772e2f3ecf69a17d6ae9c32437d95
|
data/README.md
CHANGED
@@ -14,13 +14,53 @@ gem 'ruboty-magi'
|
|
14
14
|
```
|
15
15
|
|
16
16
|
## Usage
|
17
|
+
```
|
18
|
+
> ruboty magi <option> <message>
|
19
|
+
```
|
17
20
|
|
21
|
+
### Examples
|
18
22
|
```
|
19
23
|
> ruboty magi
|
20
24
|
MELCHIOR-1:[承認] BALTHASAR-2:[承認] CASPER-3:[否定]
|
21
25
|
|
22
26
|
> ruboty magi 今日休んでもいいですか?
|
23
27
|
MELCHIOR-1:[否定] BALTHASAR-2:[否定] CASPER-3:[否定]
|
28
|
+
|
29
|
+
> ruboty magi -c
|
30
|
+
MELCHIOR-1:[可決] BALTHASAR-2:[保留] CASPER-3:[否決]
|
31
|
+
|
32
|
+
> ruboty magi -p
|
33
|
+
MELCHIOR-1:[はい] BALTHASAR-2:[いいえ] CASPER-3:[いいえ]
|
34
|
+
|
35
|
+
> ruboty magi -s
|
36
|
+
[承認][否定][否定]
|
37
|
+
|
38
|
+
> ruboty magi -sp
|
39
|
+
[はい][いいえ][はい]
|
40
|
+
|
41
|
+
> ruboty magi -sc
|
42
|
+
[可決][保留][否決]
|
43
|
+
```
|
44
|
+
|
45
|
+
### Modes
|
46
|
+
#### default
|
47
|
+
Answer Pattern: ```[承認] | [否定]```
|
48
|
+
|
49
|
+
#### complex
|
50
|
+
Answer Pattern: ```[可決] | [否決] | [保留]```
|
51
|
+
|
52
|
+
#### plain
|
53
|
+
Answer Pattern: ```[はい] | [いいえ]```
|
54
|
+
|
55
|
+
### Formats
|
56
|
+
#### default
|
57
|
+
```
|
58
|
+
MELCHIOR-1:[] BALTHASAR-2:[] CASPER-3:[]
|
59
|
+
```
|
60
|
+
|
61
|
+
#### simple
|
62
|
+
```
|
63
|
+
[][][]
|
24
64
|
```
|
25
65
|
|
26
66
|
## Contributing
|
data/lib/ruboty/handlers/magi.rb
CHANGED
@@ -2,18 +2,42 @@ module Ruboty
|
|
2
2
|
module Handlers
|
3
3
|
class Magi < Base
|
4
4
|
on(
|
5
|
-
/magi
|
5
|
+
/magi\s*(-(?<option>[a-zA-Z0-9]+)+)*.*/i,
|
6
6
|
name: 'answer',
|
7
|
-
description: '
|
7
|
+
description: 'Magi System answers a question after deep deliberation.'
|
8
8
|
)
|
9
9
|
|
10
10
|
def answer(message)
|
11
|
-
|
11
|
+
option = parse_option(message)
|
12
|
+
simple_mode = option.include?(:s)
|
13
|
+
reply_message = judge(answer_pattern(option), simple_mode)
|
14
|
+
message.reply(reply_message)
|
12
15
|
end
|
13
16
|
|
14
17
|
private
|
15
|
-
def
|
16
|
-
|
18
|
+
def parse_option(message)
|
19
|
+
message[:option] ? message[:option].strip.chars.map(&:to_sym) : []
|
20
|
+
rescue
|
21
|
+
[]
|
22
|
+
end
|
23
|
+
|
24
|
+
def answer_pattern(option)
|
25
|
+
default = %w(承認 否定)
|
26
|
+
return default unless option
|
27
|
+
|
28
|
+
case
|
29
|
+
when option.include?(:c) then %w(可決 否決 保留) # complex mode
|
30
|
+
when option.include?(:p) then %w(はい いいえ) # plain mode
|
31
|
+
else default
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def judge(pattern = [], simple_mode = false)
|
36
|
+
if simple_mode
|
37
|
+
"[#{pattern.sample}][#{pattern.sample}][#{pattern.sample}]"
|
38
|
+
else
|
39
|
+
"MELCHIOR-1:[#{pattern.sample}] BALTHASAR-2:[#{pattern.sample}] CASPER-3:[#{pattern.sample}]"
|
40
|
+
end
|
17
41
|
end
|
18
42
|
end
|
19
43
|
end
|
data/lib/ruboty/magi/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-magi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shulla Cignoir
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruboty
|