cinch-dicebag 1.0.0 → 1.0.1

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.
@@ -5,6 +5,7 @@ require 'cinch-cooldown'
5
5
  require 'cinch-storage'
6
6
  require 'time-lord'
7
7
 
8
+
8
9
  module Cinch::Plugins
9
10
  class Dicebag
10
11
  include Cinch::Plugin
@@ -27,6 +28,10 @@ module Cinch::Plugins
27
28
  m.reply (dice.nil? ? roll_dicebag(m.user.nick, m.channel) : roll(m.user.nick, dice))
28
29
  end
29
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 place.
34
+ # @return [String] A description of the roll that took place
30
35
  def roll_dicebag(nick, channel)
31
36
  return "You must use that command in the main channel." if channel.nil?
32
37
 
@@ -41,6 +46,11 @@ module Cinch::Plugins
41
46
  return message
42
47
  end
43
48
 
49
+ # Roll a specific set of dice and return the pretty result
50
+ # @param [String] nick Nickname of the user rolling.
51
+ # @param [String] dice Space delimited string of dice to role.
52
+ # (i.e. '6d12 4d20 d10'
53
+ # @return [String] String describing the dice that were rolled
44
54
  def roll(nick, dice)
45
55
  return nil if dice.nil? || nick.nil?
46
56
 
@@ -49,13 +59,12 @@ module Cinch::Plugins
49
59
  return "#{nick} rolls #{dice} totalling #{result}" unless result.nil?
50
60
  end
51
61
 
52
- def roll_die(sides, count)
53
- return 0 if sides < 1 || count < 1
54
- total = 0
55
- count.times { total += rand(sides) + 1 }
56
- return total
57
- end
58
62
 
63
+ # Takes an Array of dice rolls, sanitizes them, parses them, and dispatches
64
+ # their calculation to `roll_die`.
65
+ # @param [Array] dice Array of strings that correspond to valid die rolls.
66
+ # (i.e. ['4d6', '6d10']
67
+ # @return [Fixnum] The total from rolling all of the dice.
59
68
  def roll_dice(dice)
60
69
  # Clean out anything invalid
61
70
  dice.delete_if { |d| d.match(/\d*d\d+/).nil? }
@@ -74,6 +83,21 @@ module Cinch::Plugins
74
83
  return total
75
84
  end
76
85
 
86
+ # Rolls an n-sided die a given amount of times and returns the total
87
+ # @param [Fixnum] sides Number of sides of the die we're rolling.
88
+ # @param [Fixnum] count Number of times to roll the die.
89
+ # @return [Fixnum] The total from rolling the die.
90
+ def roll_die(sides, count)
91
+ return 0 if sides < 1 || count < 1
92
+ total = 0
93
+ count.times { total += rand(sides) + 1 }
94
+ return total
95
+ end
96
+
97
+ # Simple method to return a flavor text 'size' description based on
98
+ # how many dice you happened to get in your dicebag roll.
99
+ # @param [Fixnum] size The number of dice in the dicebag.
100
+ # @return [String] Description of the size of the bag.
77
101
  def get_bag_size(size)
78
102
  case size
79
103
  when 0..100
@@ -91,6 +115,13 @@ module Cinch::Plugins
91
115
  end
92
116
  end
93
117
 
118
+ # Score checker for Dicebag rolls. Checks a given user/channel/score
119
+ # against the current high score for that user.
120
+ # @param [String] nick Nickname of the user who rolled the score.
121
+ # @param [String] channel Name of the channel where the roll was made.
122
+ # @param [Fixnum] score The score from the bag.
123
+ # @return [String] If the new score is higher, returns an announcement
124
+ # to that effect, otherwise returns a blank string.
94
125
  def score_check(nick, channel, score)
95
126
  # If the chennel or nick are not already initialized, spin them up
96
127
  @storage.data[channel] ||= Hash.new
@@ -1,5 +1,5 @@
1
1
  module Cinch
2
2
  module Dicebag
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-dicebag
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-07 00:00:00.000000000 Z
12
+ date: 2013-06-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -186,3 +186,4 @@ summary: ! 'Cinch Plugin: Dicebag and Dice rolls'
186
186
  test_files:
187
187
  - spec/cinch-dicebag_spec.rb
188
188
  - spec/spec_helper.rb
189
+ has_rdoc: