Class: Cinch::Plugins::Dicebag
- Inherits:
-
Object
- Object
- Cinch::Plugins::Dicebag
- Includes:
- Cinch::Plugin
- Defined in:
- lib/cinch/plugins/dicebag.rb,
lib/cinch/plugins/dicebag/bag.rb,
lib/cinch/plugins/dicebag/die.rb
Overview
Cinch Plugin to allow dice rolling.
Defined Under Namespace
Instance Attribute Summary collapse
-
#storage ⇒ Object
Returns the value of attribute storage.
Instance Method Summary collapse
-
#dicebag(message) ⇒ String
Roll a random assortment of dice, total the rolls, and record the score.
-
#initialize(*args) ⇒ Dicebag
constructor
A new instance of Dicebag.
-
#roll(message, dice = '1d20') ⇒ String
Roll a specific set of dice and return the pretty result.
- #stats(message) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Dicebag
Returns a new instance of Dicebag.
27 28 29 30 31 32 33 34 35 |
# File 'lib/cinch/plugins/dicebag.rb', line 27 def initialize(*args) super # initialize storage @storage = Cinch::Storage.new(config[:filename] || 'yaml/dice.yml') # Create a bag of dice, pass a hash of the maxcount for each type # for random rolls. @bag = Bag.new(4 => 250, 6 => 750, 10 => 1500, 20 => 2000) end |
Instance Attribute Details
#storage ⇒ Object
Returns the value of attribute storage.
16 17 18 |
# File 'lib/cinch/plugins/dicebag.rb', line 16 def storage @storage end |
Instance Method Details
#dicebag(message) ⇒ String
Roll a random assortment of dice, total the rolls, and record the score.
40 41 42 43 44 45 46 47 48 |
# File 'lib/cinch/plugins/dicebag.rb', line 40 def dicebag() return if Cinch::Toolbox.() @bag.roll user = .user.nick channel = .channel.name .reply "#{user} rolls a #{@bag.size} bag of dice totalling " \ "#{@bag.score}. #{score_check(user, channel, @bag.score)}" end |
#roll(message, dice = '1d20') ⇒ String
Roll a specific set of dice and return the pretty result
65 66 67 68 69 70 71 |
# File 'lib/cinch/plugins/dicebag.rb', line 65 def roll(, dice = '1d20') result = Die.roll(dice.split(' ')) if result.is_a?(Integer) result = "#{message.user.nick} rolls #{dice} totalling #{result}" end .reply result end |
#stats(message) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/cinch/plugins/dicebag.rb', line 50 def stats() return if Cinch::Toolbox.() .user.send 'Top ten dicebag rolls:' top10 = top_ten_rolls(.channel.name) top10.each_with_index do |r, i| .user.send "#{i + 1} - #{r.first} [#{r.last}]" end end |