diff --git a/LICENSE b/LICENSE index faada8a..a0c94d9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Coosanta"s License (pls read if you want to do anything with the software!!) +Coosanta's License (pls read if you want to do anything with the software!!) Copyright (c) 2024 Coosanta diff --git a/src/bot.js b/src/bot.js index a9e9a59..3959c68 100644 --- a/src/bot.js +++ b/src/bot.js @@ -3,7 +3,7 @@ import { ActivityType, REST, Routes, Events } from "discord.js"; import { checkConfigFile, config } from "./config.js"; await checkConfigFile(); // Import and run checkConfigFile() before all other imports to set config variable. -// If this isn"t done, it will crash. +// If this isn't done, it will crash. const { discordClient } = await import("./api/client.js"); const { serverStart } = await import("./api/start_server.js"); @@ -31,7 +31,7 @@ discordClient.on("ready", async (c) => { discordClient.on("messageCreate", async (message) => { if (!message.content.startsWith(config.commands.text.prefix) || !config.commands.text.enabled) { - return; // Exit early if the message doesn"t start with the prefix or text commands are disabled. + return; // Exit early if the message doesn't start with the prefix or text commands are disabled. } // only text commands beyond this point const command = message.content.substring(1).toLowerCase(); diff --git a/src/commands/command_handler.js b/src/commands/command_handler.js index 0f650eb..79c2e85 100644 --- a/src/commands/command_handler.js +++ b/src/commands/command_handler.js @@ -1,6 +1,7 @@ -import { fileURLToPath, pathToFileURL } from "url"; import path from "path"; import fs from "fs/promises"; +import { fileURLToPath, pathToFileURL } from "url"; +import { commandsDisabled } from "./functions/disabled_commands.js"; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -48,3 +49,12 @@ export async function getCommands() { } return commandsCache; } + +export async function handleCommand(interaction, commandName, executeFunction) { + const areCommandsDisabled = commandsDisabled(commandName); + if (areCommandsDisabled) { + await interaction.reply({ content: areCommandsDisabled, ephemeral: true }); + return; + } + await executeFunction(interaction); +} diff --git a/src/commands/functions/disabled_commands.js b/src/commands/functions/disabled_commands.js index 3a25f28..bbd95a5 100644 --- a/src/commands/functions/disabled_commands.js +++ b/src/commands/functions/disabled_commands.js @@ -1,15 +1,15 @@ import { config } from "../../config.js"; export function commandsDisabled(command) { - if (!config.slash.enabled) { + if (!config.commands.slash.enabled) { let disabledResponse; - if (!config.text.enabled) { // Idiot proofing + if (!config.commands.text.enabled) { // Idiot proofing disabledResponse = "Commands are disabled! :sob: \nTry setting one of the command values to `true` in `config.json` to enable commands."; return; } - disabledResponse = `Slash commands are disabled.\nTry \`${config.text.prefix}${command}\` instead` + disabledResponse = `Slash commands are disabled.\nTry \`${config.commands.text.prefix}${command}\` instead` return disabledResponse; } } diff --git a/src/commands/functions/help_reponse.js b/src/commands/functions/help_reponse.js deleted file mode 100644 index 5c8c48d..0000000 --- a/src/commands/functions/help_reponse.js +++ /dev/null @@ -1,16 +0,0 @@ -import { EmbedBuilder } from "discord.js"; - -export function help(prefix) { - const helpEmbed = new EmbedBuilder() - .setColor(0x969696) - .setTitle("Help") - .setDescription("Available commands:") - .addFields( - { name: "START", value: `*Starts the server.*\nUsage: \`${prefix}start\`` }, - { name: "HELP", value: `*Shows the available commands.*\nUsage: \`${prefix}help\`` }, - { name: "That"s all for now.", value: "*New features will be added soon!*" } - ) - // .setTimestamp(); - - return {embeds: [helpEmbed]}; -} diff --git a/src/commands/functions/help_response.js b/src/commands/functions/help_response.js index 5c8c48d..5a2852d 100644 --- a/src/commands/functions/help_response.js +++ b/src/commands/functions/help_response.js @@ -8,7 +8,7 @@ export function help(prefix) { .addFields( { name: "START", value: `*Starts the server.*\nUsage: \`${prefix}start\`` }, { name: "HELP", value: `*Shows the available commands.*\nUsage: \`${prefix}help\`` }, - { name: "That"s all for now.", value: "*New features will be added soon!*" } + { name: "That's all for now.", value: "*New features will be added soon!*" } ) // .setTimestamp(); diff --git a/src/commands/registry/help.js b/src/commands/registry/help.js index e724246..b30a85d 100644 --- a/src/commands/registry/help.js +++ b/src/commands/registry/help.js @@ -1,18 +1,14 @@ import { SlashCommandBuilder } from "discord.js"; -import { help } from "../functions/help_reponse.js"; -import { commandsDisabled } from "../functions/disabled_commands.js"; +import { help } from "../functions/help_response.js"; +import { handleCommand } from "../command_handler.js"; export default { data: new SlashCommandBuilder() .setName("help") .setDescription("Shows the available commands."), async execute(interaction) { - let areCommandsDisabled = commandsDisabled("help"); - if (areCommandsDisabled) { - await interaction.reply(areCommandsDisabled, { ephemeral: true }); - return; - } - - await interaction.reply(help("/")); + await handleCommand(interaction, "help", async (interaction) => { + await interaction.reply(help("/")); + }); }, -} \ No newline at end of file +}; diff --git a/src/commands/registry/start.js b/src/commands/registry/start.js index 637943b..8fa1347 100644 --- a/src/commands/registry/start.js +++ b/src/commands/registry/start.js @@ -1,17 +1,14 @@ import { SlashCommandBuilder } from "discord.js"; import { serverStart } from "../../api/start_server.js"; -import { commandsDisabled } from "../functions/disabled_commands.js"; +import { handleCommand } from "../command_handler.js"; export default { data: new SlashCommandBuilder() .setName("start") .setDescription("Starts the server."), async execute(interaction) { - const areCommandsDisabled = commandsDisabled("start"); - if (areCommandsDisabled) { - interaction.reply(areCommandsDisabled, { ephemeral: true }); - return; - } - await interaction.reply(await serverStart()); + await handleCommand(interaction, "start", async (interaction) => { + await interaction.reply(await serverStart()); + }); }, };