2024-01-12 12:24:01 -05:00
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
|
|
|
const CommandError = require("../CommandModules/command_error.js");
|
2023-12-20 11:54:03 -05:00
|
|
|
//check command_source
|
|
|
|
//it would be both the command_source.js and command_manager.js files
|
2024-01-26 21:24:08 -05:00
|
|
|
async function command_manager(bot, options) {
|
2023-12-17 14:55:27 -05:00
|
|
|
bot.commandManager = {
|
|
|
|
commands: {},
|
2024-01-12 12:24:01 -05:00
|
|
|
commandlist: [],
|
|
|
|
//ohio
|
|
|
|
execute(source, commandName, args, message) {
|
|
|
|
const command = this.getCommand(commandName.toLowerCase());
|
|
|
|
//Unknown command. Type "/help" for help
|
|
|
|
const now = new Date().toLocaleString("en-US", {
|
|
|
|
timeZone: "America/CHICAGO",
|
|
|
|
});
|
2023-12-17 14:55:27 -05:00
|
|
|
try {
|
2024-01-26 21:24:08 -05:00
|
|
|
if (!bot.options.Core.CorelessMode){
|
|
|
|
if (!command || !command.execute) {
|
|
|
|
throw new CommandError(`Unknown command ${commandName}. Type "${bot.options.commands.prefixes[0]}help" for help`)
|
|
|
|
}
|
|
|
|
}else {
|
|
|
|
if (!command || !command.execute) // bot.options.command.prefixes[0]
|
|
|
|
throw new CommandError({ // sus
|
|
|
|
translate: `Unknown command %s. Type "${bot.options.commands.prefixes[0]}help" for help or click on this for the command`,
|
2024-01-12 12:24:01 -05:00
|
|
|
with: [commandName],
|
2024-01-26 21:24:08 -05:00
|
|
|
clickEvent: 'https://discord.gg'
|
|
|
|
|
|
|
|
? {//fr
|
|
|
|
// theme moment
|
2024-01-12 12:24:01 -05:00
|
|
|
action: "suggest_command",
|
2024-01-26 21:24:08 -05:00
|
|
|
value: `${bot.options.commands.prefixes[0]}help`,
|
2024-01-12 12:24:01 -05:00
|
|
|
}
|
|
|
|
: undefined,
|
|
|
|
}); //ohio
|
2024-01-26 21:24:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (command?.trustLevel > 0) {
|
2024-01-12 12:24:01 -05:00
|
|
|
const event = source?.discordMessageEvent;
|
2023-12-20 11:54:03 -05:00
|
|
|
|
2024-01-12 12:24:01 -05:00
|
|
|
const roles = event?.member?.roles?.cache;
|
2023-12-20 11:54:03 -05:00
|
|
|
|
2024-01-12 12:24:01 -05:00
|
|
|
if (
|
|
|
|
source?.sources?.discord &&
|
|
|
|
command.trustLevel === 1 &&
|
|
|
|
!roles?.some(
|
|
|
|
(role) =>
|
|
|
|
role?.name == "trusted" ||
|
|
|
|
role?.name == "FNFBoyfriendBot Owner",
|
|
|
|
)
|
|
|
|
? true
|
|
|
|
: false
|
|
|
|
)
|
|
|
|
throw new CommandError({
|
|
|
|
text: "You are not Trusted!",
|
|
|
|
color: "red",
|
|
|
|
});
|
|
|
|
if (
|
|
|
|
!source?.sources?.discord &&
|
2024-01-26 21:24:08 -05:00
|
|
|
!source?.sources?.console &&
|
2024-01-12 12:24:01 -05:00
|
|
|
command.trustLevel === 1 &&
|
|
|
|
args[0] !== bot.hash &&
|
|
|
|
args[0] !== bot.owner &&
|
|
|
|
args[0] !== bot.hashing.hash
|
2024-01-26 21:24:08 -05:00
|
|
|
) if (!bot.options.Core.CorelessMode){
|
|
|
|
|
|
|
|
throw new CommandError('&4Invalid Hash or Invalid Owner Hash')
|
|
|
|
// throw new CommandError('')
|
|
|
|
}else{
|
|
|
|
throw new CommandError({
|
2024-01-12 12:24:01 -05:00
|
|
|
text: "Invalid Hash or Invalid Owner Hash",
|
|
|
|
color: "red",
|
|
|
|
});
|
2024-01-26 21:24:08 -05:00
|
|
|
}
|
2024-01-12 12:24:01 -05:00
|
|
|
bot.hashing.updateHash();
|
|
|
|
const now = new Date().toLocaleString("en-US", {
|
|
|
|
timeZone: "America/CHICAGO",
|
|
|
|
});
|
|
|
|
const player = source?.player?.profile?.name;
|
|
|
|
const uuid = source?.player?.uuid;
|
|
|
|
const time = new Date().toLocaleTimeString("en-US", {
|
|
|
|
timeZone: "America/CHICAGO",
|
|
|
|
});
|
|
|
|
const date = new Date().toLocaleDateString("en-US", {
|
|
|
|
timeZone: "America/CHICAGO",
|
|
|
|
});
|
|
|
|
|
|
|
|
bot.console.hash = function (error, source) {
|
|
|
|
console.log(
|
|
|
|
`<\x1b[0m\x1b[35m${time} \x1b[0m\x1b[96m${date}\x1b[0m> [${bot.options.host}:${bot.options.port}\x1b[0m] ` +
|
|
|
|
`[\x1b[0m\x1b[92mHash\x1b[0m]: \x1b[0m\x1b[92mPlayer\x1b[0m: ${player}, \x1b[0m\x1b[92mUUID\x1b[0m:${uuid}, \x1b[0m\x1b[92mHash\x1b[0m:${
|
|
|
|
bot.hash || bot.hashing.hash
|
|
|
|
}\x1b[0m]`,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
bot.console.discordHash = function (error, source) {
|
|
|
|
console.log(
|
|
|
|
`<\x1b[0m\x1b[35m${time} \x1b[0m\x1b[96m${date}\x1b[0m> [${bot.options.host}:${bot.options.port}\x1b[0m] ` +
|
|
|
|
`[\x1b[0m\x1b[92mHash\x1b[0m]: \x1b[0m\x1b[92mPlayer\x1b[0m: ${player}, \x1b[0m\x1b[92mUUID\x1b[0m:${uuid}, \x1b[0m\x1b[92mHash\x1b[0m:${bot.hashing.hash}\x1b[0m]`,
|
|
|
|
);
|
|
|
|
};
|
|
|
|
bot.console.ownerHash = function (error, source) {
|
|
|
|
console.log(
|
|
|
|
`<\x1b[0m\x1b[35m${time} \x1b[0m\x1b[96m${date}\x1b[0m> [${bot.options.host}:${bot.options.port}\x1b[0m] ` +
|
|
|
|
`[\x1b[0m\x1b[31mOwnerHash\x1b[0m]: \x1b[0m\x1b[92mPlayer\x1b[0m: ${player}, \x1b[0m\x1b[92mUUID\x1b[0m:${uuid}, \x1b[0m\x1b[31mOwnerHash\x1b[0m:${bot.owner}\x1b[0m]`,
|
|
|
|
);
|
|
|
|
};
|
2023-12-24 12:11:42 -05:00
|
|
|
if (args[0] === bot.hash) {
|
2024-01-12 12:24:01 -05:00
|
|
|
bot.console.hash();
|
|
|
|
} else if (args[0] === bot.owner) {
|
|
|
|
bot.console.ownerHash();
|
2023-12-24 12:11:42 -05:00
|
|
|
}
|
2024-01-12 12:24:01 -05:00
|
|
|
if (
|
|
|
|
source?.sources?.discord &&
|
|
|
|
command.trustLevel === 2 &&
|
|
|
|
!roles?.some((role) => role.name === "FNFBoyfriendBot Owner")
|
|
|
|
)
|
2024-01-26 21:24:08 -05:00
|
|
|
|
2024-01-12 12:24:01 -05:00
|
|
|
throw new CommandError({
|
|
|
|
text: "You are not the Owner!",
|
|
|
|
color: "dark_red",
|
|
|
|
});
|
|
|
|
const owner = `${args[0]}`;
|
|
|
|
if (
|
|
|
|
!source?.sources?.discord &&
|
2024-01-26 21:24:08 -05:00
|
|
|
!source?.sources?.console &&
|
2024-01-12 12:24:01 -05:00
|
|
|
command.trustLevel === 2 &&
|
|
|
|
owner !== bot.owner
|
|
|
|
)
|
2024-01-26 21:24:08 -05:00
|
|
|
if (!bot.options.Core.CorelessMode){
|
|
|
|
|
|
|
|
throw new CommandError('&4Invalid Owner Hash')
|
|
|
|
}else{
|
2024-01-12 12:24:01 -05:00
|
|
|
throw new CommandError({
|
|
|
|
text: "Invalid Owner Hash",
|
|
|
|
color: "dark_red",
|
|
|
|
});
|
2024-01-26 21:24:08 -05:00
|
|
|
}
|
2024-01-12 12:24:01 -05:00
|
|
|
if (command.trustLevel === 3 && !source?.sources?.console)
|
2024-01-26 21:24:08 -05:00
|
|
|
if(!bot.options.Core.CorelessMode){
|
|
|
|
throw new CommandError('&9This command can only be execute via console')
|
|
|
|
}else{
|
2024-01-12 12:24:01 -05:00
|
|
|
throw new CommandError({
|
|
|
|
translate: "This command can only be executed via console",
|
|
|
|
color: "blue",
|
|
|
|
});
|
|
|
|
}
|
2024-01-26 21:24:08 -05:00
|
|
|
}
|
|
|
|
return command?.execute({ bot, source, arguments: args });
|
2023-12-17 14:55:27 -05:00
|
|
|
} catch (error) {
|
2024-01-12 12:24:01 -05:00
|
|
|
const now = new Date().toLocaleString("en-US", {
|
|
|
|
timeZone: "America/CHICAGO",
|
|
|
|
});
|
|
|
|
bot.console.warn(error.stack);
|
2024-01-26 21:24:08 -05:00
|
|
|
|
|
|
|
if (!bot.options.Core.CorelessMode){
|
|
|
|
if (error instanceof CommandError)
|
|
|
|
bot.chat(error._message)
|
|
|
|
else bot.chat('a error has occured!')
|
|
|
|
} else {
|
|
|
|
if (error instanceof CommandError)
|
|
|
|
source.sendError(error._message)
|
|
|
|
else source.sendError({
|
2024-01-12 12:24:01 -05:00
|
|
|
translate: "An Error has occured because the bot shot itself 🔫",
|
|
|
|
color: "red",
|
|
|
|
hoverEvent: { action: "show_text", contents: String(error.stack) },
|
|
|
|
});
|
2024-01-26 21:24:08 -05:00
|
|
|
}
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-12-17 14:55:27 -05:00
|
|
|
if (source.sources.discord) {
|
2024-01-12 12:24:01 -05:00
|
|
|
source.sendError(error);
|
|
|
|
}
|
2023-12-17 14:55:27 -05:00
|
|
|
}
|
2024-01-26 21:24:08 -05:00
|
|
|
},
|
|
|
|
|
2024-01-12 12:24:01 -05:00
|
|
|
|
|
|
|
executeString(source, command) {
|
|
|
|
const [commandName, ...args] = command.split(" ");
|
|
|
|
return this.execute(source, commandName, args);
|
2023-12-17 14:55:27 -05:00
|
|
|
},
|
2024-01-12 12:24:01 -05:00
|
|
|
register(command) {
|
|
|
|
this.commands[command.name] = command;
|
|
|
|
|
|
|
|
if (command.aliases) {
|
|
|
|
command.aliases.map((a) => (this.commands[a] = command));
|
2023-12-17 14:55:27 -05:00
|
|
|
}
|
|
|
|
},
|
2024-01-12 12:24:01 -05:00
|
|
|
getCommand(name) {
|
|
|
|
return this.commands[name];
|
2023-12-17 14:55:27 -05:00
|
|
|
},
|
|
|
|
|
2024-01-12 12:24:01 -05:00
|
|
|
getCommands() {
|
|
|
|
return Object.values(this.commands);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
//
|
|
|
|
commandlist = [];
|
2023-12-17 14:55:27 -05:00
|
|
|
|
2024-01-12 12:24:01 -05:00
|
|
|
for (const filename of fs.readdirSync(path.join(__dirname, "../commands"))) {
|
2023-12-17 14:55:27 -05:00
|
|
|
try {
|
2024-01-12 12:24:01 -05:00
|
|
|
const command = require(path.join(__dirname, "../commands", filename));
|
|
|
|
bot.commandManager.register(command);
|
|
|
|
bot.commandManager.commandlist.push(command);
|
2023-12-17 14:55:27 -05:00
|
|
|
} catch (error) {
|
2024-01-12 12:24:01 -05:00
|
|
|
console.error("Failed to load command", filename, ":", error);
|
2023-12-17 14:55:27 -05:00
|
|
|
}
|
2023-12-26 18:45:18 -05:00
|
|
|
|
2024-01-12 12:24:01 -05:00
|
|
|
if (process.env["anti-skid"] !== "amogus is sus") {
|
|
|
|
process.exit(0);
|
|
|
|
}
|
2023-12-17 14:55:27 -05:00
|
|
|
}
|
|
|
|
}
|
2024-01-12 12:24:01 -05:00
|
|
|
module.exports = command_manager;
|