Added command blacklist, added ability to toggle command types
This commit is contained in:
parent
1cafef76d7
commit
7fae0c1582
3 changed files with 38 additions and 4 deletions
7
config/commands.json
Normal file
7
config/commands.json
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"types": {
|
||||||
|
"classic": true,
|
||||||
|
"application": true
|
||||||
|
},
|
||||||
|
"blacklist": []
|
||||||
|
}
|
24
shard.js
24
shard.js
|
@ -17,6 +17,8 @@ import database from "./utils/database.js";
|
||||||
import { paths } from "./utils/collections.js";
|
import { paths } from "./utils/collections.js";
|
||||||
// playing messages
|
// playing messages
|
||||||
const { messages } = JSON.parse(readFileSync(new URL("./config/messages.json", import.meta.url)));
|
const { messages } = JSON.parse(readFileSync(new URL("./config/messages.json", import.meta.url)));
|
||||||
|
// command config
|
||||||
|
const { types } = JSON.parse(readFileSync(new URL("./config/commands.json", import.meta.url)));
|
||||||
// other stuff
|
// other stuff
|
||||||
import { random } from "./utils/misc.js";
|
import { random } from "./utils/misc.js";
|
||||||
// generate help page
|
// generate help page
|
||||||
|
@ -33,6 +35,11 @@ class Shard extends BaseClusterWorker {
|
||||||
}
|
}
|
||||||
|
|
||||||
async init() {
|
async init() {
|
||||||
|
if (!types.classic && !types.application) {
|
||||||
|
error("Both classic and application commands are disabled! Please enable at least one command type in config/commands.json.");
|
||||||
|
this.ipc.totalShutdown(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
// register commands and their info
|
// register commands and their info
|
||||||
const soundStatus = await checkStatus();
|
const soundStatus = await checkStatus();
|
||||||
log("info", "Attempting to load commands...");
|
log("info", "Attempting to load commands...");
|
||||||
|
@ -44,11 +51,17 @@ class Shard extends BaseClusterWorker {
|
||||||
error(`Failed to register command from ${commandFile}: ${e}`);
|
error(`Failed to register command from ${commandFile}: ${e}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (types.application) {
|
||||||
const commandArray = await update(this.bot, this.clusterID, this.workerID, this.ipc, soundStatus);
|
const commandArray = await update(this.bot, this.clusterID, this.workerID, this.ipc, soundStatus);
|
||||||
|
try {
|
||||||
|
await this.bot.bulkEditCommands(commandArray);
|
||||||
|
} catch {
|
||||||
|
log("error", "Failed to send command data to Discord, slash commands may be unavailable.");
|
||||||
|
}
|
||||||
|
}
|
||||||
log("info", "Finished loading commands.");
|
log("info", "Finished loading commands.");
|
||||||
|
|
||||||
await database.setup(this.ipc);
|
await database.setup(this.ipc);
|
||||||
await this.bot.bulkEditCommands(commandArray);
|
|
||||||
|
|
||||||
// register events
|
// register events
|
||||||
log("info", "Attempting to load events...");
|
log("info", "Attempting to load events...");
|
||||||
|
@ -56,6 +69,13 @@ class Shard extends BaseClusterWorker {
|
||||||
log("log", `Loading event from ${file}...`);
|
log("log", `Loading event from ${file}...`);
|
||||||
const eventArray = file.split("/");
|
const eventArray = file.split("/");
|
||||||
const eventName = eventArray[eventArray.length - 1].split(".")[0];
|
const eventName = eventArray[eventArray.length - 1].split(".")[0];
|
||||||
|
if (eventName === "messageCreate" && !types.classic) {
|
||||||
|
log("warn", `Skipped loading event from ${file} because classic commands are disabled...`);
|
||||||
|
continue;
|
||||||
|
} else if (eventName === "interactionCreate" && !types.application) {
|
||||||
|
log("warn", `Skipped loading event from ${file} because application commands are disabled`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
const { default: event } = await import(file);
|
const { default: event } = await import(file);
|
||||||
this.bot.on(eventName, event.bind(null, this.bot, this.clusterID, this.workerID, this.ipc));
|
this.bot.on(eventName, event.bind(null, this.bot, this.clusterID, this.workerID, this.ipc));
|
||||||
}
|
}
|
||||||
|
@ -78,8 +98,6 @@ class Shard extends BaseClusterWorker {
|
||||||
return this.ipc.broadcast("reloadSuccess");
|
return this.ipc.broadcast("reloadSuccess");
|
||||||
});
|
});
|
||||||
|
|
||||||
this.bot.privateChannels.limit = 0;
|
|
||||||
|
|
||||||
this.ipc.register("soundreload", async () => {
|
this.ipc.register("soundreload", async () => {
|
||||||
const soundStatus = await checkStatus();
|
const soundStatus = await checkStatus();
|
||||||
if (!soundStatus) {
|
if (!soundStatus) {
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import { paths, commands, info, sounds, categories, aliases as _aliases } from "./collections.js";
|
import { paths, commands, info, sounds, categories, aliases as _aliases } from "./collections.js";
|
||||||
import { log } from "./logger.js";
|
import { log } from "./logger.js";
|
||||||
|
|
||||||
|
import { readFileSync } from "fs";
|
||||||
|
|
||||||
|
const { blacklist } = JSON.parse(readFileSync(new URL("../config/commands.json", import.meta.url)));
|
||||||
|
|
||||||
let queryValue = 0;
|
let queryValue = 0;
|
||||||
|
|
||||||
// load command into memory
|
// load command into memory
|
||||||
|
@ -14,6 +18,11 @@ export async function load(client, cluster, worker, ipc, command, soundStatus, s
|
||||||
const commandArray = command.split("/");
|
const commandArray = command.split("/");
|
||||||
const commandName = commandArray[commandArray.length - 1].split(".")[0];
|
const commandName = commandArray[commandArray.length - 1].split(".")[0];
|
||||||
|
|
||||||
|
if (blacklist.includes(commandName)) {
|
||||||
|
log("warn", `Skipped loading blacklisted command ${command}...`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
props.init();
|
props.init();
|
||||||
|
|
||||||
paths.set(commandName, command);
|
paths.set(commandName, command);
|
||||||
|
|
Loading…
Reference in a new issue