protonbot 0.2.4 → 0.2.5

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: 838a7550d682f68d55fd9c8ffc7bb42f3f428562
4
- data.tar.gz: f1e5369b958f2b889cbe657a0a4522a0be768791
3
+ metadata.gz: 71ee8635b3b1867e053d538bcf6ee829130e6121
4
+ data.tar.gz: 8f509132050a6ae0b9d6aa9aee3854e05b1f8da5
5
5
  SHA512:
6
- metadata.gz: 5dcd94907a5b48c96a6cdd2f70895c1e2319e39e08cdeb25c05476df2252a14d9fb26cace45c9f9200c09b715257248ea7f097446756e1c25a41a6e21ceb5ac5
7
- data.tar.gz: 0f10bdea18ea063c5d2706095ac753f85d361a8c9fb7d87c86be6d7dd25dd057ad5c0742cb5f1da5ea91cc13fa4c251b4ae9d836d6739d52f75278a9324e72a0
6
+ metadata.gz: 1f59b5e070ca3b6599208df7ce26821821fe2c65899c3d00d54b036405588f5d5180e42e39ab9521c96ad00ca14472557c6bb017fef9f7ef437f2f93765097c7
7
+ data.tar.gz: d82bfbd92d51dd7813cbae35abd86f034163da36ed63c7865f16270467a0da36209aad8096adcb6f06b04d0d107d21a98ea970bf2d1cb92a0a9216949e40a6ee
data/CORE_PLUGIN.md CHANGED
@@ -66,6 +66,11 @@ Default permission hash:
66
66
  }
67
67
  ```
68
68
 
69
+ ### Cooldowns
70
+ These are added to prevent large amount of spam and available with different modes - `:global` (whole server), `:target_local`, `:user_local`, `:user_and_target` (default).
71
+
72
+ Method is: `ProtonBot::Hook#cooldown!(seconds, mode = :user_and_target, verbose = true)`
73
+
69
74
  ### Help
70
75
  Core plugin implements help system. To add help for new command, just use `core.help_add(group_name, command_name, syntax, description)`:
71
76
 
@@ -1,22 +1,45 @@
1
1
  class ProtonBot::Hook
2
- def cooldown!(seconds, verbose = true)
2
+ # Basic hook modifier for checking cooldowns. Added by core plugin.
3
+ # @param seconds [Integer] Cooldown
4
+ # @param mode [Symbol] :global, :user_local, :target_local, :user_and_target
5
+ # @param verbose [Boolean]
6
+ # @return [Hook] self
7
+ def cooldown!(seconds, mode = :user_and_target, verbose = true)
3
8
  self.extra[:cooldown_seconds] = seconds
4
9
  self.extra[:cooldown_verbose] = verbose
10
+ if [:global, :user_local, :target_local, :user_and_target].include? mode
11
+ self.extra[:cooldown_mode] = mode
12
+ else
13
+ self.extra[:cooldown_mode] = :user_and_target
14
+ end
15
+
5
16
  self.chain << proc do |dat, hook|
17
+ lu_sign =
18
+ case hook.extra[:cooldown_mode]
19
+ when :global
20
+ :"last_used_#{dat[:plug].name}"
21
+ when :user_local
22
+ :"last_used_#{dat[:plug].name}_#{dat[:host]}"
23
+ when :target_local
24
+ :"last_used_#{dat[:plug].name}_#{dat[:target]}"
25
+ when :user_and_target
26
+ :"last_used_#{dat[:plug].name}_#{dat[:target]}_#{dat[:host]}"
27
+ end
6
28
  if dat[:bot].plugins['core'].getpermsr(dat[:plug], dat[:host]).include? 'nocooldown'
7
29
  true
8
- elsif hook.extra[:last_used]
30
+ elsif hook.extra[lu_sign]
9
31
  curtime = Time.now.to_i
10
- cmp = hook.extra[:last_used] - curtime + hook.extra[:cooldown_seconds]
32
+ cmp = hook.extra[lu_sign] - curtime + hook.extra[:cooldown_seconds]
11
33
  if (cmp) <= 0
12
- hook.extra[:last_used] = curtime
34
+ hook.extra[lu_sign] = curtime
13
35
  true
14
36
  else
15
- dat.nreply("You need to wait %B#{cmp}%N more seconds to use this!")
37
+ dat.nreply("You need to wait %B#{cmp}%N more seconds to use this!") if
38
+ hook.extra[:cooldown_verbose]
16
39
  false
17
40
  end
18
41
  else
19
- hook.extra[:last_used] = Time.now.to_i
42
+ hook.extra[lu_sign] = Time.now.to_i
20
43
  true
21
44
  end
22
45
  end
@@ -1,4 +1,4 @@
1
1
  module ProtonBot
2
2
  # ProtonBot's version
3
- VERSION = '0.2.4'.freeze
3
+ VERSION = '0.2.5'.freeze
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protonbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nickolay Ilyushin