lita-dice 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 +18 -0
- data/.travis.yml +8 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +30 -0
- data/Rakefile +6 -0
- data/lib/lita-dice.rb +1 -0
- data/lib/lita/handlers/dice.rb +44 -0
- data/lita-dice.gemspec +24 -0
- data/spec/lita/handlers/dice_spec.rb +64 -0
- data/spec/spec_helper.rb +10 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d823820c92b752922838e962d984c0b18a9ce4c4
|
4
|
+
data.tar.gz: 43012c33b5961fbabc8598a970a0125341a4112e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 357aea70ce9358b617ecb40cd870178fd3c19b99a296f0e69de5b6aae4a4db132678c6e35834b707ca8d96df366f36790786f528c93dcf1f15c73160f215528a
|
7
|
+
data.tar.gz: c984e75e03cf391b3acbc6b66c262b2d344a78761c67e53e62ec932f7197507e0eb8e5d082e60eae03baec4fd716768b50771feb799c6be15dea89783ce0e8a1
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014 Tristan Chong
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# lita-dice
|
2
|
+
|
3
|
+
**lita-dice** is a handler for [Lita](https://github.com/jimmycuadra/lita) that allows you to roll virtual dice.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add lita-dice to your Lita instance's Gemfile:
|
8
|
+
|
9
|
+
``` ruby
|
10
|
+
gem "lita-dice"
|
11
|
+
```
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
To roll the dice:
|
16
|
+
|
17
|
+
```
|
18
|
+
[You] Lita: roll
|
19
|
+
[Lita] User rolled 5
|
20
|
+
[You] Lita: roll 2
|
21
|
+
[Lita] User rolled 3 4 (7)
|
22
|
+
[You] Lita: roll d100
|
23
|
+
[Lita] User rolled 42
|
24
|
+
[You] Lita: roll 3d20
|
25
|
+
[Lita] User rolled 13 1 15 (29)
|
26
|
+
```
|
27
|
+
|
28
|
+
## License
|
29
|
+
|
30
|
+
[MIT](http://opensource.org/licenses/MIT)
|
data/Rakefile
ADDED
data/lib/lita-dice.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "lita/handlers/dice"
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "lita"
|
2
|
+
|
3
|
+
module Lita
|
4
|
+
module Handlers
|
5
|
+
class Dice < Handler
|
6
|
+
route(/^roll(\s+(?<x>\d+)?d?(?<y>\d+)?)?/i, :roll, command: true, help: {
|
7
|
+
'roll' => 'Roll one 6-sided die.',
|
8
|
+
'roll X' => 'Roll X 6-sided dice.',
|
9
|
+
'roll XdY' => 'Roll X Y-sided dice.'})
|
10
|
+
|
11
|
+
def roll(response)
|
12
|
+
int = lambda do |n, default|
|
13
|
+
if n == nil
|
14
|
+
return default
|
15
|
+
end
|
16
|
+
n.to_i
|
17
|
+
end
|
18
|
+
|
19
|
+
x, y = response.matches.first
|
20
|
+
x = int.call(x, 1)
|
21
|
+
y = int.call(y, 6)
|
22
|
+
|
23
|
+
if x > 20 or x < 1
|
24
|
+
s = "#{response.user.name}: You can only roll between 1 and 20 dice."
|
25
|
+
elsif y > 1000 or y < 2
|
26
|
+
s = "#{response.user.name}: Dice must have between 2 and 1000 sides."
|
27
|
+
else
|
28
|
+
rolls = []
|
29
|
+
(1..x).each do |n|
|
30
|
+
rolls << (1..y).to_a.sample
|
31
|
+
end
|
32
|
+
s = "#{response.user.name} rolled #{rolls.join(' ')}"
|
33
|
+
if x > 1
|
34
|
+
total = rolls.inject(:+)
|
35
|
+
s += " (#{total})"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
response.reply s
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
Lita.register_handler(Dice)
|
43
|
+
end
|
44
|
+
end
|
data/lita-dice.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "lita-dice"
|
3
|
+
spec.version = "0.0.1"
|
4
|
+
spec.authors = ["Tristan Chong"]
|
5
|
+
spec.email = ["tristanchong@gmail.com"]
|
6
|
+
spec.description = %q{A Lita handler that allows you to roll virtual dice.}
|
7
|
+
spec.summary = %q{A Lita handler that allows you to roll virtual dice.}
|
8
|
+
spec.homepage = "https://github.com/tristaneuan/lita-dice"
|
9
|
+
spec.license = "MIT"
|
10
|
+
spec.metadata = { "lita_plugin_type" => "handler" }
|
11
|
+
|
12
|
+
spec.files = `git ls-files`.split($/)
|
13
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
14
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
15
|
+
spec.require_paths = ["lib"]
|
16
|
+
|
17
|
+
spec.add_runtime_dependency "lita", ">= 2.7"
|
18
|
+
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
20
|
+
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "rspec", ">= 3.0.0.beta2"
|
22
|
+
spec.add_development_dependency "simplecov"
|
23
|
+
spec.add_development_dependency "coveralls"
|
24
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Lita::Handlers::Dice, lita_handler: true do
|
4
|
+
it { routes_command("roll").to(:roll) }
|
5
|
+
|
6
|
+
describe "#roll" do
|
7
|
+
it "handles roll as roll 1d6" do
|
8
|
+
send_command "roll"
|
9
|
+
re = /#{user.name} rolled (\d+)/
|
10
|
+
expect(replies.first).to match(re)
|
11
|
+
capt = re.match(replies.first).captures
|
12
|
+
value = capt.first.to_i
|
13
|
+
expect(1..6).to include(value)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "handles roll X as roll Xd6" do
|
17
|
+
send_command "roll 3"
|
18
|
+
re = /#{user.name} rolled (\d+) (\d+) (\d+) \((\d+)\)/
|
19
|
+
expect(replies.first).to match(re)
|
20
|
+
capt = re.match(replies.first).captures
|
21
|
+
a, b, c, total = capt.map { |n| n.to_i }
|
22
|
+
expect(1..6).to include(a)
|
23
|
+
expect(1..6).to include(b)
|
24
|
+
expect(1..6).to include(c)
|
25
|
+
expect(a + b + c).to equal(total)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "handles roll dY as roll 1dY" do
|
29
|
+
send_command "roll d20"
|
30
|
+
re = /#{user.name} rolled (\d+)/
|
31
|
+
expect(replies.first).to match(re)
|
32
|
+
capt = re.match(replies.first).captures
|
33
|
+
value = capt.first.to_i
|
34
|
+
expect(1..20).to include(value)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "handles roll XdY with the correct values and total" do
|
38
|
+
send_command "roll 2d10"
|
39
|
+
re = /#{user.name} rolled (\d+) (\d+) \((\d+)\)/
|
40
|
+
expect(replies.first).to match(re)
|
41
|
+
capt = re.match(replies.first).captures
|
42
|
+
a, b, total = capt.map { |n| n.to_i }
|
43
|
+
expect(1..10).to include(a)
|
44
|
+
expect(1..10).to include(b)
|
45
|
+
expect(a + b).to equal(total)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "restricts the number of dice between 1 and 20" do
|
49
|
+
re = /#{user.name}: You can only roll between 1 and 20 dice\./
|
50
|
+
send_command "roll 0"
|
51
|
+
expect(replies.first).to match(re)
|
52
|
+
send_command "roll 21d10"
|
53
|
+
expect(replies.first).to match(re)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "restricts the number of sides between 2 and 1000" do
|
57
|
+
re = /#{user.name}: Dice must have between 2 and 1000 sides\./
|
58
|
+
send_command "roll d1"
|
59
|
+
expect(replies.first).to match(re)
|
60
|
+
send_command "roll 10d1001"
|
61
|
+
expect(replies.first).to match(re)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "simplecov"
|
2
|
+
require "coveralls"
|
3
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
4
|
+
SimpleCov::Formatter::HTMLFormatter,
|
5
|
+
Coveralls::SimpleCov::Formatter
|
6
|
+
]
|
7
|
+
SimpleCov.start { add_filter "/spec/" }
|
8
|
+
|
9
|
+
require "lita-dice"
|
10
|
+
require "lita/rspec"
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: lita-dice
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tristan Chong
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: lita
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0.beta2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0.beta2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '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'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A Lita handler that allows you to roll virtual dice.
|
98
|
+
email:
|
99
|
+
- tristanchong@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- lib/lita-dice.rb
|
111
|
+
- lib/lita/handlers/dice.rb
|
112
|
+
- lita-dice.gemspec
|
113
|
+
- spec/lita/handlers/dice_spec.rb
|
114
|
+
- spec/spec_helper.rb
|
115
|
+
homepage: https://github.com/tristaneuan/lita-dice
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
metadata:
|
119
|
+
lita_plugin_type: handler
|
120
|
+
post_install_message:
|
121
|
+
rdoc_options: []
|
122
|
+
require_paths:
|
123
|
+
- lib
|
124
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 2.2.2
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: A Lita handler that allows you to roll virtual dice.
|
140
|
+
test_files:
|
141
|
+
- spec/lita/handlers/dice_spec.rb
|
142
|
+
- spec/spec_helper.rb
|