From 603e732704c42215f3387b2bd4271e96d7779908 Mon Sep 17 00:00:00 2001 From: Essem Date: Thu, 1 Sep 2022 10:40:55 -0500 Subject: [PATCH] Remove creation date from mkdocs, added ability to limit owner commands to certain server, don't append help command to end of playing message if classic commands are disabled, fix interaction upload size --- .env.example | 5 ++++- classes/command.js | 1 + commands/general/broadcast.js | 2 ++ commands/general/eval.js | 1 + commands/general/exec.js | 1 + commands/general/imagereload.js | 2 +- commands/general/reload.js | 1 + commands/general/restart.js | 1 + commands/general/soundreload.js | 1 + docs/config.md | 3 ++- events/interactionCreate.js | 12 +----------- mkdocs.yml | 3 +-- shard.js | 19 ++++++++++++++----- utils/handler.js | 12 +++++++++--- 14 files changed, 40 insertions(+), 24 deletions(-) diff --git a/.env.example b/.env.example index 54cf039..f445ed5 100644 --- a/.env.example +++ b/.env.example @@ -53,4 +53,7 @@ API_TYPE=none # If API_TYPE is `azure`, set this to your Azure webhook URL AZURE_URL= # If API_TYPE is `azure`, set an optional password for webhook responses -AZURE_PASS= \ No newline at end of file +AZURE_PASS= + +# Put ID of server to limit owner-only commands to +ADMIN_SERVER= \ No newline at end of file diff --git a/classes/command.js b/classes/command.js index 773af54..39647da 100644 --- a/classes/command.js +++ b/classes/command.js @@ -66,6 +66,7 @@ class Command { static requires = []; static slashAllowed = true; static directAllowed = true; + static adminOnly = false; } export default Command; \ No newline at end of file diff --git a/commands/general/broadcast.js b/commands/general/broadcast.js index 2f7fef8..955166b 100644 --- a/commands/general/broadcast.js +++ b/commands/general/broadcast.js @@ -8,6 +8,7 @@ class BroadcastCommand extends Command { if (!owners.includes(this.author.id)) { this.success = false; resolve("Only the bot owner can broadcast messages!"); + return; } const message = this.options.message ?? this.args.join(" "); if (message?.trim()) { @@ -35,6 +36,7 @@ class BroadcastCommand extends Command { }]; static description = "Broadcasts a playing message until the command is run again or the bot restarts"; + static adminOnly = true; } export default BroadcastCommand; \ No newline at end of file diff --git a/commands/general/eval.js b/commands/general/eval.js index 5d8d110..7d54229 100644 --- a/commands/general/eval.js +++ b/commands/general/eval.js @@ -38,6 +38,7 @@ class EvalCommand extends Command { static description = "Executes JavaScript code"; static aliases = ["run"]; static arguments = ["[code]"]; + static adminOnly = true; } export default EvalCommand; \ No newline at end of file diff --git a/commands/general/exec.js b/commands/general/exec.js index c0bb4d6..46df533 100644 --- a/commands/general/exec.js +++ b/commands/general/exec.js @@ -42,6 +42,7 @@ class ExecCommand extends Command { static description = "Executes a shell command"; static aliases = ["runcmd"]; static arguments = ["[command]"]; + static adminOnly = true; } export default ExecCommand; \ No newline at end of file diff --git a/commands/general/imagereload.js b/commands/general/imagereload.js index 981604f..262e639 100644 --- a/commands/general/imagereload.js +++ b/commands/general/imagereload.js @@ -16,7 +16,7 @@ class ImageReloadCommand extends Command { } static description = "Attempts to reconnect to all available image processing servers"; - static aliases = ["magickconnect", "magick"]; + static adminOnly = true; } export default ImageReloadCommand; diff --git a/commands/general/reload.js b/commands/general/reload.js index 85c92b8..4220984 100644 --- a/commands/general/reload.js +++ b/commands/general/reload.js @@ -33,6 +33,7 @@ class ReloadCommand extends Command { static description = "Reloads a command"; static arguments = ["[command]"]; + static adminOnly = true; } export default ReloadCommand; diff --git a/commands/general/restart.js b/commands/general/restart.js index 8df5f54..17cdda1 100644 --- a/commands/general/restart.js +++ b/commands/general/restart.js @@ -16,6 +16,7 @@ class RestartCommand extends Command { static description = "Restarts me"; static aliases = ["reboot"]; + static adminOnly = true; } export default RestartCommand; \ No newline at end of file diff --git a/commands/general/soundreload.js b/commands/general/soundreload.js index d92f533..296c282 100644 --- a/commands/general/soundreload.js +++ b/commands/general/soundreload.js @@ -28,6 +28,7 @@ class SoundReloadCommand extends Command { static description = "Attempts to reconnect to all available Lavalink nodes"; static aliases = ["lava", "lavalink", "lavaconnect", "soundconnect"]; + static adminOnly = true; } export default SoundReloadCommand; \ No newline at end of file diff --git a/docs/config.md b/docs/config.md index d216a17..5d14e03 100644 --- a/docs/config.md +++ b/docs/config.md @@ -21,4 +21,5 @@ Here's an overview of the variables that are not necessarily required for the bo - `METRICS`: The HTTP port to serve [Prometheus](https://prometheus.io/)-compatible metrics on. - `API`: Set this to "none" if you want to process all images locally. Alternatively, set it to "ws" to use an image API server specified in the `image` block of `servers.json`, or "azure" to use the Azure Functions-based API. - `AZURE_URL`: Your Azure webhook URL. Only applies if `API` is set to "azure". -- `AZURE_PASS`: An optional password used for Azure requests. Only applies if `API` is set to "azure". \ No newline at end of file +- `AZURE_PASS`: An optional password used for Azure requests. Only applies if `API` is set to "azure". +- `ADMIN_SERVER`: A server to limit owner-only commands to. \ No newline at end of file diff --git a/events/interactionCreate.js b/events/interactionCreate.js index 67e6888..68371ce 100644 --- a/events/interactionCreate.js +++ b/events/interactionCreate.js @@ -36,17 +36,7 @@ export default async (client, cluster, worker, ipc, interaction) => { flags: result.flags ?? (commandClass.success ? 0 : 64) })); } else if (typeof result === "object" && result.file) { - let fileSize = 8388119; - if (interaction.channel.guild) { - switch (interaction.channel.guild.premiumTier) { - case 2: - fileSize = 52428308; - break; - case 3: - fileSize = 104856616; - break; - } - } + const fileSize = 8388119; if (result.file.length > fileSize) { if (process.env.TEMPDIR && process.env.TEMPDIR !== "") { await upload(client, ipc, result, interaction, true); diff --git a/mkdocs.yml b/mkdocs.yml index 926b880..194b115 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -40,8 +40,7 @@ theme: name: Switch to light mode plugins: - glightbox - - git-revision-date-localized: - enable_creation_date: true + - git-revision-date-localized extra: social: - icon: fontawesome/brands/twitter diff --git a/shard.js b/shard.js index f28510f..4513632 100644 --- a/shard.js +++ b/shard.js @@ -26,6 +26,8 @@ import { generateList, createPage } from "./utils/help.js"; // whether a broadcast is currently in effect let broadcast = false; +const playingSuffix = !types.classic ? ` | @${this.bot.user.username} help` : ""; + class Shard extends BaseClusterWorker { constructor(bot) { super(bot); @@ -54,7 +56,14 @@ class Shard extends BaseClusterWorker { if (types.application) { const commandArray = await update(this.bot, this.clusterID, this.workerID, this.ipc, soundStatus); try { - await this.bot.bulkEditCommands(commandArray); + log("info", "Sending application command data to Discord..."); + let cmdArray = commandArray.main; + if (process.env.ADMIN_SERVER && process.env.ADMIN_SERVER !== "") { + await this.bot.bulkEditGuildCommands(process.env.ADMIN_SERVER, commandArray.private); + } else { + cmdArray = [...commandArray.main, ...commandArray.private]; + } + await this.bot.bulkEditCommands(cmdArray); } catch (e) { log("error", e); log("error", "Failed to send command data to Discord, slash/message commands may be unavailable."); @@ -111,7 +120,7 @@ class Shard extends BaseClusterWorker { this.ipc.register("playbroadcast", (message) => { this.bot.editStatus("dnd", { - name: `${message} | @${this.bot.user.username} help`, + name: message + playingSuffix, }); broadcast = true; return this.ipc.broadcast("broadcastSuccess"); @@ -119,7 +128,7 @@ class Shard extends BaseClusterWorker { this.ipc.register("broadcastend", () => { this.bot.editStatus("dnd", { - name: `${random(messages)} | @${this.bot.user.username} help`, + name: random(messages) + playingSuffix, }); broadcast = false; return this.ipc.broadcast("broadcastEnd"); @@ -132,7 +141,7 @@ class Shard extends BaseClusterWorker { if (broadcastMessage) { broadcast = true; this.bot.editStatus("dnd", { - name: `${broadcastMessage} | @${this.bot.user.username} help`, + name: broadcastMessage + playingSuffix, }); } @@ -145,7 +154,7 @@ class Shard extends BaseClusterWorker { activityChanger() { if (!broadcast) { this.bot.editStatus("dnd", { - name: `${random(messages)} | @${this.bot.user.username} help`, + name: random(messages) + playingSuffix, }); } setTimeout(this.activityChanger.bind(this), 900000); diff --git a/utils/handler.js b/utils/handler.js index d78fdcc..5ed5e95 100644 --- a/utils/handler.js +++ b/utils/handler.js @@ -43,6 +43,7 @@ export async function load(client, cluster, worker, ipc, command, soundStatus, s flags: props.flags, slashAllowed: props.slashAllowed, directAllowed: props.directAllowed, + adminOnly: props.adminOnly, type: 1 }; @@ -84,6 +85,7 @@ export async function load(client, cluster, worker, ipc, command, soundStatus, s export async function update() { const commandArray = []; + const privateCommandArray = []; const merged = new Map([...commands, ...messageCommands]); for (const [name, command] of merged.entries()) { let cmdInfo = info.get(name); @@ -97,18 +99,19 @@ export async function update() { flags: cmd.flags, slashAllowed: cmd.slashAllowed, directAllowed: cmd.directAllowed, + adminOnly: cmd.adminOnly, type: cmdInfo.type }; info.set(name, cmdInfo); } if (cmdInfo?.type === 3) { - commandArray.push({ + (cmdInfo.adminOnly ? privateCommandArray : commandArray).push({ name: name, type: cmdInfo.type, dm_permission: cmdInfo.directAllowed }); } else if (cmdInfo?.slashAllowed) { - commandArray.push({ + (cmdInfo.adminOnly ? privateCommandArray : commandArray).push({ name, type: cmdInfo.type, description: cmdInfo.description, @@ -117,5 +120,8 @@ export async function update() { }); } } - return commandArray; + return { + main: commandArray, + private: privateCommandArray + }; } \ No newline at end of file