cinch-cooldown 1.0.1 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: afcb1d5bb660b10ac1afa239d53e5435203d5dad30f036541da1738a91fe4b3a
4
+ data.tar.gz: ff3853080487597ab97ed5b48741dc1f301b9886e1b75ae4ee702a913bfc6e24
5
+ SHA512:
6
+ metadata.gz: 1e92a9a301068474704d8282036e4170c43ade682775de898c91107b6de3fd593657088a7b6ecdd7047002a571da2bfa1d2241928f12d054e6afe40199c5c2aa
7
+ data.tar.gz: 7ecd2247605653d190459fbd02ad97016e958dc0a7494ba543ca9119dbde4b014bfd00ac859aa2e4ce8e0e4243fc4af12c21da4d492b9e39ce7c8a70acbe8408
@@ -1,4 +1,34 @@
1
+ addons:
2
+ code_climate:
3
+ repo_token: 15db41183ecae7874c0ff86ec1e24b2c340f9a977ebb5f4f4c6421e4f82bd0de
1
4
  language: ruby
5
+ before_install:
6
+ - gem update --system
7
+ - gem update bundler
8
+ env:
9
+ global:
10
+ - "JRUBY_OPTS=-Xcext.enabled=true"
2
11
  rvm:
12
+ - 1.8.7
3
13
  - 1.9.2
4
14
  - 1.9.3
15
+ - 2.0.0
16
+ - 2.1.0
17
+ - 2.2.0
18
+ - 2.3.0
19
+ - jruby-18mode
20
+ - jruby-19mode
21
+ - ruby-head
22
+ - jruby-head
23
+ - ree
24
+ matrix:
25
+ allow_failures:
26
+ - rvm: 1.8.7
27
+ - rvm: 1.9.2
28
+ - rvm: 1.9.3
29
+ - rvm: ree
30
+ - rvm: jruby-18mode
31
+ - rvm: jruby-19mode
32
+ - rvm: jruby-head
33
+ - rvm: ruby-head
34
+ fast_finish: true
data/README.md CHANGED
@@ -1,10 +1,13 @@
1
+ # Note: As of v1.2.0 the config changed to use symbols for the channel names, please be aware.
2
+
1
3
  # Cinch::Cooldown
2
4
 
3
5
  [![Gem Version](https://badge.fury.io/rb/cinch-cooldown.png)](http://badge.fury.io/rb/cinch-cooldown)
4
6
  [![Dependency Status](https://gemnasium.com/bhaberer/cinch-cooldown.png)](https://gemnasium.com/bhaberer/cinch-cooldown)
5
7
  [![Build Status](https://travis-ci.org/bhaberer/cinch-cooldown.png?branch=master)](https://travis-ci.org/bhaberer/cinch-cooldown)
6
- [![Coverage Status](https://coveralls.io/repos/bhaberer/cinch-cooldown/badge.png?branch=master)](https://coveralls.io/r/bhaberer/cinch-cooldown?branch=master)
7
- [![Code Climate](https://codeclimate.com/github/bhaberer/cinch-cooldown.png)](https://codeclimate.com/github/bhaberer/cinch-cooldown)
8
+ [![Code Climate](https://codeclimate.com/repos/56aa7be85b34ac007f002f94/badges/3a98b90ce443c23969c8/gpa.svg)](https://codeclimate.com/repos/56aa7be85b34ac007f002f94/feed)
9
+ [![Test Coverage](https://codeclimate.com/repos/56aa7be85b34ac007f002f94/badges/3a98b90ce443c23969c8/coverage.svg)](https://codeclimate.com/repos/56aa7be85b34ac007f002f94/coverage)
10
+ [![Issue Count](https://codeclimate.com/repos/56aa7be85b34ac007f002f94/badges/3a98b90ce443c23969c8/issue_count.svg)](https://codeclimate.com/repos/56aa7be85b34ac007f002f94/feed)
8
11
 
9
12
  This library is used to add a global cooldown so that users are prevented from spamming the
10
13
  channel.
@@ -30,14 +33,14 @@ Configuration Steps:
30
33
  1. You need to add the configuration to your bot in the config block. You will need to add
31
34
  config info for every channel the bot is in that you want a cooldown. The `:global` is how
32
35
  many seconds the bot will wait before listening to a command that prints something to the
33
- channel, while the `:user` directive is how long. Currently the gem is simple and assumes
34
- that the user timer will be greater than the global timer.
36
+ channel, while the `:user` directive is how long it will wait per user.
37
+ Currently the gem is simple and assumes that the user timer will be greater
38
+ than the global timer.
35
39
 
36
- c.shared[:cooldown] = { :config => { '#bottest' => { :global => 10
37
- :user => 20 } }
40
+ ```c.shared[:cooldown] = { :config => { bottest: { global: 10, user: 20 } } }```
38
41
 
39
42
  2. If you are using this with my plugins, things should just work. However if you want to use
40
- this with your own plugins, yoiu need to add a `require cinch-cooldown` to the top of said
43
+ this with your own plugins, you need to add a `'require cinch/cooldown'` to the top of said
41
44
  plugin, and an `enforce_cooldown` to the plugin after the `include Cinch::Plugin` line.
42
45
 
43
46
  ## Contributing
@@ -4,24 +4,26 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'cinch/cooldown/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "cinch-cooldown"
8
- gem.version = Cinch::Cooldown::VERSION
9
- gem.authors = ["Brian Haberer"]
10
- gem.email = ["bhaberer@gmail.com"]
11
- gem.description = %q{This gem allows you to set a shared timer across plugins that are configured to respect it.}
12
- gem.summary = %q{Global Cooldown tracker for Cinch Plugins}
13
- gem.homepage = "https://github.com/bhaberer/cinch-cooldown"
7
+ gem.name = 'cinch-cooldown'
8
+ gem.version = Cinch::Cooldowns::VERSION
9
+ gem.authors = ['Brian Haberer']
10
+ gem.email = ['bhaberer@gmail.com']
11
+ gem.description = %q(This gem allows you to set a shared timer across plugins that are configured to respect it.)
12
+ gem.summary = %q(Global Cooldown tracker for Cinch Plugins)
13
+ gem.homepage = 'https://github.com/bhaberer/cinch-cooldown'
14
14
 
15
- gem.files = `git ls-files`.split($/)
16
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(/^(test|spec|features)\//)
18
+ gem.require_paths = ['lib']
19
+ gem.license = 'MIT'
20
+ gem.required_ruby_version = '>= 2.0.0'
19
21
 
20
- gem.add_development_dependency 'rake'
21
- gem.add_development_dependency 'rspec'
22
- gem.add_development_dependency 'coveralls'
23
- gem.add_development_dependency 'cinch-test'
22
+ gem.add_development_dependency 'rake', '~> 12.3.3'
23
+ gem.add_development_dependency 'rspec', '~> 3'
24
+ gem.add_development_dependency 'cinch-test', '~> 0.1', '>= 0.1.1'
25
+ gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
24
26
 
25
- gem.add_dependency 'time-lord', '~> 1.0.1'
26
- gem.add_dependency 'cinch', '~> 2.0.5'
27
+ gem.add_dependency 'cinch', '~> 2'
28
+ gem.add_dependency 'time-lord', '~> 1.0', '>= 1.0.1'
27
29
  end
@@ -1,120 +1,6 @@
1
+ # -*- coding: utf-8 -*-
1
2
  require 'cinch/cooldown/version'
3
+ require 'cinch/plugin/hooks'
4
+ require 'cinch/plugin/cooldown'
5
+ require 'cinch/plugin/cooldowns'
2
6
  require 'time-lord'
3
-
4
- module Cinch
5
- module Plugin
6
- module ClassMethods
7
- def enforce_cooldown
8
- hook(:pre, :for => [:match], :method => lambda {|m| cooldown_finished?(m)})
9
- end
10
- end
11
-
12
- def cooldown_finished?(m)
13
- # return if we don't have a cooldown config
14
- return true unless shared[:cooldown] && shared[:cooldown][:config]
15
- synchronize(:cooldown) do
16
- # return if we don't have a channel (i.e. user is pming the bot)
17
- return true if m.channel.nil?
18
-
19
- channel = m.channel.name
20
- user = m.user.nick
21
-
22
- # Make sure the configuration is sane.
23
- return true if configuration_broken?(channel)
24
-
25
- # Make sure it's not the first command
26
- return true if first_run?(channel, user)
27
-
28
- # Check if timers are finished
29
- return true if cooldowns_finished?(channel, user)
30
-
31
- # Handle unfinished cooldowns here
32
- m.user.notice cooldown_message(channel, user)
33
- return false
34
- end
35
- end
36
-
37
- def configuration_broken?(channel)
38
- # return if the config doesn't smell right for this channel
39
- return true unless shared[:cooldown][:config].key?(channel) &&
40
- config_for(channel).key?(:global) &&
41
- config_for(channel).key?(:user)
42
- false
43
- end
44
-
45
- def first_run?(channel, user)
46
- unless shared[:cooldown].key?(channel)
47
- trigger_cooldown_for(channel, user)
48
- return true
49
- end
50
- end
51
-
52
- def cooldowns_finished?(channel, user)
53
- # Normal usage stuff starts here, check and see if the channel time is up
54
- if channel_cooldown_finished?(channel)
55
- # channel cd is up, check per user by checking if the user's even triggered a cd yet
56
- if shared[:cooldown][channel].key?(user)
57
- # User's in the config, check time
58
- if user_cooldown_finished?(channel, user)
59
- # Their time's up, run the command
60
- trigger_cooldown_for(channel, user)
61
- return true
62
- end
63
- else
64
- # User's not used bot before, run the command
65
- trigger_cooldown_for(channel, user)
66
- return true
67
- end
68
- end
69
- return false
70
- end
71
-
72
- def cooldown_message(channel, user)
73
- message = ['Sorry, you\'ll have to wait']
74
- unless channel_cooldown_finished?(channel)
75
- message << TimeLord::Period.new(cooldown_channel_expire_time(channel), Time.now).to_words
76
- message << 'before I can talk in the channel again, and'
77
- end
78
- message << TimeLord::Period.new(cooldown_user_expire_time(channel, user), Time.now).to_words
79
- message << 'before you can use any commands.'
80
-
81
- return message.join(' ')
82
- end
83
-
84
- def trigger_cooldown_for(channel, user)
85
- shared[:cooldown][channel] = { :global => Time.now, user => Time.now }
86
- end
87
-
88
- def cooldown_channel_expire_time(channel)
89
- global_cooldown_for(channel) + config_for(channel)[:global]
90
- end
91
-
92
- def cooldown_user_expire_time(channel, user)
93
- user_cooldown_for(channel, user) + config_for(channel)[:user]
94
- end
95
-
96
- def user_cooldown_finished?(channel, user)
97
- cooldown = config_for(channel)[:user]
98
- elapsed = Time.now - user_cooldown_for(channel, user)
99
- return cooldown <= elapsed
100
- end
101
-
102
- def channel_cooldown_finished?(channel)
103
- cooldown = config_for(channel)[:global]
104
- elapsed = Time.now - global_cooldown_for(channel)
105
- return cooldown <= elapsed
106
- end
107
-
108
- def config_for(chan)
109
- shared[:cooldown][:config][chan]
110
- end
111
-
112
- def global_cooldown_for(chan)
113
- shared[:cooldown][chan][:global] ||= Time.now
114
- end
115
-
116
- def user_cooldown_for(chan, nick)
117
- shared[:cooldown][chan][nick] || Time.now
118
- end
119
- end
120
- end
@@ -1,5 +1,7 @@
1
+ # -*- coding: utf-8 -*-
1
2
  module Cinch
2
- module Cooldown
3
- VERSION = "1.0.1"
3
+ # Versioning info
4
+ module Cooldowns
5
+ VERSION = '1.2.1'
4
6
  end
5
7
  end
@@ -0,0 +1,30 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Cinch
3
+ module Plugin
4
+ # An alteration to the Plugin Module to allow for configurable cooldowns.
5
+ class Cooldown
6
+ attr_accessor :time, :duration, :expires_at
7
+
8
+ def initialize(duration, time = Time.now)
9
+ @time = time
10
+ @duration = duration
11
+ @expires_at = @time + @duration
12
+ end
13
+
14
+ def time_till_expire_in_words
15
+ return 'until right now' if (expires_at - Time.now) < 0
16
+ TimeLord::Period.new(expires_at, Time.now).to_words
17
+ end
18
+
19
+ def time_till_expire
20
+ period = @expires_at - Time.now
21
+ return 0 if period < 0
22
+ period
23
+ end
24
+
25
+ def cooled_down?
26
+ time_till_expire.zero?
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,134 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Cinch
3
+ module Plugin
4
+ # Class for managing the cooldown objects.
5
+ module Cooldowns
6
+ include Cinch::Plugin
7
+
8
+ @cooldowns = {}
9
+ @config = nil
10
+
11
+ # Main method called by the hook
12
+ def self.finished?(m, shared, bot)
13
+ return unless shared.is_a?(Hash)
14
+ @config = shared[:config]
15
+ @cooldowns = shared[:cooldowns] if shared.key?(:cooldowns)
16
+
17
+ # Don't run if we there's no cooldown config
18
+ return true unless @config
19
+
20
+ bot.synchronize(:cooldown) do
21
+ # Avoid cooldown if we don't have a channel
22
+ # (i.e. user is pming the bot)
23
+ return true if m.channel.nil?
24
+
25
+ channel = channel_to_key(m.channel.name)
26
+
27
+ clean_expired_cooldowns(channel)
28
+
29
+ # return true if the cooldowns have expired
30
+ return true if cool?(channel, m.user.nick)
31
+
32
+ # Otherwise message the user about unfinished cooldowns
33
+ m.user.notice message(channel, m.user.nick)
34
+
35
+ # and return false so the command gets dropped by the hook
36
+ false
37
+ end
38
+ end
39
+
40
+ # Main cooldown data check
41
+ def self.cool?(channel, user)
42
+ # Make sure the configuration is sane.
43
+ return true if config_broken?(channel) ||
44
+ # Make sure it's not the first command
45
+ first_run?(channel, user) ||
46
+ # Check if timers are finished
47
+ cooldowns_finished?(channel, user)
48
+
49
+ # Otherwise trigger cooldown
50
+ false
51
+ end
52
+
53
+ def self.config_broken?(channel)
54
+ # return true if the config doesn't have needed info this channel
55
+ return true unless @config.key?(channel) &&
56
+ config_for(channel).key?(:global) &&
57
+ config_for(channel).key?(:user)
58
+ # otherwise abort cooldown enforcement
59
+ false
60
+ end
61
+
62
+ def self.channel_to_key(channel)
63
+ return channel if channel.is_a?(Symbol)
64
+ channel[/\w+/].to_sym
65
+ end
66
+
67
+ def self.config_for(chan)
68
+ @config[chan]
69
+ end
70
+
71
+ def self.first_run?(channel, user)
72
+ unless @cooldowns.key?(channel)
73
+ trigger_cooldown_for(channel, user)
74
+ return true
75
+ end
76
+ false
77
+ end
78
+
79
+ def self.purge!
80
+ @cooldowns = {}
81
+ end
82
+
83
+ def self.cooldowns_finished?(channel, user)
84
+ # Chuck all the cooldowns that have expired
85
+ clean_expired_cooldowns(channel)
86
+
87
+ # if the channel's cooldown is up
88
+ if @cooldowns[channel][:global].nil?
89
+ # And their cd's up, or they've not used bot before, run the command
90
+ if @cooldowns[channel][user].nil?
91
+ # trigger a new cooldown
92
+ trigger_cooldown_for(channel, user)
93
+ # and run the command
94
+ return true
95
+ end
96
+ end
97
+ false
98
+ end
99
+
100
+ def self.clean_expired_cooldowns(channel)
101
+ return unless @cooldowns.key?(channel)
102
+ @cooldowns[channel].each_pair do |key, cooldown|
103
+ @cooldowns[channel].delete(key) if cooldown.cooled_down?
104
+ end
105
+ end
106
+
107
+ def self.message(channel, user)
108
+ cds = []
109
+ if @cooldowns[channel].key?(:global)
110
+ chan_exp = @cooldowns[channel][:global].time_till_expire_in_words
111
+ cds << "#{chan_exp} before I can talk in the channel again"
112
+ elsif @cooldowns[channel].key?(user)
113
+ user_exp = @cooldowns[channel][user].time_till_expire_in_words
114
+ cds << "#{user_exp} before you can use any commands"
115
+ end
116
+ ['Sorry, cooldown is in effect:', cds.join(', and ')].join(' ')
117
+ end
118
+
119
+ def self.trigger_cooldown_for(channel, user)
120
+ # Make sure the channel array has been init
121
+ @cooldowns[channel] ||= {}
122
+
123
+ # Create a cooldown for the channel
124
+ @cooldowns[channel][:global] =
125
+ Cooldown.new(@config[channel][:global])
126
+ # Create a cooldown for the user
127
+ @cooldowns[channel][user] =
128
+ Cooldown.new(@config[channel][:user])
129
+
130
+ warn "[[ Cooldown Triggered for user: #{user} ]]"
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,14 @@
1
+ # -*- coding: utf-8 -*-
2
+ module Cinch
3
+ # An alteration to the Plugin Module to allow for configurable cooldowns.
4
+ module Plugin
5
+ # Add the pre hook to all messages triggered
6
+ module ClassMethods
7
+ def enforce_cooldown
8
+ hook(:pre,
9
+ for: [:match],
10
+ method: ->(m) { Cooldowns.finished?(m, shared[:cooldown], @bot) })
11
+ end
12
+ end
13
+ end
14
+ end
@@ -2,81 +2,111 @@ require 'spec_helper'
2
2
 
3
3
  class MyPlugin
4
4
  include Cinch::Plugin
5
-
6
5
  enforce_cooldown
7
-
8
- match /thing/
6
+ match(/thing/)
9
7
  def execute(m)
10
8
  m.reply 'OMG'
11
9
  end
12
10
  end
13
11
 
14
- def bot_for_cooldowns(global = 10, user = 0)
15
- @bot = Cinch::Test::MockBot.new do
16
- configure do |c|
17
- c.nick = 'testbot'
18
- c.server = nil
19
- c.channels = ['foo']
20
- c.reconnect = false
21
- c.plugins.plugins = [MyPlugin]
22
- c.shared[:cooldown] = { :config => { '#foo' => { :global => global, :user => user } } }
23
- end
24
- end
12
+ def bot_for_cooldowns(global: 10, user: 0, channel: 'foo')
13
+ Cinch::Test::MockBot.new do
14
+ configure do |c|
15
+ c.nick = 'testbot'
16
+ c.server = nil
17
+ c.channels = ['channel']
18
+ c.reconnect = false
19
+ c.plugins.plugins = [MyPlugin]
20
+ c.shared[:cooldown] = { config: { channel.to_sym => { global: global, user: user } } }
21
+ end
22
+ end
25
23
  end
26
24
 
27
- describe Cinch::Cooldown do
25
+ describe Cinch::Cooldowns do
28
26
  include Cinch::Test
29
27
 
30
- it 'should not trigger cooldowns on private messages' do
31
- @bot = bot_for_cooldowns(10)
32
- get_replies(make_message(@bot, "!thing"))
33
- get_replies(make_message(@bot, "!thing")).first.text.
34
- should match "OMG"
28
+ after(:each) do
29
+ Cinch::Plugin::Cooldowns.purge!
35
30
  end
36
31
 
37
- it 'should allow plugins to mandate a global cooldown between responses in channel' do
38
- @bot = bot_for_cooldowns(10)
39
- get_replies(make_message(@bot, "!thing", channel: '#foo'))
40
- get_replies(make_message(@bot, "!thing", channel: '#foo')).first.text.
41
- should match(/Sorry, you'll have to wait \d+ seconds from now before I can talk/)
42
- end
32
+ let(:bot) { bot_for_cooldowns }
43
33
 
44
- it 'should allow plugins allow responses after the global cooldown' do
45
- @bot = bot_for_cooldowns(5)
46
- get_replies(make_message(@bot, "!thing", channel: '#foo'))
47
- sleep 5
48
- get_replies(make_message(@bot, "!thing", channel: '#foo')).first.text.
49
- should == 'OMG'
34
+ context 'when sending the bot a pm' do
35
+ it 'do not trigger cooldowns' do
36
+ get_replies(make_message(bot, "!thing"))
37
+ reply = get_replies(make_message(bot, "!thing")).first.text
38
+ expect(reply).to match('OMG')
39
+ end
50
40
  end
51
41
 
52
- it 'should allow plugins to mandate a minimum time between responses in channel' do
53
- @bot = bot_for_cooldowns(5, 10)
54
- get_replies(make_message(@bot, "!thing", channel: '#foo'))
55
- sleep 6
56
- get_replies(make_message(@bot, "!thing", channel: '#foo')).first.text.
57
- should match(/Sorry, you'll have to wait \d+ seconds from now before you can use/)
42
+ context 'when using global cooldowns' do
43
+ it 'allows a global cooldown between responses in channel' do
44
+ get_replies(make_message(bot, "!thing", channel: '#foo'))
45
+ reply = get_replies(make_message(bot, "!thing", channel: '#foo')).first.text
46
+ expect(reply).to match(/Sorry, cooldown is in effect: \d+ seconds from now/)
47
+ end
48
+
49
+ it 'allows responses after the global cooldown expires' do
50
+ bot = bot_for_cooldowns(global: 5, user: 5)
51
+ get_replies(make_message(bot, "!thing", channel: '#foo'))
52
+ sleep 7
53
+ reply = get_replies(make_message(bot, "!thing", channel: '#foo')).first.text
54
+ expect(reply).to eq('OMG')
55
+ end
56
+
57
+ it 'triggers for other users if the global cooldown is finished' do
58
+ bot = bot_for_cooldowns(global: 0, user: 20)
59
+ reply_a = get_replies(make_message(bot, "!thing", channel: '#foo', nick: 'test1')).first.text
60
+ expect(reply_a).to eq('OMG')
61
+ sleep 1
62
+ reply_b = get_replies(make_message(bot, "!thing", channel: '#foo', nick: 'test2')).first.text
63
+ expect(reply_b).to eq('OMG')
64
+ end
65
+
66
+ it 'does not trigger for other users if the global cooldown is not finished' do
67
+ bot = bot_for_cooldowns(global: 10, user: 20)
68
+ reply_good = get_replies(make_message(bot, "!thing", channel: '#foo', nick: 'test1')).first.text
69
+ expect(reply_good).to eq('OMG')
70
+ reply_cool = get_replies(make_message(bot, "!thing", channel: '#foo', nick: 'test2')).first.text
71
+ expect(reply_cool).not_to eq('OMG')
72
+ end
58
73
  end
59
74
 
60
- it 'should allow plugins to mandate a minimum time between responses in channel' do
61
- @bot = bot_for_cooldowns(5, 10)
62
- get_replies(make_message(@bot, "!thing", channel: '#foo'))
63
- sleep 10
64
- get_replies(make_message(@bot, "!thing", channel: '#foo')).first.text.
65
- should == 'OMG'
75
+ context 'when using user cooldowns' do
76
+ it 'does not allow users to use commands in the period between cooldowns' do
77
+ bot = bot_for_cooldowns(global: 5, user: 10)
78
+ get_replies(make_message(bot, "!thing", channel: '#foo'))
79
+ sleep 7
80
+ reply = get_replies(make_message(bot, "!thing", channel: '#foo')).first.text
81
+ expect(reply).to match(/Sorry, cooldown is in effect: \d+ seconds from now before you can use/)
82
+ end
83
+
84
+ it 'allows users to use commands after their cooldown period ends' do
85
+ bot = bot_for_cooldowns(global: 5, user: 10)
86
+ get_replies(make_message(bot, "!thing", channel: '#foo'))
87
+ sleep 12
88
+ reply = get_replies(make_message(bot, "!thing", channel: '#foo')).first.text
89
+ expect(reply).to eq('OMG')
90
+ end
66
91
  end
67
92
 
68
- it 'should not trigger if the config for the current channel does not exist' do
69
- @bot = bot_for_cooldowns(5, 10)
70
- get_replies(make_message(@bot, "!thing", channel: '#bar'))
71
- get_replies(make_message(@bot, "!thing", channel: '#bar')).first.text.
72
- should == 'OMG'
93
+ it 'manages mutiple users incurring simultaneous cooldowns' do
94
+ bot = bot_for_cooldowns(global: 5, user: 10)
95
+ get_replies(make_message(bot, "!thing", channel: '#foo'))
96
+ get_replies(make_message(bot, "thing", channel: '#foo'))
97
+ sleep 6
98
+ get_replies(make_message(bot, "!thing", channel: '#foo', nick: 'george'))
99
+ sleep 5
100
+ expect(get_replies(make_message(bot, "!thing", channel: '#foo')).first.text)
101
+ .to eq('OMG')
73
102
  end
74
103
 
75
- it 'should trigger for other users if the global cooldown is not finished' do
76
- @bot = bot_for_cooldowns(10, 20)
77
- get_replies(make_message(@bot, "!thing", channel: '#foo', nick: 'test1')).first.text.
78
- should == 'OMG'
79
- get_replies(make_message(@bot, "!thing", channel: '#foo', nick: 'test2')).first.text.
80
- should_not == 'OMG'
104
+ context 'when configuration issues arise' do
105
+ it 'does not trigger if the config for the current channel does not exist' do
106
+ bot = bot_for_cooldowns(global: 5, user: 10)
107
+ get_replies(make_message(bot, "!thing", channel: '#bar'))
108
+ expect(get_replies(make_message(bot, "!thing", channel: '#bar')).first.text)
109
+ .to eq('OMG')
110
+ end
81
111
  end
82
112
  end
@@ -1,11 +1,5 @@
1
- require 'coveralls'
2
- require 'simplecov'
3
-
4
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
5
- SimpleCov::Formatter::HTMLFormatter,
6
- Coveralls::SimpleCov::Formatter
7
- ]
8
- SimpleCov.start
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
9
3
 
10
4
  require 'cinch/cooldown'
11
5
  require 'cinch/test'
metadata CHANGED
@@ -1,112 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-cooldown
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
5
- prerelease:
4
+ version: 1.2.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Brian Haberer
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-04 00:00:00.000000000 Z
11
+ date: 2021-01-27 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
- version: '0'
19
+ version: 12.3.3
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '0'
26
+ version: 12.3.3
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - "~>"
36
32
  - !ruby/object:Gem::Version
37
- version: '0'
33
+ version: '3'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - "~>"
44
39
  - !ruby/object:Gem::Version
45
- version: '0'
40
+ version: '3'
46
41
  - !ruby/object:Gem::Dependency
47
- name: coveralls
42
+ name: cinch-test
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.1'
48
+ - - ">="
52
49
  - !ruby/object:Gem::Version
53
- version: '0'
50
+ version: 0.1.1
54
51
  type: :development
55
52
  prerelease: false
56
53
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
54
  requirements:
59
- - - ! '>='
55
+ - - "~>"
60
56
  - !ruby/object:Gem::Version
61
- version: '0'
57
+ version: '0.1'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.1.1
62
61
  - !ruby/object:Gem::Dependency
63
- name: cinch-test
62
+ name: codeclimate-test-reporter
64
63
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
64
  requirements:
67
- - - ! '>='
65
+ - - "~>"
68
66
  - !ruby/object:Gem::Version
69
- version: '0'
67
+ version: '0.4'
70
68
  type: :development
71
69
  prerelease: false
72
70
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
71
  requirements:
75
- - - ! '>='
72
+ - - "~>"
76
73
  - !ruby/object:Gem::Version
77
- version: '0'
74
+ version: '0.4'
78
75
  - !ruby/object:Gem::Dependency
79
- name: time-lord
76
+ name: cinch
80
77
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
78
  requirements:
83
- - - ~>
79
+ - - "~>"
84
80
  - !ruby/object:Gem::Version
85
- version: 1.0.1
81
+ version: '2'
86
82
  type: :runtime
87
83
  prerelease: false
88
84
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
85
  requirements:
91
- - - ~>
86
+ - - "~>"
92
87
  - !ruby/object:Gem::Version
93
- version: 1.0.1
88
+ version: '2'
94
89
  - !ruby/object:Gem::Dependency
95
- name: cinch
90
+ name: time-lord
96
91
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
92
  requirements:
99
- - - ~>
93
+ - - "~>"
100
94
  - !ruby/object:Gem::Version
101
- version: 2.0.5
95
+ version: '1.0'
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: 1.0.1
102
99
  type: :runtime
103
100
  prerelease: false
104
101
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
102
  requirements:
107
- - - ~>
103
+ - - "~>"
108
104
  - !ruby/object:Gem::Version
109
- version: 2.0.5
105
+ version: '1.0'
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: 1.0.1
110
109
  description: This gem allows you to set a shared timer across plugins that are configured
111
110
  to respect it.
112
111
  email:
@@ -115,8 +114,8 @@ executables: []
115
114
  extensions: []
116
115
  extra_rdoc_files: []
117
116
  files:
118
- - .gitignore
119
- - .travis.yml
117
+ - ".gitignore"
118
+ - ".travis.yml"
120
119
  - Gemfile
121
120
  - LICENSE.txt
122
121
  - README.md
@@ -124,33 +123,34 @@ files:
124
123
  - cinch-cooldown.gemspec
125
124
  - lib/cinch/cooldown.rb
126
125
  - lib/cinch/cooldown/version.rb
126
+ - lib/cinch/plugin/cooldown.rb
127
+ - lib/cinch/plugin/cooldowns.rb
128
+ - lib/cinch/plugin/hooks.rb
127
129
  - spec/cinch-cooldown_spec.rb
128
130
  - spec/spec_helper.rb
129
131
  homepage: https://github.com/bhaberer/cinch-cooldown
130
- licenses: []
131
- post_install_message:
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
132
136
  rdoc_options: []
133
137
  require_paths:
134
138
  - lib
135
139
  required_ruby_version: !ruby/object:Gem::Requirement
136
- none: false
137
140
  requirements:
138
- - - ! '>='
141
+ - - ">="
139
142
  - !ruby/object:Gem::Version
140
- version: '0'
143
+ version: 2.0.0
141
144
  required_rubygems_version: !ruby/object:Gem::Requirement
142
- none: false
143
145
  requirements:
144
- - - ! '>='
146
+ - - ">="
145
147
  - !ruby/object:Gem::Version
146
148
  version: '0'
147
149
  requirements: []
148
- rubyforge_project:
149
- rubygems_version: 1.8.24
150
- signing_key:
151
- specification_version: 3
150
+ rubygems_version: 3.2.6
151
+ signing_key:
152
+ specification_version: 4
152
153
  summary: Global Cooldown tracker for Cinch Plugins
153
154
  test_files:
154
155
  - spec/cinch-cooldown_spec.rb
155
156
  - spec/spec_helper.rb
156
- has_rdoc: