2024-07-06 11:02:11 -04:00
|
|
|
const fs=require("fs");
|
|
|
|
const Command=require("../util/Command.js");
|
2024-07-22 15:01:52 -04:00
|
|
|
const hashcheck=require("../util/hashcheck.js");
|
2024-07-18 01:49:55 -04:00
|
|
|
const settings = require("../settings.json");
|
2024-07-21 02:31:35 -04:00
|
|
|
let cmds=Object.create(null);
|
2024-07-06 11:02:11 -04:00
|
|
|
module.exports={
|
|
|
|
load:()=>{
|
|
|
|
module.exports.loadCMD();
|
|
|
|
},
|
|
|
|
loadBot:(b)=>{
|
2024-07-18 01:49:55 -04:00
|
|
|
b.prefix=settings.prefix;
|
2024-07-06 11:02:11 -04:00
|
|
|
b.lastCmd=0;
|
2024-07-16 11:53:32 -04:00
|
|
|
b.runCommand=(name, uuid, text, prefix)=>{
|
2024-07-16 17:22:42 -04:00
|
|
|
if(uuid=="00000000-0000-0000-0000-000000000000") return;
|
2024-07-06 11:02:11 -04:00
|
|
|
if(Date.now-b.lastCmd<=1000){
|
2024-07-16 09:59:37 -04:00
|
|
|
console.log("Executed too early, "+(Date.now-b.lastCmd)+"ms left");
|
|
|
|
return;
|
2024-07-06 11:02:11 -04:00
|
|
|
}
|
|
|
|
const cmd=text.split(" ");
|
2024-07-22 15:01:52 -04:00
|
|
|
let verify=hashcheck(cmd);
|
2024-07-06 11:02:11 -04:00
|
|
|
if(cmds[cmd[0].toLowerCase()]){
|
|
|
|
try{
|
2024-07-22 15:01:52 -04:00
|
|
|
cmds[cmd[0].toLowerCase()].execute(new Command(uuid,name,"nick N/A",text,prefix,b,verify))
|
2024-07-06 11:02:11 -04:00
|
|
|
} catch(e) { console.log(e); b.chat("An error occured (check console for more info)") }
|
|
|
|
}
|
|
|
|
}
|
2024-07-16 11:53:32 -04:00
|
|
|
b.printHelp=(uuid,prefix)=>{
|
2024-07-06 11:02:11 -04:00
|
|
|
let helpCmds=[];
|
|
|
|
for(const i in cmds){
|
|
|
|
if(cmds[i].hidden) continue;
|
2024-07-16 11:53:32 -04:00
|
|
|
helpCmds.push(prefix+i)
|
2024-07-06 11:02:11 -04:00
|
|
|
}
|
2024-07-22 15:01:52 -04:00
|
|
|
b.tellraw(uuid,{"text":"Commands: "+helpCmds.join(" ")});
|
2024-07-06 11:02:11 -04:00
|
|
|
}
|
|
|
|
b.printCmdHelp=(uuid,cmd)=>{
|
2024-07-22 15:01:52 -04:00
|
|
|
b.tellraw(uuid,{"text":cmd+cmds[cmd].usage+" - "+cmds[cmd].desc});
|
2024-07-06 11:02:11 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
loadCMD:()=>{
|
|
|
|
const botplug = []
|
|
|
|
const bpl = fs.readdirSync('./plugins/commands')
|
|
|
|
for (const i in bpl) {
|
|
|
|
if (!bpl[i].endsWith('.js')) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
try {
|
2024-07-16 10:43:20 -04:00
|
|
|
commandName=bpl[i].split(".js")[0];
|
|
|
|
cmds[commandName]=require(`./commands/${bpl[i]}`);
|
|
|
|
console.log("Loaded command "+commandName)
|
|
|
|
if(cmds[commandName].aliases){
|
|
|
|
for(const j in cmds[commandName].aliases){
|
|
|
|
cmds[cmds[commandName].aliases[j]]={
|
|
|
|
execute:cmds[commandName].execute,
|
|
|
|
desc:"Alias to "+commandName,
|
|
|
|
usage:cmds[commandName].usage,
|
|
|
|
hidden:true,
|
|
|
|
consoleIndex:cmds[commandName].consoleIndex
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
2024-07-06 11:02:11 -04:00
|
|
|
} catch (e) { console.log(e); }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
cmds
|
|
|
|
}
|