From 02a6e256b56d4ef01ecd6b5ff18b6fe84a4897bd Mon Sep 17 00:00:00 2001 From: Essem Date: Tue, 28 Jun 2022 16:15:31 -0500 Subject: [PATCH] Added static command field to disable a command in DMs --- classes/command.js | 1 + classes/musicCommand.js | 1 + classes/soundboardCommand.js | 1 + commands/general/channel.js | 1 + commands/general/command.js | 2 ++ commands/general/serverinfo.js | 1 + commands/music/music.js | 1 + commands/soundboard/soundboard.js | 1 + commands/tags/tags.js | 1 + docs/custom-commands.md | 1 + events/messageCreate.js | 3 +++ utils/handler.js | 9 ++++++--- 12 files changed, 20 insertions(+), 3 deletions(-) diff --git a/classes/command.js b/classes/command.js index 6c27f1d..21698aa 100644 --- a/classes/command.js +++ b/classes/command.js @@ -64,6 +64,7 @@ class Command { static flags = []; static requires = []; static slashAllowed = true; + static directAllowed = true; } export default Command; \ No newline at end of file diff --git a/classes/musicCommand.js b/classes/musicCommand.js index 847f441..d4d228a 100644 --- a/classes/musicCommand.js +++ b/classes/musicCommand.js @@ -12,6 +12,7 @@ class MusicCommand extends Command { static requires = ["sound"]; static slashAllowed = false; + static directAllowed = false; } export default MusicCommand; diff --git a/classes/soundboardCommand.js b/classes/soundboardCommand.js index c1d5d80..76ce096 100644 --- a/classes/soundboardCommand.js +++ b/classes/soundboardCommand.js @@ -9,6 +9,7 @@ class SoundboardCommand extends Command { static requires = ["sound"]; static slashAllowed = false; + static directAllowed = false; } export default SoundboardCommand; diff --git a/commands/general/channel.js b/commands/general/channel.js index b11c651..84caffe 100644 --- a/commands/general/channel.js +++ b/commands/general/channel.js @@ -43,6 +43,7 @@ class ChannelCommand extends Command { static description = "Enables/disables me in a channel (does not work with slash commands)"; static arguments = ["[enable/disable]", "{id}"]; static slashAllowed = false; + static directAllowed = false; } export default ChannelCommand; diff --git a/commands/general/command.js b/commands/general/command.js index 7bcdd56..380fa53 100644 --- a/commands/general/command.js +++ b/commands/general/command.js @@ -34,6 +34,8 @@ class CommandCommand extends Command { static description = "Enables/disables a command for a server"; static aliases = ["cmd"]; static arguments = ["[enable/disable]", "[command]"]; + static slashAllowed = false; + static directAllowed = false; } export default CommandCommand; diff --git a/commands/general/serverinfo.js b/commands/general/serverinfo.js index aba0f2e..71d9812 100644 --- a/commands/general/serverinfo.js +++ b/commands/general/serverinfo.js @@ -49,6 +49,7 @@ class ServerInfoCommand extends Command { static description = "Gets some info about the server"; static aliases = ["server"]; + static directAllowed = false; } export default ServerInfoCommand; diff --git a/commands/music/music.js b/commands/music/music.js index 430c1b9..6f55687 100644 --- a/commands/music/music.js +++ b/commands/music/music.js @@ -38,6 +38,7 @@ class MusicAIOCommand extends Command { static description = "Handles music playback"; static requires = ["sound"]; static aliases = ["m"]; + static directAllowed = false; } export default MusicAIOCommand; diff --git a/commands/soundboard/soundboard.js b/commands/soundboard/soundboard.js index 6767c8b..39aaaef 100644 --- a/commands/soundboard/soundboard.js +++ b/commands/soundboard/soundboard.js @@ -26,6 +26,7 @@ class SoundboardAIOCommand extends Command { static description = "Plays a sound effect"; static requires = ["sound"]; static aliases = ["sound", "sb"]; + static directAllowed = false; } export default SoundboardAIOCommand; \ No newline at end of file diff --git a/commands/tags/tags.js b/commands/tags/tags.js index bfa4593..737df88 100644 --- a/commands/tags/tags.js +++ b/commands/tags/tags.js @@ -155,6 +155,7 @@ class TagsCommand extends Command { type: 1, description: "Gets a random tag" }]; + static directAllowed = false; } export default TagsCommand; diff --git a/docs/custom-commands.md b/docs/custom-commands.md index 1adb0a6..35b3454 100644 --- a/docs/custom-commands.md +++ b/docs/custom-commands.md @@ -75,6 +75,7 @@ static flags = [{ }]; ``` - `slashAllowed`: Specifies whether or not the command is available via slash commands. +- `directAllowed`: Specifies whether or not a command is available in direct messages. ## The `run` Function The main JS code of your command is specified in the `run` function. This function should return a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) of your command output, which is why the `run` function [is an async function by default](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function). The return value inside the `Promise` should be either a string or an object; you should return a string whenever you intend to reply with plain text, or an object if you intend to reply with something else, such as an embed or attachment. \ No newline at end of file diff --git a/events/messageCreate.js b/events/messageCreate.js index 3f69240..e279e56 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -84,6 +84,9 @@ export default async (client, cluster, worker, ipc, message) => { const cmd = commands.get(aliased ?? command); if (!cmd) return; + // block certain commands from running in DMs + if (!cmd.directAllowed && !message.channel.guild) return; + // actually run the command log("log", `${message.author.username} (${message.author.id}) ran classic command ${command}`); const reference = { diff --git a/utils/handler.js b/utils/handler.js index 7c88401..76a7e78 100644 --- a/utils/handler.js +++ b/utils/handler.js @@ -28,7 +28,8 @@ export async function load(client, cluster, worker, ipc, command, soundStatus, s aliases: props.aliases, params: props.arguments, flags: props.flags, - slashAllowed: props.slashAllowed + slashAllowed: props.slashAllowed, + directAllowed: props.directAllowed }); const categoryCommands = categories.get(category); @@ -69,7 +70,8 @@ export async function update() { aliases: cmd.aliases, params: cmd.arguments, flags: cmd.flags, - slashAllowed: cmd.slashAllowed + slashAllowed: cmd.slashAllowed, + directAllowed: cmd.directAllowed }; info.set(name, cmdInfo); } @@ -77,7 +79,8 @@ export async function update() { name, type: 1, description: cmdInfo.description, - options: cmdInfo.flags + options: cmdInfo.flags, + dm_permission: cmdInfo.directAllowed }); } return commandArray;