From 85cce2407073e891b2a88ef494fb682930a2fcb2 Mon Sep 17 00:00:00 2001 From: Pagos Date: Thu, 22 Feb 2024 19:09:15 +0100 Subject: [PATCH 1/2] Rarity command now works #2273 --- Discord/src/commands/player/RarityCommand.ts | 43 +++++++++++++++++++ .../handlers/CommandHandlers.ts | 7 +++ Lang/en/commands.json | 4 ++ Lang/en/discordBuilder.json | 4 ++ Lang/fr/commands.json | 4 ++ Lang/fr/discordBuilder.json | 4 ++ 6 files changed, 66 insertions(+) create mode 100644 Discord/src/commands/player/RarityCommand.ts diff --git a/Discord/src/commands/player/RarityCommand.ts b/Discord/src/commands/player/RarityCommand.ts new file mode 100644 index 000000000..a965c5f62 --- /dev/null +++ b/Discord/src/commands/player/RarityCommand.ts @@ -0,0 +1,43 @@ +import {makePacket, PacketContext} from "../../../../Lib/src/packets/DraftBotPacket"; +import {CommandRarityPacketReq, CommandRarityPacketRes} from "../../../../Lib/src/packets/commands/CommandRarityPacket"; +import {DiscordCache} from "../../bot/DiscordCache"; +import i18n from "../../translations/i18n"; +import {DraftBotEmbed} from "../../messages/DraftBotEmbed"; +import {SlashCommandBuilderGenerator} from "../SlashCommandBuilderGenerator"; +import {ICommand} from "../ICommand"; + +function getPacket(): CommandRarityPacketReq { + return makePacket(CommandRarityPacketReq, {}); +} + +export async function handleCommandRarityPacketRes(packet: CommandRarityPacketRes, context: PacketContext): Promise { + const interaction = DiscordCache.getInteraction(context.discord!.interaction); + + if (interaction) { + await interaction.reply({ + embeds: [new DraftBotEmbed() + .setTitle(i18n.t("commands:rarity.title", { + lng: interaction.channel.language + } + )) + .setDescription(i18n.t("commands:rarity.rarities", { + common: packet.common, + uncommon: packet.uncommon, + exotic: packet.exotic, + rare: packet.rare, + special: packet.special, + epic: packet.epic, + legendary: packet.legendary, + unique: packet.unique, + lng: interaction.channel.language + }))] + }); + } +} + +export const commandInfo: ICommand = { + slashCommandBuilder: SlashCommandBuilderGenerator.generateBaseCommand("rarity"), + getPacket, + requirements: {}, + mainGuildCommand: false +}; \ No newline at end of file diff --git a/Discord/src/packetHandlers/handlers/CommandHandlers.ts b/Discord/src/packetHandlers/handlers/CommandHandlers.ts index 22227388f..ff552b4df 100644 --- a/Discord/src/packetHandlers/handlers/CommandHandlers.ts +++ b/Discord/src/packetHandlers/handlers/CommandHandlers.ts @@ -13,6 +13,8 @@ import {handleCommandUpdatePacketRes} from "../../commands/player/UpdateCommand" import { CommandUpdatePacketRes } from "../../../../Lib/src/packets/commands/CommandUpdatePacket"; import {CommandTestPacketReq, CommandTestPacketRes} from "../../../../Lib/src/packets/commands/CommandTestPacket"; import {handleCommandTestPacketRes} from "../../commands/player/TestCommand"; +import {CommandRarityPacketRes} from "../../../../Lib/src/packets/commands/CommandRarityPacket"; +import {handleCommandRarityPacketRes} from "../../commands/player/RarityCommand"; export default class CommandHandlers { @packetHandler(CommandPingPacketRes) @@ -48,4 +50,9 @@ export default class CommandHandlers { testRes(socket: WebSocket, packet: CommandTestPacketRes, context: PacketContext): void { handleCommandTestPacketRes(packet, context).then(); } + + @packetHandler(CommandRarityPacketRes) + rarityRes(socket: WebSocket, packet: CommandRarityPacketRes, context: PacketContext): void { + handleCommandRarityPacketRes(packet, context).then(); + } } \ No newline at end of file diff --git a/Lang/en/commands.json b/Lang/en/commands.json index 47069bc23..a9defaa9c 100644 --- a/Lang/en/commands.json +++ b/Lang/en/commands.json @@ -120,6 +120,10 @@ }, "title": "{{effect}} | {{pseudo}} | Level {{level}}" }, + "rarity": { + "title": ":slot_machine: Equipment rarity", + "rarities": ":small_orange_diamond: Basic | Owned at the beginning of the game\n:large_orange_diamond: Common | {{common}}%\n:fire: Uncommon | {{uncommon}}%\n:trident: Exotic | {{exotic}}%\n:comet: Rare | {{rare}}%\n:dizzy: Special | {{special}}%\n:star: Epic | {{epic}}%\n:star2: Legendary | {{legendary}}%\n:gem: Mythical | {{unique}}%" + }, "update": { "description": "The latest version of the bot's core is **{{coreVersion}}**. The Discord module's version is **{{discordModuleVersion}}**.\n\nInformations about the changelog can be found here:\nhttps://guide.draftbot.com/v/en/lore/change-logs", "title": ":scroll: Changelog" diff --git a/Lang/en/discordBuilder.json b/Lang/en/discordBuilder.json index d7429451c..c8b982c21 100644 --- a/Lang/en/discordBuilder.json +++ b/Lang/en/discordBuilder.json @@ -61,6 +61,10 @@ } } }, + "rarity": { + "description": "Displays the different equipment rarities.", + "name": "rarity" + }, "update": { "description": "Displays the bot's latest version.", "name": "update" diff --git a/Lang/fr/commands.json b/Lang/fr/commands.json index 44ab75d59..08132109a 100644 --- a/Lang/fr/commands.json +++ b/Lang/fr/commands.json @@ -120,6 +120,10 @@ }, "title": "{{effect}} | {{pseudo}} | Niveau {{level}}" }, + "rarity": { + "title": ":slot_machine: Rareté des équipements", + "rarities": ":small_orange_diamond: Basique | Possédé en début de jeu\n:large_orange_diamond: Commun | {{common}}%\n:fire: Peu commun | {{uncommon}}%\n:trident: Exotique | {{exotic}}%\n:comet: Rare | {{rare}}%\n:dizzy: Spécial | {{special}}%\n:star: Épique | {{epic}}%\n:star2: Légendaire | {{legendary}}%\n:gem: Mythique | {{unique}}%" + }, "update": { "description": "La version actuelle du noyau du bot est la **{{coreVersion}}**. Celle du module Discord est la **{{discordModuleVersion}}**.\n\nToutes les informations concernant les mises à jour sont disponibles ici :\nhttps://guide.draftbot.com/lore/historique-des-mises-a-jour", "title": ":scroll: Mises à jour" diff --git a/Lang/fr/discordBuilder.json b/Lang/fr/discordBuilder.json index ceb0cb8d9..886f7346e 100644 --- a/Lang/fr/discordBuilder.json +++ b/Lang/fr/discordBuilder.json @@ -61,6 +61,10 @@ } } }, + "rarity": { + "description": "Affiche les différentes raretés des équipements.", + "name": "rarete" + }, "update": { "description": "Affiche la version actuelle du bot.", "name": "nouveautes" From d135ff2eca202e4507edeb3368f5b5be5ad9bb9b Mon Sep 17 00:00:00 2001 From: BastLast Date: Thu, 22 Feb 2024 23:19:07 +0100 Subject: [PATCH 2/2] eslint fix in rarity command #2273 --- Discord/src/commands/player/RarityCommand.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Discord/src/commands/player/RarityCommand.ts b/Discord/src/commands/player/RarityCommand.ts index a965c5f62..a4d970bce 100644 --- a/Discord/src/commands/player/RarityCommand.ts +++ b/Discord/src/commands/player/RarityCommand.ts @@ -18,8 +18,7 @@ export async function handleCommandRarityPacketRes(packet: CommandRarityPacketRe embeds: [new DraftBotEmbed() .setTitle(i18n.t("commands:rarity.title", { lng: interaction.channel.language - } - )) + })) .setDescription(i18n.t("commands:rarity.rarities", { common: packet.common, uncommon: packet.uncommon,