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.chat.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
// get current cooldown res for chat
24
let cooldown = Libs.CooldownLib.chat.getCooldown("GemBonusCooldown");
25
​
26
// for user:
27
// let cooldown = Libs.CooldownLib.user.getCooldown("GemBonusCooldown");
28
​
29
cooldown.value(); // current cooldown in second
30
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!
​
Last modified 24d ago
Copy link
Contents
Example