From cf659ae1b5c0f53a127fb1104d3cc39d71e29244 Mon Sep 17 00:00:00 2001 From: "NullDev (Shadow)" Date: Tue, 26 Mar 2024 00:43:42 +0100 Subject: [PATCH] ask to create channel if it doesnt exist --- locales/English_en.json | 6 +++-- locales/French_fr.json | 6 +++-- locales/German_de.json | 6 +++-- locales/Japanese_ja.json | 6 +++-- locales/Russian_ru.json | 6 +++-- locales/Spanish_es-ES.json | 6 +++-- src/commands/admin/set-channel.js | 37 +++++++++++++++++++++++++------ 7 files changed, 54 insertions(+), 19 deletions(-) diff --git a/locales/English_en.json b/locales/English_en.json index 031d91d..c1da246 100644 --- a/locales/English_en.json +++ b/locales/English_en.json @@ -22,7 +22,8 @@ "stats_on_bot": "Bots don't get count stats :)", "cheat_mode_enabled": "Stats are deactivated in cheat mode because no one can lose.", "math_only": "Only math expressions are allowed in this channel! Counting normally has been disabled.", - "tex_on_windows": "The bot is currently running on Windows and therefore cannot execute this command." + "tex_on_windows": "The bot is currently running on Windows and therefore cannot execute this command.", + "no_channel_perm": "It seems like I don't have the permission to create channels." }, "replies": { "bot_info_tagline": "Discord Bot for counting. Allows arithmetic expressions.", @@ -80,6 +81,7 @@ "help_preamble": "You can visit to see, what expressions and syntax is possible. To check, if an expression is a valid count, you can use `/calc` to see if the result is correct.\nSupport Server: ", "admin_help_preamble": "Setup: Set the counting channel with `/set-channel`, then alternatively configure options with `/set-language`, `/toggle-arithmetic`, `/set-timeout`, `/cooldown` and `/timeout-increment`.\nSupport Server: \nWiki: ", "pin_highscore": "Highscore pinning has been %s!", - "rounding": "Rounding has been %s!" + "rounding": "Rounding has been %s!", + "channel_create": "I can't find the channel `%s`. Do you want me to create it?" } } diff --git a/locales/French_fr.json b/locales/French_fr.json index ee26255..22f0de7 100644 --- a/locales/French_fr.json +++ b/locales/French_fr.json @@ -22,7 +22,8 @@ "stats_on_bot": "Les bots n'ont pas de statistiques de comptage :)", "cheat_mode_enabled": "Les stats sont désactivées en mode triche car personne ne peut perdre.", "math_only": "Seules les expressions mathématiques sont autorisées dans ce canal ! Le comptage normal a été désactivé.", - "tex_on_windows": "Le bot est actuellement en cours d'exécution sur Windows et ne peut donc pas exécuter cette commande." + "tex_on_windows": "Le bot est actuellement en cours d'exécution sur Windows et ne peut donc pas exécuter cette commande.", + "no_channel_perm": "Il semble que je n'ai pas la permission de créer des salons." }, "replies": { "bot_info_tagline": "Bot Discord pour compter. Autorise les expressions arithmétiques.", @@ -80,6 +81,7 @@ "help_preamble": "Vous pouvez visiter pour voir quelles expressions et syntaxes sont possibles. Pour vérifier si une expression est un compte valide, vous pouvez utiliser `/calc` pour voir si le résultat est correct.\nSupport Server: ", "admin_help_preamble": "Configuration: Définissez le canal de comptage avec `/set-channel`, puis configurez éventuellement les options avec `/set-language`, `/toggle-arithmetic`, `/set-timeout`, `/cooldown` et `/timeout-increment`.\nSupport Server: \nWiki: ", "pin_highscore": "épingler le highscore a été %s!", - "rounding": "L'arrondi a été %s!" + "rounding": "L'arrondi a été %s!", + "channel_create": "Je ne trouve pas le salon `%s`. Voulez-vous que je le crée ?" } } diff --git a/locales/German_de.json b/locales/German_de.json index 0de0ce7..60e3ed6 100644 --- a/locales/German_de.json +++ b/locales/German_de.json @@ -22,7 +22,8 @@ "stats_on_bot": "Bots bekommen keine Zähl-Stats :)", "cheat_mode_enabled": "Stats sind deaktiviert im cheat mode, weil niemand verlieren kann.", "math_only": "Nur Mathe-Ausdrücke sind in diesem Channel erlaubt! Normales Zählen wurde deaktiviert.", - "tex_on_windows": "Der Bot läuft derzeit auf Windows und kann daher diesen Befehl nicht ausführen." + "tex_on_windows": "Der Bot läuft derzeit auf Windows und kann daher diesen Befehl nicht ausführen.", + "no_channel_perm": "Es sieht so aus, als hätte ich nicht die Berechtigung, um Channel zu erstellen." }, "replies": { "bot_info_tagline": "Discord Bot zum Zählen. Erlaubt arithmetische Ausdrücke.", @@ -80,6 +81,7 @@ "help_preamble": "Besuche , um zu sehen, welche Ausdrücke und Syntax möglich sind. Um zu überprüfen, ob ein Ausdruck eine gültige Zählung ist, kann `/calc` verwendet werden, um zu sehen, ob das Ergebnis korrekt ist.\nSupport Server: ", "admin_help_preamble": "Einrichtung: Zählchannel mit `/set-channel` einstellen. Danach, optionale Einstellungen mit `/set-language`, `/toggle-arithmetic`, `/set-timeout`, `/cooldown` und `/timeout-increment` konfigurieren.\nSupport Server: \nWiki: ", "pin_highscore": "Highscore pinning wurde %s!", - "rounding": "Runden wurde %s!" + "rounding": "Runden wurde %s!", + "channel_create": "Ich kann den Channel `%s` nicht finden. Möchtest du, dass ich ihn erstelle?" } } diff --git a/locales/Japanese_ja.json b/locales/Japanese_ja.json index 9aa6122..d5f8a97 100644 --- a/locales/Japanese_ja.json +++ b/locales/Japanese_ja.json @@ -22,7 +22,8 @@ "stats_on_bot": "ボットはカウント統計を取得しません :)", "cheat_mode_enabled": "チートモードでは、誰も負けることができないため、統計は無効になっています。", "math_only": "このチャンネルでは数学のみの表現が許可されています!通常のカウントは無効になっています。", - "tex_on_windows": "このボットは現在Windowsで実行されているため、このコマンドを実行できません。" + "tex_on_windows": "このボットは現在Windowsで実行されているため、このコマンドを実行できません。", + "no_channel_perm": "チャンネルを作成する権限がありません。" }, "replies": { "bot_info_tagline": "数をカウントするDiscord Botです。算術表現を許可します。", @@ -80,6 +81,7 @@ "help_preamble": " を訪れて、どのような表現や構文が可能かを確認できます。表現が有効なカウントであるかどうかを確認するには、`/calc`を使用して結果が正しいかどうかを確認できます。\nSupport Server: ", "admin_help_preamble": "設定:`/set-channel`でカウントチャネルを設定し、次に `/set-language`、`/toggle-arithmetic`、`/set-timeout`、`/cooldown`、`/timeout-increment` でオプションを構成できます。\nSupport Server: \nWiki: ", "pin_highscore": "ハイスコアのピン留めが%sされました!", - "rounding": "丸めは%sされました!" + "rounding": "丸めは%sされました!", + "channel_create": "私はチャンネル`%s`を見つけることができません。作成しますか?" } } diff --git a/locales/Russian_ru.json b/locales/Russian_ru.json index cb565da..f5a9987 100644 --- a/locales/Russian_ru.json +++ b/locales/Russian_ru.json @@ -22,7 +22,8 @@ "stats_on_bot": "Боты не считают статистику :)", "cheat_mode_enabled": "Статистика отключена в режиме читов, потому что никто не может проиграть.", "math_only": "В этом канале разрешены только математические выражения! Подсчет обычно был отключен.", - "tex_on_windows": "Бот в настоящее время работает под управлением Windows и поэтому не может выполнить эту команду." + "tex_on_windows": "Бот в настоящее время работает под управлением Windows и поэтому не может выполнить эту команду.", + "no_channel_perm": "Похоже, у меня нет разрешения на создание каналов." }, "replies": { "bot_info_tagline": "Бот Discord для подсчёта. Поддерживает арифметические выражения.", @@ -80,6 +81,7 @@ "help_preamble": "Вы можете посетить , чтобы узнать, какие выражения и синтаксис возможны. Чтобы проверить, является ли выражение допустимым подсчетом, вы можете использовать `/calc`, чтобы увидеть, правильный ли результат.\nSupport Server: ", "admin_help_preamble": "Настройка: Установите канал подсчета с помощью `/set-channel`, затем при необходимости настройте опции с помощью `/set-language`, `/toggle-arithmetic`, `/set-timeout`, `/cooldown` и `/timeout-increment`.\nSupport Server: \nWiki: ", "pin_highscore": "Закрепление рекордов было %s!", - "rounding": "Округление было %s!" + "rounding": "Округление было %s!", + "channel_create": "Я не могу найти канал `%s`. Хотите, чтобы я создал его?" } } diff --git a/locales/Spanish_es-ES.json b/locales/Spanish_es-ES.json index 227b52b..28b1bc4 100644 --- a/locales/Spanish_es-ES.json +++ b/locales/Spanish_es-ES.json @@ -22,7 +22,8 @@ "stats_on_bot": "Los bots no obtienen estadísticas de conteo :)", "cheat_mode_enabled": "Las estadísticas están desactivadas en modo trampa porque nadie puede perder.", "math_only": "¡Solo se permiten expresiones matemáticas en este canal! El conteo normal ha sido desactivado.", - "tex_on_windows": "El bot actualmente se está ejecutando en Windows y, por lo tanto, no puede ejecutar este comando." + "tex_on_windows": "El bot actualmente se está ejecutando en Windows y, por lo tanto, no puede ejecutar este comando.", + "no_channel_perm": "Parece que no tengo permiso para crear canales." }, "replies": { "bot_info_tagline": "Bot para Discord, Permite expresiones matemáticas.", @@ -80,6 +81,7 @@ "help_preamble": "Puede visitar para ver qué expresiones y sintaxis son posibles. Para verificar si una expresión es un recuento válido, puede usar `/calc` para ver si el resultado es correcto.\nSupport Server: ", "admin_help_preamble": "Configuración: Establezca el canal de conteo con `/set-channel`, luego configure opcionalmente opciones con `/set-language`, `/toggle-arithmetic`, `/set-timeout`, `/cooldown` y `/timeout-increment`.\nSupport Server: \nWiki: ", "pin_highscore": "¡El pin de la puntuación más alta ha sido %s!", - "rounding": "¡El redondeo ha sido %s!" + "rounding": "¡El redondeo ha sido %s!", + "channel_create": "No puedo encontrar el canal `%s`. ¿Quieres que lo cree?" } } diff --git a/src/commands/admin/set-channel.js b/src/commands/admin/set-channel.js index 6e70ad3..0b5ad65 100644 --- a/src/commands/admin/set-channel.js +++ b/src/commands/admin/set-channel.js @@ -1,6 +1,7 @@ import path from "node:path"; import { SlashCommandBuilder, PermissionFlagsBits, ChannelType } from "discord.js"; import { QuickDB } from "quick.db"; +import createYesNoInteraction from "../../events/yesNoInteraction.js"; import translations from "../../../locales/commands/translations.js"; import __ from "../../service/i18n.js"; @@ -42,19 +43,41 @@ export default { let val = String(channel.value)?.match(/^<#(\d+)>$/)?.[1]; if (!val) val = (await interaction.guild?.channels.fetch().catch(() => null))?.find(ch => ch?.name === channel.value && ch?.type === ChannelType.GuildText)?.id; if (!val){ - return await interaction.reply({ - content: await __("errors.channel_not_found")(interaction.guildId), - ephemeral: true, + const answer = await createYesNoInteraction(interaction, { + promptText: await __("replies.channel_create", String(channel.value))(interaction.guildId), }); + + if (answer === "yes"){ + val = (await interaction.guild?.channels.create({ // @ts-ignore + name: String(channel.value).replaceAll("#", "") || "counting", + type: ChannelType.GuildText, + }).catch(async() => { + interaction.followUp({ content: + await __("errors.no_channel_perm")(interaction.guildId), + }); + return null; + }))?.id; + } + else if (answer === "no"){ + await interaction.followUp({ + content: await __("generic.aborted")(interaction.guildId), + }); + } } + if (!val) return null; await db.set(`guild-${interaction.guildId}.channel`, val); await db.delete(`guild-${interaction.guildId}.lastUser`); await db.set(`guild-${interaction.guildId}.count`, 0); - return await interaction.reply({ - content: await __("replies.channel_set", channel.value ?? val)(interaction.guildId), - ephemeral: true, - }); + return interaction.deferred + ? await interaction.followUp({ + content: await __("replies.channel_set", channel.value ?? val)(interaction.guildId), + ephemeral: true, + }) + : await interaction.reply({ + content: await __("replies.channel_set", channel.value ?? val)(interaction.guildId), + ephemeral: true, + }); }, };