cinch-dicebag 0.0.1 → 0.0.2
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.
- data/README.md +1 -1
- data/lib/cinch/plugins/dicebag/dicebag.rb +33 -25
- data/lib/cinch/plugins/dicebag/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -33,29 +33,29 @@ module Cinch::Plugins
|
|
33
33
|
return
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
36
|
+
dice = { :d4 => rand(250), :d6 => rand(500), :d10 => rand(750), :d20 => rand(1000) }
|
37
|
+
result = roll_dice(dice.map { |die, count| "#{count}#{die}" })
|
38
|
+
|
39
|
+
total = dice.values.inject(:+)
|
40
|
+
size = case total
|
41
|
+
when 0..100
|
42
|
+
'tiny'
|
43
|
+
when 101..500
|
44
|
+
'small'
|
45
|
+
when 501..1000
|
46
|
+
'medium'
|
47
|
+
when 1001..1500
|
48
|
+
'large'
|
49
|
+
when 1501..2000
|
50
|
+
'hefty'
|
51
|
+
else
|
52
|
+
'huge'
|
53
|
+
end
|
55
54
|
|
56
55
|
m.reply "#{m.user.nick} rolls a #{size} bag of dice totalling #{result[:total]}."
|
57
56
|
|
58
57
|
channel = m.channel.name
|
58
|
+
nick = m.user.nick.downcase
|
59
59
|
|
60
60
|
unless @storage.data.key?(channel)
|
61
61
|
@storage.data[channel] = Hash.new
|
@@ -72,16 +72,18 @@ module Cinch::Plugins
|
|
72
72
|
m.reply "This is a new high score, their old score was #{old[:score]}, #{old[:time].ago.to_words}."
|
73
73
|
end
|
74
74
|
|
75
|
-
# Keep an eye on this and only do it on changes if it becomes a perf issue.
|
76
75
|
synchronize(:dice_save) do
|
77
76
|
@storage.save
|
78
77
|
end
|
79
78
|
end
|
80
79
|
|
81
80
|
def roll_specific(m, bag)
|
82
|
-
result = roll_dice(bag)
|
83
|
-
|
84
|
-
|
81
|
+
result = roll_dice(bag.split(' '))
|
82
|
+
if result.nil?
|
83
|
+
m.reply "I'm sorry that's not the right way to roll dice.", true
|
84
|
+
else
|
85
|
+
m.reply "#{m.user.nick} rolls #{result[:rolls].join(', ')} totalling #{result[:total]}"
|
86
|
+
end
|
85
87
|
end
|
86
88
|
|
87
89
|
private
|
@@ -89,7 +91,9 @@ module Cinch::Plugins
|
|
89
91
|
def roll_dice(dice)
|
90
92
|
rolls = []
|
91
93
|
total = 0
|
92
|
-
|
94
|
+
|
95
|
+
# Clean out anything invalid
|
96
|
+
dice.delete_if { |d| d.match(/\d+d\d+/).nil? }
|
93
97
|
dice.each do |die|
|
94
98
|
if die.match(/\d+d\d+/)
|
95
99
|
count = die.match(/(\d+)d\d+/)[1].to_i rescue 0
|
@@ -106,7 +110,11 @@ module Cinch::Plugins
|
|
106
110
|
end
|
107
111
|
end
|
108
112
|
end
|
109
|
-
|
113
|
+
if rolls.empty? || total.zero?
|
114
|
+
return nil
|
115
|
+
else
|
116
|
+
return { :rolls => rolls, :total => total }
|
117
|
+
end
|
110
118
|
end
|
111
119
|
|
112
120
|
def roll_dice_type(sides, count)
|
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: 0.0.
|
4
|
+
version: 0.0.2
|
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-05-
|
12
|
+
date: 2013-05-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: cinch
|