lita-random 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -3
- data/.travis.yml +8 -1
- data/CHANGELOG.md +10 -28
- data/Gemfile +1 -1
- data/README.md +40 -22
- data/Rakefile +0 -3
- data/lib/lita/handlers/random.rb +109 -79
- data/lita-random.gemspec +2 -1
- metadata +37 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6a25f9cefa5cb1ce12f145126748c76bfed3c13
|
4
|
+
data.tar.gz: 147c9a8eaac238fa7caad05c147c27fccefcb434
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3794f616b4fc18a76576f1bcafdad6e931a0333de9d9cf24ee759ed500db7a1ab6f5da9ef146c6641bfeb28197937f3f0b8d3b33f6e0cd317cdbf6a0f2e77bcd
|
7
|
+
data.tar.gz: a0042ac3fdb4548a70e408d84c304c41fe5b9f0789b78844db1693be6c13ffb2d900aae7af7b3b5eb52abce4e5c0c35f4e40079f3e8398e5c76d6cda1197826b
|
data/.rubocop.yml
CHANGED
@@ -2,11 +2,14 @@ AllCops:
|
|
2
2
|
Exclude:
|
3
3
|
- vendor/**/*
|
4
4
|
|
5
|
-
Style/AccessModifierIndentation:
|
6
|
-
EnforcedStyle: outdent
|
7
|
-
|
8
5
|
Style/AndOr:
|
9
6
|
Enabled: false
|
10
7
|
|
8
|
+
Style/LambdaCall:
|
9
|
+
Enabled: false
|
10
|
+
|
11
11
|
Style/TrailingComma:
|
12
12
|
Enabled: false
|
13
|
+
|
14
|
+
Style/AccessModifierIndentation:
|
15
|
+
EnforcedStyle: outdent
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,93 +1,75 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [v0.
|
3
|
+
## [v0.6.0](https://github.com/braiden-vasco/lita-random/tree/v0.6.0) (2015-10-24)
|
4
|
+
[Full Changelog](https://github.com/braiden-vasco/lita-random/compare/v0.5.1...v0.6.0)
|
5
|
+
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- Support keyword arguments partially [\#46](https://github.com/braiden-vasco/lita-random/pull/46) ([braiden-vasco](https://github.com/braiden-vasco))
|
9
|
+
- Test like Lita [\#45](https://github.com/braiden-vasco/lita-random/pull/45) ([braiden-vasco](https://github.com/braiden-vasco))
|
10
|
+
- Test with Rubinius [\#44](https://github.com/braiden-vasco/lita-random/pull/44) ([braiden-vasco](https://github.com/braiden-vasco))
|
11
|
+
- Don't use version label and version PRs [\#43](https://github.com/braiden-vasco/lita-random/pull/43) ([braiden-vasco](https://github.com/braiden-vasco))
|
4
12
|
|
13
|
+
## [v0.5.1](https://github.com/braiden-vasco/lita-random/tree/v0.5.1) (2015-06-25)
|
5
14
|
[Full Changelog](https://github.com/braiden-vasco/lita-random/compare/v0.5.0...v0.5.1)
|
6
15
|
|
7
16
|
**Merged pull requests:**
|
8
17
|
|
9
18
|
- Test with multiple versions of Ruby [\#39](https://github.com/braiden-vasco/lita-random/pull/39) ([braiden-vasco](https://github.com/braiden-vasco))
|
10
|
-
|
11
19
|
- Remove open-ended dependencies [\#38](https://github.com/braiden-vasco/lita-random/pull/38) ([braiden-vasco](https://github.com/braiden-vasco))
|
12
|
-
|
13
20
|
- Remove unnecessary dependencies [\#37](https://github.com/braiden-vasco/lita-random/pull/37) ([braiden-vasco](https://github.com/braiden-vasco))
|
14
21
|
|
15
22
|
## [v0.5.0](https://github.com/braiden-vasco/lita-random/tree/v0.5.0) (2015-06-24)
|
16
|
-
|
17
23
|
[Full Changelog](https://github.com/braiden-vasco/lita-random/compare/v0.4.0...v0.5.0)
|
18
24
|
|
19
25
|
**Merged pull requests:**
|
20
26
|
|
21
27
|
- Add command "random case" [\#34](https://github.com/braiden-vasco/lita-random/pull/34) ([braiden-vasco](https://github.com/braiden-vasco))
|
22
|
-
|
23
28
|
- Add command "sample" [\#33](https://github.com/braiden-vasco/lita-random/pull/33) ([braiden-vasco](https://github.com/braiden-vasco))
|
24
|
-
|
25
29
|
- Add command "shuffle" [\#31](https://github.com/braiden-vasco/lita-random/pull/31) ([braiden-vasco](https://github.com/braiden-vasco))
|
26
|
-
|
27
30
|
- Move development dependencies to gemspec [\#30](https://github.com/braiden-vasco/lita-random/pull/30) ([braiden-vasco](https://github.com/braiden-vasco))
|
28
31
|
|
29
32
|
## [v0.4.0](https://github.com/braiden-vasco/lita-random/tree/v0.4.0) (2015-06-23)
|
30
|
-
|
31
33
|
[Full Changelog](https://github.com/braiden-vasco/lita-random/compare/v0.3.0...v0.4.0)
|
32
34
|
|
33
35
|
**Merged pull requests:**
|
34
36
|
|
35
37
|
- Add password generator [\#28](https://github.com/braiden-vasco/lita-random/pull/28) ([braiden-vasco](https://github.com/braiden-vasco))
|
36
|
-
|
37
38
|
- Add smart password generator [\#27](https://github.com/braiden-vasco/lita-random/pull/27) ([braiden-vasco](https://github.com/braiden-vasco))
|
38
|
-
|
39
39
|
- Add help for commands [\#26](https://github.com/braiden-vasco/lita-random/pull/26) ([braiden-vasco](https://github.com/braiden-vasco))
|
40
40
|
|
41
41
|
## [v0.3.0](https://github.com/braiden-vasco/lita-random/tree/v0.3.0) (2015-06-21)
|
42
|
-
|
43
42
|
[Full Changelog](https://github.com/braiden-vasco/lita-random/compare/v0.2.0...v0.3.0)
|
44
43
|
|
45
44
|
**Merged pull requests:**
|
46
45
|
|
47
46
|
- Add UUID generator [\#23](https://github.com/braiden-vasco/lita-random/pull/23) ([braiden-vasco](https://github.com/braiden-vasco))
|
48
|
-
|
49
47
|
- Optional spaces between commands, add more aliases [\#22](https://github.com/braiden-vasco/lita-random/pull/22) ([braiden-vasco](https://github.com/braiden-vasco))
|
50
|
-
|
51
48
|
- Add hexadecimal string generator [\#21](https://github.com/braiden-vasco/lita-random/pull/21) ([braiden-vasco](https://github.com/braiden-vasco))
|
52
|
-
|
53
49
|
- Add base64 generator [\#20](https://github.com/braiden-vasco/lita-random/pull/20) ([braiden-vasco](https://github.com/braiden-vasco))
|
54
|
-
|
55
50
|
- Refactor regular expressions [\#19](https://github.com/braiden-vasco/lita-random/pull/19) ([braiden-vasco](https://github.com/braiden-vasco))
|
56
51
|
|
57
52
|
## [v0.2.0](https://github.com/braiden-vasco/lita-random/tree/v0.2.0) (2015-06-21)
|
58
|
-
|
59
53
|
[Full Changelog](https://github.com/braiden-vasco/lita-random/compare/v0.1.0...v0.2.0)
|
60
54
|
|
61
55
|
**Merged pull requests:**
|
62
56
|
|
63
57
|
- Allow float ranges [\#17](https://github.com/braiden-vasco/lita-random/pull/17) ([braiden-vasco](https://github.com/braiden-vasco))
|
64
|
-
|
65
58
|
- Basic testing [\#15](https://github.com/braiden-vasco/lita-random/pull/15) ([braiden-vasco](https://github.com/braiden-vasco))
|
66
59
|
|
67
60
|
## [v0.1.0](https://github.com/braiden-vasco/lita-random/tree/v0.1.0) (2015-06-20)
|
68
|
-
|
69
61
|
**Merged pull requests:**
|
70
62
|
|
71
63
|
- Add instructions [\#11](https://github.com/braiden-vasco/lita-random/pull/11) ([braiden-vasco](https://github.com/braiden-vasco))
|
72
|
-
|
73
64
|
- Basic implementation [\#10](https://github.com/braiden-vasco/lita-random/pull/10) ([braiden-vasco](https://github.com/braiden-vasco))
|
74
|
-
|
75
65
|
- Initialize Lita handler [\#9](https://github.com/braiden-vasco/lita-random/pull/9) ([braiden-vasco](https://github.com/braiden-vasco))
|
76
|
-
|
77
66
|
- Add changelog generator [\#8](https://github.com/braiden-vasco/lita-random/pull/8) ([braiden-vasco](https://github.com/braiden-vasco))
|
78
|
-
|
79
67
|
- Use YARD [\#7](https://github.com/braiden-vasco/lita-random/pull/7) ([braiden-vasco](https://github.com/braiden-vasco))
|
80
|
-
|
81
68
|
- Configure Coveralls [\#6](https://github.com/braiden-vasco/lita-random/pull/6) ([braiden-vasco](https://github.com/braiden-vasco))
|
82
|
-
|
83
69
|
- Configure Travis CI [\#5](https://github.com/braiden-vasco/lita-random/pull/5) ([braiden-vasco](https://github.com/braiden-vasco))
|
84
|
-
|
85
70
|
- Add README [\#4](https://github.com/braiden-vasco/lita-random/pull/4) ([braiden-vasco](https://github.com/braiden-vasco))
|
86
|
-
|
87
71
|
- Configure testing [\#3](https://github.com/braiden-vasco/lita-random/pull/3) ([braiden-vasco](https://github.com/braiden-vasco))
|
88
|
-
|
89
72
|
- Configure linting [\#2](https://github.com/braiden-vasco/lita-random/pull/2) ([braiden-vasco](https://github.com/braiden-vasco))
|
90
|
-
|
91
73
|
- Initialize gem [\#1](https://github.com/braiden-vasco/lita-random/pull/1) ([braiden-vasco](https://github.com/braiden-vasco))
|
92
74
|
|
93
75
|
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -5,26 +5,44 @@ Lita::Handlers::Random
|
|
5
5
|
[![Build Status](https://travis-ci.org/braiden-vasco/lita-random.svg)](https://travis-ci.org/braiden-vasco/lita-random)
|
6
6
|
[![Coverage Status](https://coveralls.io/repos/braiden-vasco/lita-random/badge.svg)](https://coveralls.io/r/braiden-vasco/lita-random)
|
7
7
|
|
8
|
-
Generator of random numbers and strings for the Lita chat bot.
|
8
|
+
Generator of random numbers and strings for the [Lita](http://lita.io) chat bot.
|
9
9
|
|
10
10
|
Usage
|
11
11
|
-----
|
12
12
|
|
13
|
-
At first, see the documentation for Lita:
|
13
|
+
At first, see the documentation for Lita: http://docs.lita.io/
|
14
14
|
|
15
15
|
### Installation
|
16
16
|
|
17
17
|
Add **lita-random** to your Lita instance's Gemfile:
|
18
18
|
|
19
19
|
```ruby
|
20
|
-
gem 'lita-random', '~> 0.
|
20
|
+
gem 'lita-random', '~> 0.6.0'
|
21
21
|
```
|
22
22
|
|
23
23
|
### Commands
|
24
24
|
|
25
|
-
The space between instructions can be
|
25
|
+
The space between instructions can be skipped, so you can write
|
26
26
|
`random hex` as `randomhex`, `rand b64` as `randb64`
|
27
27
|
|
28
|
+
Arguments for all commands (excluding `random case`, `shuffle` and `sample`)
|
29
|
+
can be passed as keyword arguments too. Put them after
|
30
|
+
positional arguments with two dashes before, or the first letter
|
31
|
+
of argument name with one dash. Examples:
|
32
|
+
|
33
|
+
```
|
34
|
+
You: lita random 5 10
|
35
|
+
Lita: 7
|
36
|
+
You: lita random 5 --to 5
|
37
|
+
Lita: 9
|
38
|
+
You: lita random 5 -t 10
|
39
|
+
Lita: 5
|
40
|
+
You: lita random --to 10 --from 5
|
41
|
+
Lita: 6
|
42
|
+
You: lita random -f 5 -t 10
|
43
|
+
Lita: 9
|
44
|
+
```
|
45
|
+
|
28
46
|
Command `random` has alias `rand`
|
29
47
|
|
30
48
|
* `random` -
|
@@ -36,19 +54,19 @@ Command `random` has alias `rand`
|
|
36
54
|
* `random <from> <to>` -
|
37
55
|
random integer or float number, greater or equal to `from` and lesser than `to`
|
38
56
|
|
39
|
-
* `random case <
|
40
|
-
randomize case of each character of string `
|
57
|
+
* `random case <string>` -
|
58
|
+
randomize case of each character of string `string`
|
41
59
|
|
42
60
|
Command `base64` has alias `b64`
|
43
61
|
|
44
|
-
* `random base64 <
|
45
|
-
random base64 string, length of source string is `
|
46
|
-
length of result is about `
|
62
|
+
* `random base64 <size=16>` -
|
63
|
+
random base64 string, length of source string is `size`,
|
64
|
+
length of result is about `size * 4 / 3` (24 with default value of `size`)
|
47
65
|
|
48
66
|
Command `hex` has aliases `hx` and `x`
|
49
67
|
|
50
|
-
* `random hex <
|
51
|
-
random hexadecimal string with length `
|
68
|
+
* `random hex <size=16>` -
|
69
|
+
random hexadecimal string with length `size * 2`
|
52
70
|
|
53
71
|
Command `uuid` has alias `uid`
|
54
72
|
|
@@ -59,18 +77,18 @@ Command `uuid` has alias `uid`
|
|
59
77
|
|
60
78
|
Command `password` has alias `pass`
|
61
79
|
|
62
|
-
* `random password <
|
63
|
-
random password with length `
|
80
|
+
* `random password <length=16>` -
|
81
|
+
random password with length `length` containing characters
|
64
82
|
in upper and lower case, and digits
|
65
83
|
|
66
|
-
* `random smart password <
|
67
|
-
random pronounceable password with a minimum length of `
|
84
|
+
* `random smart password <length=8>` -
|
85
|
+
random pronounceable password with a minimum length of `length`
|
68
86
|
|
69
87
|
* `shuffle <array, ...>` -
|
70
88
|
new array with elements of `array` shuffled
|
71
89
|
|
72
|
-
* `sample <
|
73
|
-
choose `
|
90
|
+
* `sample <count=1> <array, ...>` -
|
91
|
+
choose `count` random elements from `array`
|
74
92
|
|
75
93
|
### Examples
|
76
94
|
|
@@ -82,12 +100,12 @@ Lita: 0.8332672468501509
|
|
82
100
|
|
83
101
|
You: lita random 5
|
84
102
|
Lita: 2
|
85
|
-
You: lita rand 100
|
103
|
+
You: lita rand --to 100
|
86
104
|
Lita: 24
|
87
105
|
|
88
|
-
You: lita random 1.5
|
106
|
+
You: lita random -f 1.5
|
89
107
|
Lita: 1.1828046952104034
|
90
|
-
You: lita random 5
|
108
|
+
You: lita random 10 --from 5
|
91
109
|
Lita: 8
|
92
110
|
You: lita rand 1000 2000
|
93
111
|
Lita: 1240
|
@@ -104,7 +122,7 @@ Lita: NMkIhB+iG2VNpg==
|
|
104
122
|
|
105
123
|
You: lita random hex
|
106
124
|
Lita: 7d6f39cf53303db862bac5e1b36eb0fa
|
107
|
-
You: lita randx 10
|
125
|
+
You: lita randx -s 10
|
108
126
|
Lita: 0d8297837d6e63b8c25b
|
109
127
|
|
110
128
|
You: lita random uuid
|
@@ -112,7 +130,7 @@ Lita: f1281565-3c8a-475d-a1aa-565ff840a42c
|
|
112
130
|
|
113
131
|
You: lita random password
|
114
132
|
Lita: TXXBu7XEBdwFF7fP
|
115
|
-
You: lita randpass 8
|
133
|
+
You: lita randpass --length 8
|
116
134
|
Lita: 7lFateFs
|
117
135
|
|
118
136
|
You: lita random smart password
|
data/Rakefile
CHANGED
@@ -5,8 +5,6 @@ gemspec = Gem::Specification.load('lita-random.gemspec')
|
|
5
5
|
github_user, github_project =
|
6
6
|
gemspec.homepage.scan(%r{^https://github\.com/([^/]+)/([^/]+)/?$})[0]
|
7
7
|
|
8
|
-
DEFAULT_EXCLUDE_LABELS = 'duplicate,question,invalid,wontfix'
|
9
|
-
|
10
8
|
require 'bundler/gem_tasks'
|
11
9
|
|
12
10
|
task default: [:spec, :lint]
|
@@ -25,7 +23,6 @@ task :changelog, [:token] do |_t, args|
|
|
25
23
|
cmd << " -u #{github_user}"
|
26
24
|
cmd << " -p #{github_project}"
|
27
25
|
cmd << " -t #{args[:token]}" if args[:token]
|
28
|
-
cmd << " --exclude-labels version,#{DEFAULT_EXCLUDE_LABELS}"
|
29
26
|
|
30
27
|
sh cmd
|
31
28
|
end
|
data/lib/lita/handlers/random.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'lita-keyword-arguments'
|
2
|
+
|
1
3
|
##
|
2
4
|
# Lita module.
|
3
5
|
#
|
@@ -22,16 +24,16 @@ module Lita
|
|
22
24
|
'random integer or float number, ' \
|
23
25
|
'greater or equal to `from` and lesser than `to`',
|
24
26
|
|
25
|
-
'random case <
|
26
|
-
'randomize case of each character of string `
|
27
|
+
'random case <string>' =>
|
28
|
+
'randomize case of each character of string `string`',
|
27
29
|
|
28
|
-
'random base64 <
|
29
|
-
'random base64 string, length of source string is
|
30
|
-
'length of result is about `
|
31
|
-
'(24 with default value of `
|
30
|
+
'random base64 <size=16>' =>
|
31
|
+
'random base64 string, length of source string is `size`, ' \
|
32
|
+
'length of result is about `size * 4 / 3` ' \
|
33
|
+
'(24 with default value of `size`)',
|
32
34
|
|
33
|
-
'random hex <
|
34
|
-
'random hexadecimal string with length `
|
35
|
+
'random hex <size=16>' =>
|
36
|
+
'random hexadecimal string with length `size * 2`',
|
35
37
|
|
36
38
|
'random uuid' =>
|
37
39
|
'v4 random UUID (Universally Unique IDentifier). ' \
|
@@ -39,54 +41,45 @@ module Lita
|
|
39
41
|
'It doesn’t contain meaningful information ' \
|
40
42
|
'such as MAC address, time, etc.',
|
41
43
|
|
42
|
-
'random password <
|
43
|
-
'random password with length `
|
44
|
+
'random password <length=16>' =>
|
45
|
+
'random password with length `length` containing characters ' \
|
44
46
|
'in upper and lower case, and digits',
|
45
47
|
|
46
|
-
'random smart password <
|
47
|
-
'random pronounceable password with a minimum length of `
|
48
|
+
'random smart password <length=8>' =>
|
49
|
+
'random pronounceable password with a minimum length of `length`',
|
48
50
|
|
49
51
|
'shuffle <array, ...>' =>
|
50
52
|
'new array with elements of `array` shuffled',
|
51
53
|
|
52
|
-
'sample <
|
53
|
-
'choose `
|
54
|
+
'sample <count=1> <array, ...>' =>
|
55
|
+
'choose `count` random elements from `array`',
|
54
56
|
}
|
55
57
|
|
56
|
-
route(
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
route(
|
59
|
+
/^rand(om)?((\s+(?<from>\d+(\.\d+)?))?\s+(?<to>\d+(\.\d+)?))?($|\s*-)/i,
|
60
|
+
:route_random,
|
61
|
+
command: true, help: HELP,
|
62
|
+
kwargs: {
|
63
|
+
from: { short: 'f' },
|
64
|
+
to: { short: 't' },
|
65
|
+
}
|
66
|
+
)
|
60
67
|
|
61
|
-
|
62
|
-
|
63
|
-
to = response.
|
64
|
-
response.reply(::Random.rand(to).to_s)
|
65
|
-
end
|
68
|
+
def route_random(response)
|
69
|
+
from = extract_argument(response, 0, :from, &method(:str_to_num)) || 0
|
70
|
+
to = extract_argument(response, 1, :to, &method(:str_to_num)) || 1.0
|
66
71
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
+
rescue RuntimeError # rubocop:disable Lint/HandleExceptions
|
73
|
+
else
|
74
|
+
result = if from.is_a?(Float) || to.is_a?(Float)
|
75
|
+
# In Rubinius,
|
76
|
+
# ::Random.rand can not exclude non Integer end value
|
77
|
+
::Random.rand(from..(to - Float::EPSILON))
|
78
|
+
else
|
79
|
+
::Random.rand(from...to)
|
80
|
+
end
|
72
81
|
|
73
|
-
|
74
|
-
:route_random_from_to, command: true)
|
75
|
-
def route_random_from_to(response)
|
76
|
-
from = response.matches[0][1].to_i
|
77
|
-
to = response.matches[0][2].to_i
|
78
|
-
response.reply(::Random.rand(from...to).to_s)
|
79
|
-
end
|
80
|
-
|
81
|
-
route(/^rand(om)?\s+(?<from>\d+\.\d+)\s+(?<to>\d+)?$/i,
|
82
|
-
:route_random_float_from_to, command: true)
|
83
|
-
route(/^rand(om)?\s+(?<from>\d+(\.\d+)?)\s+(?<to>\d+\.\d+)?$/i,
|
84
|
-
:route_random_float_from_to, command: true)
|
85
|
-
def route_random_float_from_to(response)
|
86
|
-
matches = response.matches[0]
|
87
|
-
from = matches[0].to_f
|
88
|
-
to = matches[1].to_f
|
89
|
-
response.reply(::Random.rand(from...to).to_s)
|
82
|
+
response.reply(result.to_s)
|
90
83
|
end
|
91
84
|
|
92
85
|
route(/^rand(om)?\s*case(\s+(?<s>.*))?$/i,
|
@@ -95,28 +88,38 @@ module Lita
|
|
95
88
|
response.reply(random_case(response.matches[0][0] || ''))
|
96
89
|
end
|
97
90
|
|
98
|
-
route(
|
91
|
+
route(
|
92
|
+
/^rand(om)?\s*b(ase)?64(\s+(?<n>\d+))?($|\s)/i,
|
93
|
+
:route_random_base64,
|
94
|
+
command: true,
|
95
|
+
kwargs: {
|
96
|
+
size: { short: 's' },
|
97
|
+
}
|
98
|
+
)
|
99
|
+
|
99
100
|
def route_random_base64(response)
|
100
|
-
response
|
101
|
-
end
|
101
|
+
size = extract_argument(response, 0, :size, &:to_i) || 16
|
102
102
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
n = response.matches[0][0].to_i
|
107
|
-
response.reply(SecureRandom.base64(n))
|
103
|
+
rescue RuntimeError # rubocop:disable Lint/HandleExceptions
|
104
|
+
else
|
105
|
+
response.reply(SecureRandom.base64(size))
|
108
106
|
end
|
109
107
|
|
110
|
-
route(
|
108
|
+
route(
|
109
|
+
/^rand(om)?\s*(he?)?x(\s+(?<n>\d+))?($|\s)/i,
|
110
|
+
:route_random_hex,
|
111
|
+
command: true,
|
112
|
+
kwargs: {
|
113
|
+
size: { short: 's' },
|
114
|
+
}
|
115
|
+
)
|
116
|
+
|
111
117
|
def route_random_hex(response)
|
112
|
-
response
|
113
|
-
end
|
118
|
+
size = extract_argument(response, 0, :size, &:to_i) || 16
|
114
119
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
n = response.matches[0][0].to_i
|
119
|
-
response.reply(SecureRandom.hex(n))
|
120
|
+
rescue RuntimeError # rubocop:disable Lint/HandleExceptions
|
121
|
+
else
|
122
|
+
response.reply(SecureRandom.hex(size))
|
120
123
|
end
|
121
124
|
|
122
125
|
route(/^rand(om)?\s*u?uid$/i, :route_random_uuid, command: true)
|
@@ -124,28 +127,37 @@ module Lita
|
|
124
127
|
response.reply(SecureRandom.uuid)
|
125
128
|
end
|
126
129
|
|
127
|
-
route(
|
128
|
-
|
130
|
+
route(
|
131
|
+
/^rand(om)?\s*smart\s*pass(word)?(\s+(?<n>\d+))?($|\s)/i,
|
132
|
+
:route_random_smart_pass,
|
133
|
+
command: true,
|
134
|
+
kwargs: {
|
135
|
+
length: { short: 'l' },
|
136
|
+
}
|
137
|
+
)
|
138
|
+
|
129
139
|
def route_random_smart_pass(response)
|
130
|
-
response
|
131
|
-
end
|
140
|
+
length = extract_argument(response, 0, :length, &:to_i) || 8
|
132
141
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
min_length = response.matches[0][0].to_i
|
137
|
-
response.reply(smart_password(min_length))
|
142
|
+
rescue RuntimeError # rubocop:disable Lint/HandleExceptions
|
143
|
+
else
|
144
|
+
response.reply(smart_password(length))
|
138
145
|
end
|
139
146
|
|
140
|
-
route(
|
147
|
+
route(
|
148
|
+
/^rand(om)?\s*pass(word)?(\s+(?<n>\d+))?($|\s)/i,
|
149
|
+
:route_random_pass,
|
150
|
+
command: true,
|
151
|
+
kwargs: {
|
152
|
+
length: { short: 'l' },
|
153
|
+
}
|
154
|
+
)
|
155
|
+
|
141
156
|
def route_random_pass(response)
|
142
|
-
response
|
143
|
-
end
|
157
|
+
length = extract_argument(response, 0, :length, &:to_i) || 16
|
144
158
|
|
145
|
-
|
146
|
-
|
147
|
-
def route_random_pass_n(response)
|
148
|
-
length = response.matches[0][0].to_i
|
159
|
+
rescue RuntimeError # rubocop:disable Lint/HandleExceptions
|
160
|
+
else
|
149
161
|
response.reply(password(length))
|
150
162
|
end
|
151
163
|
|
@@ -183,7 +195,7 @@ module Lita
|
|
183
195
|
true => %w(a e i o u y),
|
184
196
|
}
|
185
197
|
|
186
|
-
def smart_password(min_length
|
198
|
+
def smart_password(min_length)
|
187
199
|
password = ''
|
188
200
|
sequence_id = false
|
189
201
|
while password.length < min_length
|
@@ -196,9 +208,27 @@ module Lita
|
|
196
208
|
|
197
209
|
PASS_CHARS = [*'a'..'z', *'A'..'Z', *'0'..'9']
|
198
210
|
|
199
|
-
def password(length
|
211
|
+
def password(length)
|
200
212
|
(0...length).map { |_| PASS_CHARS.sample }.join
|
201
213
|
end
|
214
|
+
|
215
|
+
def extract_argument(response, index, name)
|
216
|
+
matches = response.matches[0]
|
217
|
+
kwargs = response.extensions[:kwargs]
|
218
|
+
|
219
|
+
positional = matches[index]
|
220
|
+
kw = kwargs[name]
|
221
|
+
|
222
|
+
fail if positional && kw
|
223
|
+
|
224
|
+
s = positional || kw
|
225
|
+
|
226
|
+
block_given? && s ? yield(s) : s
|
227
|
+
end
|
228
|
+
|
229
|
+
def str_to_num(s)
|
230
|
+
s =~ /\./ ? s.to_f : s.to_i
|
231
|
+
end
|
202
232
|
end
|
203
233
|
|
204
234
|
Lita.register_handler(Random)
|
data/lita-random.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
4
|
spec.name = 'lita-random'
|
5
|
-
spec.version = '0.
|
5
|
+
spec.version = '0.6.0'
|
6
6
|
spec.authors = ['Braiden Vasco']
|
7
7
|
spec.email = ['braiden-vasco@mailtor.net']
|
8
8
|
|
@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.add_development_dependency 'simplecov', '~> 0.10'
|
33
33
|
|
34
34
|
spec.add_runtime_dependency 'lita', '~> 4.4'
|
35
|
+
spec.add_runtime_dependency 'lita-keyword-arguments', '~> 1.0'
|
35
36
|
end
|
metadata
CHANGED
@@ -1,113 +1,127 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lita-random
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Braiden Vasco
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.7'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: github_changelog_generator
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '1.6'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - ~>
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '1.6'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rubocop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0.31'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.31'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - ~>
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '3.3'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - ~>
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '3.3'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - ~>
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0.10'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - ~>
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.10'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: lita
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - ~>
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '4.4'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - ~>
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '4.4'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: lita-keyword-arguments
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.0'
|
111
125
|
description: Generator of random numbers and strings for the Lita chat bot.
|
112
126
|
email:
|
113
127
|
- braiden-vasco@mailtor.net
|
@@ -115,11 +129,11 @@ executables: []
|
|
115
129
|
extensions: []
|
116
130
|
extra_rdoc_files: []
|
117
131
|
files:
|
118
|
-
- .gitignore
|
119
|
-
- .rspec
|
120
|
-
- .rubocop.yml
|
121
|
-
- .simplecov
|
122
|
-
- .travis.yml
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".rubocop.yml"
|
135
|
+
- ".simplecov"
|
136
|
+
- ".travis.yml"
|
123
137
|
- CHANGELOG.md
|
124
138
|
- Gemfile
|
125
139
|
- LICENSE
|
@@ -143,12 +157,12 @@ require_paths:
|
|
143
157
|
- lib
|
144
158
|
required_ruby_version: !ruby/object:Gem::Requirement
|
145
159
|
requirements:
|
146
|
-
- -
|
160
|
+
- - ">="
|
147
161
|
- !ruby/object:Gem::Version
|
148
162
|
version: '0'
|
149
163
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
164
|
requirements:
|
151
|
-
- -
|
165
|
+
- - ">="
|
152
166
|
- !ruby/object:Gem::Version
|
153
167
|
version: '0'
|
154
168
|
requirements: []
|