From 408c5aaab811db4cc5cd6058d9138e742bdaa372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christer=20War=C3=A9n?= Date: Thu, 8 Jun 2023 00:28:48 +0300 Subject: [PATCH] Limit commands in maintenance mode --- src/client/commands/list.ts | 7 +++++++ src/client/commands/next.ts | 19 +++++++++++++++---- src/client/commands/prev.ts | 19 +++++++++++++++---- src/client/events/interactionCreate.ts | 7 ------- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/client/commands/list.ts b/src/client/commands/list.ts index 165b93d..563d418 100644 --- a/src/client/commands/list.ts +++ b/src/client/commands/list.ts @@ -8,6 +8,13 @@ export default { category: 'radio', execute(interaction: ButtonInteraction | ChatInputCommandInteraction | StringSelectMenuInteraction, client: RadioClient) { + if(client.config.maintenanceMode){ + return interaction.reply({ + content: client.messages.emojis["error"] + client.messages.maintenance, + ephemeral: true + }); + } + if(!client.stations) { return interaction.reply({ content: client.messages.emojis["error"] + client.messages.replace(client.messages.errorToGetPlaylist, { diff --git a/src/client/commands/next.ts b/src/client/commands/next.ts index 43a3b92..60dfd46 100644 --- a/src/client/commands/next.ts +++ b/src/client/commands/next.ts @@ -11,10 +11,21 @@ export default { if (client.funcs.check(client, interaction, command)) { const radio = client.radio?.get(interaction.guild?.id); - if(!client.stations) return interaction.reply({ - content: client.messages.emojis["error"] + client.messages.maintenance, - ephemeral: true - }); + if(client.config.maintenanceMode){ + return interaction.reply({ + content: client.messages.emojis["error"] + client.messages.maintenance, + ephemeral: true + }); + } + + if(!client.stations) { + return interaction.reply({ + content: client.messages.emojis["error"] + client.messages.replace(client.messages.errorToGetPlaylist, { + "%client.config.supportGuild%": client.config.supportGuild + }), + ephemeral: true + }); + } let index: number = client.stations.findIndex((station: station) => station.name == radio.station.name) + 1; if(index == client.stations?.length) index = 0; diff --git a/src/client/commands/prev.ts b/src/client/commands/prev.ts index d705c46..fa8e39c 100644 --- a/src/client/commands/prev.ts +++ b/src/client/commands/prev.ts @@ -11,10 +11,21 @@ export default { if (client.funcs.check(client, interaction, command)) { const radio = client.radio?.get(interaction.guild?.id); - if(!client.stations) return interaction.reply({ - content: client.messages.emojis["error"] + client.messages.maintenance, - ephemeral: true - }); + if(client.config.maintenanceMode){ + return interaction.reply({ + content: client.messages.emojis["error"] + client.messages.maintenance, + ephemeral: true + }); + } + + if(!client.stations) { + return interaction.reply({ + content: client.messages.emojis["error"] + client.messages.replace(client.messages.errorToGetPlaylist, { + "%client.config.supportGuild%": client.config.supportGuild + }), + ephemeral: true + }); + } let index = client.stations.findIndex((station: station) => station.name == radio.station.name) - 1; if(index == -1) index = client.stations.length - 1; diff --git a/src/client/events/interactionCreate.ts b/src/client/events/interactionCreate.ts index 25387ca..0002943 100644 --- a/src/client/events/interactionCreate.ts +++ b/src/client/events/interactionCreate.ts @@ -4,13 +4,6 @@ import RadioClient from "../../Client"; export default function interactionCreate(client: RadioClient, interaction: Interaction) { if(!(interaction.isButton()) && !(interaction.isChatInputCommand()) && !(interaction.isStringSelectMenu())) return; - if(client.config.maintenanceMode){ - return interaction.reply({ - content: client.messages.emojis["error"] + client.messages.maintenance, - ephemeral: true - }); - } - //@ts-ignore const permissions = interaction.channel?.permissionsFor(interaction.client.user); if (!permissions.has(PermissionFlagsBits.ViewChannel)) return;