owobot/plugins/command.js
7cc5c4f330d47060 de78065438 Initial commit
2024-07-06 11:02:11 -04:00

50 lines
1.7 KiB
JavaScript
Executable file

const fs=require("fs");
const Command=require("../util/Command.js");
let cmds={};
module.exports={
load:()=>{
module.exports.loadCMD();
},
loadBot:(b)=>{
b.prefix="\""
b.lastCmd=0;
b.runCommand=(name, uuid, text)=>{
if(Date.now-b.lastCmd<=1000){
console.log("Executed too early, "+(Date.now-b.lastCmd)+"ms left")
}
const cmd=text.split(" ");
if(cmds[cmd[0].toLowerCase()]){
try{
cmds[cmd[0].toLowerCase()].execute(new Command(uuid,name,"nick N/A",text,"prefix N/A",b,false))
} catch(e) { console.log(e); b.chat("An error occured (check console for more info)") }
} else {
b.chat("Command not found")
}
}
b.printHelp=(uuid)=>{
let helpCmds=[];
for(const i in cmds){
if(cmds[i].hidden) continue;
helpCmds.push(b.prefix+i)
}
b.tellraw(uuid,JSON.stringify({"text":"Commands: "+helpCmds.join(" ")}));
}
b.printCmdHelp=(uuid,cmd)=>{
b.tellraw(uuid,JSON.stringify({"text":"Commands: "+cmd+cmds[cmd].usage+" - "+cmds[cmd].desc}));
}
},
loadCMD:()=>{
const botplug = []
const bpl = fs.readdirSync('./plugins/commands')
for (const i in bpl) {
if (!bpl[i].endsWith('.js')) {
continue
}
try {
cmds[bpl[i].split(".js")[0]]=require(`./commands/${bpl[i]}`);
console.log("Loaded command "+bpl[i].split(".js")[0])
} catch (e) { console.log(e); }
}
},
cmds
}