cinch-cooldown 1.1.7 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ac9fa7f01e72f833c759dee51fc66b47b918054
4
- data.tar.gz: 9dbcca3ebba66164bbc5ac895e8b3449b1665493
3
+ metadata.gz: 393c4f5341d42e05e70f725c9a019fb0a8f1fbe4
4
+ data.tar.gz: f4f33cd1c65c061fa5e1e54af3ee0d02f9aeef84
5
5
  SHA512:
6
- metadata.gz: 320d14e0db3fd326dce550eb0b5950ba7b3c018ceca90b913930e8886f53e44670cbf7e8c6494ff3514935ac615090a1463388fcf535a3f933e397b4e3b1b03a
7
- data.tar.gz: 7be10c894fc3ceaeb063958f6bab87e85b1ba778dbbb4decfbcaf75be0a4141625422119843e5ec003eedade8ea3587bdee36b596f9ca4dfd66f11d0c59f3d5c
6
+ metadata.gz: 1a28ce8585c8ce633e0a9833a620a13d86bc7d9b3aded1f22c3e98ee8c11e10c05e841c4cc38a4d5dc9cb310ed5fd6c694edf810155dd76b8ce8890937018baa
7
+ data.tar.gz: e56839afc32ded54f3e5a33daa563b0b83bbf48747b3b4706fa91b1bb6a7c50e5ec440c913ec584c03913aa8a27fd2499e325e6e68b9cfc80d0fe77e0e15301d
@@ -15,6 +15,7 @@ rvm:
15
15
  - 2.0.0
16
16
  - 2.1.0
17
17
  - 2.2.0
18
+ - 2.3.0
18
19
  - jruby-18mode
19
20
  - jruby-19mode
20
21
  - ruby-head
@@ -29,4 +30,5 @@ matrix:
29
30
  - rvm: jruby-18mode
30
31
  - rvm: jruby-19mode
31
32
  - rvm: jruby-head
33
+ - rvm: ruby-head
32
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,10 +33,11 @@ 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, :user => 20 } } }```
40
+ ```c.shared[:cooldown] = { :config => { bottest: { global: 10, user: 20 } } }```
37
41
 
38
42
  2. If you are using this with my plugins, things should just work. However if you want to use
39
43
  this with your own plugins, you need to add a `'require cinch/cooldown'` to the top of said
@@ -2,6 +2,6 @@
2
2
  module Cinch
3
3
  # Versioning info
4
4
  module Cooldowns
5
- VERSION = '1.1.7'
5
+ VERSION = '1.2.0'
6
6
  end
7
7
  end
@@ -22,13 +22,15 @@ module Cinch
22
22
  # (i.e. user is pming the bot)
23
23
  return true if m.channel.nil?
24
24
 
25
- clean_expired_cooldowns(m.channel.name)
25
+ channel = channel_to_key(m.channel.name)
26
+
27
+ clean_expired_cooldowns(channel)
26
28
 
27
29
  # return true if the cooldowns have expired
28
- return true if cool?(m.channel.name, m.user.nick)
30
+ return true if cool?(channel, m.user.nick)
29
31
 
30
32
  # Otherwise message the user about unfinished cooldowns
31
- m.user.notice message(m.channel.name, m.user.nick)
33
+ m.user.notice message(channel, m.user.nick)
32
34
 
33
35
  # and return false so the command gets dropped by the hook
34
36
  false
@@ -57,6 +59,11 @@ module Cinch
57
59
  false
58
60
  end
59
61
 
62
+ def self.channel_to_key(channel)
63
+ return channel if channel.is_a?(Symbol)
64
+ channel[/\w+/].to_sym
65
+ end
66
+
60
67
  def self.config_for(chan)
61
68
  @config[chan]
62
69
  end
@@ -2,25 +2,22 @@ require 'spec_helper'
2
2
 
3
3
  class MyPlugin
4
4
  include Cinch::Plugin
5
-
6
5
  enforce_cooldown
7
-
8
6
  match(/thing/)
9
-
10
7
  def execute(m)
11
8
  m.reply 'OMG'
12
9
  end
13
10
  end
14
11
 
15
- def bot_for_cooldowns(global = 10, user = 0)
12
+ def bot_for_cooldowns(global: 10, user: 0, channel: 'foo')
16
13
  Cinch::Test::MockBot.new do
17
14
  configure do |c|
18
15
  c.nick = 'testbot'
19
16
  c.server = nil
20
- c.channels = ['foo']
17
+ c.channels = ['channel']
21
18
  c.reconnect = false
22
19
  c.plugins.plugins = [MyPlugin]
23
- c.shared[:cooldown] = { :config => { '#foo' => { :global => global, :user => user } } }
20
+ c.shared[:cooldown] = { config: { channel.to_sym => { global: global, user: user } } }
24
21
  end
25
22
  end
26
23
  end
@@ -32,46 +29,69 @@ describe Cinch::Cooldowns do
32
29
  Cinch::Plugin::Cooldowns.purge!
33
30
  end
34
31
 
35
- it 'should not trigger cooldowns on private messages' do
36
- bot = bot_for_cooldowns(10)
37
- get_replies(make_message(bot, "!thing"))
38
- expect(get_replies(make_message(bot, "!thing")).first.text)
39
- .to match('OMG')
40
- end
32
+ let(:bot) { bot_for_cooldowns }
41
33
 
42
- it 'should allow plugins to mandate a global cooldown between responses in channel' do
43
- bot = bot_for_cooldowns(10)
44
- get_replies(make_message(bot, "!thing", channel: '#foo'))
45
- expect(get_replies(make_message(bot, "!thing", channel: '#foo')).first.text)
46
- .to match(/Sorry, cooldown is in effect: \d+ seconds from now before/)
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
47
40
  end
48
41
 
49
- it 'should allow plugins allow responses after the global cooldown' do
50
- bot = bot_for_cooldowns(5, 5)
51
- get_replies(make_message(bot, "!thing", channel: '#foo'))
52
- sleep 7
53
- expect(get_replies(make_message(bot, "!thing", channel: '#foo')).first.text)
54
- .to eq('OMG')
55
- end
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
56
48
 
57
- it 'should allow plugins to mandate a minimum time between responses in channel' do
58
- bot = bot_for_cooldowns(5, 10)
59
- get_replies(make_message(bot, "!thing", channel: '#foo'))
60
- sleep 7
61
- expect(get_replies(make_message(bot, "!thing", channel: '#foo')).first.text)
62
- .to match(/Sorry, cooldown is in effect: \d+ seconds from now before you can use/)
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
63
73
  end
64
74
 
65
- it 'should allow plugins to mandate a minimum time between responses in channel' do
66
- bot = bot_for_cooldowns(5, 10)
67
- get_replies(make_message(bot, "!thing", channel: '#foo'))
68
- sleep 12
69
- expect(get_replies(make_message(bot, "!thing", channel: '#foo')).first.text)
70
- .to eq('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
71
91
  end
72
92
 
73
- it 'should aplugins to mandate a minimum time between responses in channel' do
74
- bot = bot_for_cooldowns(5, 10)
93
+ it 'manages mutiple users incurring simultaneous cooldowns' do
94
+ bot = bot_for_cooldowns(global: 5, user: 10)
75
95
  get_replies(make_message(bot, "!thing", channel: '#foo'))
76
96
  get_replies(make_message(bot, "thing", channel: '#foo'))
77
97
  sleep 6
@@ -81,26 +101,12 @@ describe Cinch::Cooldowns do
81
101
  .to eq('OMG')
82
102
  end
83
103
 
84
- it 'should not trigger if the config for the current channel does not exist' do
85
- bot = bot_for_cooldowns(5, 10)
86
- get_replies(make_message(bot, "!thing", channel: '#bar'))
87
- expect(get_replies(make_message(bot, "!thing", channel: '#bar')).first.text)
88
- .to eq('OMG')
89
- end
90
-
91
- it 'should trigger for other users if the global cooldown is finished' do
92
- bot = bot_for_cooldowns(0, 20)
93
- expect(get_replies(make_message(bot, "!thing", channel: '#foo', nick: 'test1')).first.text)
94
- .to eq('OMG')
95
- sleep 1
96
- expect(get_replies(make_message(bot, "!thing", channel: '#foo', nick: 'test2')).first.text)
97
- .to eq('OMG')
98
- end
99
- it 'should trigger for other users if the global cooldown is finished' do
100
- bot = bot_for_cooldowns(10, 20)
101
- expect(get_replies(make_message(bot, "!thing", channel: '#foo', nick: 'test1')).first.text)
102
- .to eq('OMG')
103
- expect(get_replies(make_message(bot, "!thing", channel: '#foo', nick: 'test2')).first.text)
104
- .not_to eq('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
105
111
  end
106
112
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cinch-cooldown
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Haberer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-28 00:00:00.000000000 Z
11
+ date: 2017-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  requirements: []
150
150
  rubyforge_project:
151
- rubygems_version: 2.5.1
151
+ rubygems_version: 2.6.8
152
152
  signing_key:
153
153
  specification_version: 4
154
154
  summary: Global Cooldown tracker for Cinch Plugins