Skip to content

Commit

Permalink
feat: add translations for hangman (#97)
Browse files Browse the repository at this point in the history
* feat: add translations for hangman

* chore: translations for command data

* chore: somethings
  • Loading branch information
imnaiyar authored Oct 17, 2024
1 parent 69455d2 commit 2cb3f2d
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 11 deletions.
1 change: 1 addition & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pull_request_label:
- crowdin
- translations
pull_request_title: "chore: New Crowdin Translations"
commit_message: "chore: New translations %original_file_name% from Crowdin"
files:
Expand Down
45 changes: 45 additions & 0 deletions locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@
"SEASONAL_CHART": "Seasonal Price Chart by {{CREDIT}}",
"LOCATION_TITLE": "Location by {{CREDIT}}"
},
"hangman": {
"NOT_PLAYABLE": "This game can only be played in channels where I can send messages. This command is in accessible in user-app context, make sure you run the command in a server I am a member of or in my DM.",
"GAME_ACTIVE": "There is already a game running in this channel, please wait for it to finish. Or run in a different channel!"
},
"commands": {
"GUIDES": {
"name": "guides",
Expand Down Expand Up @@ -531,6 +535,47 @@
"EMBED_AUTHOR": "Daily Quests",
"EMBED_DESCRIPTION": "Daily quests for today"
}
},
"SKYGAME": {
"name": "skygame",
"description": "Various fun games based around Sky: CotL",
"SUB": {
"HANGMAN": {
"name": "hangman",
"description": "Play a game of hangman based on sky-related words, or a custom word",
"options": {
"mode": {
"name": "mode",
"description": "The mode of this game",
"choices": {
"single": "Single Player",
"double": "Double Player"
}
}
}
},
"LEADERBOARD": {
"name": "leaderboard",
"description": "View the leaderboard for the skygames",
"options": {
"game": {
"name": "game",
"description": "The game to view the leaderboard for",
"choices": {
"hangman": "Hangman"
}
},
"leaderboard-type": {
"name": "leaderboard-type",
"description": "Gloabal leaderboard or server specific (default: global)",
"choices": {
"global": "Global",
"server": "Server"
}
}
}
}
}
}
},
"buttons": {
Expand Down
31 changes: 28 additions & 3 deletions src/bot/commands/commands-data/fun-commands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Command } from "#bot/structures/Command";
import { ApplicationCommandOptionType } from "discord.js";
import { useTranslations as x } from "#bot/handlers/useTranslation";

// #region Hug
export const HUG_DATA: Omit<Command, "interactionRun" | "messageRun"> = {
Expand Down Expand Up @@ -29,36 +30,60 @@ export const SKY_GAME_DATA: Omit<Command, "interactionRun" | "messageRun"> = {
name: "skygame",
description: "Various fun games based around Sky: CotL",
slash: {
name_localizations: x("commands.SKYGAME.name"),
description_localizations: x("commands.SKYGAME.description"),
integration_types: [0, 1],
contexts: [0, 1, 2],
options: [
{
name: "hangman",
name_localizations: x("commands.SKYGAME.SUB.HANGMAN.name"),
description_localizations: x("commands.SKYGAME.SUB.HANGMAN.description"),
description: "Play a game of hangman based on sky-related words, or a custom word",
type: ApplicationCommandOptionType.Subcommand,
options: [
{
type: ApplicationCommandOptionType.String,
name: "mode",
name_localizations: x("commands.SKYGAME.SUB.HANGMAN.options.mode.name"),
description_localizations: x("commands.SKYGAME.SUB.HANGMAN.options.mode.description"),
description: "The mode of the game",
choices: [
{ name: "Single Player", value: "single" },
{ name: "Double Player", value: "double" },
{
name: "Single Player",
value: "single",
name_localizations: x("commands.SKYGAME.SUB.HANGMAN.options.mode.choices.single"),
},
{
name: "Double Player",
value: "double",
name_localizations: x("commands.SKYGAME.SUB.HANGMAN.options.mode.choices.double"),
},
],
required: true,
},
],
},
{
name: "leaderboard",
name_localizations: x("commands.SKYGAME.SUB.LEADERBOARD.name"),
description_localizations: x("commands.SKYGAME.SUB.LEADERBOARD.description"),
description: "View the leaderboard for the skygames",
type: ApplicationCommandOptionType.Subcommand,
options: [
{
type: ApplicationCommandOptionType.String,
name: "game",
name_localizations: x("commands.SKYGAME.SUB.LEADERBOARD.options.game.name"),
description_localizations: x("commands.SKYGAME.SUB.LEADERBOARD.options.game.description"),
description: "The game to view the leaderboard for",
choices: [{ name: "Hangman", value: "hangman" }],
choices: [
{
name: "Hangman",
value: "hangman",
name_localizations: x("commands.SKYGAME.SUB.LEADERBOARD.options.game.choices.hangman"),
},
],
required: true,
},
{
Expand Down
4 changes: 3 additions & 1 deletion src/bot/commands/inputCommands/admin/reminders.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/**
* This code is a mess, when I wrote it, I didn't know what I was doing. Now that I do know what I am doing, I still can't optimize it as I didnt know what I was doing, so I have no idea what I did here. :>
* This code is a mess, when I wrote it, I didn't know what I was doing.
* Now that I do know what I am doing, I still can't optimize it as I didnt know what I was doing,
* so I have no idea what I did here. :>
* So this may need full rewrite
*/

Expand Down
2 changes: 1 addition & 1 deletion src/bot/commands/inputCommands/fun/skygame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default {
const sub = interaction.options.getSubcommand(true);
switch (sub) {
case "hangman":
await handleHangman(interaction);
await handleHangman(interaction, _t);
return;
case "leaderboard":
{
Expand Down
7 changes: 4 additions & 3 deletions src/bot/commands/inputCommands/fun/sub/hangman.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Hangman } from "#bot/libs/classes/HangMan";
import type { getTranslator } from "#bot/i18n";
import {
ChatInputCommandInteraction,
User,
Expand All @@ -21,7 +22,7 @@ const constants = {
["double"]: `${BASE}\n- Each player will answer in turn, randomly picking for the first round, the player who guesses correctly will stay in the round until they guess incorrectly (or fail to do so within time), the round will pass to next person. Whoever guesses the word first wins.`,
};

export const handleHangman = async (interaction: ChatInputCommandInteraction) => {
export const handleHangman = async (interaction: ChatInputCommandInteraction, t: ReturnType<typeof getTranslator>) => {
const { client } = interaction;
const mode = interaction.options.getString("mode", true);
if (
Expand All @@ -30,14 +31,14 @@ export const handleHangman = async (interaction: ChatInputCommandInteraction) =>
Object.keys(interaction.authorizingIntegrationOwners).every((k) => k === "1")
) {
return void (await interaction.reply({
content: "This game can only be played in channels where I can send messages.",
content: t("hangman.NOT_PLAYABLE"),
ephemeral: true,
}));
}

if (client.gameData.has(interaction.channel.id)) {
return void (await interaction.reply({
content: "There is already a game running in this channel, please wait for it to finish. Or run in a different channel!",
content: t("hangman.GAME_ACTIVE"),
ephemeral: true,
}));
}
Expand Down
6 changes: 3 additions & 3 deletions src/bot/libs/registerCommands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
await import("dotenv/config");
import "dotenv/config";
import { SkyHelper } from "#structures";
const client = new SkyHelper();
const root = process.isBun ? "src/" : "dist/";
Expand All @@ -12,10 +12,10 @@ client.on("ready", async () => {
client.logger.success(`Registered ${client.application.commands.cache.size} commands`);

client.logger.success("Successfully reloaded application (/) commands.");
client.destroy();
process.exit(0);
} catch (error) {
client.logger.error(error);
client.destroy();
process.exit(1);
}
});
client.login(process.env.TOKEN);

0 comments on commit 2cb3f2d

Please sign in to comment.