Cooldown Lib
Use this Lib to make cooldown.
Cooldown have name and can be for user or for chat.

Example

Command /bonus
1
function onEnding(time){
2
// can give bonus now
3
Bot.sendMessage("You have bonus now");
4
// your other code here
5
//..
6
​
7
return true; // if false - cooldown is not restarted
8
}
9
​
10
function onWaiting(waitTime){
11
// we have active cooldown
12
Bot.sendMessage("Please wait: " + waitTime + " secs" );
13
}
14
​
15
Libs.CooldownLib.user.watch({
16
// you need name for cooldown
17
name: "GemBonusCooldown",
18
time: 120, // cooldown time, 120 secs - 2 minute
19
onEnding: onEnding,
20
onWaiting: onWaiting
21
})
22
​
23
// or cooldown for chat:
24
/*
25
Libs.CooldownLib.chat.watch({
26
// you need name for cooldown
27
name: "GemBonusCooldown",
28
time: 120, // cooldown time, 120 secs - 2 minute
29
onEnding: onEnding,
30
onWaiting: onWaiting
31
})
32
*/
33
​
34
// get current cooldown res for chat
35
let cooldown = Libs.CooldownLib.chat.getCooldown("GemBonusCooldown");
36
​
37
// for user:
38
// let cooldown = Libs.CooldownLib.user.getCooldown("GemBonusCooldown");
39
​
40
cooldown.value(); // current cooldown in second
41
cooldown.set(60 + cooldown.value()) // add 60 sec to cooldown
Copied!
Command /bust
1
// get current cooldown Res - see ResourcesLib
2
let cooldown = Libs.CooldownLib.chat.getCooldown("GemBonusCooldown");
3
​
4
// for user:
5
// let cooldown = Libs.CooldownLib.user.getCooldown("GemBonusCooldown");
6
​
7
var curValue = cooldown.value(); // current cooldown in second
8
cooldown.set(curValue - 40) // reduce 40 sec from cooldown
Copied!
​
Copy link
Contents
Example