2024-07-07 15:44:16 -04:00
|
|
|
function command_loop (bot, options, config) {
|
|
|
|
bot.cloop = {
|
|
|
|
list: [],
|
|
|
|
add (command, interval) {
|
2024-09-07 21:13:24 -04:00
|
|
|
let timer;
|
|
|
|
timer = ({ timer: setInterval(() => bot.core.run(command), interval), command, interval })
|
|
|
|
this.list.push(timer)
|
|
|
|
|
2024-08-09 23:26:27 -04:00
|
|
|
bot.on('end', () => {
|
|
|
|
this.clear()
|
|
|
|
})
|
2024-09-07 21:13:24 -04:00
|
|
|
|
|
|
|
bot.on('packet.login', () => {
|
2024-10-17 20:38:21 -04:00
|
|
|
if (this.list.length === 0) return
|
2024-09-07 21:13:24 -04:00
|
|
|
timer = ({ timer: setInterval(() => bot.core.run(command), interval), command, interval })
|
|
|
|
this.list.push(timer);
|
|
|
|
})
|
2024-07-07 15:44:16 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
remove (index) {
|
|
|
|
clearInterval(this.list[index].timer)
|
2024-07-20 20:27:17 -04:00
|
|
|
bot.cloop.list.splice(index, 1)
|
2024-07-07 15:44:16 -04:00
|
|
|
},
|
2024-09-07 21:13:24 -04:00
|
|
|
|
2024-07-07 15:44:16 -04:00
|
|
|
clear () {
|
|
|
|
for (const cloop of this.list) clearInterval(cloop.timer)
|
|
|
|
this.list = []
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = command_loop;
|