cinch-dicebag 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: ab59f8709ed5aee1d8354910616d518933583bda
4
+ data.tar.gz: 353ef745e42b012d36c2e4efad611ef885eabcba
5
+ SHA512:
6
+ metadata.gz: 20e7c611ae9235b4dab39e4d78717a39e169ecbbceecf2effacbb7870ea93b89cbbee0f744ff78e019300d9f285478290aaa167469e06b5d79670288b6dc2357
7
+ data.tar.gz: f38172852b8b6d52c37895a60167318f9010c2b8fe9655d558a701ef1aec62b8b024fc24da9e2beb8df3cc0f5ae7fe98aff1bdba2fe88fd51da8b969c7d848c9
@@ -1,4 +1,24 @@
1
1
  language: ruby
2
+ env:
3
+ global:
4
+ - "JRUBY_OPTS=-Xcext.enabled=true"
2
5
  rvm:
3
- - 1.9.2
6
+ - 2.1.0
7
+ - 2.0.0
4
8
  - 1.9.3
9
+ - 1.9.2
10
+ - 1.8.7
11
+ - jruby-18mode
12
+ - jruby-19mode
13
+ - rbx
14
+ - ruby-head
15
+ - jruby-head
16
+ - ree
17
+ matrix:
18
+ allow_failures:
19
+ - rvm: 1.8.7
20
+ - rvm: ree
21
+ - rvm: jruby-18mode
22
+ - rvm: jruby-19mode
23
+ - rvm: jruby-head
24
+ fast_finish: true
@@ -55,11 +55,8 @@ module Cinch::Plugins
55
55
  def roll(m, dice = '1d20')
56
56
  result = roll_dice(dice.split(' '))
57
57
 
58
- if result.is_a?(String)
59
- m.reply result
60
- elsif result.is_a?(Integer)
61
- m.reply "#{m.user.nick} rolls #{dice} totalling #{result}"
62
- end
58
+ result = "#{m.user.nick} rolls #{dice} totalling #{result}" if result.is_a?(Integer)
59
+ m.reply result
63
60
  end
64
61
 
65
62
  # Takes an Array of dice rolls, sanitizes them, parses them, and dispatches
@@ -69,18 +66,18 @@ module Cinch::Plugins
69
66
  # @return [Fixnum] The total from rolling all of the dice.
70
67
  def roll_dice(dice)
71
68
  # Clean out anything invalid
72
- dice.delete_if { |d| d.match(/\d*d\d+/).nil? }
69
+ dice.delete_if { |d| d.match(/\d*d\d+([\-\+]\d+)?/).nil? }
73
70
 
74
71
  return roll_check?(dice) if roll_check?(dice)
75
-
76
- total = 0
77
-
72
+
78
73
  # Roll each group and total up the returned value
74
+ total = nil
79
75
  dice.each do |die|
76
+ total ||= 0
80
77
  total += roll_die(die)
81
78
  end
82
79
 
83
- return total.to_i unless total.zero?
80
+ total
84
81
  end
85
82
 
86
83
  # Takes an array of rolls and does sanity on it.
@@ -98,15 +95,27 @@ module Cinch::Plugins
98
95
  # @param [Fixn] count Number of times to roll the die.
99
96
  # @return [Fixnum] The total from rolling the die.
100
97
  def roll_die(die)
98
+ modifier = die[/[\-\+]\d+/]
99
+
101
100
  count = (die[/(\d+)d\d+/, 1] || 1).to_i
102
101
  sides = die[/\d?d(\d+)/, 1].to_i
102
+
103
103
  return 0 if count.nil? || sides.nil? || sides < 1 || count < 1
104
+
104
105
  total = 0
105
106
  count.times { total += rand(sides) + 1 }
106
107
 
108
+ return total += parse_modifier(modifier) unless modifier.nil?
109
+
107
110
  total
108
111
  end
109
112
 
113
+ def parse_modifier(modifier)
114
+ operator = modifier[/\A[\+\-]/]
115
+ int = modifier[/\d+\z/].to_i
116
+ 0.send(operator, int)
117
+ end
118
+
110
119
  # Simple method to return a flavor text 'size' description based on
111
120
  # how many dice you happened to get in your dicebag roll.
112
121
  # @param [Fixnum] size The number of dice in the dicebag.
@@ -2,6 +2,6 @@
2
2
  module Cinch
3
3
  # Versioning information for plugin
4
4
  module Dicebag
5
- VERSION = '1.0.8'
5
+ VERSION = '1.0.9'
6
6
  end
7
7
  end
@@ -18,6 +18,19 @@ describe Cinch::Plugins::Dicebag do
18
18
  should_not be_nil
19
19
  end
20
20
 
21
+ it 'should allow "+" modifiers' do
22
+ roll = get_replies(make_message(@bot, '!roll 1d3+5', { nick: 'ted' })).first.text
23
+ roll = roll[/totalling (\d+)/, 1]
24
+ (6..8).should include roll.to_i
25
+ end
26
+
27
+ it 'should allow "-" modifiers' do
28
+ roll = get_replies(make_message(@bot, '!roll 1d1-5', { nick: 'ted' }))
29
+ .first
30
+ .text[/totalling (\-?\d+)/, 1].to_i
31
+ .should == -4
32
+ end
33
+
21
34
  it 'should return a roll in bounds from rolling dice' do
22
35
  roll = get_replies(make_message(@bot, '!roll 3d3', { nick: 'ted' })).first.text
23
36
  roll = roll[/totalling (\d+)/, 1]
@@ -78,7 +91,6 @@ describe Cinch::Plugins::Dicebag do
78
91
  text = get_replies(make_message(@bot, '!dicebag' , { nick: 'brian', channel: '#foo' })).first.text
79
92
  text.should match(/A new high score/)
80
93
  text.should match(/Their old high roll was \d+/)
81
-
82
94
  end
83
95
  end
84
96
 
@@ -94,18 +106,32 @@ describe Cinch::Plugins::Dicebag do
94
106
  it 'should clear out any invalid dice rolls' do
95
107
  @bot.plugins.first.roll_dice(['33']).should be_nil
96
108
  end
109
+
110
+ it 'should allow modifiers' do
111
+ @bot.plugins.first.roll_dice(['1d1+1', '1d1-4']).should == -1
112
+ end
97
113
  end
98
114
 
99
115
  describe 'roll_die' do
100
116
  it 'should return an acceptable value for a given roll' do
101
117
  @bot.plugins.first.roll_die('1d1').should == 1
102
- (5..15).should include(@bot.plugins.first.roll_die('3d5'))
118
+ (3..15).should include(@bot.plugins.first.roll_die('3d5'))
103
119
  end
104
120
 
105
121
  it 'should return 0 for any negetive values' do
106
122
  @bot.plugins.first.roll_die('1d-1').should == 0
107
123
  @bot.plugins.first.roll_die('-1d-1').should == 0
108
124
  end
125
+
126
+ it 'should add modifiers to the total' do
127
+ @bot.plugins.first.roll_die('1d1+2').should == 3
128
+ @bot.plugins.first.roll_die('3d1-2').should == 1
129
+ end
130
+
131
+ it 'should allow modifiers to take the total below zero' do
132
+ @bot.plugins.first.roll_die('1d1-1').should == 0
133
+ @bot.plugins.first.roll_die('1d1-2').should == -1
134
+ end
109
135
  end
110
136
 
111
137
  describe 'get_bag_size' do
@@ -149,4 +175,3 @@ describe Cinch::Plugins::Dicebag do
149
175
  end
150
176
  end
151
177
  end
152
-
metadata CHANGED
@@ -1,20 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-dicebag
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
5
- prerelease:
4
+ version: 1.0.9
6
5
  platform: ruby
7
6
  authors:
8
7
  - Brian Haberer
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-02-19 00:00:00.000000000 Z
11
+ date: 2014-07-01 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
@@ -22,7 +20,6 @@ dependencies:
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ! '>='
28
25
  - !ruby/object:Gem::Version
@@ -30,7 +27,6 @@ dependencies:
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
31
  - - ! '>='
36
32
  - !ruby/object:Gem::Version
@@ -38,7 +34,6 @@ dependencies:
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
38
  - - ! '>='
44
39
  - !ruby/object:Gem::Version
@@ -46,7 +41,6 @@ dependencies:
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: coveralls
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
45
  - - ! '>='
52
46
  - !ruby/object:Gem::Version
@@ -54,7 +48,6 @@ dependencies:
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
52
  - - ! '>='
60
53
  - !ruby/object:Gem::Version
@@ -62,7 +55,6 @@ dependencies:
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: cinch-test
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - ! '>='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - ! '>='
76
67
  - !ruby/object:Gem::Version
@@ -78,7 +69,6 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: cinch
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
73
  - - ! '>='
84
74
  - !ruby/object:Gem::Version
@@ -86,7 +76,6 @@ dependencies:
86
76
  type: :runtime
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
80
  - - ! '>='
92
81
  - !ruby/object:Gem::Version
@@ -94,7 +83,6 @@ dependencies:
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: time-lord
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
87
  - - ~>
100
88
  - !ruby/object:Gem::Version
@@ -102,7 +90,6 @@ dependencies:
102
90
  type: :runtime
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
94
  - - ~>
108
95
  - !ruby/object:Gem::Version
@@ -110,7 +97,6 @@ dependencies:
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: cinch-cooldown
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
101
  - - ! '>='
116
102
  - !ruby/object:Gem::Version
@@ -118,7 +104,6 @@ dependencies:
118
104
  type: :runtime
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
108
  - - ! '>='
124
109
  - !ruby/object:Gem::Version
@@ -126,7 +111,6 @@ dependencies:
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: cinch-storage
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
115
  - - ~>
132
116
  - !ruby/object:Gem::Version
@@ -134,7 +118,6 @@ dependencies:
134
118
  type: :runtime
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
122
  - - ~>
140
123
  - !ruby/object:Gem::Version
@@ -142,7 +125,6 @@ dependencies:
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: cinch-toolbox
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
129
  - - ~>
148
130
  - !ruby/object:Gem::Version
@@ -150,7 +132,6 @@ dependencies:
150
132
  type: :runtime
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
136
  - - ~>
156
137
  - !ruby/object:Gem::Version
@@ -178,29 +159,27 @@ files:
178
159
  homepage: https://github.com/bhaberer/cinch-dicebag
179
160
  licenses:
180
161
  - MIT
162
+ metadata: {}
181
163
  post_install_message:
182
164
  rdoc_options: []
183
165
  require_paths:
184
166
  - lib
185
167
  required_ruby_version: !ruby/object:Gem::Requirement
186
- none: false
187
168
  requirements:
188
169
  - - ! '>='
189
170
  - !ruby/object:Gem::Version
190
171
  version: '0'
191
172
  required_rubygems_version: !ruby/object:Gem::Requirement
192
- none: false
193
173
  requirements:
194
174
  - - ! '>='
195
175
  - !ruby/object:Gem::Version
196
176
  version: '0'
197
177
  requirements: []
198
178
  rubyforge_project:
199
- rubygems_version: 1.8.25
179
+ rubygems_version: 2.2.2
200
180
  signing_key:
201
- specification_version: 3
181
+ specification_version: 4
202
182
  summary: ! 'Cinch Plugin: Dicebag and Dice rolls'
203
183
  test_files:
204
184
  - spec/cinch-dicebag_spec.rb
205
185
  - spec/spec_helper.rb
206
- has_rdoc: