cinch-dicebag 1.0.13 → 1.0.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: 8cadf85224bd800c25264d54cfee7bd153439006
4
- data.tar.gz: aaa7727e81fd0826c4dff26ccd2bf0e530d4fdbd
2
+ SHA1:
3
+ metadata.gz: bce7c45a031f56498b1317ce18abd158978c5dca
4
+ data.tar.gz: c350523add02d918d1c4ee42e22204cc29f1c1bb
5
5
  SHA512:
6
- metadata.gz: 58eb0f35068118884637e3d32f89bdf49271899127fd137f1fe88b2eaadaa14f2eca75cff847b7bd8ac5304f157c1e578ce4516e62e30d1dc96f9ece2aa7e722
7
- data.tar.gz: c10fafc541bba7b8f6817c01c17667d2e527fae5139ccf447993c0437c7e2c8cc9f819b5596917fce21ab7b39cfecb0ebb22f9fee87e74260673e412b339d4e3
6
+ metadata.gz: 6b385370b7d791de6af79bbb4a013ba8730b05651c3a8fb1abcee3d5f2a8cc8835bb8702e1b3495d8eb20f8abfa84e2f1bf09cd5c2a3ec2c891cc54223a82af9
7
+ data.tar.gz: 5db89bf5fd9185240dc64317bab4a9a3b7e1bcc4a9002acb8ac44598ea33ca796f413f3553351d08932caabe835e2f4303d462d3135e19b092f5ed3daccbafc3
@@ -1,8 +1,16 @@
1
1
  language: ruby
2
+ addons:
3
+ code_climate:
4
+ repo_token: d811b9c7bc95cfa5b0a3b7095e070abed229092bdbb1a5d53b738e4bd4ed973b
5
+ before_install:
6
+ - gem update --system
7
+ - gem update bundler
2
8
  env:
3
9
  global:
4
10
  - "JRUBY_OPTS=-Xcext.enabled=true"
5
11
  rvm:
12
+ - 2.3.0
13
+ - 2.2.0
6
14
  - 2.1.0
7
15
  - 2.0.0
8
16
  - 1.9.3
@@ -15,9 +23,13 @@ rvm:
15
23
  - ree
16
24
  matrix:
17
25
  allow_failures:
26
+ - rvm: 1.9.3
27
+ - rvm: 1.9.2
28
+ - rvm: 1.8.7
18
29
  - rvm: 1.8.7
19
30
  - rvm: ree
20
31
  - rvm: jruby-18mode
21
32
  - rvm: jruby-19mode
22
33
  - rvm: jruby-head
34
+ - rvm: ruby-head
23
35
  fast_finish: true
@@ -19,8 +19,9 @@ Gem::Specification.new do |gem|
19
19
 
20
20
  gem.add_development_dependency 'rake', '~> 10'
21
21
  gem.add_development_dependency 'rspec', '~> 3'
22
- gem.add_development_dependency 'coveralls', '~> 0.7'
23
- gem.add_development_dependency 'cinch-test', '~> 0.1', '>= 0.1.0'
22
+ gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
23
+ gem.add_development_dependency 'cinch-test', '~> 0.1', '>= 0.1.1'
24
+
24
25
  gem.add_dependency 'cinch', '~> 2'
25
26
  gem.add_dependency 'cinch-cooldown', '~> 1.1', '>= 1.1.5'
26
27
  gem.add_dependency 'cinch-storage', '~> 1.1'
@@ -21,37 +21,39 @@ module Cinch
21
21
 
22
22
  match(/dicebag\z/, method: :dicebag)
23
23
  match(/dicebag stats/, method: :stats)
24
- match /roll(?:\s(.*))/, method: :roll
25
- match /roll\z/, method: :roll
24
+ match(/roll(?:\s(.*))/, method: :roll)
25
+ match(/roll\z/, method: :roll)
26
26
 
27
27
  def initialize(*args)
28
28
  super
29
+ # initialize storage
29
30
  @storage = Cinch::Storage.new(config[:filename] || 'yaml/dice.yml')
30
- @bag = Bag.new(4 => 250, 6 => 750, 10 => 1200, 20 => 1000)
31
+
32
+ # Create a bag of dice, pass a hash of the maxcount for each type
33
+ # for random rolls.
34
+ @bag = Bag.new(4 => 250, 6 => 750, 10 => 1500, 20 => 2000)
31
35
  end
32
36
 
33
37
  # Roll a random assortment of dice, total the rolls, and record the score.
34
- # @param [String] nick Nickname of the user rolling.
35
- # @param [Cinch::Channel] channel The Channel object where the roll took
36
- # place.
38
+ # @param [Message] message Nickname of the user rolling.
37
39
  # @return [String] A description of the roll that took place
38
- def dicebag(m)
39
- return if Cinch::Toolbox.sent_via_private_message?(m)
40
+ def dicebag(message)
41
+ return if Cinch::Toolbox.sent_via_private_message?(message)
40
42
 
41
43
  @bag.roll
42
- user = m.user.nick.downcase
43
- channel = m.channel.name
44
- m.reply "#{m.user.nick} rolls a #{@bag.size} bag of dice totalling " \
45
- "#{@bag.score}. #{score_check(user, channel, @bag.score)}"
44
+ user = message.user.nick
45
+ channel = message.channel.name
46
+ message.reply "#{user} rolls a #{@bag.size} bag of dice totalling " \
47
+ "#{@bag.score}. #{score_check(user, channel, @bag.score)}"
46
48
  end
47
49
 
48
- def stats(m)
49
- return if Cinch::Toolbox.sent_via_private_message?(m)
50
+ def stats(message)
51
+ return if Cinch::Toolbox.sent_via_private_message?(message)
50
52
 
51
- m.user.send 'Top ten dicebag rolls:'
52
- top10 = top_ten_rolls(m.channel.name)
53
+ message.user.send 'Top ten dicebag rolls:'
54
+ top10 = top_ten_rolls(message.channel.name)
53
55
  top10.each_with_index do |r, i|
54
- m.user.send "#{i + 1} - #{r.first} [#{r.last}]"
56
+ message.user.send "#{i + 1} - #{r.first} [#{r.last}]"
55
57
  end
56
58
  end
57
59
 
@@ -60,12 +62,12 @@ module Cinch
60
62
  # @param [String] dice Space delimited string of dice to role.
61
63
  # (i.e. '6d12 4d20 d10'
62
64
  # @return [String] String describing the dice that were rolled
63
- def roll(m, dice = '1d20')
65
+ def roll(message, dice = '1d20')
64
66
  result = Die.roll(dice.split(' '))
65
67
  if result.is_a?(Integer)
66
- result = "#{m.user.nick} rolls #{dice} totalling #{result}"
68
+ result = "#{message.user.nick} rolls #{dice} totalling #{result}"
67
69
  end
68
- m.reply result
70
+ message.reply result
69
71
  end
70
72
 
71
73
  private
@@ -84,6 +86,7 @@ module Cinch
84
86
  # @return [String] If the new score is higher, returns an announcement
85
87
  # to that effect, otherwise returns a blank string.
86
88
  def score_check(nick, channel, score)
89
+ nick = nick.downcase
87
90
  # If the chennel or nick are not already initialized, spin them up
88
91
  @storage.data[channel] ||= {}
89
92
  @storage.data[channel][nick] ||= { score: score, time: Time.now }
@@ -4,6 +4,11 @@ module Cinch
4
4
  # Class to handle rolling of a preset bag of dice.
5
5
  class Bag
6
6
  attr_accessor :count, :dice, :score
7
+
8
+ # Create a new bag
9
+ # @param [Hash] dice_hash Hash of dice, in the format of
10
+ # { :num_sides => :max_dice_to_roll, ... }
11
+ # The bag will randomly roll (1-:max_dice_to_roll) :num_sided dice.
7
12
  def initialize(dice_hash)
8
13
  fail unless good_hash?(dice_hash)
9
14
  @dice = dice_hash
@@ -11,16 +16,22 @@ module Cinch
11
16
  @score = 0
12
17
  end
13
18
 
19
+ def stats
20
+ max_score = @dice.keys.inject(0) { |sum, x| sum + (x * @dice[x]) }
21
+ min_score = @dice.keys.count
22
+ max_count = @dice.values.inject(0) { |sum, x| sum + x }
23
+ min_count = @dice.keys.count
24
+ { min_count: min_count, max_count: max_count,
25
+ min_score: min_score, max_score: max_score }
26
+ end
27
+
28
+ # Roll the bag of dice, this will roll the dice and update the current
29
+ # score and count
14
30
  def roll
15
31
  dice = die_array
16
32
  @score = Die.roll(dice)
17
33
  @count = dice.map { |d| d[/(\d+)d\d+/, 1].to_i || 1 }.inject(0, :+)
18
- end
19
-
20
- def good_hash?(dice_hash)
21
- dice_hash.keys { |k| return false unless k.is_a?(Integer) }
22
- dice_hash.values { |k| return false unless k.is_a?(Integer) }
23
- true
34
+ return self
24
35
  end
25
36
 
26
37
  # Simple method to return a flavor text 'size' description based on
@@ -28,21 +39,33 @@ module Cinch
28
39
  # @param [Fixnum] size The number of dice in the dicebag.
29
40
  # @return [String] Description of the size of the bag.
30
41
  def size
31
- case @count
32
- when 0..1000 then 'tiny'
33
- when 1001..1500 then 'small'
34
- when 1501..2500 then 'medium'
35
- when 2501..3500 then 'large'
36
- when 3501..4500 then 'hefty'
42
+ case
43
+ when @count < 1000 then 'tiny'
44
+ when @count < 2000 then 'small'
45
+ when @count < 3000 then 'medium'
46
+ when @count < 4000 then 'large'
47
+ when @count < 5000 then 'hefty'
37
48
  else 'massive'
38
49
  end
39
50
  end
40
51
 
41
52
  private
42
53
 
54
+ # Check to make sure that the passed hash of dice looks basically
55
+ # reasonable.
56
+ # e.g. { 4 => 10, 6 => 20, 100 => 20 }
57
+ def good_hash?(dice_hash)
58
+ dice_hash.keys { |k| return false unless k.is_a?(Integer) }
59
+ dice_hash.values { |k| return false unless k.is_a?(Integer) }
60
+ true
61
+ end
62
+
63
+ # Render the @dice hash as an array of rolls to pass to the Die module.
64
+ # This also is where we randomly select how many dice from the range
65
+ # are actually rolled.
43
66
  def die_array
44
67
  @dice.keys.map do |sides|
45
- "#{rand(@dice[sides])}d#{sides}"
68
+ "#{rand(@dice[sides] + 1)}d#{sides}"
46
69
  end
47
70
  end
48
71
  end
@@ -19,6 +19,7 @@ module Cinch
19
19
  # Clean out anything invalid
20
20
  dice = clean_roll(dice)
21
21
 
22
+ # Initialize a total
22
23
  total = nil
23
24
 
24
25
  # Return if the sanity fails
@@ -33,31 +34,37 @@ module Cinch
33
34
  total
34
35
  end
35
36
 
36
- private
37
-
38
37
  # Rolls an n-sided die a given amount of times and returns the total
39
38
  # @param [String] count Number of times to roll the die.
40
39
  # @return [Fixnum] The total from rolling the die.
41
40
  def self.cast(die)
41
+ # Pull out the data from the roll.
42
42
  modifier = die[MOD_REGEX]
43
43
  count = (die[ROLLS_REGEX, 1] || 1).to_i
44
44
  sides = die[SIDES_REGEX, 1].to_i
45
45
 
46
+ # init the total
46
47
  total = 0
48
+
49
+ # Bail if the roll isn't sane looking.
47
50
  return total unless check_die_sanity(count, sides)
48
51
 
52
+ # Roll dem dice!
49
53
  count.times { total += rand(sides) + 1 }
50
54
 
55
+ # Parse the modifier and apply it, if there is one
51
56
  return total += parse_modifier(modifier) unless modifier.nil?
52
57
 
53
58
  total
54
59
  end
55
60
 
61
+ # Makes sure people aren't doing silly things.
56
62
  def self.check_die_sanity(count, sides)
57
63
  return false if count.nil? || sides.nil? || sides < 1 || count < 1
58
64
  true
59
65
  end
60
66
 
67
+ # Remove any stupid crap people try to sneak into the rolls.
61
68
  def self.clean_roll(dice)
62
69
  dice.delete_if { |d| d.match(/\d*d\d+([\-\+]\d+)?/).nil? }
63
70
  dice
@@ -67,16 +74,14 @@ module Cinch
67
74
  # @param [Array] dice Array of strings that correspond to valid
68
75
  # die rolls. (i.e. ['4d6', '6d10']
69
76
  # @return [Boolean] Result of sanity check.
70
- def self.die_check?(dice_list)
77
+ def self.die_check?(dice)
71
78
  # Check to make sure it's not a stupid large roll, they clog threads.
72
- count =
73
- dice_list.map do |d|
74
- d[/(\d+)d\d+/, 1].to_i || 1
75
- end.inject(0, :+)
79
+ count = dice.map { |d| d[/(\d+)d\d+/, 1].to_i || 1 }.inject(0, :+)
76
80
  return false if count >= 10_000
77
81
  true
78
82
  end
79
83
 
84
+ # Parse out the modified and return it as an int.
80
85
  def self.parse_modifier(modifier)
81
86
  operator = modifier[/\A[\+\-]/]
82
87
  int = modifier[/\d+\z/].to_i
@@ -2,6 +2,6 @@
2
2
  module Cinch
3
3
  # Versioning information for plugin
4
4
  module Dicebag
5
- VERSION = '1.0.13'
5
+ VERSION = '1.0.14'
6
6
  end
7
7
  end
@@ -186,32 +186,32 @@ describe Cinch::Plugins::Dicebag do
186
186
  end
187
187
 
188
188
  it 'should return the proper size for small range' do
189
- @bag.count = 1000
189
+ @bag.count = 900
190
190
  expect(@bag.size).to eq('tiny')
191
191
  end
192
192
 
193
193
  it 'should return the proper size for small range' do
194
- @bag.count = 1001
194
+ @bag.count = 1000
195
195
  expect(@bag.size).to eq('small')
196
196
  end
197
197
 
198
198
  it 'should return the proper size for small range' do
199
- @bag.count = rand(399) + 1001
199
+ @bag.count = rand(999) + 1000
200
200
  expect(@bag.size).to eq('small')
201
201
  end
202
202
 
203
203
  it 'should return the proper size for small range' do
204
- @bag.count = 1500
204
+ @bag.count = 1999
205
205
  expect(@bag.size).to eq('small')
206
206
  end
207
207
 
208
208
  it 'should return the proper size for medium range' do
209
- @bag.count = 1501
209
+ @bag.count = 2500
210
210
  expect(@bag.size).to eq('medium')
211
211
  end
212
212
 
213
213
  it 'should return the proper size for medium range' do
214
- @bag.count = rand(499) + 1501
214
+ @bag.count = rand(999) + 2000
215
215
  expect(@bag.size).to eq('medium')
216
216
  end
217
217
 
@@ -221,12 +221,12 @@ describe Cinch::Plugins::Dicebag do
221
221
  end
222
222
 
223
223
  it 'should return the proper size for large range' do
224
- @bag.count = 2501
224
+ @bag.count = 3500
225
225
  expect(@bag.size).to eq('large')
226
226
  end
227
227
 
228
228
  it 'should return the proper size for large range' do
229
- @bag.count = rand(499) + 2501
229
+ @bag.count = rand(999) + 3000
230
230
  expect(@bag.size).to eq('large')
231
231
  end
232
232
 
@@ -236,12 +236,12 @@ describe Cinch::Plugins::Dicebag do
236
236
  end
237
237
 
238
238
  it 'should return the proper size for hefty range' do
239
- @bag.count = 3501
239
+ @bag.count = 4500
240
240
  expect(@bag.size).to eq('hefty')
241
241
  end
242
242
 
243
243
  it 'should return the proper size for hefty range' do
244
- @bag.count = rand(499) + 3501
244
+ @bag.count = rand(999) + 4000
245
245
  expect(@bag.size).to eq('hefty')
246
246
  end
247
247
 
@@ -251,12 +251,12 @@ describe Cinch::Plugins::Dicebag do
251
251
  end
252
252
 
253
253
  it 'should return the proper size for huge range' do
254
- @bag.count = 4501
254
+ @bag.count = 5000
255
255
  expect(@bag.size).to eq('massive')
256
256
  end
257
257
 
258
258
  it 'should return the proper size for huge range' do
259
- @bag.count = 20001
259
+ @bag.count = 20000
260
260
  expect(@bag.size).to eq('massive')
261
261
  end
262
262
  end
@@ -1,11 +1,5 @@
1
- require 'coveralls'
2
- require 'simplecov'
3
-
4
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
- SimpleCov::Formatter::HTMLFormatter,
6
- Coveralls::SimpleCov::Formatter
7
- ]
8
- SimpleCov.start
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
9
3
 
10
4
  require 'cinch-dicebag'
11
5
  require 'cinch/test'
metadata CHANGED
@@ -1,137 +1,137 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-dicebag
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.13
4
+ version: 1.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Haberer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-15 00:00:00.000000000 Z
11
+ date: 2016-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '10'
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: '10'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '3'
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: '3'
41
41
  - !ruby/object:Gem::Dependency
42
- name: coveralls
42
+ name: codeclimate-test-reporter
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.7'
47
+ version: '0.4'
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
- version: '0.7'
54
+ version: '0.4'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: cinch-test
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0.1'
62
- - - ! '>='
62
+ - - ">="
63
63
  - !ruby/object:Gem::Version
64
- version: 0.1.0
64
+ version: 0.1.1
65
65
  type: :development
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - ~>
69
+ - - "~>"
70
70
  - !ruby/object:Gem::Version
71
71
  version: '0.1'
72
- - - ! '>='
72
+ - - ">="
73
73
  - !ruby/object:Gem::Version
74
- version: 0.1.0
74
+ version: 0.1.1
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: cinch
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - ~>
79
+ - - "~>"
80
80
  - !ruby/object:Gem::Version
81
81
  version: '2'
82
82
  type: :runtime
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - ~>
86
+ - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: '2'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: cinch-cooldown
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - ~>
93
+ - - "~>"
94
94
  - !ruby/object:Gem::Version
95
95
  version: '1.1'
96
- - - ! '>='
96
+ - - ">="
97
97
  - !ruby/object:Gem::Version
98
98
  version: 1.1.5
99
99
  type: :runtime
100
100
  prerelease: false
101
101
  version_requirements: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - ~>
103
+ - - "~>"
104
104
  - !ruby/object:Gem::Version
105
105
  version: '1.1'
106
- - - ! '>='
106
+ - - ">="
107
107
  - !ruby/object:Gem::Version
108
108
  version: 1.1.5
109
109
  - !ruby/object:Gem::Dependency
110
110
  name: cinch-storage
111
111
  requirement: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - ~>
113
+ - - "~>"
114
114
  - !ruby/object:Gem::Version
115
115
  version: '1.1'
116
116
  type: :runtime
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - ~>
120
+ - - "~>"
121
121
  - !ruby/object:Gem::Version
122
122
  version: '1.1'
123
123
  - !ruby/object:Gem::Dependency
124
124
  name: cinch-toolbox
125
125
  requirement: !ruby/object:Gem::Requirement
126
126
  requirements:
127
- - - ~>
127
+ - - "~>"
128
128
  - !ruby/object:Gem::Version
129
129
  version: '1.1'
130
130
  type: :runtime
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
- - - ~>
134
+ - - "~>"
135
135
  - !ruby/object:Gem::Version
136
136
  version: '1.1'
137
137
  description: Cinch Plugin that allows uses in the channel to roll specific dice or
@@ -142,8 +142,8 @@ executables: []
142
142
  extensions: []
143
143
  extra_rdoc_files: []
144
144
  files:
145
- - .gitignore
146
- - .travis.yml
145
+ - ".gitignore"
146
+ - ".travis.yml"
147
147
  - Gemfile
148
148
  - LICENSE.txt
149
149
  - README.md
@@ -166,20 +166,20 @@ require_paths:
166
166
  - lib
167
167
  required_ruby_version: !ruby/object:Gem::Requirement
168
168
  requirements:
169
- - - ! '>='
169
+ - - ">="
170
170
  - !ruby/object:Gem::Version
171
171
  version: '0'
172
172
  required_rubygems_version: !ruby/object:Gem::Requirement
173
173
  requirements:
174
- - - ! '>='
174
+ - - ">="
175
175
  - !ruby/object:Gem::Version
176
176
  version: '0'
177
177
  requirements: []
178
178
  rubyforge_project:
179
- rubygems_version: 2.2.2
179
+ rubygems_version: 2.4.8
180
180
  signing_key:
181
181
  specification_version: 4
182
- summary: ! 'Cinch Plugin: Dicebag and Dice rolls'
182
+ summary: 'Cinch Plugin: Dicebag and Dice rolls'
183
183
  test_files:
184
184
  - spec/cinch-dicebag_spec.rb
185
185
  - spec/spec_helper.rb