cinch-dicebag 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
- metadata.gz: 03ffcf66f79f8ac4138c0616c87bdec979c8a68b
4
- data.tar.gz: 2ffd9ee34d9838564ce75c3823645f4d6b8d6016
3
+ metadata.gz: d3e9da9b55919a8e302f89dc06454ba9f21a906e
4
+ data.tar.gz: 3299d3573675957103835f15b9bb8b257fe44cda
5
5
  SHA512:
6
- metadata.gz: 28deec95c393d146cf89c89aa49f476838f5e23aa045217addfdb3fccd7fb8a553be9c669b3a160e6956c29da0e611190370a4d60ffc726b30a781febf5ba1d0
7
- data.tar.gz: 63c0c078021222b79ebed0dd726c191d5e57eb3ee87799f6f94c767d41f106c4c3d65dd87cd415742e9ba218226df1c865ca1e744f5dfc164692f90c92cc9af6
6
+ metadata.gz: dc9f46e21fca7b2409ef821cc3e404b19618cb4a937d7b5ab08952072eef854de894b4ffec874d7b7f16522f0593decfec711c44d211e59d39716664678649e8
7
+ data.tar.gz: 777863cd4e71c574ff280dafbdadf3a1b5133b8849c27016eaa6be803e4679753b3851c6f2276740da4541e71e74b8f6c3497f05417851428f08d347a050143d
@@ -8,24 +8,21 @@ Gem::Specification.new do |gem|
8
8
  gem.version = Cinch::Dicebag::VERSION
9
9
  gem.authors = ['Brian Haberer']
10
10
  gem.email = ['bhaberer@gmail.com']
11
- gem.description = %q{Cinch Plugin that allows uses in the channel to roll specific dice or roll a random assortment of dice to compete for high scores.}
12
- gem.summary = %q{Cinch Plugin: Dicebag and Dice rolls}
11
+ gem.description = %q(Cinch Plugin that allows uses in the channel to roll specific dice or roll a random assortment of dice to compete for high scores.)
12
+ gem.summary = %q(Cinch Plugin: Dicebag and Dice rolls)
13
13
  gem.homepage = 'https://github.com/bhaberer/cinch-dicebag'
14
14
  gem.license = 'MIT'
15
-
16
15
  gem.files = `git ls-files`.split($/)
17
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(/^(test|spec|features)\//)
19
18
  gem.require_paths = ['lib']
20
19
 
21
- gem.add_development_dependency 'rake'
22
- gem.add_development_dependency 'rspec'
23
- gem.add_development_dependency 'coveralls'
24
- gem.add_development_dependency 'cinch-test'
25
-
26
- gem.add_dependency 'cinch', '>= 2.0.12'
27
- gem.add_dependency 'time-lord', '~> 1.0.1'
28
- gem.add_dependency 'cinch-cooldown', '>= 1.1.1'
29
- gem.add_dependency 'cinch-storage', '~> 1.1.0'
30
- gem.add_dependency 'cinch-toolbox', '~> 1.1.0'
20
+ gem.add_development_dependency 'rake', '~> 10'
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'
24
+ gem.add_dependency 'cinch', '~> 2'
25
+ gem.add_dependency 'cinch-cooldown', '~> 1.1', '>= 1.1.1'
26
+ gem.add_dependency 'cinch-storage', '~> 1.1'
27
+ gem.add_dependency 'cinch-toolbox', '~> 1.1'
31
28
  end
@@ -5,93 +5,96 @@ require 'cinch/cooldown'
5
5
  require 'cinch/storage'
6
6
  require 'time-lord'
7
7
 
8
- module Cinch::Plugins
9
- # Cinch Plugin to allow dice rolling.
10
- class Dicebag
11
- include Cinch::Plugin
12
-
13
- enforce_cooldown
14
-
15
- attr_accessor :storage
16
-
17
- self.help = 'Roll a random bag of dice with .dicebag, you can also ' +
18
- 'use .roll (dice count)d(sides) to roll specific dice ' +
19
- '(e.g. .roll 4d6 3d20)'
20
-
21
- match /dicebag\z/, method: :dicebag
22
- match /dicebag stats/, method: :stats
23
- match /roll(?:\s(.*))/, method: :roll
24
- match /roll\z/, method: :roll
25
-
26
- def initialize(*args)
27
- super
28
- @storage = Cinch::Storage.new(config[:filename] || 'yaml/dice.yml')
29
- @bag = Bag.new({ 4 => 250, 6 => 500, 10 => 750, 20 => 1000 })
30
- end
31
-
32
- # Roll a random assortment of dice, total the rolls, and record the score.
33
- # @param [String] nick Nickname of the user rolling.
34
- # @param [Cinch::Channel] channel The Channel object where the roll took
35
- # place.
36
- # @return [String] A description of the roll that took place
37
- def dicebag(m)
38
- return if Cinch::Toolbox.sent_via_private_message?(m)
39
-
40
- @bag.roll
41
-
42
- m.reply "#{m.user.nick} rolls a #{@bag.size} bag of dice totalling " +
43
- "#{@bag.score}. " +
44
- score_check(m.user.nick.downcase, m.channel.name, @bag.score)
45
- end
46
-
47
- def stats(m)
48
- return if Cinch::Toolbox.sent_via_private_message?(m)
49
-
50
- m.user.send 'Top ten dicebag rolls:'
51
- top10 = top_ten_rolls(m.channel.name)
52
- top10.each_with_index { |r, i| m.user.send "#{i + 1} - #{r.first} [#{r.last}]"}
53
- end
54
-
55
- # Roll a specific set of dice and return the pretty result
56
- # @param [String] nick Nickname of the user rolling.
57
- # @param [String] dice Space delimited string of dice to role.
58
- # (i.e. '6d12 4d20 d10'
59
- # @return [String] String describing the dice that were rolled
60
- def roll(m, dice = '1d20')
61
- result = Die.roll(dice.split(' '))
62
- result = "#{m.user.nick} rolls #{dice} totalling #{result}" if result.is_a?(Integer)
63
-
64
- m.reply result
65
- end
66
-
67
- private
68
-
69
- def top_ten_rolls(channel)
70
- scores = @storage.data[channel].dup
71
- scores.sort { |a, b| b[1][:score] <=> a[1][:score] }
72
- .map { |s| [s.first, s.last[:score]] }[0..9]
73
- end
74
-
75
- # Score checker for Dicebag rolls. Checks a given user/channel/score
76
- # against the current high score for that user.
77
- # @param [String] nick Nickname of the user who rolled the score.
78
- # @param [String] channel Name of the channel where the roll was made.
79
- # @param [Fixnum] score The score from the bag.
80
- # @return [String] If the new score is higher, returns an announcement
81
- # to that effect, otherwise returns a blank string.
82
- def score_check(nick, channel, score)
83
- # If the chennel or nick are not already initialized, spin them up
84
- @storage.data[channel] ||= {}
85
- @storage.data[channel][nick] ||= { score: score, time: Time.now }
86
-
87
- # Check and see if this is a higher score.
88
- old = @storage.data[channel][nick]
89
- return '' unless @storage.data[channel][nick][:score] < score
90
-
91
- @storage.data[channel][nick] = { score: score, time: Time.now }
92
- @storage.synced_save(@bot)
93
- "A new high score! Their old high roll was #{old[:score]}, " +
94
- "#{old[:time].ago.to_words}."
8
+ module Cinch
9
+ module Plugins
10
+ # Cinch Plugin to allow dice rolling.
11
+ class Dicebag
12
+ include Cinch::Plugin
13
+
14
+ attr_accessor :storage
15
+
16
+ self.help = 'Roll a random bag of dice with .dicebag, you can also ' \
17
+ 'use .roll (dice count)d(sides) to roll specific dice ' \
18
+ '(e.g. .roll 4d6 3d20)'
19
+
20
+ match(/dicebag\z/, method: :dicebag)
21
+ match(/dicebag stats/, method: :stats)
22
+ match /roll(?:\s(.*))/, method: :roll
23
+ match /roll\z/, method: :roll
24
+
25
+ def initialize(*args)
26
+ super
27
+ @storage = Cinch::Storage.new(config[:filename] || 'yaml/dice.yml')
28
+ @bag = Bag.new(4 => 250, 6 => 500, 10 => 750, 20 => 1000)
29
+ end
30
+
31
+ # Roll a random assortment of dice, total the rolls, and record the score.
32
+ # @param [String] nick Nickname of the user rolling.
33
+ # @param [Cinch::Channel] channel The Channel object where the roll took
34
+ # place.
35
+ # @return [String] A description of the roll that took place
36
+ def dicebag(m)
37
+ return if Cinch::Toolbox.sent_via_private_message?(m)
38
+
39
+ @bag.roll
40
+ user = m.user.nick.downcase
41
+ channel = m.channel.name
42
+ m.reply "#{m.user.nick} rolls a #{@bag.size} bag of dice totalling " \
43
+ "#{@bag.score}. #{score_check(user, channel, @bag.score)}"
44
+ end
45
+
46
+ def stats(m)
47
+ return if Cinch::Toolbox.sent_via_private_message?(m)
48
+
49
+ m.user.send 'Top ten dicebag rolls:'
50
+ top10 = top_ten_rolls(m.channel.name)
51
+ top10.each_with_index do |r, i|
52
+ m.user.send "#{i + 1} - #{r.first} [#{r.last}]"
53
+ end
54
+ end
55
+
56
+ # Roll a specific set of dice and return the pretty result
57
+ # @param [String] nick Nickname of the user rolling.
58
+ # @param [String] dice Space delimited string of dice to role.
59
+ # (i.e. '6d12 4d20 d10'
60
+ # @return [String] String describing the dice that were rolled
61
+ def roll(m, dice = '1d20')
62
+ result = Die.roll(dice.split(' '))
63
+ if result.is_a?(Integer)
64
+ result = "#{m.user.nick} rolls #{dice} totalling #{result}"
65
+ end
66
+ m.reply result
67
+ end
68
+
69
+ private
70
+
71
+ def top_ten_rolls(channel)
72
+ scores = @storage.data[channel].dup
73
+ scores.sort { |a, b| b[1][:score] <=> a[1][:score] }
74
+ .map { |s| [s.first, s.last[:score]] }[0..9]
75
+ end
76
+
77
+ # Score checker for Dicebag rolls. Checks a given user/channel/score
78
+ # against the current high score for that user.
79
+ # @param [String] nick Nickname of the user who rolled the score.
80
+ # @param [String] channel Name of the channel where the roll was made.
81
+ # @param [Fixnum] score The score from the bag.
82
+ # @return [String] If the new score is higher, returns an announcement
83
+ # to that effect, otherwise returns a blank string.
84
+ def score_check(nick, channel, score)
85
+ # If the chennel or nick are not already initialized, spin them up
86
+ @storage.data[channel] ||= {}
87
+ @storage.data[channel][nick] ||= { score: score, time: Time.now }
88
+
89
+ # Check and see if this is a higher score.
90
+ old = @storage.data[channel][nick]
91
+ return '' unless @storage.data[channel][nick][:score] < score
92
+
93
+ @storage.data[channel][nick] = { score: score, time: Time.now }
94
+ @storage.synced_save(@bot)
95
+ "A new high score! Their old high roll was #{old[:score]}, " \
96
+ "#{old[:time].ago.to_words}."
97
+ end
95
98
  end
96
99
  end
97
100
  end
@@ -1,46 +1,49 @@
1
- module Cinch::Plugins
2
- class Dicebag
3
- class Bag
4
- attr_accessor :count, :dice, :score
5
- def initialize(dice_hash)
6
- fail unless good_hash?(dice_hash)
7
- @dice = dice_hash
8
- @count = 0
9
- @score = 0
10
- end
1
+ module Cinch
2
+ module Plugins
3
+ class Dicebag
4
+ # Class to handle rolling of a preset bag of dice.
5
+ class Bag
6
+ attr_accessor :count, :dice, :score
7
+ def initialize(dice_hash)
8
+ fail unless good_hash?(dice_hash)
9
+ @dice = dice_hash
10
+ @count = 0
11
+ @score = 0
12
+ end
11
13
 
12
- def roll
13
- dice = die_array
14
- @score = Die.roll(dice)
15
- @count = dice.map { |d| d[/(\d+)d\d+/, 1].to_i || 1 }.inject(0, :+)
16
- end
14
+ def roll
15
+ dice = die_array
16
+ @score = Die.roll(dice)
17
+ @count = dice.map { |d| d[/(\d+)d\d+/, 1].to_i || 1 }.inject(0, :+)
18
+ end
17
19
 
18
- def good_hash?(dice_hash)
19
- dice_hash.keys { |k| return false unless k.is_a?(Integer) }
20
- dice_hash.values { |k| return false unless k.is_a?(Integer) }
21
- true
22
- end
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
24
+ end
23
25
 
24
- # Simple method to return a flavor text 'size' description based on
25
- # how many dice you happened to get in your dicebag roll.
26
- # @param [Fixnum] size The number of dice in the dicebag.
27
- # @return [String] Description of the size of the bag.
28
- def size
29
- case count
30
- when 0..100 then 'tiny'
31
- when 101..500 then 'small'
32
- when 501..1000 then 'medium'
33
- when 1001..1500 then 'large'
34
- when 1501..2000 then 'hefty'
35
- else 'huge'
26
+ # Simple method to return a flavor text 'size' description based on
27
+ # how many dice you happened to get in your dicebag roll.
28
+ # @param [Fixnum] size The number of dice in the dicebag.
29
+ # @return [String] Description of the size of the bag.
30
+ def size
31
+ case count
32
+ when 0..100 then 'tiny'
33
+ when 101..500 then 'small'
34
+ when 501..1000 then 'medium'
35
+ when 1001..1500 then 'large'
36
+ when 1501..2000 then 'hefty'
37
+ else 'huge'
38
+ end
36
39
  end
37
- end
38
40
 
39
- private
41
+ private
40
42
 
41
- def die_array
42
- @dice.keys.map do |sides|
43
- "#{sides}d#{@dice[sides]}"
43
+ def die_array
44
+ @dice.keys.map do |sides|
45
+ "#{sides}d#{@dice[sides]}"
46
+ end
44
47
  end
45
48
  end
46
49
  end
@@ -1,77 +1,87 @@
1
- module Cinch::Plugins
2
- class Dicebag
3
- module Die
4
- MOD_REGEX = /[\-\+]\d+/
5
- ROLLS_REGEX = /(\d+)d\d+/
6
- SIDES_REGEX = /\d?d(\d+)/
7
-
8
- # Takes a dice roll string or Array of dice rolls, sanitizes them, parses
9
- # them, and dispatches their calculation to `Die.cast`.
10
- # @param [Array] dice Array of strings that correspond to valid die rolls.
11
- # (i.e. ['4d6', '6d10']
12
- # @return [Fixnum] The total from rolling all of the dice.
13
- def self.roll(dice)
14
- # Convert to an array if it's a single die roll
15
- dice = [dice] if dice.is_a?(String)
16
-
17
- # Clean out anything invalid
18
- dice = clean_roll(dice)
19
-
20
- total = nil
21
-
22
- # Return if the sanity fails
23
- return 'I don\'t have that many dice in my bag!' unless die_check?(dice)
24
-
25
- # Roll each group and total up the returned value
26
- dice.each do |die|
27
- total ||= 0
28
- total += cast(die)
1
+ module Cinch
2
+ module Plugins
3
+ class Dicebag
4
+ # Module to manage the actuall roling of specific dice.
5
+ module Die
6
+ MOD_REGEX = /[\-\+]\d+/
7
+ ROLLS_REGEX = /(\d+)d\d+/
8
+ SIDES_REGEX = /\d?d(\d+)/
9
+
10
+ # Takes a dice roll string or Array of dice rolls, sanitizes them,
11
+ # parses them, and dispatches their calculation to `Die.cast`.
12
+ # @param [Array] dice Array of strings that correspond to valid die
13
+ # rolls. (i.e. ['4d6', '6d10']
14
+ # @return [Fixnum] The total from rolling all of the dice.
15
+ def self.roll(dice)
16
+ # Convert to an array if it's a single die roll
17
+ dice = [dice] if dice.is_a?(String)
18
+
19
+ # Clean out anything invalid
20
+ dice = clean_roll(dice)
21
+
22
+ total = nil
23
+
24
+ # Return if the sanity fails
25
+ return 'I don\'t have that many dice!' unless die_check?(dice)
26
+
27
+ # Roll each group and total up the returned value
28
+ dice.each do |die|
29
+ total ||= 0
30
+ total += cast(die)
31
+ end
32
+
33
+ total
29
34
  end
30
35
 
31
- total
32
- end
33
-
34
- private
36
+ private
35
37
 
36
- # Rolls an n-sided die a given amount of times and returns the total
37
- # @param [String] count Number of times to roll the die.
38
- # @return [Fixnum] The total from rolling the die.
39
- def self.cast(die)
40
- modifier = die[MOD_REGEX]
38
+ # Rolls an n-sided die a given amount of times and returns the total
39
+ # @param [String] count Number of times to roll the die.
40
+ # @return [Fixnum] The total from rolling the die.
41
+ def self.cast(die)
42
+ modifier = die[MOD_REGEX]
43
+ count = (die[ROLLS_REGEX, 1] || 1).to_i
44
+ sides = die[SIDES_REGEX, 1].to_i
41
45
 
42
- count = (die[ROLLS_REGEX, 1] || 1).to_i
43
- sides = die[SIDES_REGEX, 1].to_i
46
+ total = 0
47
+ return total unless check_die_sanity(count, sides)
44
48
 
45
- return 0 if count.nil? || sides.nil? || sides < 1 || count < 1
49
+ count.times { total += rand(sides) + 1 }
46
50
 
47
- total = 0
48
- count.times { total += rand(sides) + 1 }
51
+ return total += parse_modifier(modifier) unless modifier.nil?
49
52
 
50
- return total += parse_modifier(modifier) unless modifier.nil?
53
+ total
54
+ end
51
55
 
52
- total
53
- end
56
+ def self.check_die_sanity(count, sides)
57
+ return false if count.nil? || sides.nil? || sides < 1 || count < 1
58
+ true
59
+ end
54
60
 
55
- def self.clean_roll(dice)
56
- dice.delete_if { |d| d.match(/\d*d\d+([\-\+]\d+)?/).nil? }
57
- dice
58
- end
61
+ def self.clean_roll(dice)
62
+ dice.delete_if { |d| d.match(/\d*d\d+([\-\+]\d+)?/).nil? }
63
+ dice
64
+ end
59
65
 
60
- # Takes an array of rolls and does sanity on it.
61
- # @param [Array] dice Array of strings that correspond to valid die rolls.
62
- # (i.e. ['4d6', '6d10']
63
- # @return [Boolean] Result of sanity check.
64
- def self.die_check?(dice_list)
65
- # Check to make sure it's not a stupid large roll, they clog threads.
66
- count = dice_list.map { |d| d[/(\d+)d\d+/, 1].to_i || 1 }.inject(0, :+)
67
- return false if count >= 10_000
68
- true
69
- end
66
+ # Takes an array of rolls and does sanity on it.
67
+ # @param [Array] dice Array of strings that correspond to valid
68
+ # die rolls. (i.e. ['4d6', '6d10']
69
+ # @return [Boolean] Result of sanity check.
70
+ def self.die_check?(dice_list)
71
+ # 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, :+)
76
+ return false if count >= 10_000
77
+ true
78
+ end
70
79
 
71
- def self.parse_modifier(modifier)
72
- operator = modifier[/\A[\+\-]/]
73
- int = modifier[/\d+\z/].to_i
74
- 0.send(operator, int)
80
+ def self.parse_modifier(modifier)
81
+ operator = modifier[/\A[\+\-]/]
82
+ int = modifier[/\d+\z/].to_i
83
+ 0.send(operator, int)
84
+ end
75
85
  end
76
86
  end
77
87
  end
@@ -2,6 +2,6 @@
2
2
  module Cinch
3
3
  # Versioning information for plugin
4
4
  module Dicebag
5
- VERSION = '1.0.10'
5
+ VERSION = '1.0.11'
6
6
  end
7
7
  end
@@ -9,80 +9,82 @@ describe Cinch::Plugins::Dicebag do
9
9
 
10
10
  describe 'rolling specific dice' do
11
11
  it 'should return a roll from rolling dice' do
12
- get_replies(make_message(@bot, '!roll 3d3', { nick: 'ted' })).first.
13
- should_not be_nil
12
+ message = get_replies(make_message(@bot, '!roll 3d3', { nick: 'ted' }))
13
+ expect(message.first)
14
+ .to_not be_nil
14
15
  end
15
16
 
16
17
  it 'should return a roll from using a blank roll' do
17
- get_replies(make_message(@bot, '!roll', { nick: 'ted' })).first.
18
- should_not be_nil
18
+ expect(get_replies(make_message(@bot, '!roll', { nick: 'ted' })).first)
19
+ .to_not be_nil
19
20
  end
20
21
 
21
22
  it 'should allow "+" modifiers' do
22
- roll = get_replies(make_message(@bot, '!roll 1d3+5', { nick: 'ted' })).first.text
23
+ roll = get_replies(make_message(@bot, '!roll 1d3+5', { nick: 'ted' }))
24
+ .first.text
23
25
  roll = roll[/totalling (\d+)/, 1]
24
- (6..8).should include roll.to_i
26
+ expect(6..8).to include(roll.to_i)
25
27
  end
26
28
 
27
29
  it 'should allow "-" modifiers' do
28
30
  roll = get_replies(make_message(@bot, '!roll 1d1-5', { nick: 'ted' }))
29
31
  .first
30
32
  .text[/totalling (\-?\d+)/, 1].to_i
31
- .should == -4
33
+ expect(roll).to eq(-4)
32
34
  end
33
35
 
34
36
  it 'should return a roll in bounds from rolling dice' do
35
37
  roll = get_replies(make_message(@bot, '!roll 3d3', { nick: 'ted' })).first.text
36
38
  roll = roll[/totalling (\d+)/, 1]
37
- (3..9).should include roll.to_i
39
+ expect(3..9).to include(roll.to_i)
38
40
  end
39
41
 
40
42
  it 'should disallow rolling stupid numbers of dice' do
41
- get_replies(make_message(@bot, '!roll 100001d20', { nick: 'ted' })).first.
42
- should include 'I don\'t have that many dice in my bag!'
43
+ expect(get_replies(make_message(@bot, '!roll 100001d20', { nick: 'ted' })).first.text)
44
+ .to include('I don\'t have that many dice!')
43
45
  end
44
46
 
45
47
  it 'should disallow rolling stupid numbers of dice (multiple dice types)' do
46
- get_replies(make_message(@bot, '!roll 5000d3 5000d20 1d30', { nick: 'ted' })).first.
47
- should include 'I don\'t have that many dice in my bag!'
48
+ expect(get_replies(make_message(@bot, '!roll 5000d3 5000d20 1d30', { nick: 'ted' })).first.text)
49
+ .to include('I don\'t have that many dice!')
48
50
  end
49
51
 
50
52
  it 'should return a roll from rolling mixes of dice' do
51
- get_replies(make_message(@bot, '!roll 3d3 d7 3d21', { nick: 'ted' })).first.
52
- should_not be_nil
53
+ expect(get_replies(make_message(@bot, '!roll 3d3 d7 3d21', { nick: 'ted' })).first)
54
+ .to_not be_nil
53
55
  end
54
56
 
55
57
  it 'should return a roll in bounds from rolling mixes of dice' do
56
58
  roll = get_replies(make_message(@bot, '!roll 3d3 d7 3d21', { nick: 'ted' })).first.text
57
59
  roll = roll[/totalling (\d+)/, 1]
58
- (7..79).should include roll.to_i
60
+ expect(7..79).to include(roll.to_i)
59
61
  end
60
62
 
61
63
  it 'should return a roll from rolling a single die' do
62
- get_replies(make_message(@bot, '!roll d3', { nick: 'ted' })).first.
63
- should_not be_nil
64
+ expect(get_replies(make_message(@bot, '!roll d3', { nick: 'ted' })).first)
65
+ .to_not be_nil
64
66
  end
65
67
 
66
68
  it 'should return a string describing the dice that were rolled' do
67
69
  text = get_replies(make_message(@bot, '!roll 3d3', { nick: 'ted' })).first.text
68
- text.should match(/rolls\s3d3\stotalling\s\d+/)
70
+ expect(text).to match(/rolls\s3d3\stotalling\s\d+/)
69
71
  end
70
72
  end
71
73
 
72
74
  describe 'roll_dicebag' do
73
75
  it 'should return a string' do
74
- get_replies(make_message(@bot, '!dicebag' , { nick: 'ted', channel: '#bar' })).first.
75
- should_not be_nil
76
+ expect(get_replies(make_message(@bot, '!dicebag' , { nick: 'ted', channel: '#bar' })).first)
77
+ .to_not be_nil
76
78
  end
77
79
 
78
80
  it 'should return an error if the user is not in a channel' do
79
- get_replies(make_message(@bot, '!dicebag' , { nick: 'ted' })).first.text.
80
- should == 'You must use that command in the main channel.'
81
+ expect(get_replies(make_message(@bot, '!dicebag' , { nick: 'ted' })).first.text)
82
+ .to eq('You must use that command in the main channel.')
81
83
  end
82
84
 
83
85
  it 'should return a string describing the user\'s bag roll' do
84
- get_replies(make_message(@bot, '!dicebag' , { nick: 'ted', channel: '#bar' })).first.text.
85
- should match(/ted rolls a [a-z]+ bag of dice totalling \d+/)
86
+ expect(get_replies(make_message(@bot, '!dicebag' , { nick: 'ted', channel: '#bar' })).first.text)
87
+ .to match(/ted rolls a [a-z]+ bag of dice totalling \d+/)
86
88
  end
87
89
  end
88
90
 
@@ -107,59 +109,59 @@ describe Cinch::Plugins::Dicebag do
107
109
 
108
110
  it 'should announce a high score if the old score is higher' do
109
111
  text = get_replies(make_message(@bot, '!dicebag' , { nick: 'brian', channel: '#foo' })).first.text
110
- text.should match(/A new high score/)
111
- text.should match(/Their old high roll was \d+/)
112
+ expect(text).to match(/A new high score/)
113
+ expect(text).to match(/Their old high roll was \d+/)
112
114
  end
113
115
 
114
116
  it 'should allow users to get a copy of the high scores' do
115
117
  replies = get_replies(make_message(@bot, '!dicebag stats' , { nick: 'brian', channel: '#foo' }))
116
- replies[1].text.should == '1 - omega [15]'
117
- replies[5].text.should == '5 - grill [11]'
118
+ expect(replies[1].text).to eq('1 - omega [15]')
119
+ expect(replies[5].text).to eq('5 - grill [11]')
118
120
  end
119
121
 
120
122
  it 'should only show the first 10 scores' do
121
123
  replies = get_replies(make_message(@bot, '!dicebag stats' , { nick: 'brian', channel: '#foo' }))
122
- replies.length.should == 11
124
+ expect(replies.length).to eq(11)
123
125
  end
124
126
  end
125
127
 
126
128
  describe 'roll_dice' do
127
129
  it 'should return nil if the dice list is empty' do
128
- Cinch::Plugins::Dicebag::Die.roll([]).should be_nil
130
+ expect(Cinch::Plugins::Dicebag::Die.roll([])).to be_nil
129
131
  end
130
132
 
131
133
  it 'should return a non zero total on a normal dice list' do
132
- Cinch::Plugins::Dicebag::Die.roll(['3d3', '4d5']).should_not be_zero
134
+ expect(Cinch::Plugins::Dicebag::Die.roll(['3d3', '4d5'])).to_not be_zero
133
135
  end
134
136
 
135
137
  it 'should clear out any invalid dice rolls' do
136
- Cinch::Plugins::Dicebag::Die.roll(['33']).should be_nil
138
+ expect(Cinch::Plugins::Dicebag::Die.roll(['33'])).to be_nil
137
139
  end
138
140
 
139
141
  it 'should allow modifiers' do
140
- Cinch::Plugins::Dicebag::Die.roll(['1d1+1', '1d1-4']).should == -1
142
+ expect(Cinch::Plugins::Dicebag::Die.roll(['1d1+1', '1d1-4'])).to eq(-1)
141
143
  end
142
144
  end
143
145
 
144
146
  describe 'Die.roll' do
145
147
  it 'should return an acceptable value for a given roll' do
146
- Cinch::Plugins::Dicebag::Die.roll('1d1').should == 1
147
- (3..15).should include(Cinch::Plugins::Dicebag::Die.roll('3d5'))
148
+ expect(Cinch::Plugins::Dicebag::Die.roll('1d1')).to eq(1)
149
+ expect(3..15).to include(Cinch::Plugins::Dicebag::Die.roll('3d5'))
148
150
  end
149
151
 
150
152
  it 'should return nil for any negetive values' do
151
- Cinch::Plugins::Dicebag::Die.roll('1d-1').should == nil
152
- Cinch::Plugins::Dicebag::Die.roll('-1d-1').should == nil
153
+ expect(Cinch::Plugins::Dicebag::Die.roll('1d-1')).to eq(nil)
154
+ expect(Cinch::Plugins::Dicebag::Die.roll('-1d-1')).to eq(nil)
153
155
  end
154
156
 
155
157
  it 'should add modifiers to the total' do
156
- Cinch::Plugins::Dicebag::Die.roll('1d1+2').should == 3
157
- Cinch::Plugins::Dicebag::Die.roll('3d1-2').should == 1
158
+ expect(Cinch::Plugins::Dicebag::Die.roll('1d1+2')).to eq(3)
159
+ expect(Cinch::Plugins::Dicebag::Die.roll('3d1-2')).to eq(1)
158
160
  end
159
161
 
160
162
  it 'should allow modifiers to take the total below zero' do
161
- Cinch::Plugins::Dicebag::Die.roll('1d1-1').should == 0
162
- Cinch::Plugins::Dicebag::Die.roll('1d1-2').should == -1
163
+ expect(Cinch::Plugins::Dicebag::Die.roll('1d1-1')).to eq(0)
164
+ expect(Cinch::Plugins::Dicebag::Die.roll('1d1-2')).to eq(-1)
163
165
  end
164
166
  end
165
167
 
@@ -170,92 +172,92 @@ describe Cinch::Plugins::Dicebag do
170
172
 
171
173
  it 'should return \'huge\' for out of bounds queries' do
172
174
  @bag.count = 50000
173
- @bag.size.should == 'huge'
175
+ expect(@bag.size).to eq('huge')
174
176
  end
175
177
 
176
178
  it 'should return the proper size for tiny range' do
177
179
  @bag.count = 0
178
- @bag.size.should == 'tiny'
180
+ expect(@bag.size).to eq('tiny')
179
181
  end
180
182
 
181
183
  it 'should return the proper size for small range' do
182
184
  @bag.count = rand(100)
183
- @bag.size.should == 'tiny'
185
+ expect(@bag.size).to eq('tiny')
184
186
  end
185
187
 
186
188
  it 'should return the proper size for small range' do
187
189
  @bag.count = 100
188
- @bag.size.should == 'tiny'
190
+ expect(@bag.size).to eq('tiny')
189
191
  end
190
192
 
191
193
  it 'should return the proper size for small range' do
192
194
  @bag.count = 101
193
- @bag.size.should == 'small'
195
+ expect(@bag.size).to eq('small')
194
196
  end
195
197
 
196
198
  it 'should return the proper size for small range' do
197
199
  @bag.count = rand(399) + 101
198
- @bag.size.should == 'small'
200
+ expect(@bag.size).to eq('small')
199
201
  end
200
202
 
201
203
  it 'should return the proper size for small range' do
202
204
  @bag.count = 500
203
- @bag.size.should == 'small'
205
+ expect(@bag.size).to eq('small')
204
206
  end
205
207
 
206
208
  it 'should return the proper size for medium range' do
207
209
  @bag.count = 501
208
- @bag.size.should == 'medium'
210
+ expect(@bag.size).to eq('medium')
209
211
  end
210
212
 
211
213
  it 'should return the proper size for medium range' do
212
214
  @bag.count = rand(499) + 501
213
- @bag.size.should == 'medium'
215
+ expect(@bag.size).to eq('medium')
214
216
  end
215
217
 
216
218
  it 'should return the proper size for medium range' do
217
219
  @bag.count = 1000
218
- @bag.size.should == 'medium'
220
+ expect(@bag.size).to eq('medium')
219
221
  end
220
222
 
221
223
  it 'should return the proper size for large range' do
222
224
  @bag.count = 1001
223
- @bag.size.should == 'large'
225
+ expect(@bag.size).to eq('large')
224
226
  end
225
227
 
226
228
  it 'should return the proper size for large range' do
227
229
  @bag.count = rand(499) + 1001
228
- @bag.size.should == 'large'
230
+ expect(@bag.size).to eq('large')
229
231
  end
230
232
 
231
233
  it 'should return the proper size for large range' do
232
234
  @bag.count = 1500
233
- @bag.size.should == 'large'
235
+ expect(@bag.size).to eq('large')
234
236
  end
235
237
 
236
238
  it 'should return the proper size for hefty range' do
237
239
  @bag.count = 1501
238
- @bag.size.should == 'hefty'
240
+ expect(@bag.size).to eq('hefty')
239
241
  end
240
242
 
241
243
  it 'should return the proper size for hefty range' do
242
244
  @bag.count = rand(499) + 1501
243
- @bag.size.should == 'hefty'
245
+ expect(@bag.size).to eq('hefty')
244
246
  end
245
247
 
246
248
  it 'should return the proper size for hefty range' do
247
249
  @bag.count = 2000
248
- @bag.size.should == 'hefty'
250
+ expect(@bag.size).to eq('hefty')
249
251
  end
250
252
 
251
253
  it 'should return the proper size for huge range' do
252
254
  @bag.count = 2001
253
- @bag.size.should == 'huge'
255
+ expect(@bag.size).to eq('huge')
254
256
  end
255
257
 
256
258
  it 'should return the proper size for huge range' do
257
259
  @bag.count = 20001
258
- @bag.size.should == 'huge'
260
+ expect(@bag.size).to eq('huge')
259
261
  end
260
262
  end
261
263
  end
metadata CHANGED
@@ -1,103 +1,98 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-dicebag
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
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-07-22 00:00:00.000000000 Z
11
+ date: 2014-07-30 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
- version: '0'
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
- version: '0'
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
- version: '0'
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
- version: '0'
40
+ version: '3'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: coveralls
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '0.7'
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'
54
+ version: '0.7'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: cinch-test
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
59
62
  - - ! '>='
60
63
  - !ruby/object:Gem::Version
61
- version: '0'
64
+ version: 0.1.0
62
65
  type: :development
63
66
  prerelease: false
64
67
  version_requirements: !ruby/object:Gem::Requirement
65
68
  requirements:
66
- - - ! '>='
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: cinch
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ! '>='
69
+ - - ~>
74
70
  - !ruby/object:Gem::Version
75
- version: 2.0.12
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
71
+ version: '0.1'
80
72
  - - ! '>='
81
73
  - !ruby/object:Gem::Version
82
- version: 2.0.12
74
+ version: 0.1.0
83
75
  - !ruby/object:Gem::Dependency
84
- name: time-lord
76
+ name: cinch
85
77
  requirement: !ruby/object:Gem::Requirement
86
78
  requirements:
87
79
  - - ~>
88
80
  - !ruby/object:Gem::Version
89
- version: 1.0.1
81
+ version: '2'
90
82
  type: :runtime
91
83
  prerelease: false
92
84
  version_requirements: !ruby/object:Gem::Requirement
93
85
  requirements:
94
86
  - - ~>
95
87
  - !ruby/object:Gem::Version
96
- version: 1.0.1
88
+ version: '2'
97
89
  - !ruby/object:Gem::Dependency
98
90
  name: cinch-cooldown
99
91
  requirement: !ruby/object:Gem::Requirement
100
92
  requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: '1.1'
101
96
  - - ! '>='
102
97
  - !ruby/object:Gem::Version
103
98
  version: 1.1.1
@@ -105,6 +100,9 @@ dependencies:
105
100
  prerelease: false
106
101
  version_requirements: !ruby/object:Gem::Requirement
107
102
  requirements:
103
+ - - ~>
104
+ - !ruby/object:Gem::Version
105
+ version: '1.1'
108
106
  - - ! '>='
109
107
  - !ruby/object:Gem::Version
110
108
  version: 1.1.1
@@ -114,28 +112,28 @@ dependencies:
114
112
  requirements:
115
113
  - - ~>
116
114
  - !ruby/object:Gem::Version
117
- version: 1.1.0
115
+ version: '1.1'
118
116
  type: :runtime
119
117
  prerelease: false
120
118
  version_requirements: !ruby/object:Gem::Requirement
121
119
  requirements:
122
120
  - - ~>
123
121
  - !ruby/object:Gem::Version
124
- version: 1.1.0
122
+ version: '1.1'
125
123
  - !ruby/object:Gem::Dependency
126
124
  name: cinch-toolbox
127
125
  requirement: !ruby/object:Gem::Requirement
128
126
  requirements:
129
127
  - - ~>
130
128
  - !ruby/object:Gem::Version
131
- version: 1.1.0
129
+ version: '1.1'
132
130
  type: :runtime
133
131
  prerelease: false
134
132
  version_requirements: !ruby/object:Gem::Requirement
135
133
  requirements:
136
134
  - - ~>
137
135
  - !ruby/object:Gem::Version
138
- version: 1.1.0
136
+ version: '1.1'
139
137
  description: Cinch Plugin that allows uses in the channel to roll specific dice or
140
138
  roll a random assortment of dice to compete for high scores.
141
139
  email: