cinch-dicebag 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,4 @@
1
- nguage: ruby
1
+ language: ruby
2
2
  rvm:
3
- - ruby-head
4
3
  - 1.9.2
5
4
  - 1.9.3
data/README.md CHANGED
@@ -34,13 +34,13 @@ Just add the plugin to your list:
34
34
  end
35
35
  end
36
36
 
37
- Then in channel use .roll:
37
+ Then in channel use !roll:
38
38
 
39
- .roll 5d20
39
+ !roll 5d20
40
40
 
41
- You can also use .dicebag to roll a random assortment of dice.
41
+ You can also use !dicebag to roll a random assortment of dice.
42
42
 
43
- < Brian > .dicebag
43
+ < Brian > !dicebag
44
44
  < bot > Brian rolls a large bag of dice totalling 11052.
45
45
 
46
46
  ## Contributing
@@ -20,10 +20,11 @@ Gem::Specification.new do |gem|
20
20
  gem.add_development_dependency 'rake'
21
21
  gem.add_development_dependency 'rspec'
22
22
  gem.add_development_dependency 'coveralls'
23
+ gem.add_development_dependency 'cinch-test'
23
24
 
24
- gem.add_dependency 'cinch', '>= 2.0.0'
25
+ gem.add_dependency 'cinch', '>= 2.0.5'
25
26
  gem.add_dependency 'time-lord', '~> 1.0.1'
26
- gem.add_dependency 'cinch-cooldown', '>= 1.0.0'
27
- gem.add_dependency 'cinch-storage', '~> 0.0.2'
28
- gem.add_dependency 'cinch-toolbox', '~> 1.0.0'
27
+ gem.add_dependency 'cinch-cooldown', '>= 1.0.1'
28
+ gem.add_dependency 'cinch-storage', '~> 1.0.1'
29
+ gem.add_dependency 'cinch-toolbox', '~> 1.0.3'
29
30
  end
@@ -1,7 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  require 'cinch'
3
- require 'cinch-toolbox'
4
- require 'cinch-cooldown'
3
+ require 'cinch/toolbox'
4
+ require 'cinch/cooldown'
5
5
  require 'cinch-storage'
6
6
  require 'time-lord'
7
7
 
@@ -16,34 +16,36 @@ module Cinch::Plugins
16
16
 
17
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')"
18
18
 
19
- match /dicebag/
20
- match /roll (.*)/
19
+ match /dicebag/, method: :roll_dicebag
20
+ match /roll (.*)/, method: :roll
21
21
 
22
22
  def initialize(*args)
23
23
  super
24
24
  @storage = CinchStorage.new(config[:filename] || 'yaml/dice.yml')
25
25
  end
26
26
 
27
- def execute(m, dice = nil)
28
- m.reply (dice.nil? ? roll_dicebag(m.user.nick, m.channel) : roll(m.user.nick, dice))
29
- end
30
-
31
27
  # Roll a random assortment of dice, total the rolls, and record the score.
32
28
  # @param [String] nick Nickname of the user rolling.
33
29
  # @param [Cinch::Channel] channel The Channel object where the roll took place.
34
30
  # @return [String] A description of the roll that took place
35
- def roll_dicebag(nick, channel)
36
- return "You must use that command in the main channel." if channel.nil?
31
+ def roll_dicebag(m)
32
+ if m.channel.nil?
33
+ m.reply "You must use that command in the main channel."
34
+ return
35
+ end
37
36
 
38
- dice = { :d4 => rand(250), :d6 => rand(500), :d10 => rand(750), :d20 => rand(1000) }
37
+ nick = m.user.nick
38
+ channel = m.channel.name
39
+
40
+ dice = { d4: rand(250), d6: rand(500), d10: rand(750), d20: rand(1000) }
39
41
 
40
42
  total = roll_dice(dice.map { |die, count| "#{count}#{die}" })
41
43
  size = get_bag_size(dice.values.inject(:+))
42
44
 
43
45
  message = "#{nick} rolls a #{size} bag of dice totalling #{total}. " +
44
- score_check(nick.downcase, channel.name, total)
46
+ score_check(nick.downcase, channel, total)
45
47
 
46
- return message
48
+ m.reply message
47
49
  end
48
50
 
49
51
  # Roll a specific set of dice and return the pretty result
@@ -51,12 +53,12 @@ module Cinch::Plugins
51
53
  # @param [String] dice Space delimited string of dice to role.
52
54
  # (i.e. '6d12 4d20 d10'
53
55
  # @return [String] String describing the dice that were rolled
54
- def roll(nick, dice)
55
- return nil if dice.nil? || nick.nil?
56
+ def roll(m, dice)
57
+ return if dice.nil?
56
58
 
57
59
  result = roll_dice(dice.split(' '))
58
60
 
59
- return "#{nick} rolls #{dice} totalling #{result}" unless result.nil?
61
+ m.reply "#{m.user.nick} rolls #{dice} totalling #{result}" unless result.nil?
60
62
  end
61
63
 
62
64
 
@@ -80,7 +82,7 @@ module Cinch::Plugins
80
82
  end
81
83
  end
82
84
 
83
- return total
85
+ return total unless total.zero?
84
86
  end
85
87
 
86
88
  # Rolls an n-sided die a given amount of times and returns the total
@@ -1,5 +1,5 @@
1
1
  module Cinch
2
2
  module Dicebag
3
- VERSION = "1.0.2"
3
+ VERSION = "1.0.3"
4
4
  end
5
5
  end
@@ -1,126 +1,143 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Cinch::Plugins::Dicebag do
4
+ include Cinch::Test
4
5
 
5
6
  before(:all) do
6
- @plugin = Cinch::Plugins::Dicebag.new
7
+ @bot = make_bot(Cinch::Plugins::Dicebag, { filename: '/dev/null' })
7
8
  end
8
9
 
9
10
  describe 'rolling specific dice' do
10
- it "should return a string from rolling multiple dice" do
11
- @plugin.roll('thom', '3d3').should_not be_nil
11
+ it "should return a roll from rolling dice" do
12
+ get_replies(make_message(@bot, '!roll 3d3', { nick: 'ted' })).first.
13
+ should_not be_nil
12
14
  end
13
15
 
14
- it "should return a string from rolling mixes of dice" do
15
- @plugin.roll('thom', '3d3 d7 3d25').should_not be_nil
16
+ it "should return a roll in bounds from rolling dice" do
17
+ roll = get_replies(make_message(@bot, '!roll 3d3', { nick: 'ted' })).first.text
18
+ roll = roll[/totalling (\d+)/, 1]
19
+ (3..9).should include(roll.to_i)
16
20
  end
17
21
 
18
- it "should return a string from rolling a single die" do
19
- @plugin.roll('thom', 'd3').should_not be_nil
22
+ it "should return a roll from rolling mixes of dice" do
23
+ get_replies(make_message(@bot, '!roll 3d3 d7 3d21', { nick: 'ted' })).first.
24
+ should_not be_nil
20
25
  end
21
26
 
22
- it "should not return a string from rolling dice without a name" do
23
- @plugin.roll(nil, '3d3').should be_nil
27
+ it "should return a roll in bounds from rolling mixes of dice" do
28
+ roll = get_replies(make_message(@bot, '!roll 3d3 d7 3d21', { nick: 'ted' })).first.text
29
+ roll = roll[/totalling (\d+)/, 1]
30
+ (7..79).should include(roll.to_i)
31
+ end
32
+
33
+ it "should return a roll from rolling a single die" do
34
+ get_replies(make_message(@bot, '!roll d3', { nick: 'ted' })).first.
35
+ should_not be_nil
24
36
  end
25
37
 
26
38
  it "should not return a string from rolling dice without a name" do
27
- @plugin.roll('joe', nil).should be_nil
39
+ get_replies(make_message(@bot, '!roll .' , { nick: 'ted' })).first.
40
+ should be_nil
28
41
  end
29
42
 
30
43
  it "should return a string describing the dice that were rolled" do
31
- text = @plugin.roll('thom', '3d3')
32
- text.match(/rolls\s3d3\stotalling\s\d+/).should_not be_nil
44
+ text = get_replies(make_message(@bot, '!roll 3d3', { nick: 'ted' })).first.text
45
+ text.should match(/rolls\s3d3\stotalling\s\d+/)
33
46
  end
34
47
  end
35
48
 
36
49
  describe 'roll_dicebag' do
37
50
  it "should return a string" do
38
- @plugin.roll_dicebag('user', Cinch::Channel.new('foo', fake_bot)).should_not be_nil
51
+ get_replies(make_message(@bot, '!dicebag' , { nick: 'ted', channel: '#bar' })).first.
52
+ should_not be_nil
39
53
  end
40
54
 
41
55
  it "should return an error if the user is not in a channel" do
42
- @plugin.roll_dicebag('user', nil).
56
+ get_replies(make_message(@bot, '!dicebag' , { nick: 'ted' })).first.text.
43
57
  should be_eql("You must use that command in the main channel.")
44
58
  end
45
59
 
46
60
  it "should return a string describing the user's bag roll" do
47
- text = @plugin.roll_dicebag('user', Cinch::Channel.new('foo', fake_bot))
48
- text.match(/user rolls a [a-z]+ bag of dice totalling \d+/).should_not be_nil
61
+ get_replies(make_message(@bot, '!dicebag' , { nick: 'ted', channel: '#bar' })).first.text.
62
+ should match(/ted rolls a [a-z]+ bag of dice totalling \d+/)
49
63
  end
50
64
 
51
65
  it "should announce a high score if the old score is higher" do
52
- @plugin.storage.data['foo']['brian'] = { :score => 1, :time => Time.now }
53
- text = @plugin.roll_dicebag('brian', Cinch::Channel.new('foo', fake_bot))
54
- text.match(/A new high score/).should_not be_nil
55
- text.match(/Their old high roll was \d+/).should_not be_nil
66
+ get_replies(make_message(@bot, '!dicebag' , { nick: 'brian', channel: '#foo' }))
67
+ @bot.plugins.first.storage.data['#foo']['brian'] = { score: 1, time: Time.now }
68
+ text = get_replies(make_message(@bot, '!dicebag' , { nick: 'brian', channel: '#foo' })).first.text
69
+ text.should match(/A new high score/)
70
+ text.should match(/Their old high roll was \d+/)
71
+
56
72
  end
57
73
  end
58
74
 
59
75
  describe 'roll_dice' do
60
- it "should return zero if the dice list is empty" do
61
- @plugin.roll_dice([]).should be_zero
76
+ it "should return nil if the dice list is empty" do
77
+ @bot.plugins.first.roll_dice([]).should be_nil
62
78
  end
63
79
 
64
80
  it "should return a non zero total on a normal dice list" do
65
- @plugin.roll_dice(['3d3', '4d5']).should_not be_zero
81
+ @bot.plugins.first.roll_dice(['3d3', '4d5']).should_not be_zero
66
82
  end
67
83
 
68
84
  it "should clear out any invalid dice rolls" do
69
- @plugin.roll_dice(['33']).should be_zero
85
+ @bot.plugins.first.roll_dice(['33']).should be_nil
70
86
  end
71
87
  end
72
88
 
73
89
  describe "roll_die" do
74
90
  it "should return an acceptable value for a given roll" do
75
- @plugin.roll_die(1, 1).should == 1
76
- (5..15).should include(@plugin.roll_die(3, 5))
91
+ @bot.plugins.first.roll_die(1, 1).should == 1
92
+ (5..15).should include(@bot.plugins.first.roll_die(3, 5))
77
93
  end
78
94
 
79
95
  it "should return 0 for any negetive values" do
80
- @plugin.roll_die(-1, 1).should == 0
81
- @plugin.roll_die( 1, -1).should == 0
82
- @plugin.roll_die(-1, -1).should == 0
96
+ @bot.plugins.first.roll_die(-1, 1).should == 0
97
+ @bot.plugins.first.roll_die( 1, -1).should == 0
98
+ @bot.plugins.first.roll_die(-1, -1).should == 0
83
99
  end
84
100
  end
85
101
 
86
102
  describe "get_bag_size" do
87
103
  it "should return 'huge' for out of bounds queries" do
88
- @plugin.get_bag_size(50000).should == 'huge'
104
+ @bot.plugins.first.get_bag_size(50000).should == 'huge'
89
105
  end
90
106
 
91
107
  it "should return the proper size for tiny range" do
92
- @plugin.get_bag_size(0).should == 'tiny'
93
- @plugin.get_bag_size(rand(100)).should == 'tiny'
94
- @plugin.get_bag_size(100).should == 'tiny'
108
+ @bot.plugins.first.get_bag_size(0).should == 'tiny'
109
+ @bot.plugins.first.get_bag_size(rand(100)).should == 'tiny'
110
+ @bot.plugins.first.get_bag_size(100).should == 'tiny'
95
111
  end
96
112
 
97
113
  it "should return the proper size for small range" do
98
- @plugin.get_bag_size(101).should == 'small'
99
- @plugin.get_bag_size(rand(399) + 101).should == 'small'
100
- @plugin.get_bag_size(500).should == 'small'
114
+ @bot.plugins.first.get_bag_size(101).should == 'small'
115
+ @bot.plugins.first.get_bag_size(rand(399) + 101).should == 'small'
116
+ @bot.plugins.first.get_bag_size(500).should == 'small'
101
117
  end
102
118
 
103
119
  it "should return the proper size for medium range" do
104
- @plugin.get_bag_size(501).should == 'medium'
105
- @plugin.get_bag_size(rand(499) + 501).should == 'medium'
106
- @plugin.get_bag_size(1000).should == 'medium'
120
+ @bot.plugins.first.get_bag_size(501).should == 'medium'
121
+ @bot.plugins.first.get_bag_size(rand(499) + 501).should == 'medium'
122
+ @bot.plugins.first.get_bag_size(1000).should == 'medium'
107
123
  end
108
124
 
109
125
  it "should return the proper size for large range" do
110
- @plugin.get_bag_size(1001).should == 'large'
111
- @plugin.get_bag_size(rand(499) + 1001).should == 'large'
112
- @plugin.get_bag_size(1500).should == 'large'
126
+ @bot.plugins.first.get_bag_size(1001).should == 'large'
127
+ @bot.plugins.first.get_bag_size(rand(499) + 1001).should == 'large'
128
+ @bot.plugins.first.get_bag_size(1500).should == 'large'
113
129
  end
114
130
 
115
131
  it "should return the proper size for hefty range" do
116
- @plugin.get_bag_size(1501).should == 'hefty'
117
- @plugin.get_bag_size(rand(499) + 1501).should == 'hefty'
118
- @plugin.get_bag_size(2000).should == 'hefty'
132
+ @bot.plugins.first.get_bag_size(1501).should == 'hefty'
133
+ @bot.plugins.first.get_bag_size(rand(499) + 1501).should == 'hefty'
134
+ @bot.plugins.first.get_bag_size(2000).should == 'hefty'
119
135
  end
120
136
 
121
137
  it "should return the proper size for huge range" do
122
- @plugin.get_bag_size(2001).should == 'huge'
123
- @plugin.get_bag_size(20001).should == 'huge'
138
+ @bot.plugins.first.get_bag_size(2001).should == 'huge'
139
+ @bot.plugins.first.get_bag_size(20001).should == 'huge'
124
140
  end
125
141
  end
126
142
  end
143
+
@@ -1,26 +1,11 @@
1
1
  require 'coveralls'
2
- Coveralls.wear!
3
- require 'cinch-dicebag'
2
+ require 'simplecov'
4
3
 
5
- def fake_bot
6
- bot = Cinch::Bot.new do
7
- configure do |c|
8
- c.plugins.options[Cinch::Plugins::Dicebag][:filename] = '/dev/null'
9
- end
10
- end
11
- bot.loggers.level = :fatal
12
- bot
13
- return bot
14
- end
4
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
+ SimpleCov::Formatter::HTMLFormatter,
6
+ Coveralls::SimpleCov::Formatter
7
+ ]
8
+ SimpleCov.start
15
9
 
16
- module Cinch
17
- module Plugin
18
- def initialize(opts = {})
19
- @bot = fake_bot
20
- @handlers = []
21
- @timers = []
22
- # Don't init the bot
23
- # __register
24
- end
25
- end
26
- end
10
+ require 'cinch-dicebag'
11
+ require 'cinch/test'
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.2
4
+ version: 1.0.3
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-17 00:00:00.000000000 Z
12
+ date: 2013-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -59,6 +59,22 @@ dependencies:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: cinch-test
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
62
78
  - !ruby/object:Gem::Dependency
63
79
  name: cinch
64
80
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +82,7 @@ dependencies:
66
82
  requirements:
67
83
  - - ! '>='
68
84
  - !ruby/object:Gem::Version
69
- version: 2.0.0
85
+ version: 2.0.5
70
86
  type: :runtime
71
87
  prerelease: false
72
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +90,7 @@ dependencies:
74
90
  requirements:
75
91
  - - ! '>='
76
92
  - !ruby/object:Gem::Version
77
- version: 2.0.0
93
+ version: 2.0.5
78
94
  - !ruby/object:Gem::Dependency
79
95
  name: time-lord
80
96
  requirement: !ruby/object:Gem::Requirement
@@ -98,7 +114,7 @@ dependencies:
98
114
  requirements:
99
115
  - - ! '>='
100
116
  - !ruby/object:Gem::Version
101
- version: 1.0.0
117
+ version: 1.0.1
102
118
  type: :runtime
103
119
  prerelease: false
104
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,7 +122,7 @@ dependencies:
106
122
  requirements:
107
123
  - - ! '>='
108
124
  - !ruby/object:Gem::Version
109
- version: 1.0.0
125
+ version: 1.0.1
110
126
  - !ruby/object:Gem::Dependency
111
127
  name: cinch-storage
112
128
  requirement: !ruby/object:Gem::Requirement
@@ -114,7 +130,7 @@ dependencies:
114
130
  requirements:
115
131
  - - ~>
116
132
  - !ruby/object:Gem::Version
117
- version: 0.0.2
133
+ version: 1.0.1
118
134
  type: :runtime
119
135
  prerelease: false
120
136
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,7 +138,7 @@ dependencies:
122
138
  requirements:
123
139
  - - ~>
124
140
  - !ruby/object:Gem::Version
125
- version: 0.0.2
141
+ version: 1.0.1
126
142
  - !ruby/object:Gem::Dependency
127
143
  name: cinch-toolbox
128
144
  requirement: !ruby/object:Gem::Requirement
@@ -130,7 +146,7 @@ dependencies:
130
146
  requirements:
131
147
  - - ~>
132
148
  - !ruby/object:Gem::Version
133
- version: 1.0.0
149
+ version: 1.0.3
134
150
  type: :runtime
135
151
  prerelease: false
136
152
  version_requirements: !ruby/object:Gem::Requirement
@@ -138,7 +154,7 @@ dependencies:
138
154
  requirements:
139
155
  - - ~>
140
156
  - !ruby/object:Gem::Version
141
- version: 1.0.0
157
+ version: 1.0.3
142
158
  description: Cinch Plugin that allows uses in the channel to roll specific dice or
143
159
  roll a random assortment of dice to compete for high scores.
144
160
  email:
@@ -179,11 +195,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
195
  version: '0'
180
196
  requirements: []
181
197
  rubyforge_project:
182
- rubygems_version: 1.8.24
198
+ rubygems_version: 1.8.25
183
199
  signing_key:
184
200
  specification_version: 3
185
201
  summary: ! 'Cinch Plugin: Dicebag and Dice rolls'
186
202
  test_files:
187
203
  - spec/cinch-dicebag_spec.rb
188
204
  - spec/spec_helper.rb
189
- has_rdoc: