Skip to content

Commit

Permalink
ask to create channel if it doesnt exist
Browse files Browse the repository at this point in the history
  • Loading branch information
NullDev committed Mar 25, 2024
1 parent e7b283c commit cf659ae
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 19 deletions.
6 changes: 4 additions & 2 deletions locales/English_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -80,6 +81,7 @@
"help_preamble": "You can visit <https://arithmetica.xyz/wiki> 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: <https://discord.gg/hgFyq43dug>",
"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: <https://discord.gg/hgFyq43dug>\nWiki: <https://arithmetica.xyz/wiki>",
"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?"
}
}
6 changes: 4 additions & 2 deletions locales/French_fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -80,6 +81,7 @@
"help_preamble": "Vous pouvez visiter <https://arithmetica.xyz/wiki> 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: <https://discord.gg/hgFyq43dug>",
"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: <https://discord.gg/hgFyq43dug>\nWiki: <https://arithmetica.xyz/wiki>",
"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 ?"
}
}
6 changes: 4 additions & 2 deletions locales/German_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -80,6 +81,7 @@
"help_preamble": "Besuche <https://arithmetica.xyz/wiki>, 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: <https://discord.gg/hgFyq43dug>",
"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: <https://discord.gg/hgFyq43dug>\nWiki: <https://arithmetica.xyz/wiki>",
"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?"
}
}
6 changes: 4 additions & 2 deletions locales/Japanese_ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -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です。算術表現を許可します。",
Expand Down Expand Up @@ -80,6 +81,7 @@
"help_preamble": "<https://arithmetica.xyz/wiki> を訪れて、どのような表現や構文が可能かを確認できます。表現が有効なカウントであるかどうかを確認するには、`/calc`を使用して結果が正しいかどうかを確認できます。\nSupport Server: <https://discord.gg/hgFyq43dug>",
"admin_help_preamble": "設定:`/set-channel`でカウントチャネルを設定し、次に `/set-language`、`/toggle-arithmetic`、`/set-timeout`、`/cooldown`、`/timeout-increment` でオプションを構成できます。\nSupport Server: <https://discord.gg/hgFyq43dug>\nWiki: <https://arithmetica.xyz/wiki>",
"pin_highscore": "ハイスコアのピン留めが%sされました!",
"rounding": "丸めは%sされました!"
"rounding": "丸めは%sされました!",
"channel_create": "私はチャンネル`%s`を見つけることができません。作成しますか?"
}
}
6 changes: 4 additions & 2 deletions locales/Russian_ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 для подсчёта. Поддерживает арифметические выражения.",
Expand Down Expand Up @@ -80,6 +81,7 @@
"help_preamble": "Вы можете посетить <https://arithmetica.xyz/wiki>, чтобы узнать, какие выражения и синтаксис возможны. Чтобы проверить, является ли выражение допустимым подсчетом, вы можете использовать `/calc`, чтобы увидеть, правильный ли результат.\nSupport Server: <https://discord.gg/hgFyq43dug>",
"admin_help_preamble": "Настройка: Установите канал подсчета с помощью `/set-channel`, затем при необходимости настройте опции с помощью `/set-language`, `/toggle-arithmetic`, `/set-timeout`, `/cooldown` и `/timeout-increment`.\nSupport Server: <https://discord.gg/hgFyq43dug>\nWiki: <https://arithmetica.xyz/wiki>",
"pin_highscore": "Закрепление рекордов было %s!",
"rounding": "Округление было %s!"
"rounding": "Округление было %s!",
"channel_create": "Я не могу найти канал `%s`. Хотите, чтобы я создал его?"
}
}
6 changes: 4 additions & 2 deletions locales/Spanish_es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -80,6 +81,7 @@
"help_preamble": "Puede visitar <https://arithmetica.xyz/wiki> 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: <https://discord.gg/hgFyq43dug>",
"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: <https://discord.gg/hgFyq43dug>\nWiki: <https://arithmetica.xyz/wiki>",
"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?"
}
}
37 changes: 30 additions & 7 deletions src/commands/admin/set-channel.js
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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,
});
},
};

0 comments on commit cf659ae

Please sign in to comment.