cinch-dicebag 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1,3 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  require 'cinch/plugins/dicebag/version'
2
- require 'cinch/plugins/dicebag/dicebag'
3
+ require 'cinch/plugins/dicebag'
@@ -5,8 +5,8 @@ require 'cinch/cooldown'
5
5
  require 'cinch-storage'
6
6
  require 'time-lord'
7
7
 
8
-
9
8
  module Cinch::Plugins
9
+ # Cinch Plugin to allow dice rolling.
10
10
  class Dicebag
11
11
  include Cinch::Plugin
12
12
 
@@ -14,7 +14,9 @@ module Cinch::Plugins
14
14
 
15
15
  attr_accessor :storage
16
16
 
17
- self.help = "Roll a random bag of dice with .dicebag, you can also use .roll (dice count)d(sides) to roll specific dice (e.g. '.roll 4d6 3d20')"
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)'
18
20
 
19
21
  match /dicebag/, method: :roll_dicebag
20
22
  match /roll (.*)/, method: :roll
@@ -26,26 +28,22 @@ module Cinch::Plugins
26
28
 
27
29
  # Roll a random assortment of dice, total the rolls, and record the score.
28
30
  # @param [String] nick Nickname of the user rolling.
29
- # @param [Cinch::Channel] channel The Channel object where the roll took place.
31
+ # @param [Cinch::Channel] channel The Channel object where the roll took
32
+ # place.
30
33
  # @return [String] A description of the roll that took place
31
34
  def roll_dicebag(m)
32
35
  if m.channel.nil?
33
- m.reply "You must use that command in the main channel."
36
+ m.reply 'You must use that command in the main channel'
34
37
  return
35
38
  end
36
39
 
37
- nick = m.user.nick
38
- channel = m.channel.name
39
-
40
40
  dice = { d4: rand(250), d6: rand(500), d10: rand(750), d20: rand(1000) }
41
-
42
41
  total = roll_dice(dice.map { |die, count| "#{count}#{die}" })
43
42
  size = get_bag_size(dice.values.inject(:+))
44
43
 
45
- message = "#{nick} rolls a #{size} bag of dice totalling #{total}. " +
46
- score_check(nick.downcase, channel, total)
47
-
48
- m.reply message
44
+ m.reply "#{m.user.nick} rolls a #{size} bag of dice totalling " +
45
+ "#{total}. " +
46
+ score_check(m.user.nick.downcase, m.channel.name, total)
49
47
  end
50
48
 
51
49
  # Roll a specific set of dice and return the pretty result
@@ -58,10 +56,11 @@ module Cinch::Plugins
58
56
 
59
57
  result = roll_dice(dice.split(' '))
60
58
 
61
- m.reply "#{m.user.nick} rolls #{dice} totalling #{result}" unless result.nil?
59
+ unless result.nil?
60
+ m.reply "#{m.user.nick} rolls #{dice} totalling #{result}"
61
+ end
62
62
  end
63
63
 
64
-
65
64
  # Takes an Array of dice rolls, sanitizes them, parses them, and dispatches
66
65
  # their calculation to `roll_die`.
67
66
  # @param [Array] dice Array of strings that correspond to valid die rolls.
@@ -93,7 +92,7 @@ module Cinch::Plugins
93
92
  return 0 if sides < 1 || count < 1
94
93
  total = 0
95
94
  count.times { total += rand(sides) + 1 }
96
- return total
95
+ total
97
96
  end
98
97
 
99
98
  # Simple method to return a flavor text 'size' description based on
@@ -102,18 +101,12 @@ module Cinch::Plugins
102
101
  # @return [String] Description of the size of the bag.
103
102
  def get_bag_size(size)
104
103
  case size
105
- when 0..100
106
- 'tiny'
107
- when 101..500
108
- 'small'
109
- when 501..1000
110
- 'medium'
111
- when 1001..1500
112
- 'large'
113
- when 1501..2000
114
- 'hefty'
115
- else
116
- 'huge'
104
+ when 0..100 then 'tiny'
105
+ when 101..500 then 'small'
106
+ when 501..1000 then 'medium'
107
+ when 1001..1500 then 'large'
108
+ when 1501..2000 then 'hefty'
109
+ else 'huge'
117
110
  end
118
111
  end
119
112
 
@@ -126,18 +119,17 @@ module Cinch::Plugins
126
119
  # to that effect, otherwise returns a blank string.
127
120
  def score_check(nick, channel, score)
128
121
  # If the chennel or nick are not already initialized, spin them up
129
- @storage.data[channel] ||= Hash.new
130
- @storage.data[channel][nick] ||= { :score => score, :time => Time.now }
122
+ @storage.data[channel] ||= {}
123
+ @storage.data[channel][nick] ||= { score: score, time: Time.now }
131
124
 
132
125
  # Check and see if this is a higher score.
133
126
  old = @storage.data[channel][nick]
134
- if @storage.data[channel][nick][:score] < score
135
- @storage.data[channel][nick] = { :score => score, :time => Time.now }
136
- @storage.synced_save(@bot)
137
- return "A new high score! Their old high roll was #{old[:score]}, #{old[:time].ago.to_words}."
138
- else
139
- return ''
140
- end
127
+ return '' unless @storage.data[channel][nick][:score] < score
128
+
129
+ @storage.data[channel][nick] = { score: score, time: Time.now }
130
+ @storage.synced_save(@bot)
131
+ "A new high score! Their old high roll was #{old[:score]}, " +
132
+ "#{old[:time].ago.to_words}."
141
133
  end
142
134
  end
143
135
  end
@@ -1,5 +1,7 @@
1
+ # -*- encoding : utf-8 -*-
1
2
  module Cinch
3
+ # Versioning information for plugin
2
4
  module Dicebag
3
- VERSION = "1.0.3"
5
+ VERSION = '1.0.4'
4
6
  end
5
7
  end
@@ -54,7 +54,7 @@ describe Cinch::Plugins::Dicebag do
54
54
 
55
55
  it "should return an error if the user is not in a channel" do
56
56
  get_replies(make_message(@bot, '!dicebag' , { nick: 'ted' })).first.text.
57
- should be_eql("You must use that command in the main channel.")
57
+ should be_eql("You must use that command in the main channel")
58
58
  end
59
59
 
60
60
  it "should return a string describing the user's bag roll" do
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.3
4
+ version: 1.0.4
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-07-09 00:00:00.000000000 Z
12
+ date: 2013-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -171,7 +171,7 @@ files:
171
171
  - Rakefile
172
172
  - cinch-dicebag.gemspec
173
173
  - lib/cinch-dicebag.rb
174
- - lib/cinch/plugins/dicebag/dicebag.rb
174
+ - lib/cinch/plugins/dicebag.rb
175
175
  - lib/cinch/plugins/dicebag/version.rb
176
176
  - spec/cinch-dicebag_spec.rb
177
177
  - spec/spec_helper.rb
@@ -202,3 +202,4 @@ summary: ! 'Cinch Plugin: Dicebag and Dice rolls'
202
202
  test_files:
203
203
  - spec/cinch-dicebag_spec.rb
204
204
  - spec/spec_helper.rb
205
+ has_rdoc: