protonbot 0.2.4 → 0.2.5
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.
- checksums.yaml +4 -4
- data/CORE_PLUGIN.md +5 -0
- data/lib/protonbot/core_plugin/apis/cooldowns.rb +29 -6
- data/lib/protonbot/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71ee8635b3b1867e053d538bcf6ee829130e6121
|
4
|
+
data.tar.gz: 8f509132050a6ae0b9d6aa9aee3854e05b1f8da5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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[
|
30
|
+
elsif hook.extra[lu_sign]
|
9
31
|
curtime = Time.now.to_i
|
10
|
-
cmp = hook.extra[
|
32
|
+
cmp = hook.extra[lu_sign] - curtime + hook.extra[:cooldown_seconds]
|
11
33
|
if (cmp) <= 0
|
12
|
-
hook.extra[
|
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[
|
42
|
+
hook.extra[lu_sign] = Time.now.to_i
|
20
43
|
true
|
21
44
|
end
|
22
45
|
end
|
data/lib/protonbot/version.rb
CHANGED