53 lines
No EOL
2.2 KiB
JavaScript
53 lines
No EOL
2.2 KiB
JavaScript
const desc = "loop commands";
|
|
const usages = " - cloop add <interval> <command>\n - cloop clear\n - cloop remove <index>\n - cloop list";
|
|
const trustLevel = 1;
|
|
const config = require("../config.json");
|
|
var clooplist = [];
|
|
var cloops = [];
|
|
|
|
function inject (client) {
|
|
const command = ((args) => {
|
|
switch (args[1]) {
|
|
case "add":
|
|
clooplist.push({ command: args.slice(3).join(" "), interval: parseInt(args[2]) });
|
|
client.bcraw(`${config.publicColor}Added ${config.trustedColor}${args.slice(3).join(" ")}${config.publicColor} with interval ${config.trustedColor}${parseInt(args[2])}${config.publicColor} to the cloops`);
|
|
cloops.push(setInterval(() => { client.cmdCore.run(args.slice(3).join(" ")); }, parseInt(args[2])));
|
|
break;
|
|
|
|
case "clear":
|
|
for (var i of cloops) {
|
|
clearInterval(i);
|
|
}
|
|
clooplist = [];
|
|
cloops = [];
|
|
client.bcraw(`${config.publicColor}Cleared the cloops`);
|
|
break;
|
|
|
|
case "list":
|
|
var result = [];
|
|
for (var i in clooplist) {
|
|
result.push(`&l${i}: &r${clooplist[i].command}&f &l(${clooplist[i].interval})&r`);
|
|
}
|
|
client.bcraw(`&7Cloops &8(${config.publicColor}${clooplist.length}&8) &7» &f${result.join("&8, &f")}`);
|
|
break;
|
|
|
|
case "remove":
|
|
if (cloops[parseInt(args[2])]) {
|
|
clearInterval(cloops[parseInt(args[2])])
|
|
cloops = cloops.filter(element => cloops.indexOf(element) != parseInt(args[2]));
|
|
client.bcraw(`${config.publicColor}Removed cloop ${config.trustedColor}${parseInt(args[2])}${config.publicColor}`);
|
|
} else {
|
|
client.cmdError("Nothing changed. That cloop is not in the list")
|
|
}
|
|
break;
|
|
|
|
default:
|
|
client.cmdError("Incorrect argument for command");
|
|
break;
|
|
}
|
|
})
|
|
client.runCommand = command;
|
|
return command;
|
|
}
|
|
|
|
module.exports = { inject, desc, usages, trustLevel }; |