FridayNightFunkinBoyfriendBot/src/modules/command_loop.js

33 lines
804 B
JavaScript
Raw Normal View History

2024-11-22 12:49:22 -05:00
function command_loop (context) {
const bot = context.bot;
2024-07-07 15:44:16 -04:00
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', () => {
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;