cinch-dicebag 1.0.10 → 1.0.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +12 -0
- data/cinch-dicebag.gemspec +12 -14
- data/lib/cinch/plugins/dicebag.rb +95 -87
- data/lib/cinch/plugins/dicebag/bag.rb +63 -37
- data/lib/cinch/plugins/dicebag/die.rb +78 -63
- data/lib/cinch/plugins/dicebag/version.rb +1 -1
- data/spec/cinch-dicebag_spec.rb +77 -75
- data/spec/spec_helper.rb +2 -8
- metadata +56 -59
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 737d5d1176e002405d852c856b4355a0c4454a548f20fef8e557ab6b566ccec9
|
4
|
+
data.tar.gz: 2d7035798fee93df2b368ec31db1ddd97c300e82514f12c0ad0f9a30faa4a876
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2da4e8c8a2aff23a3be079d2a4dcb0070d4ae5e21bf2364a4063b0c664b7d3a1f7ab4c9ecfca51688ff90cb92b42c6bb6aff5c1ee61381bfc1b1161ea76d6dd5
|
7
|
+
data.tar.gz: afa3c62c79b51daf4f36e9213a50ff4d4240d5484feb1070ef831aeda79086685836d9ff02726f87f8699663111ed3d8772e74b8396a5d7a5154aa2162aa0e7c
|
data/.travis.yml
CHANGED
@@ -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
|
data/cinch-dicebag.gemspec
CHANGED
@@ -8,24 +8,22 @@ 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
|
12
|
-
gem.summary = %q
|
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(
|
18
|
-
gem.test_files = gem.files.grep(
|
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
|
22
|
-
gem.add_development_dependency
|
23
|
-
gem.add_development_dependency
|
24
|
-
gem.add_development_dependency
|
20
|
+
gem.add_development_dependency 'rake', '~> 12.3.3'
|
21
|
+
gem.add_development_dependency 'rspec', '~> 3'
|
22
|
+
gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
|
23
|
+
gem.add_development_dependency 'cinch-test', '~> 0.1', '>= 0.1.1'
|
25
24
|
|
26
|
-
gem.add_dependency
|
27
|
-
gem.add_dependency
|
28
|
-
gem.add_dependency
|
29
|
-
gem.add_dependency
|
30
|
-
gem.add_dependency 'cinch-toolbox', '~> 1.1.0'
|
25
|
+
gem.add_dependency 'cinch', '~> 2'
|
26
|
+
gem.add_dependency 'cinch-cooldown', '~> 1.1', '>= 1.1.5'
|
27
|
+
gem.add_dependency 'cinch-storage', '~> 1.1'
|
28
|
+
gem.add_dependency 'cinch-toolbox', '~> 1.1'
|
31
29
|
end
|
@@ -5,93 +5,101 @@ require 'cinch/cooldown'
|
|
5
5
|
require 'cinch/storage'
|
6
6
|
require 'time-lord'
|
7
7
|
|
8
|
-
module Cinch
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
#
|
84
|
-
@
|
85
|
-
@
|
86
|
-
|
87
|
-
#
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
8
|
+
module Cinch
|
9
|
+
module Plugins
|
10
|
+
# Cinch Plugin to allow dice rolling.
|
11
|
+
class Dicebag
|
12
|
+
include Cinch::Plugin
|
13
|
+
|
14
|
+
enforce_cooldown
|
15
|
+
|
16
|
+
attr_accessor :storage
|
17
|
+
|
18
|
+
self.help = 'Roll a random bag of dice with .dicebag, you can also ' \
|
19
|
+
'use .roll (dice count)d(sides) to roll specific dice ' \
|
20
|
+
'(e.g. .roll 4d6 3d20)'
|
21
|
+
|
22
|
+
match(/dicebag\z/, method: :dicebag)
|
23
|
+
match(/dicebag stats/, method: :stats)
|
24
|
+
match(/roll(?:\s(.*))/, method: :roll)
|
25
|
+
match(/roll\z/, method: :roll)
|
26
|
+
|
27
|
+
def initialize(*args)
|
28
|
+
super
|
29
|
+
# initialize storage
|
30
|
+
@storage = Cinch::Storage.new(config[:filename] || 'yaml/dice.yml')
|
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)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Roll a random assortment of dice, total the rolls, and record the score.
|
38
|
+
# @param [Message] message Nickname of the user rolling.
|
39
|
+
# @return [String] A description of the roll that took place
|
40
|
+
def dicebag(message)
|
41
|
+
return if Cinch::Toolbox.sent_via_private_message?(message)
|
42
|
+
|
43
|
+
@bag.roll
|
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)}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def stats(message)
|
51
|
+
return if Cinch::Toolbox.sent_via_private_message?(message)
|
52
|
+
|
53
|
+
message.user.send 'Top ten dicebag rolls:'
|
54
|
+
top10 = top_ten_rolls(message.channel.name)
|
55
|
+
top10.each_with_index do |r, i|
|
56
|
+
message.user.send "#{i + 1} - #{r.first} [#{r.last}]"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Roll a specific set of dice and return the pretty result
|
61
|
+
# @param [String] nick Nickname of the user rolling.
|
62
|
+
# @param [String] dice Space delimited string of dice to role.
|
63
|
+
# (i.e. '6d12 4d20 d10'
|
64
|
+
# @return [String] String describing the dice that were rolled
|
65
|
+
def roll(message, dice = '1d20')
|
66
|
+
result = Die.roll(dice.split(' '))
|
67
|
+
if result.is_a?(Integer)
|
68
|
+
result = "#{message.user.nick} rolls #{dice} totalling #{result}"
|
69
|
+
end
|
70
|
+
message.reply result
|
71
|
+
end
|
72
|
+
|
73
|
+
private
|
74
|
+
|
75
|
+
def top_ten_rolls(channel)
|
76
|
+
scores = @storage.data[channel].dup
|
77
|
+
scores.sort { |a, b| b[1][:score] <=> a[1][:score] }
|
78
|
+
.map { |s| [s.first, s.last[:score]] }[0..9]
|
79
|
+
end
|
80
|
+
|
81
|
+
# Score checker for Dicebag rolls. Checks a given user/channel/score
|
82
|
+
# against the current high score for that user.
|
83
|
+
# @param [String] nick Nickname of the user who rolled the score.
|
84
|
+
# @param [String] channel Name of the channel where the roll was made.
|
85
|
+
# @param [Fixnum] score The score from the bag.
|
86
|
+
# @return [String] If the new score is higher, returns an announcement
|
87
|
+
# to that effect, otherwise returns a blank string.
|
88
|
+
def score_check(nick, channel, score)
|
89
|
+
nick = nick.downcase
|
90
|
+
# If the chennel or nick are not already initialized, spin them up
|
91
|
+
@storage.data[channel] ||= {}
|
92
|
+
@storage.data[channel][nick] ||= { score: score, time: Time.now }
|
93
|
+
|
94
|
+
# Check and see if this is a higher score.
|
95
|
+
old = @storage.data[channel][nick]
|
96
|
+
return '' unless @storage.data[channel][nick][:score] < score
|
97
|
+
|
98
|
+
@storage.data[channel][nick] = { score: score, time: Time.now }
|
99
|
+
@storage.synced_save(@bot)
|
100
|
+
"A new high score! Their old high roll was #{old[:score]}, " \
|
101
|
+
"#{old[:time].ago.to_words}."
|
102
|
+
end
|
95
103
|
end
|
96
104
|
end
|
97
105
|
end
|
@@ -1,46 +1,72 @@
|
|
1
|
-
module Cinch
|
2
|
-
|
3
|
-
class
|
4
|
-
|
5
|
-
|
6
|
-
|
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
|
11
7
|
|
12
|
-
|
13
|
-
dice
|
14
|
-
|
15
|
-
|
16
|
-
|
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.
|
12
|
+
def initialize(dice_hash)
|
13
|
+
fail unless good_hash?(dice_hash)
|
14
|
+
@dice = dice_hash
|
15
|
+
@count = 0
|
16
|
+
@score = 0
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
23
27
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
28
|
+
# Roll the bag of dice, this will roll the dice and update the current
|
29
|
+
# score and count
|
30
|
+
def roll
|
31
|
+
dice = die_array
|
32
|
+
@score = Die.roll(dice)
|
33
|
+
@count = dice.map { |d| d[/(\d+)d\d+/, 1].to_i || 1 }.inject(0, :+)
|
34
|
+
return self
|
35
|
+
end
|
36
|
+
|
37
|
+
# Simple method to return a flavor text 'size' description based on
|
38
|
+
# how many dice you happened to get in your dicebag roll.
|
39
|
+
# @param [Fixnum] size The number of dice in the dicebag.
|
40
|
+
# @return [String] Description of the size of the bag.
|
41
|
+
def size
|
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'
|
48
|
+
else 'massive'
|
49
|
+
end
|
36
50
|
end
|
37
|
-
end
|
38
51
|
|
39
|
-
|
52
|
+
private
|
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
|
40
62
|
|
41
|
-
|
42
|
-
|
43
|
-
|
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.
|
66
|
+
def die_array
|
67
|
+
@dice.keys.map do |sides|
|
68
|
+
"#{rand(@dice[sides] + 1)}d#{sides}"
|
69
|
+
end
|
44
70
|
end
|
45
71
|
end
|
46
72
|
end
|
@@ -1,77 +1,92 @@
|
|
1
|
-
module Cinch
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
#
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
total
|
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
|
+
# Initialize a total
|
23
|
+
total = nil
|
24
|
+
|
25
|
+
# Return if the sanity fails
|
26
|
+
return 'I don\'t have that many dice!' unless die_check?(dice)
|
27
|
+
|
28
|
+
# Roll each group and total up the returned value
|
29
|
+
dice.each do |die|
|
30
|
+
total ||= 0
|
31
|
+
total += cast(die)
|
32
|
+
end
|
33
|
+
|
34
|
+
total
|
29
35
|
end
|
30
36
|
|
31
|
-
total
|
32
|
-
|
33
|
-
|
34
|
-
|
37
|
+
# Rolls an n-sided die a given amount of times and returns the total
|
38
|
+
# @param [String] count Number of times to roll the die.
|
39
|
+
# @return [Fixnum] The total from rolling the die.
|
40
|
+
def self.cast(die)
|
41
|
+
# Pull out the data from the roll.
|
42
|
+
modifier = die[MOD_REGEX]
|
43
|
+
count = (die[ROLLS_REGEX, 1] || 1).to_i
|
44
|
+
sides = die[SIDES_REGEX, 1].to_i
|
35
45
|
|
36
|
-
|
37
|
-
|
38
|
-
# @return [Fixnum] The total from rolling the die.
|
39
|
-
def self.cast(die)
|
40
|
-
modifier = die[MOD_REGEX]
|
46
|
+
# init the total
|
47
|
+
total = 0
|
41
48
|
|
42
|
-
|
43
|
-
|
49
|
+
# Bail if the roll isn't sane looking.
|
50
|
+
return total unless check_die_sanity(count, sides)
|
44
51
|
|
45
|
-
|
52
|
+
# Roll dem dice!
|
53
|
+
count.times { total += rand(sides) + 1 }
|
46
54
|
|
47
|
-
|
48
|
-
|
55
|
+
# Parse the modifier and apply it, if there is one
|
56
|
+
return total += parse_modifier(modifier) unless modifier.nil?
|
49
57
|
|
50
|
-
|
58
|
+
total
|
59
|
+
end
|
51
60
|
|
52
|
-
|
53
|
-
|
61
|
+
# Makes sure people aren't doing silly things.
|
62
|
+
def self.check_die_sanity(count, sides)
|
63
|
+
return false if count.nil? || sides.nil? || sides < 1 || count < 1
|
64
|
+
true
|
65
|
+
end
|
54
66
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
67
|
+
# Remove any stupid crap people try to sneak into the rolls.
|
68
|
+
def self.clean_roll(dice)
|
69
|
+
dice.delete_if { |d| d.match(/\d*d\d+([\-\+]\d+)?/).nil? }
|
70
|
+
dice
|
71
|
+
end
|
59
72
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
73
|
+
# Takes an array of rolls and does sanity on it.
|
74
|
+
# @param [Array] dice Array of strings that correspond to valid
|
75
|
+
# die rolls. (i.e. ['4d6', '6d10']
|
76
|
+
# @return [Boolean] Result of sanity check.
|
77
|
+
def self.die_check?(dice)
|
78
|
+
# Check to make sure it's not a stupid large roll, they clog threads.
|
79
|
+
count = dice.map { |d| d[/(\d+)d\d+/, 1].to_i || 1 }.inject(0, :+)
|
80
|
+
return false if count >= 10_000
|
81
|
+
true
|
82
|
+
end
|
70
83
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
84
|
+
# Parse out the modified and return it as an int.
|
85
|
+
def self.parse_modifier(modifier)
|
86
|
+
operator = modifier[/\A[\+\-]/]
|
87
|
+
int = modifier[/\d+\z/].to_i
|
88
|
+
0.send(operator, int)
|
89
|
+
end
|
75
90
|
end
|
76
91
|
end
|
77
92
|
end
|
data/spec/cinch-dicebag_spec.rb
CHANGED
@@ -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' }))
|
13
|
-
|
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
|
-
|
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' }))
|
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).
|
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
|
-
|
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).
|
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
|
-
|
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
|
-
|
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
|
-
|
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).
|
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
|
-
|
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.
|
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
|
-
|
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
|
-
|
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
|
-
|
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.
|
111
|
-
text.
|
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.
|
117
|
-
replies[5].text.
|
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.
|
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([]).
|
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']).
|
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']).
|
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']).
|
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').
|
147
|
-
(3..15).
|
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').
|
152
|
-
Cinch::Plugins::Dicebag::Die.roll('-1d-1').
|
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').
|
157
|
-
Cinch::Plugins::Dicebag::Die.roll('3d1-2').
|
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').
|
162
|
-
Cinch::Plugins::Dicebag::Die.roll('1d1-2').
|
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.
|
175
|
+
expect(@bag.size).to eq('massive')
|
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.
|
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
|
-
@bag.count = rand(
|
183
|
-
@bag.size.
|
184
|
+
@bag.count = rand(1000)
|
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
|
-
@bag.count =
|
188
|
-
@bag.size.
|
189
|
+
@bag.count = 900
|
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
|
-
@bag.count =
|
193
|
-
@bag.size.
|
194
|
+
@bag.count = 1000
|
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
|
-
@bag.count = rand(
|
198
|
-
@bag.size.
|
199
|
+
@bag.count = rand(999) + 1000
|
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
|
-
@bag.count =
|
203
|
-
@bag.size.
|
204
|
+
@bag.count = 1999
|
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
|
-
@bag.count =
|
208
|
-
@bag.size.
|
209
|
+
@bag.count = 2500
|
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
|
-
@bag.count = rand(
|
213
|
-
@bag.size.
|
214
|
+
@bag.count = rand(999) + 2000
|
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
|
-
@bag.count =
|
218
|
-
@bag.size.
|
219
|
+
@bag.count = 2500
|
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
|
-
@bag.count =
|
223
|
-
@bag.size.
|
224
|
+
@bag.count = 3500
|
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
|
-
@bag.count = rand(
|
228
|
-
@bag.size.
|
229
|
+
@bag.count = rand(999) + 3000
|
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
|
-
@bag.count =
|
233
|
-
@bag.size.
|
234
|
+
@bag.count = 3500
|
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
|
-
@bag.count =
|
238
|
-
@bag.size.
|
239
|
+
@bag.count = 4500
|
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
|
-
@bag.count = rand(
|
243
|
-
@bag.size.
|
244
|
+
@bag.count = rand(999) + 4000
|
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
|
-
@bag.count =
|
248
|
-
@bag.size.
|
249
|
+
@bag.count = 4500
|
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
|
-
@bag.count =
|
253
|
-
@bag.size.
|
254
|
+
@bag.count = 5000
|
255
|
+
expect(@bag.size).to eq('massive')
|
254
256
|
end
|
255
257
|
|
256
258
|
it 'should return the proper size for huge range' do
|
257
|
-
@bag.count =
|
258
|
-
@bag.size.
|
259
|
+
@bag.count = 20000
|
260
|
+
expect(@bag.size).to eq('massive')
|
259
261
|
end
|
260
262
|
end
|
261
263
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,5 @@
|
|
1
|
-
require
|
2
|
-
|
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,141 +1,139 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch-dicebag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Haberer
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-27 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:
|
19
|
+
version: 12.3.3
|
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:
|
26
|
+
version: 12.3.3
|
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: '
|
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: '
|
40
|
+
version: '3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
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'
|
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'
|
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
|
-
version: '0'
|
61
|
+
version: '0.1'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 0.1.1
|
62
65
|
type: :development
|
63
66
|
prerelease: false
|
64
67
|
version_requirements: !ruby/object:Gem::Requirement
|
65
68
|
requirements:
|
66
|
-
- -
|
69
|
+
- - "~>"
|
67
70
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
-
|
70
|
-
name: cinch
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ! '>='
|
71
|
+
version: '0.1'
|
72
|
+
- - ">="
|
74
73
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ! '>='
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 2.0.12
|
74
|
+
version: 0.1.1
|
83
75
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
76
|
+
name: cinch
|
85
77
|
requirement: !ruby/object:Gem::Requirement
|
86
78
|
requirements:
|
87
|
-
- - ~>
|
79
|
+
- - "~>"
|
88
80
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
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:
|
88
|
+
version: '2'
|
97
89
|
- !ruby/object:Gem::Dependency
|
98
90
|
name: cinch-cooldown
|
99
91
|
requirement: !ruby/object:Gem::Requirement
|
100
92
|
requirements:
|
101
|
-
- -
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '1.1'
|
96
|
+
- - ">="
|
102
97
|
- !ruby/object:Gem::Version
|
103
|
-
version: 1.1.
|
98
|
+
version: 1.1.5
|
104
99
|
type: :runtime
|
105
100
|
prerelease: false
|
106
101
|
version_requirements: !ruby/object:Gem::Requirement
|
107
102
|
requirements:
|
108
|
-
- -
|
103
|
+
- - "~>"
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '1.1'
|
106
|
+
- - ">="
|
109
107
|
- !ruby/object:Gem::Version
|
110
|
-
version: 1.1.
|
108
|
+
version: 1.1.5
|
111
109
|
- !ruby/object:Gem::Dependency
|
112
110
|
name: cinch-storage
|
113
111
|
requirement: !ruby/object:Gem::Requirement
|
114
112
|
requirements:
|
115
|
-
- - ~>
|
113
|
+
- - "~>"
|
116
114
|
- !ruby/object:Gem::Version
|
117
|
-
version: 1.1
|
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
|
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
|
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
|
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:
|
@@ -144,8 +142,8 @@ executables: []
|
|
144
142
|
extensions: []
|
145
143
|
extra_rdoc_files: []
|
146
144
|
files:
|
147
|
-
- .gitignore
|
148
|
-
- .travis.yml
|
145
|
+
- ".gitignore"
|
146
|
+
- ".travis.yml"
|
149
147
|
- Gemfile
|
150
148
|
- LICENSE.txt
|
151
149
|
- README.md
|
@@ -162,26 +160,25 @@ homepage: https://github.com/bhaberer/cinch-dicebag
|
|
162
160
|
licenses:
|
163
161
|
- MIT
|
164
162
|
metadata: {}
|
165
|
-
post_install_message:
|
163
|
+
post_install_message:
|
166
164
|
rdoc_options: []
|
167
165
|
require_paths:
|
168
166
|
- lib
|
169
167
|
required_ruby_version: !ruby/object:Gem::Requirement
|
170
168
|
requirements:
|
171
|
-
- -
|
169
|
+
- - ">="
|
172
170
|
- !ruby/object:Gem::Version
|
173
171
|
version: '0'
|
174
172
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
173
|
requirements:
|
176
|
-
- -
|
174
|
+
- - ">="
|
177
175
|
- !ruby/object:Gem::Version
|
178
176
|
version: '0'
|
179
177
|
requirements: []
|
180
|
-
|
181
|
-
|
182
|
-
signing_key:
|
178
|
+
rubygems_version: 3.2.6
|
179
|
+
signing_key:
|
183
180
|
specification_version: 4
|
184
|
-
summary:
|
181
|
+
summary: 'Cinch Plugin: Dicebag and Dice rolls'
|
185
182
|
test_files:
|
186
183
|
- spec/cinch-dicebag_spec.rb
|
187
184
|
- spec/spec_helper.rb
|