Skip to content

Commit

Permalink
petCommand WIP #2273
Browse files Browse the repository at this point in the history
  • Loading branch information
BastLast committed Mar 16, 2024
1 parent 4314f96 commit 0b3d724
Show file tree
Hide file tree
Showing 11 changed files with 187 additions and 40 deletions.
7 changes: 2 additions & 5 deletions Core/src/commands/pet/PetCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@ import {WebsocketClient} from "../../../../Lib/src/instances/WebsocketClient";
import {DraftBotPacket, makePacket, PacketContext} from "../../../../Lib/src/packets/DraftBotPacket";
import {Players} from "../../core/database/game/models/Player";
import {CommandPetPacketReq, CommandPetPacketRes} from "../../../../Lib/src/packets/commands/CommandPetPacket";
import {Maps} from "../../core/maps/Maps";
import {MapCache} from "../../core/maps/MapCache";

import {PetEntities} from "../../core/database/game/models/PetEntity";
import {Pet, PetDataController} from "../../data/Pet";
import {PetDataController} from "../../data/Pet";

export default class PetCommand {
@packetHandler(CommandPetPacketReq)
async execute(client: WebsocketClient, packet: CommandPetPacketReq, context: PacketContext, response: DraftBotPacket[]): Promise<void> {

const player = packet.askedPlayer.keycloakId ? await Players.getByKeycloakId(packet.askedPlayer.keycloakId) : await Players.getByRank(packet.askedPlayer.rank);
const pet = await PetEntities.getById(player.petId);
const petModel = PetDataController.instance.getById(pet.petId);
if (!pet) {
response.push(makePacket(CommandPetPacketRes, {
foundPet: false
}));
}
else {
const petModel = PetDataController.instance.getById(pet.petId);
response.push(makePacket(CommandPetPacketRes, {
foundPet: true,
data: {
Expand Down
2 changes: 1 addition & 1 deletion Core/src/data/BigEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class BigEvent extends Data<number> {
public readonly tags: string[];

/**
* The possibilities condition are checked to choose to allow the possibility or not
* The possibility condition is checked to choose to allow the possibility or not
* @param player
*/
public async getPossibilities(player: Player): Promise<[string, Possibility][]> {
Expand Down
53 changes: 26 additions & 27 deletions Discord/src/commands/guild/GuildCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,38 @@ export async function handleCommandGuildPacketRes(packet: CommandGuildPacketRes,
return;
}

let membersInfos = "";
for (const member of packet.data!.members) {
membersInfos += i18n.t("commands:guild.memberInfos", {
lng: interaction.userLanguage,
icon: getMemberTypeIcon(member, packet, interaction),
pseudo: (await KeycloakUtils.getUserByKeycloakId(keycloakConfig, member.keycloakId))?.attributes.gameUsername,
ranking: member.rank,
score: member.score,
islandStatusIcon: getIslandStatusIcon(member, interaction)
});
}

const guildCommandEmbed = new DraftBotEmbed()
.setThumbnail(GuildConstants.ICON);
.setThumbnail(GuildConstants.ICON)
.setTitle(i18n.t("commands:guild.embedTitle", {
lng: interaction.userLanguage,
guildName: packet.data?.name,
level: packet.data?.level
}))
.addFields({
name: i18n.t("commands:guild.members", {
lng: interaction.userLanguage,
memberCount: packet.data!.members.length,
maxGuildMembers: GuildConstants.MAX_GUILD_MEMBERS
}),
value: membersInfos
});

if (packet.data!.level >= GuildConstants.GOLDEN_GUILD_LEVEL) {
guildCommandEmbed.setColor(ColorConstants.GOLD);
}

guildCommandEmbed.setTitle(i18n.t("commands:guild.embedTitle", {
lng: interaction.userLanguage,
guildName: packet.data?.name,
level: packet.data?.level
}));

if (packet.data!.description) {
guildCommandEmbed.setDescription(
Expand All @@ -123,27 +143,6 @@ export async function handleCommandGuildPacketRes(packet: CommandGuildPacketRes,
);
}

let membersInfos = "";
for (const member of packet.data!.members) {
membersInfos += i18n.t("commands:guild.memberInfos", {
lng: interaction.userLanguage,
icon: getMemberTypeIcon(member, packet, interaction),
pseudo: (await KeycloakUtils.getUserByKeycloakId(keycloakConfig, member.keycloakId))?.attributes.gameUsername,
ranking: member.rank,
score: member.score,
islandStatusIcon: getIslandStatusIcon(member, interaction)
});
}

guildCommandEmbed.addFields({
name: i18n.t("commands:guild.members", {
lng: interaction.userLanguage,
memberCount: packet.data!.members.length,
maxGuildMembers: GuildConstants.MAX_GUILD_MEMBERS
}),
value: membersInfos
});

const pveIslandInfo = packet.data!.members.some(
member => member.keycloakId === context.keycloakId
) ?
Expand Down
28 changes: 24 additions & 4 deletions Discord/src/commands/pet/PetCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {KeycloakUser} from "../../../../Lib/src/keycloak/KeycloakUser";
import {KeycloakUtils} from "../../../../Lib/src/keycloak/KeycloakUtils";
import {keycloakConfig} from "../../bot/DraftBotShard";
import {Effect} from "../../../../Lib/src/enums/Effect";
import {PetData, PetUtils} from "../../utils/PetUtils";

/**
* Display all the information about a Pet
Expand Down Expand Up @@ -55,7 +56,26 @@ export async function handleCommandPetPacketRes(packet: CommandPetPacketRes, con
return;
}

const PetCommandEmbed = new DraftBotEmbed();
const petData: PetData = {
emote: packet.data!.emote,
typeId: packet.data!.typeId,
nickname: packet.data!.nickname,
sex: packet.data!.sex,
rarity: packet.data!.rarity,
loveLevel: packet.data!.loveLevel
};

const PetCommandEmbed = new DraftBotEmbed()
.formatAuthor(
i18n.t("commands:pet.embedTitle", {
lng: interaction.userLanguage,
pseudo: interaction.user.username
}),
interaction.user
)
.setDescription(
PetUtils.petToString(interaction.userLanguage, petData)
);

await interaction.reply({
embeds: [PetCommandEmbed],
Expand All @@ -65,12 +85,12 @@ export async function handleCommandPetPacketRes(packet: CommandPetPacketRes, con
}

export const commandInfo: ICommand = {
slashCommandBuilder: SlashCommandBuilderGenerator.generateBaseCommand("Pet")
slashCommandBuilder: SlashCommandBuilderGenerator.generateBaseCommand("pet")
.addUserOption(option =>
SlashCommandBuilderGenerator.generateOption("Pet", "user", option)
SlashCommandBuilderGenerator.generateOption("pet", "user", option)
.setRequired(false))
.addIntegerOption(option =>
SlashCommandBuilderGenerator.generateOption("Pet", "rank", option)
SlashCommandBuilderGenerator.generateOption("pet", "rank", option)
.setRequired(false)) as SlashCommandBuilder,
getPacket,
requirements: {
Expand Down
7 changes: 7 additions & 0 deletions Discord/src/packetHandlers/handlers/CommandHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import {handleCommandGuildPacketRes} from "../../commands/guild/GuildCommand";
import {CommandGuildPacketRes} from "../../../../Lib/src/packets/commands/CommandGuildPacket";
import {reportResult} from "../../commands/player/ReportCommand";
import {CommandReportBigEventResultRes} from "../../../../Lib/src/packets/commands/CommandReportPacket";
import { CommandPetPacketRes } from "../../../../Lib/src/packets/commands/CommandPetPacket";
import {handleCommandPetPacketRes} from "../../commands/pet/PetCommand";

export default class CommandHandlers {
@packetHandler(CommandPingPacketRes)
Expand All @@ -40,6 +42,11 @@ export default class CommandHandlers {
await handleCommandProfilePacketRes(packet, context);
}

@packetHandler(CommandPetPacketRes)
async petRes(socket: WebSocket, packet: CommandPetPacketRes, context: PacketContext): Promise<void> {
await handleCommandPetPacketRes(packet, context);
}

@packetHandler(CommandGuildPacketRes)
async guildRes(socket: WebSocket, packet: CommandGuildPacketRes, context: PacketContext): Promise<void> {
await handleCommandGuildPacketRes(packet, context);
Expand Down
56 changes: 56 additions & 0 deletions Discord/src/utils/PetUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {Language} from "../../../Lib/src/Language";
import {PetConstants} from "../../../Lib/src/constants/PetConstants";
import i18n from "../translations/i18n";

export type PetData = {
emote: string,
typeId: number,
nickname: string,
sex: string,
rarity: number,
loveLevel: number
};

export class PetUtils {

static petToString(language: Language, petData: PetData): string {
const sexDisplay = `${
i18n.t(`commands:pet.sexDisplay.${
petData.sex === PetConstants.SEX.MALE ? PetConstants.SEX.MALE_FULL : PetConstants.SEX.FEMALE_FULL
}`, {lng: language})} ${
petData.sex === PetConstants.SEX.MALE ? PetConstants.ICONS.MALE : PetConstants.ICONS.FEMALE
}`;
return i18n.t("commands:pet.petField", {
lng: language,
emote: petData.emote,
type: PetUtils.getPetTypeName(language, petData.typeId, petData.sex),
nickname: PetUtils.displayNickname(language, petData.nickname),
rarity: PetUtils.getRarityDisplay(petData.rarity),
sex: sexDisplay,
loveLevel: petData.loveLevel
});
}

static getRarityDisplay(rarity: number): string {
return PetConstants.ICONS.RARITY.repeat(rarity);
}

static displayNickname(language: Language, nickname: string): string {
return nickname ? nickname : i18n.t("commands:pet.noNickname", {lng: language});
}

static getPetTypeName(language: Language, typeId: number, sex: string): string {
return i18n.t(
`models:pets:${typeId}.${
sex === PetConstants.SEX.MALE ?
PetConstants.SEX.MALE_FULL :
PetConstants.SEX.FEMALE_FULL}`,
{lng: language}
);
}

static getLoveLevelDisplay(loveLevel: number, sex: string, language: Language): string {
const sexStringContext :string = sex === PetConstants.SEX.MALE ? PetConstants.SEX.MALE_FULL : PetConstants.SEX.FEMALE_FULL;
return i18n.t("commands:pet.loveLevels.0.0", {context: sexStringContext, lng: language});
}
}
14 changes: 14 additions & 0 deletions Lang/en/discordBuilder.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@
"description": "Displays the ping of the bot and allow the player to check if the bot is online.",
"name": "ping"
},
"pet": {
"description": "Displays information about the pet of a player.",
"name": "pet",
"options": {
"rank": {
"description": "The rank of the player whose pet should be displayed.",
"name": "rank"
},
"user": {
"description": "The user whose pet should be displayed.",
"name": "user"
}
}
},
"guild": {
"description": "Displays information about a guild.",
"name": "guild",
Expand Down
37 changes: 37 additions & 0 deletions Lang/fr/commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,43 @@
"description": "Les badges sont des distinctions difficiles à obtenir qui ont été créées pour récompenser les personnes ayant le plus soutenu le développement du bot. La liste des badges est disponible sur le guide du bot.\n(via ce lien : https://guide.draftbot.com/notions-avancees/badges)",
"title": ":military_medal: Informations détaillées :"
},
"pet": {
"embedTitle": "Familier de {{pseudo}} :",
"petField": "**Type :** {{emote}} {{type}}\n**Surnom :** {{nickname}}\n\n**Rareté :** {{rarity}}\n**Sexe :** {{sex}}\n**Mentalité :** {{loveLevel}}",
"noNickname": "Aucun surnom",
"loveLevels": {
"0": {
"0_male": ":smirk_cat: Fielleux",
"0_female": ":smirk_cat: Fielleuse"
},
"1": {
"1_male": ":pouting_cat: Sauvage",
"1_female": ":pouting_cat: Sauvage"
},
"2": {
"2_male": ":scream_cat: Craintif",
"2_female": ":scream_cat: Craintive"
},
"3": {
"3_male": ":smiley_cat: Apprivoisé",
"3_female": ":smiley_cat: Apprivoisée"
},
"4": {
"4_male": ":heart_eyes_cat: Dressé",
"4_female": ":heart_eyes_cat: Dressée"
}
},
"hungry": "\uD83E\uDD24 affamé",
"diet": {
"diet_null": "\uD83E\uDD6A Omnivore",
"diet_herbivorous": "\uD83E\uDD6C Herbivore",
"diet_carnivorous": "\uD83E\uDD69 Carnivore"
},
"sexDisplay": {
"female": "Femelle",
"male": "Mâle"
}
},
"guild": {
"embedTitle": "Guilde {{guildName}} | Niveau {{level}}",
"description": ":scroll: `{{description}}`",
Expand Down
14 changes: 14 additions & 0 deletions Lang/fr/discordBuilder.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@
"description": "Affiche la latence du bot et permet au joueur de vérifier si le bot est en ligne.",
"name": "ping"
},
"pet": {
"description": "Afficher les informations du familier d'un joueur.",
"name": "familier",
"options": {
"rank": {
"description": "Le classement du joueur dont le familier doit être affiché.",
"name": "classement"
},
"user": {
"description": "L'utilisateur dont le familier doit être affiché.",
"name": "utilisateur"
}
}
},
"guild": {
"description": "Affiche des informations sur une guilde.",
"name": "guilde",
Expand Down
5 changes: 3 additions & 2 deletions Lang/fr/error.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@
"commandDoesntExist": "ERREUR: Commande inconnue",
"interactionNotForYou": "Cette interaction n'est pas pour vous !",
"playerBlocked": "Vous ne pouvez pas effectuer cela car vous avez une action en attente ({{reasons}}) !",
"playerDoesntExist": "Ce joueur n'existe pas !",
"playerDoesntExist": "Le joueur demandé n'a pas été trouvé !",
"titleBlocked": "{{pseudo}}, cette personne est bloquée !",
"titleCanceled": "{{pseudo}}, annulation prise en compte !",
"titleDidntWork": "{{pseudo}}, hmmm... Cela n'a pas fonctionné !",
"guildDoesntExist": "La guilde demandée n'existe pas",
"guildDoesntExist": "Aucune guilde n'a été trouvée.",
"petDoesntExist": "Aucun familier n'a été trouvé.",
"unexpectedError": "Une erreur est survenue :("
}
4 changes: 3 additions & 1 deletion Lib/src/constants/PetConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ export abstract class PetConstants {

static readonly SEX = {
MALE: "m",
FEMALE: "f"
FEMALE: "f",
MALE_FULL: "male",
FEMALE_FULL: "female"
};

static readonly PET_INTERACTIONS = {
Expand Down

0 comments on commit 0b3d724

Please sign in to comment.