From 4396c7842ad57f017414d4ee40dcbb7e6d3ff620 Mon Sep 17 00:00:00 2001 From: Ntalcme Date: Sat, 21 Dec 2024 23:27:11 +0100 Subject: [PATCH 01/10] WIP on guildElder command #2273 --- Core/src/commands/guild/GuildElderCommand.ts | 146 ++++++++++++++++++ Core/src/commands/guild/GuildKickCommand.ts | 2 +- .../commands/CommandGuildElderPacket.ts | 29 ++++ .../ReactionCollectorGuildElder.ts | 34 ++++ 4 files changed, 210 insertions(+), 1 deletion(-) create mode 100644 Core/src/commands/guild/GuildElderCommand.ts create mode 100644 Lib/src/packets/commands/CommandGuildElderPacket.ts create mode 100644 Lib/src/packets/interaction/ReactionCollectorGuildElder.ts diff --git a/Core/src/commands/guild/GuildElderCommand.ts b/Core/src/commands/guild/GuildElderCommand.ts new file mode 100644 index 000000000..b7a53cc77 --- /dev/null +++ b/Core/src/commands/guild/GuildElderCommand.ts @@ -0,0 +1,146 @@ +import Player, {Players} from "../../core/database/game/models/Player"; +import {DraftBotPacket, makePacket, PacketContext} from "../../../../Lib/src/packets/DraftBotPacket"; +import {Guilds} from "../../core/database/game/models/Guild"; +import { + CommandGuildElderAcceptPacketRes, + CommandGuildElderPacketRes +} from "../../../../Lib/src/packets/commands/CommandGuildElderPacket"; +import {draftBotInstance} from "../../index"; +import {commandRequires, CommandUtils} from "../../core/utils/CommandUtils"; +import {GuildConstants} from "../../../../Lib/src/constants/GuildConstants"; +import {GuildRole} from "../../../../Lib/src/enums/GuildRole"; +import {ReactionCollectorGuildKick} from "../../../../Lib/src/packets/interaction/ReactionCollectorGuildKick"; +import {EndCallback, ReactionCollectorInstance} from "../../core/utils/ReactionsCollector"; +import {ReactionCollectorAcceptReaction} from "../../../../Lib/src/packets/interaction/ReactionCollectorPacket"; +import {BlockingUtils} from "../../core/utils/BlockingUtils"; +import {BlockingConstants} from "../../../../Lib/src/constants/BlockingConstants"; + +/** + * Return true if promotedPlayer can be promoted + * @param player + * @param promotedPlayer + * @param response + */ +async function isEligible(player: Player, promotedPlayer: Player, response: DraftBotPacket[]): Promise { + if (promotedPlayer === null) { + response.push(makePacket(CommandGuildElderPacketRes, { + foundPlayer: false, + sameGuild: false, + himself: false, + alreadyElder: false + })); + return false; + } + let promotedGuild; + try { + promotedGuild = await Guilds.getById(promotedPlayer.guildId); + } + catch (error) { + promotedGuild = null; + } + + const guild = await Guilds.getById(player.guildId); + if (promotedGuild === null || promotedGuild.id !== player.guildId) { + response.push(makePacket(CommandGuildElderPacketRes, { + foundPlayer: true, + sameGuild: false, + himself: false, + alreadyElder: false + })); + return false; + } + + if (promotedPlayer.id === player.id) { + response.push(makePacket(CommandGuildElderPacketRes, { + foundPlayer: true, + sameGuild: true, + himself: true, + alreadyElder: false + })); + return false; + } + + if (promotedPlayer.id === guild.id) { + response.push(makePacket(CommandGuildElderPacketRes, { + foundPlayer: true, + sameGuild: true, + himself: false, + alreadyElder: true + })); + return false; + } + return true; +} + +/** + * Promote promotedPlayer as elder of the guild + * @param player + * @param promotedPlayer + * @param response + */ +async function acceptGuildElder(player: Player, promotedPlayer: Player, response: DraftBotPacket[]): Promise { + await player.reload(); + if (! await isEligible(player,promotedPlayer,response)) { + return; + } + const guild = await Guilds.getById(player.guildId); + guild.elderId = promotedPlayer.id; + + await Promise.all([ + promotedPlayer.save(), + guild.save() + ]); + draftBotInstance.logsDatabase.logGuildElderAdd(guild, promotedPlayer.keycloakId).then(); + + response.push(makePacket(CommandGuildElderAcceptPacketRes, { + promotedKeycloakId: promotedPlayer.keycloakId, + guildName: guild.name + })); +} + +export default class GuildElderCommand { + @commandRequires(CommandGuildElderPacketReq, { + notBlocked: true, + disallowedEffects: CommandUtils.DISALLOWED_EFFECTS.NOT_STARTED_OR_DEAD, + level: GuildConstants.REQUIRED_LEVEL, + guildNeeded: true, + guildRoleNeeded: GuildRole.CHIEF + }) + async execute(response: DraftBotPacket[], player: Player, packet: CommandGuildElderPacketReq, context: PacketContext): Promise { + const promotedPlayer = await Players.getAskedPlayer(packet.askedPlayerKeycloakId, player); + + if (! await isEligible(player, promotedPlayer, response)) { + return; + } + const collector = new ReactionCollectorGuildElder( + promotedPlayer.keycloakId + ); + + const endCallback: EndCallback = async (collector: ReactionCollectorInstance, response: DraftBotPacket[]): Promise => { + const reaction = collector.getFirstReaction(); + if (reaction && reaction.reaction.type === ReactionCollectorAcceptReaction.name) { + await acceptGuildElder(player, promotedPlayer, response); + } + else { + response.push(makePacket(CommandGuildElderRefusePacketRes, { + promotedKeycloakId: promotedPlayer.keycloakId + })); + } + BlockingUtils.unblockPlayer(player.id, BlockingConstants.REASONS.GUILD_ELDER); + }; + + const collectorPacket = new ReactionCollectorInstance( + collector, + context, + { + allowedPlayerKeycloakIds: [player.keycloakId], + reactionLimit: 1 + }, + endCallback + ) + .block(player.id, BlockingConstants.REASONS.GUILD_ELDER) + .build(); + + response.push(collectorPacket); + } +} \ No newline at end of file diff --git a/Core/src/commands/guild/GuildKickCommand.ts b/Core/src/commands/guild/GuildKickCommand.ts index 49d929a4b..22bc04b4b 100644 --- a/Core/src/commands/guild/GuildKickCommand.ts +++ b/Core/src/commands/guild/GuildKickCommand.ts @@ -78,7 +78,7 @@ async function isNotEligible(player: Player, kickedPlayer: Player, response: Dra } if (kickedPlayer.id === player.id) { - // Different guild + // Same player response.push(makePacket(CommandGuildKickPacketRes, { foundPlayer: true, sameGuild: true, diff --git a/Lib/src/packets/commands/CommandGuildElderPacket.ts b/Lib/src/packets/commands/CommandGuildElderPacket.ts new file mode 100644 index 000000000..9f76acca7 --- /dev/null +++ b/Lib/src/packets/commands/CommandGuildElderPacket.ts @@ -0,0 +1,29 @@ +import {DraftBotPacket, PacketDirection, sendablePacket} from "../DraftBotPacket"; + +@sendablePacket(PacketDirection.BACK_TO_FRONT) +export class CommandGuildElderPacketRes extends DraftBotPacket { + foundPlayer!: boolean; + + sameGuild!: boolean; + + himself!: boolean; + + alreadyElder!: boolean; +} + +@sendablePacket(PacketDirection.BACK_TO_FRONT) +export class CommandGuildElderAcceptPacketRes extends DraftBotPacket { + promotedKeycloakId!: string; + + guildName!: string; +} + +@sendablePacket(PacketDirection.BACK_TO_FRONT) +export class CommandGuildElderRefusePacketRes extends DraftBotPacket { + promotedKeycloakId!: string; +} + +@sendablePacket(PacketDirection.FRONT_TO_BACK) +export class CommandGuildElderPacketReq extends DraftBotPacket { + askedPlayerKeycloakId!: string; +} \ No newline at end of file diff --git a/Lib/src/packets/interaction/ReactionCollectorGuildElder.ts b/Lib/src/packets/interaction/ReactionCollectorGuildElder.ts new file mode 100644 index 000000000..42f1af628 --- /dev/null +++ b/Lib/src/packets/interaction/ReactionCollectorGuildElder.ts @@ -0,0 +1,34 @@ +import { + ReactionCollector, + ReactionCollectorAcceptReaction, + ReactionCollectorCreationPacket, + ReactionCollectorData, + ReactionCollectorRefuseReaction +} from "./ReactionCollectorPacket"; + +export class ReactionCollectorGuildElderData extends ReactionCollectorData { + promotedKeycloakId!: string; +} + +export class ReactionCollectorGuildElder extends ReactionCollector { + private readonly promotedKeycloakId: string; + + constructor(promotedKeycloakId: string) { + super(); + this.kickedKeycloakId = promotedKeycloakId; + } + + creationPacket(id: string, endTime: number): ReactionCollectorCreationPacket { + return { + id, + endTime, + reactions: [ + this.buildReaction(ReactionCollectorAcceptReaction, {}), + this.buildReaction(ReactionCollectorRefuseReaction, {}) + ], + data: this.buildData(ReactionCollectorGuildKickData, { + kickedKeycloakId: this.kickedKeycloakId + }) + }; + } +} \ No newline at end of file From 528aaac032a4bf540a2be3acd3944cdf324a6685 Mon Sep 17 00:00:00 2001 From: Ntalcme Date: Sat, 28 Dec 2024 13:53:40 +0100 Subject: [PATCH 02/10] small fix #2273 --- Core/src/commands/guild/GuildElderCommand.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Core/src/commands/guild/GuildElderCommand.ts b/Core/src/commands/guild/GuildElderCommand.ts index b7a53cc77..1a5614a88 100644 --- a/Core/src/commands/guild/GuildElderCommand.ts +++ b/Core/src/commands/guild/GuildElderCommand.ts @@ -2,8 +2,8 @@ import Player, {Players} from "../../core/database/game/models/Player"; import {DraftBotPacket, makePacket, PacketContext} from "../../../../Lib/src/packets/DraftBotPacket"; import {Guilds} from "../../core/database/game/models/Guild"; import { - CommandGuildElderAcceptPacketRes, - CommandGuildElderPacketRes + CommandGuildElderAcceptPacketRes, CommandGuildElderPacketReq, + CommandGuildElderPacketRes, CommandGuildElderRefusePacketRes } from "../../../../Lib/src/packets/commands/CommandGuildElderPacket"; import {draftBotInstance} from "../../index"; import {commandRequires, CommandUtils} from "../../core/utils/CommandUtils"; @@ -14,6 +14,7 @@ import {EndCallback, ReactionCollectorInstance} from "../../core/utils/Reactions import {ReactionCollectorAcceptReaction} from "../../../../Lib/src/packets/interaction/ReactionCollectorPacket"; import {BlockingUtils} from "../../core/utils/BlockingUtils"; import {BlockingConstants} from "../../../../Lib/src/constants/BlockingConstants"; +import {ReactionCollectorGuildElder} from "../../../../Lib/src/packets/interaction/ReactionCollectorGuildElder"; /** * Return true if promotedPlayer can be promoted @@ -107,7 +108,7 @@ export default class GuildElderCommand { guildRoleNeeded: GuildRole.CHIEF }) async execute(response: DraftBotPacket[], player: Player, packet: CommandGuildElderPacketReq, context: PacketContext): Promise { - const promotedPlayer = await Players.getAskedPlayer(packet.askedPlayerKeycloakId, player); + const promotedPlayer = await Players.getAskedPlayer({keycloakId: packet.askedPlayerKeycloakId}, player); if (! await isEligible(player, promotedPlayer, response)) { return; From debc50182a67ad282d6173705e145ca9c17c44ff Mon Sep 17 00:00:00 2001 From: Ntalcme Date: Mon, 30 Dec 2024 22:59:42 +0100 Subject: [PATCH 03/10] front guildElder command #2273 --- Core/src/commands/guild/GuildElderCommand.ts | 1 - .../src/commands/guild/GuildElderCommand.ts | 168 ++++++++++++++++++ .../src/commands/guild/GuildKickCommand.ts | 10 +- .../handlers/CommandHandlers.ts | 24 +++ .../handlers/ReactionCollectorHandlers.ts | 3 + Lang/en/discordBuilder.json | 10 ++ Lang/fr/commands.json | 13 ++ Lang/fr/discordBuilder.json | 12 ++ .../ReactionCollectorGuildElder.ts | 6 +- 9 files changed, 240 insertions(+), 7 deletions(-) create mode 100644 Discord/src/commands/guild/GuildElderCommand.ts diff --git a/Core/src/commands/guild/GuildElderCommand.ts b/Core/src/commands/guild/GuildElderCommand.ts index 1a5614a88..86dcc7274 100644 --- a/Core/src/commands/guild/GuildElderCommand.ts +++ b/Core/src/commands/guild/GuildElderCommand.ts @@ -9,7 +9,6 @@ import {draftBotInstance} from "../../index"; import {commandRequires, CommandUtils} from "../../core/utils/CommandUtils"; import {GuildConstants} from "../../../../Lib/src/constants/GuildConstants"; import {GuildRole} from "../../../../Lib/src/enums/GuildRole"; -import {ReactionCollectorGuildKick} from "../../../../Lib/src/packets/interaction/ReactionCollectorGuildKick"; import {EndCallback, ReactionCollectorInstance} from "../../core/utils/ReactionsCollector"; import {ReactionCollectorAcceptReaction} from "../../../../Lib/src/packets/interaction/ReactionCollectorPacket"; import {BlockingUtils} from "../../core/utils/BlockingUtils"; diff --git a/Discord/src/commands/guild/GuildElderCommand.ts b/Discord/src/commands/guild/GuildElderCommand.ts new file mode 100644 index 000000000..6a7456503 --- /dev/null +++ b/Discord/src/commands/guild/GuildElderCommand.ts @@ -0,0 +1,168 @@ +import {ReactionCollectorCreationPacket} from "../../../../Lib/src/packets/interaction/ReactionCollectorPacket"; +import {makePacket, PacketContext} from "../../../../Lib/src/packets/DraftBotPacket"; +import {DiscordCache} from "../../bot/DiscordCache"; +import {KeycloakUtils} from "../../../../Lib/src/keycloak/KeycloakUtils"; +import {keycloakConfig} from "../../bot/DraftBotShard"; +import {DraftBotEmbed} from "../../messages/DraftBotEmbed"; +import i18n from "../../translations/i18n"; +import {DiscordCollectorUtils} from "../../utils/DiscordCollectorUtils"; +import {ReactionCollectorGuildElderData} from "../../../../Lib/src/packets/interaction/ReactionCollectorGuildElder"; +import { + CommandGuildElderAcceptPacketRes, + CommandGuildElderPacketReq, + CommandGuildElderPacketRes, + CommandGuildElderRefusePacketRes +} from "../../../../Lib/src/packets/commands/CommandGuildElderPacket"; +import {sendErrorMessage, SendManner} from "../../utils/ErrorUtils"; +import {ICommand} from "../ICommand"; +import {SlashCommandBuilderGenerator} from "../SlashCommandBuilderGenerator"; +import {DraftbotInteraction} from "../../messages/DraftbotInteraction"; +import {KeycloakUser} from "../../../../Lib/src/keycloak/KeycloakUser"; +import {PacketUtils} from "../../utils/PacketUtils"; +import {SlashCommandBuilder} from "@discordjs/builders"; + +/** + * Create a collector to confirm the promotion + * @param packet + * @param context + */ +export async function createGuildElderCollector(packet: ReactionCollectorCreationPacket, context: PacketContext): Promise { + const interaction = DiscordCache.getInteraction(context.discord!.interaction)!; + await interaction.deferReply(); + const data = packet.data.data as ReactionCollectorGuildElderData; + const elderPlayer = (await KeycloakUtils.getUserByKeycloakId(keycloakConfig, data.promotedKeycloakId))!; + const embed = new DraftBotEmbed().formatAuthor(i18n.t("commands:guildElder.title", { + lng: interaction.userLanguage, + pseudo: interaction.user.displayName + }), interaction.user) + .setDescription( + i18n.t("commands:guildElder.confirmDesc", { + lng: interaction.userLanguage, + elderPseudo: elderPlayer.attributes.gameUsername + }) + ); + + await DiscordCollectorUtils.createAcceptRefuseCollector(interaction, embed, packet, context); +} + +/** + * Handle the response of the server after a guild elder, + * this packet is only sent if the promotion cannot be done for some reason + * @param packet + * @param context + */ +export async function handleCommandGuildElderPacketRes(packet: CommandGuildElderPacketRes, context: PacketContext): Promise { + const interaction = DiscordCache.getInteraction(context.discord!.interaction); + if (!interaction) { + return; + } + if (!packet.foundPlayer) { + await sendErrorMessage( + interaction.user, + interaction, + i18n.t("commands:guildElder.notSameGuild", {lng: interaction.userLanguage}), + {sendManner: SendManner.REPLY} + ); + return; + } + if (packet.sameGuild) { + await sendErrorMessage( + interaction.user, + interaction, + i18n.t("commands:guildElder.notSameGuild", {lng: interaction.userLanguage}), + {sendManner: SendManner.REPLY} + ); + return; + } + if (packet.himself) { + await sendErrorMessage( + interaction.user, + interaction, + i18n.t("commands:guildElder.chiefError", {lng: interaction.userLanguage}), + {sendManner: SendManner.REPLY} + ); + } + if (packet.alreadyElder) { + await sendErrorMessage( + interaction.user, + interaction, + i18n.t("commands:guildElder.alreadyElder", {lng: interaction.userLanguage}), + {sendManner: SendManner.REPLY} + ); + } +} + +/** + * Handle the response of the server after a guild elder, + * this packet is only sent if the promotion is refused + * @param packet + * @param context + */ +export async function handleCommandGuildElderRefusePacketRes(packet: CommandGuildElderRefusePacketRes, context: PacketContext): Promise { + const originalInteraction = DiscordCache.getInteraction(context.discord!.interaction!); + if (!originalInteraction) { + return; + } + const buttonInteraction = DiscordCache.getButtonInteraction(context.discord!.buttonInteraction!); + const promotedPlayer = (await KeycloakUtils.getUserByKeycloakId(keycloakConfig, packet.promotedKeycloakId))!; + await buttonInteraction?.editReply({ + embeds: [ + new DraftBotEmbed().formatAuthor(i18n.t("commands:guildElder.canceledTitle", { + lng: originalInteraction.userLanguage, + pseudo: originalInteraction.user.displayName + }), originalInteraction.user) + .setDescription( + i18n.t("commands:guildElder.canceledDesc", { + lng: originalInteraction.userLanguage, + elderPseudo: promotedPlayer.attributes.gameUsername + }) + ) + .setErrorColor() + ] + }); +} + +/** + * Handle the response of the server after a guild elder, + * this packet is only sent if the promotion is accepted + * @param packet + * @param context + */ +export async function handleCommandGuildElderAcceptPacketRes(packet: CommandGuildElderAcceptPacketRes, context: PacketContext): Promise { + const originalInteraction = DiscordCache.getInteraction(context.discord!.interaction!); + const buttonInteraction = DiscordCache.getButtonInteraction(context.discord!.buttonInteraction!); + const promotedPlayer = (await KeycloakUtils.getUserByKeycloakId(keycloakConfig, packet.promotedKeycloakId!))!; + if (buttonInteraction && originalInteraction) { + await buttonInteraction.editReply({ + embeds: [ + new DraftBotEmbed().formatAuthor(i18n.t("commands:guildElder.successElderAddTitle", { + lng: originalInteraction.userLanguage, + elderPseudo: promotedPlayer.attributes.gameUsername + }), originalInteraction.user) + .setDescription( + i18n.t("commands:guildElder.acceptedDesc", {lng: originalInteraction.userLanguage}) + ) + ] + }); + } +} + +/** + * Promote a player from a guild + */ +async function getPacket(interaction: DraftbotInteraction, user: KeycloakUser): Promise { + const askedPlayer = await PacketUtils.prepareAskedPlayer(interaction, user); + if (!askedPlayer || !askedPlayer.keycloakId) { + return null; + } + return makePacket(CommandGuildElderPacketReq, {askedPlayerKeycloakId: askedPlayer.keycloakId}); +} + +export const commandInfo: ICommand = { + slashCommandBuilder: SlashCommandBuilderGenerator.generateBaseCommand("guildElder") + .addUserOption(option => + SlashCommandBuilderGenerator.generateOption("guildElder", "user", option) + .setRequired(true)) as SlashCommandBuilder, + getPacket, + mainGuildCommand: false +}; \ No newline at end of file diff --git a/Discord/src/commands/guild/GuildKickCommand.ts b/Discord/src/commands/guild/GuildKickCommand.ts index 8a4ccf6fe..18d786572 100644 --- a/Discord/src/commands/guild/GuildKickCommand.ts +++ b/Discord/src/commands/guild/GuildKickCommand.ts @@ -6,13 +6,17 @@ import {SlashCommandBuilderGenerator} from "../SlashCommandBuilderGenerator"; import {SlashCommandBuilder} from "@discordjs/builders"; import {DiscordCache} from "../../bot/DiscordCache"; import {KeycloakUser} from "../../../../Lib/src/keycloak/KeycloakUser"; -import {CommandGuildKickAcceptPacketRes, CommandGuildKickPacketReq, CommandGuildKickPacketRes, CommandGuildKickRefusePacketRes} from "../../../../Lib/src/packets/commands/CommandGuildKickPacket"; +import { + CommandGuildKickAcceptPacketRes, + CommandGuildKickPacketReq, + CommandGuildKickPacketRes, + CommandGuildKickRefusePacketRes +} from "../../../../Lib/src/packets/commands/CommandGuildKickPacket"; import {ReactionCollectorCreationPacket} from "../../../../Lib/src/packets/interaction/ReactionCollectorPacket"; import {DraftBotEmbed} from "../../messages/DraftBotEmbed"; import {DiscordCollectorUtils} from "../../utils/DiscordCollectorUtils"; import {ReactionCollectorGuildKickData} from "../../../../Lib/src/packets/interaction/ReactionCollectorGuildKick"; import {PacketUtils} from "../../utils/PacketUtils"; -import {CommandProfilePacketReq} from "../../../../Lib/src/packets/commands/CommandProfilePacket"; import {sendErrorMessage, SendManner} from "../../utils/ErrorUtils"; import {KeycloakUtils} from "../../../../Lib/src/keycloak/KeycloakUtils"; import {keycloakConfig} from "../../bot/DraftBotShard"; @@ -20,7 +24,7 @@ import {keycloakConfig} from "../../bot/DraftBotShard"; /** * Kick a player from a guild */ -async function getPacket(interaction: DraftbotInteraction, user: KeycloakUser): Promise { +async function getPacket(interaction: DraftbotInteraction, user: KeycloakUser): Promise { const askedPlayer = await PacketUtils.prepareAskedPlayer(interaction, user); if (!askedPlayer) { return null; diff --git a/Discord/src/packetHandlers/handlers/CommandHandlers.ts b/Discord/src/packetHandlers/handlers/CommandHandlers.ts index 53bdb9b35..1a0af532a 100644 --- a/Discord/src/packetHandlers/handlers/CommandHandlers.ts +++ b/Discord/src/packetHandlers/handlers/CommandHandlers.ts @@ -162,6 +162,15 @@ import { handleCommandUnlockRefusePacketRes } from "../../commands/player/UnlockCommand"; import {handleClassicError} from "../../utils/ErrorUtils"; +import { + CommandGuildElderAcceptPacketRes, + CommandGuildElderPacketRes, CommandGuildElderRefusePacketRes +} from "../../../../Lib/src/packets/commands/CommandGuildElderPacket"; +import { + handleCommandGuildElderAcceptPacketRes, + handleCommandGuildElderPacketRes, + handleCommandGuildElderRefusePacketRes +} from "../../commands/guild/GuildElderCommand"; export default class CommandHandlers { @packetHandler(CommandPingPacketRes) @@ -288,6 +297,21 @@ export default class CommandHandlers { await handleCommandGuildKickAcceptPacketRes(packet, context); } + @packetHandler(CommandGuildElderPacketRes) + async guildElderRes(packet: CommandGuildElderPacketRes, context: PacketContext): Promise { + await handleCommandGuildElderPacketRes(packet, context); + } + + @packetHandler(CommandGuildElderRefusePacketRes) + async guildElderRefuseRes(packet: CommandGuildElderRefusePacketRes, context: PacketContext): Promise { + await handleCommandGuildElderRefusePacketRes(packet, context); + } + + @packetHandler(CommandGuildElderAcceptPacketRes) + async guildElderAcceptRes(packet: CommandGuildElderAcceptPacketRes, context: PacketContext): Promise { + await handleCommandGuildElderAcceptPacketRes(packet, context); + } + @packetHandler(CommandInventoryPacketRes) async inventoryRes(packet: CommandInventoryPacketRes, context: PacketContext): Promise { diff --git a/Discord/src/packetHandlers/handlers/ReactionCollectorHandlers.ts b/Discord/src/packetHandlers/handlers/ReactionCollectorHandlers.ts index 25412e066..0905debf0 100644 --- a/Discord/src/packetHandlers/handlers/ReactionCollectorHandlers.ts +++ b/Discord/src/packetHandlers/handlers/ReactionCollectorHandlers.ts @@ -39,6 +39,8 @@ import {smallShopCollector} from "../../smallEvents/shop"; import {epicItemShopCollector} from "../../smallEvents/epicItemShop"; import {ReactionCollectorEpicShopSmallEventData} from "../../../../Lib/src/packets/interaction/ReactionCollectorEpicShopSmallEvent"; import {ReactionCollectorShopSmallEventData} from "../../../../Lib/src/packets/interaction/ReactionCollectorShopSmallEvent"; +import {createGuildElderCollector} from "../../commands/guild/GuildElderCommand"; +import {ReactionCollectorGuildElderData} from "../../../../Lib/src/packets/interaction/ReactionCollectorGuildElder"; export default class ReactionCollectorHandler { @@ -52,6 +54,7 @@ export default class ReactionCollectorHandler { ReactionCollectorHandler.collectorMap.set(ReactionCollectorPetFreeData.name, createPetFreeCollector); ReactionCollectorHandler.collectorMap.set(ReactionCollectorGuildCreateData.name, createGuildCreateCollector); ReactionCollectorHandler.collectorMap.set(ReactionCollectorGuildKickData.name, createGuildKickCollector); + ReactionCollectorHandler.collectorMap.set(ReactionCollectorGuildElderData.name, createGuildElderCollector); ReactionCollectorHandler.collectorMap.set(ReactionCollectorLotteryData.name, lotteryCollector); ReactionCollectorHandler.collectorMap.set(ReactionCollectorInteractOtherPlayersPoorData.name, interactOtherPlayersCollector); ReactionCollectorHandler.collectorMap.set(ReactionCollectorWitchData.name, witchCollector); diff --git a/Lang/en/discordBuilder.json b/Lang/en/discordBuilder.json index 1020fcaec..b325a9d67 100644 --- a/Lang/en/discordBuilder.json +++ b/Lang/en/discordBuilder.json @@ -109,6 +109,16 @@ } } }, + "guildElder": { + "description": "Promote a guild member to elder.", + "name": "guildelder", + "options": { + "user": { + "description": "The user concerned by the command.", + "name": "user" + } + } + }, "profile": { "description": "Displays the profile of a player.", "name": "profile", diff --git a/Lang/fr/commands.json b/Lang/fr/commands.json index 4cb15b352..deb5d97e7 100644 --- a/Lang/fr/commands.json +++ b/Lang/fr/commands.json @@ -82,6 +82,19 @@ "notSameGuild": "Vous ne pouvez pas expulser un joueur qui n'est pas dans votre guilde.", "himself": "Vous ne pouvez pas vous expulser vous-même de la guilde." }, + "guildElder": { + "notSameGuild": "Ce joueur n'appartient pas à votre guilde.", + "notChiefError": "Vous devez être chef de la guilde pour effectuer cette commande.", + "chiefError": "En tant que chef de la guilde, vous ne pouvez pas être l'aîné.", + "alreadyElder": "Le joueur est déjà aîné de votre guilde.", + "title": "{{pseudo}}, confirmez-vous votre choix ?", + "confirmDesc": ":question: {{elderPseudo}} deviendra l'aîné de la guilde `{guildName}`.", + "successElderAddTitle": "{{elderPseudo}} est le nouvel aîné de la guilde {guildName} !", + "acceptedDesc": "L'aîné sert à aider le chef dans la gestion de la guilde. Il faut donc le choisir avec prudence ! Mais rassurez-vous, si vous n'êtes pas satisfait de votre aîné, vous pouvez le remplacer avec la commande {command:guildelder}, ou si vous avez une âme de dictateur, vous pouvez définitivement le supprimer avec {command:guildelderremove}.", + "canceledDesc": "L'aîné n'a pas été promu.", + "canceledTitle": "Annulation prise en compte.", + "problemWhilePromoting": "Une erreur est survenue lors de la promotion du joueur." + }, "help": { "aliasFieldTitle": "Alias", "aliasesFieldTitle": "Alias", diff --git a/Lang/fr/discordBuilder.json b/Lang/fr/discordBuilder.json index 50edc8941..637b9d41a 100644 --- a/Lang/fr/discordBuilder.json +++ b/Lang/fr/discordBuilder.json @@ -229,6 +229,18 @@ "description": "Récupérer la récompense journalière de la guilde.", "name": "bonusjournalierguilde" }, + + "guildElder": { + "description": "Promouvoir un membre de la guilde au rang d'aîné.", + "name": "aineguilde", + "options": { + "user": { + "description": "L'utilisateur concerné par la commande.", + "name": "utilisateur" + } + } + }, + "daily": { "description": "Utiliser votre objet équipé pour obtenir un bonus journalier.", "name": "bonusjournalier" diff --git a/Lib/src/packets/interaction/ReactionCollectorGuildElder.ts b/Lib/src/packets/interaction/ReactionCollectorGuildElder.ts index 42f1af628..d12ef3037 100644 --- a/Lib/src/packets/interaction/ReactionCollectorGuildElder.ts +++ b/Lib/src/packets/interaction/ReactionCollectorGuildElder.ts @@ -15,7 +15,7 @@ export class ReactionCollectorGuildElder extends ReactionCollector { constructor(promotedKeycloakId: string) { super(); - this.kickedKeycloakId = promotedKeycloakId; + this.promotedKeycloakId = promotedKeycloakId; } creationPacket(id: string, endTime: number): ReactionCollectorCreationPacket { @@ -26,8 +26,8 @@ export class ReactionCollectorGuildElder extends ReactionCollector { this.buildReaction(ReactionCollectorAcceptReaction, {}), this.buildReaction(ReactionCollectorRefuseReaction, {}) ], - data: this.buildData(ReactionCollectorGuildKickData, { - kickedKeycloakId: this.kickedKeycloakId + data: this.buildData(ReactionCollectorGuildElderData, { + promotedKeycloakId: this.promotedKeycloakId }) }; } From 6e058b00e6ef9e0c39e55fe6dcaff4d15c024339 Mon Sep 17 00:00:00 2001 From: Ntalcme Date: Thu, 2 Jan 2025 04:14:38 +0100 Subject: [PATCH 04/10] =?UTF-8?q?Split=20du=20packet=20en=204=20packets=20?= =?UTF-8?q?diff=C3=A9rent=20#2273?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/src/commands/guild/GuildElderCommand.ts | 43 ++++++------------- .../src/commands/guild/GuildElderCommand.ts | 39 ++++++++++++----- .../handlers/CommandHandlers.ts | 34 ++++++++++++--- Lang/fr/commands.json | 1 + .../commands/CommandGuildElderPacket.ts | 31 ++++++++----- 5 files changed, 91 insertions(+), 57 deletions(-) diff --git a/Core/src/commands/guild/GuildElderCommand.ts b/Core/src/commands/guild/GuildElderCommand.ts index 86dcc7274..5a2acae34 100644 --- a/Core/src/commands/guild/GuildElderCommand.ts +++ b/Core/src/commands/guild/GuildElderCommand.ts @@ -2,8 +2,13 @@ import Player, {Players} from "../../core/database/game/models/Player"; import {DraftBotPacket, makePacket, PacketContext} from "../../../../Lib/src/packets/DraftBotPacket"; import {Guilds} from "../../core/database/game/models/Guild"; import { - CommandGuildElderAcceptPacketRes, CommandGuildElderPacketReq, - CommandGuildElderPacketRes, CommandGuildElderRefusePacketRes + CommandGuildElderAcceptPacketRes, + CommandGuildElderAlreadyElderPacketRes, + CommandGuildElderFoundPlayerPacketRes, + CommandGuildElderHimselfPacketRes, + CommandGuildElderPacketReq, + CommandGuildElderRefusePacketRes, + CommandGuildElderSameGuildPacketRes } from "../../../../Lib/src/packets/commands/CommandGuildElderPacket"; import {draftBotInstance} from "../../index"; import {commandRequires, CommandUtils} from "../../core/utils/CommandUtils"; @@ -23,12 +28,7 @@ import {ReactionCollectorGuildElder} from "../../../../Lib/src/packets/interacti */ async function isEligible(player: Player, promotedPlayer: Player, response: DraftBotPacket[]): Promise { if (promotedPlayer === null) { - response.push(makePacket(CommandGuildElderPacketRes, { - foundPlayer: false, - sameGuild: false, - himself: false, - alreadyElder: false - })); + response.push(makePacket(CommandGuildElderFoundPlayerPacketRes, {foundPlayer: false})); return false; } let promotedGuild; @@ -41,32 +41,17 @@ async function isEligible(player: Player, promotedPlayer: Player, response: Draf const guild = await Guilds.getById(player.guildId); if (promotedGuild === null || promotedGuild.id !== player.guildId) { - response.push(makePacket(CommandGuildElderPacketRes, { - foundPlayer: true, - sameGuild: false, - himself: false, - alreadyElder: false - })); + response.push(makePacket(CommandGuildElderSameGuildPacketRes, {sameGuild: false})); return false; } if (promotedPlayer.id === player.id) { - response.push(makePacket(CommandGuildElderPacketRes, { - foundPlayer: true, - sameGuild: true, - himself: true, - alreadyElder: false - })); + response.push(makePacket(CommandGuildElderHimselfPacketRes, {himself: true})); return false; } - if (promotedPlayer.id === guild.id) { - response.push(makePacket(CommandGuildElderPacketRes, { - foundPlayer: true, - sameGuild: true, - himself: false, - alreadyElder: true - })); + if (promotedPlayer.id === guild.elderId) { + response.push(makePacket(CommandGuildElderAlreadyElderPacketRes, {alreadyElder: true})); return false; } return true; @@ -80,7 +65,7 @@ async function isEligible(player: Player, promotedPlayer: Player, response: Draf */ async function acceptGuildElder(player: Player, promotedPlayer: Player, response: DraftBotPacket[]): Promise { await player.reload(); - if (! await isEligible(player,promotedPlayer,response)) { + if (!await isEligible(player, promotedPlayer, response)) { return; } const guild = await Guilds.getById(player.guildId); @@ -109,7 +94,7 @@ export default class GuildElderCommand { async execute(response: DraftBotPacket[], player: Player, packet: CommandGuildElderPacketReq, context: PacketContext): Promise { const promotedPlayer = await Players.getAskedPlayer({keycloakId: packet.askedPlayerKeycloakId}, player); - if (! await isEligible(player, promotedPlayer, response)) { + if (!await isEligible(player, promotedPlayer, response)) { return; } const collector = new ReactionCollectorGuildElder( diff --git a/Discord/src/commands/guild/GuildElderCommand.ts b/Discord/src/commands/guild/GuildElderCommand.ts index 6a7456503..c0621ea5c 100644 --- a/Discord/src/commands/guild/GuildElderCommand.ts +++ b/Discord/src/commands/guild/GuildElderCommand.ts @@ -9,9 +9,12 @@ import {DiscordCollectorUtils} from "../../utils/DiscordCollectorUtils"; import {ReactionCollectorGuildElderData} from "../../../../Lib/src/packets/interaction/ReactionCollectorGuildElder"; import { CommandGuildElderAcceptPacketRes, + CommandGuildElderAlreadyElderPacketRes, + CommandGuildElderFoundPlayerPacketRes, + CommandGuildElderHimselfPacketRes, CommandGuildElderPacketReq, - CommandGuildElderPacketRes, - CommandGuildElderRefusePacketRes + CommandGuildElderRefusePacketRes, + CommandGuildElderSameGuildPacketRes } from "../../../../Lib/src/packets/commands/CommandGuildElderPacket"; import {sendErrorMessage, SendManner} from "../../utils/ErrorUtils"; import {ICommand} from "../ICommand"; @@ -45,13 +48,8 @@ export async function createGuildElderCollector(packet: ReactionCollectorCreatio await DiscordCollectorUtils.createAcceptRefuseCollector(interaction, embed, packet, context); } -/** - * Handle the response of the server after a guild elder, - * this packet is only sent if the promotion cannot be done for some reason - * @param packet - * @param context - */ -export async function handleCommandGuildElderPacketRes(packet: CommandGuildElderPacketRes, context: PacketContext): Promise { + +export async function handleCommandGuildElderFoundPlayerPacketRes(packet: CommandGuildElderFoundPlayerPacketRes, context: PacketContext): Promise { const interaction = DiscordCache.getInteraction(context.discord!.interaction); if (!interaction) { return; @@ -60,18 +58,30 @@ export async function handleCommandGuildElderPacketRes(packet: CommandGuildElder await sendErrorMessage( interaction.user, interaction, - i18n.t("commands:guildElder.notSameGuild", {lng: interaction.userLanguage}), + i18n.t("commands:guildElder.playerNotFound", {lng: interaction.userLanguage}), {sendManner: SendManner.REPLY} ); + } +} + +export async function handleCommandGuildElderSameGuildPacketRes(packet: CommandGuildElderSameGuildPacketRes, context: PacketContext): Promise { + const interaction = DiscordCache.getInteraction(context.discord!.interaction); + if (!interaction) { return; } - if (packet.sameGuild) { + if (!packet.sameGuild) { await sendErrorMessage( interaction.user, interaction, i18n.t("commands:guildElder.notSameGuild", {lng: interaction.userLanguage}), {sendManner: SendManner.REPLY} ); + } +} + +export async function handleCommandGuildElderHimselfPacketRes(packet: CommandGuildElderHimselfPacketRes, context: PacketContext): Promise { + const interaction = DiscordCache.getInteraction(context.discord!.interaction); + if (!interaction) { return; } if (packet.himself) { @@ -82,6 +92,13 @@ export async function handleCommandGuildElderPacketRes(packet: CommandGuildElder {sendManner: SendManner.REPLY} ); } +} + +export async function handleCommandGuildElderAlreadyElderPacketRes(packet: CommandGuildElderAlreadyElderPacketRes, context: PacketContext): Promise { + const interaction = DiscordCache.getInteraction(context.discord!.interaction); + if (!interaction) { + return; + } if (packet.alreadyElder) { await sendErrorMessage( interaction.user, diff --git a/Discord/src/packetHandlers/handlers/CommandHandlers.ts b/Discord/src/packetHandlers/handlers/CommandHandlers.ts index 1a0af532a..53f671c59 100644 --- a/Discord/src/packetHandlers/handlers/CommandHandlers.ts +++ b/Discord/src/packetHandlers/handlers/CommandHandlers.ts @@ -164,12 +164,19 @@ import { import {handleClassicError} from "../../utils/ErrorUtils"; import { CommandGuildElderAcceptPacketRes, - CommandGuildElderPacketRes, CommandGuildElderRefusePacketRes + CommandGuildElderAlreadyElderPacketRes, + CommandGuildElderFoundPlayerPacketRes, + CommandGuildElderHimselfPacketRes, + CommandGuildElderRefusePacketRes, + CommandGuildElderSameGuildPacketRes } from "../../../../Lib/src/packets/commands/CommandGuildElderPacket"; import { handleCommandGuildElderAcceptPacketRes, - handleCommandGuildElderPacketRes, - handleCommandGuildElderRefusePacketRes + handleCommandGuildElderAlreadyElderPacketRes, + handleCommandGuildElderFoundPlayerPacketRes, + handleCommandGuildElderHimselfPacketRes, + handleCommandGuildElderRefusePacketRes, + handleCommandGuildElderSameGuildPacketRes } from "../../commands/guild/GuildElderCommand"; export default class CommandHandlers { @@ -297,9 +304,24 @@ export default class CommandHandlers { await handleCommandGuildKickAcceptPacketRes(packet, context); } - @packetHandler(CommandGuildElderPacketRes) - async guildElderRes(packet: CommandGuildElderPacketRes, context: PacketContext): Promise { - await handleCommandGuildElderPacketRes(packet, context); + @packetHandler(CommandGuildElderSameGuildPacketRes) + async guildElderSameGuildRes(packet: CommandGuildElderSameGuildPacketRes, context: PacketContext): Promise { + await handleCommandGuildElderSameGuildPacketRes(packet, context); + } + + @packetHandler(CommandGuildElderHimselfPacketRes) + async guildElderHimselfRes(packet: CommandGuildElderHimselfPacketRes, context: PacketContext): Promise { + await handleCommandGuildElderHimselfPacketRes(packet, context); + } + + @packetHandler(CommandGuildElderAlreadyElderPacketRes) + async guildElderAlreadyElderRes(packet: CommandGuildElderAlreadyElderPacketRes, context: PacketContext): Promise { + await handleCommandGuildElderAlreadyElderPacketRes(packet, context); + } + + @packetHandler(CommandGuildElderFoundPlayerPacketRes) + async guildElderFoundPlayerRes(packet: CommandGuildElderFoundPlayerPacketRes, context: PacketContext): Promise { + await handleCommandGuildElderFoundPlayerPacketRes(packet, context); } @packetHandler(CommandGuildElderRefusePacketRes) diff --git a/Lang/fr/commands.json b/Lang/fr/commands.json index deb5d97e7..638a5e8a6 100644 --- a/Lang/fr/commands.json +++ b/Lang/fr/commands.json @@ -83,6 +83,7 @@ "himself": "Vous ne pouvez pas vous expulser vous-même de la guilde." }, "guildElder": { + "playerNotFound": "Ce joueur n'a pas été trouvé.", "notSameGuild": "Ce joueur n'appartient pas à votre guilde.", "notChiefError": "Vous devez être chef de la guilde pour effectuer cette commande.", "chiefError": "En tant que chef de la guilde, vous ne pouvez pas être l'aîné.", diff --git a/Lib/src/packets/commands/CommandGuildElderPacket.ts b/Lib/src/packets/commands/CommandGuildElderPacket.ts index 9f76acca7..1f8e50181 100644 --- a/Lib/src/packets/commands/CommandGuildElderPacket.ts +++ b/Lib/src/packets/commands/CommandGuildElderPacket.ts @@ -1,16 +1,5 @@ import {DraftBotPacket, PacketDirection, sendablePacket} from "../DraftBotPacket"; -@sendablePacket(PacketDirection.BACK_TO_FRONT) -export class CommandGuildElderPacketRes extends DraftBotPacket { - foundPlayer!: boolean; - - sameGuild!: boolean; - - himself!: boolean; - - alreadyElder!: boolean; -} - @sendablePacket(PacketDirection.BACK_TO_FRONT) export class CommandGuildElderAcceptPacketRes extends DraftBotPacket { promotedKeycloakId!: string; @@ -26,4 +15,24 @@ export class CommandGuildElderRefusePacketRes extends DraftBotPacket { @sendablePacket(PacketDirection.FRONT_TO_BACK) export class CommandGuildElderPacketReq extends DraftBotPacket { askedPlayerKeycloakId!: string; +} + +@sendablePacket(PacketDirection.BACK_TO_FRONT) +export class CommandGuildElderSameGuildPacketRes extends DraftBotPacket { + sameGuild!: boolean; +} + +@sendablePacket(PacketDirection.BACK_TO_FRONT) +export class CommandGuildElderHimselfPacketRes extends DraftBotPacket { + himself!: boolean; +} + +@sendablePacket(PacketDirection.BACK_TO_FRONT) +export class CommandGuildElderAlreadyElderPacketRes extends DraftBotPacket { + alreadyElder!: boolean; +} + +@sendablePacket(PacketDirection.BACK_TO_FRONT) +export class CommandGuildElderFoundPlayerPacketRes extends DraftBotPacket { + foundPlayer!: boolean; } \ No newline at end of file From 80ab3dde05df7f7dc176ec2b3212d11d6ac3120b Mon Sep 17 00:00:00 2001 From: Ntalcme Date: Wed, 8 Jan 2025 06:29:11 +0100 Subject: [PATCH 05/10] End of command guildelder #2273 --- Core/src/commands/guild/GuildElderCommand.ts | 6 ++++++ Discord/src/commands/guild/GuildElderCommand.ts | 3 ++- Lang/fr/commands.json | 4 ++-- .../packets/interaction/ReactionCollectorGuildElder.ts | 8 +++++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Core/src/commands/guild/GuildElderCommand.ts b/Core/src/commands/guild/GuildElderCommand.ts index 5a2acae34..c05bb4c91 100644 --- a/Core/src/commands/guild/GuildElderCommand.ts +++ b/Core/src/commands/guild/GuildElderCommand.ts @@ -65,6 +65,7 @@ async function isEligible(player: Player, promotedPlayer: Player, response: Draf */ async function acceptGuildElder(player: Player, promotedPlayer: Player, response: DraftBotPacket[]): Promise { await player.reload(); + // Do all necessary checks again just in case something changed during the menu if (!await isEligible(player, promotedPlayer, response)) { return; } @@ -97,7 +98,10 @@ export default class GuildElderCommand { if (!await isEligible(player, promotedPlayer, response)) { return; } + const guildName = (await Guilds.getById(player.guildId)).name; + const collector = new ReactionCollectorGuildElder( + guildName, promotedPlayer.keycloakId ); @@ -112,6 +116,7 @@ export default class GuildElderCommand { })); } BlockingUtils.unblockPlayer(player.id, BlockingConstants.REASONS.GUILD_ELDER); + BlockingUtils.unblockPlayer(promotedPlayer.id, BlockingConstants.REASONS.GUILD_ELDER); }; const collectorPacket = new ReactionCollectorInstance( @@ -124,6 +129,7 @@ export default class GuildElderCommand { endCallback ) .block(player.id, BlockingConstants.REASONS.GUILD_ELDER) + .block(promotedPlayer.id, BlockingConstants.REASONS.GUILD_ELDER) .build(); response.push(collectorPacket); diff --git a/Discord/src/commands/guild/GuildElderCommand.ts b/Discord/src/commands/guild/GuildElderCommand.ts index c0621ea5c..750e11f47 100644 --- a/Discord/src/commands/guild/GuildElderCommand.ts +++ b/Discord/src/commands/guild/GuildElderCommand.ts @@ -41,7 +41,8 @@ export async function createGuildElderCollector(packet: ReactionCollectorCreatio .setDescription( i18n.t("commands:guildElder.confirmDesc", { lng: interaction.userLanguage, - elderPseudo: elderPlayer.attributes.gameUsername + elderPseudo: elderPlayer.attributes.gameUsername, + guildName: data.guildName }) ); diff --git a/Lang/fr/commands.json b/Lang/fr/commands.json index 638a5e8a6..67a78f8c3 100644 --- a/Lang/fr/commands.json +++ b/Lang/fr/commands.json @@ -89,8 +89,8 @@ "chiefError": "En tant que chef de la guilde, vous ne pouvez pas être l'aîné.", "alreadyElder": "Le joueur est déjà aîné de votre guilde.", "title": "{{pseudo}}, confirmez-vous votre choix ?", - "confirmDesc": ":question: {{elderPseudo}} deviendra l'aîné de la guilde `{guildName}`.", - "successElderAddTitle": "{{elderPseudo}} est le nouvel aîné de la guilde {guildName} !", + "confirmDesc": ":question: {{elderPseudo}} deviendra l'aîné de la guilde `{{guildName}}`.", + "successElderAddTitle": "{{elderPseudo}} est le nouvel aîné de la guilde {{guildName}} !", "acceptedDesc": "L'aîné sert à aider le chef dans la gestion de la guilde. Il faut donc le choisir avec prudence ! Mais rassurez-vous, si vous n'êtes pas satisfait de votre aîné, vous pouvez le remplacer avec la commande {command:guildelder}, ou si vous avez une âme de dictateur, vous pouvez définitivement le supprimer avec {command:guildelderremove}.", "canceledDesc": "L'aîné n'a pas été promu.", "canceledTitle": "Annulation prise en compte.", diff --git a/Lib/src/packets/interaction/ReactionCollectorGuildElder.ts b/Lib/src/packets/interaction/ReactionCollectorGuildElder.ts index d12ef3037..2887b05b1 100644 --- a/Lib/src/packets/interaction/ReactionCollectorGuildElder.ts +++ b/Lib/src/packets/interaction/ReactionCollectorGuildElder.ts @@ -7,14 +7,19 @@ import { } from "./ReactionCollectorPacket"; export class ReactionCollectorGuildElderData extends ReactionCollectorData { + guildName!: string; + promotedKeycloakId!: string; } export class ReactionCollectorGuildElder extends ReactionCollector { + private readonly guildName: string; + private readonly promotedKeycloakId: string; - constructor(promotedKeycloakId: string) { + constructor(guildName: string, promotedKeycloakId: string) { super(); + this.guildName = guildName; this.promotedKeycloakId = promotedKeycloakId; } @@ -27,6 +32,7 @@ export class ReactionCollectorGuildElder extends ReactionCollector { this.buildReaction(ReactionCollectorRefuseReaction, {}) ], data: this.buildData(ReactionCollectorGuildElderData, { + guildName: this.guildName, promotedKeycloakId: this.promotedKeycloakId }) }; From 4027b9b6fdc66b96ce26519e63e962305335356a Mon Sep 17 00:00:00 2001 From: Ntalcme Date: Wed, 8 Jan 2025 07:14:55 +0100 Subject: [PATCH 06/10] small fix #2273 --- Discord/src/commands/guild/GuildElderCommand.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Discord/src/commands/guild/GuildElderCommand.ts b/Discord/src/commands/guild/GuildElderCommand.ts index 750e11f47..9413c7904 100644 --- a/Discord/src/commands/guild/GuildElderCommand.ts +++ b/Discord/src/commands/guild/GuildElderCommand.ts @@ -155,7 +155,8 @@ export async function handleCommandGuildElderAcceptPacketRes(packet: CommandGuil embeds: [ new DraftBotEmbed().formatAuthor(i18n.t("commands:guildElder.successElderAddTitle", { lng: originalInteraction.userLanguage, - elderPseudo: promotedPlayer.attributes.gameUsername + elderPseudo: promotedPlayer.attributes.gameUsername, + guildName: packet.guildName }), originalInteraction.user) .setDescription( i18n.t("commands:guildElder.acceptedDesc", {lng: originalInteraction.userLanguage}) From 1b59a2dd7065e7b1ef1d5a50cfe8625dcb164661 Mon Sep 17 00:00:00 2001 From: Ntalcme Date: Sat, 11 Jan 2025 05:53:26 +0100 Subject: [PATCH 07/10] Another small fix #2273 --- Core/src/commands/guild/GuildElderCommand.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Core/src/commands/guild/GuildElderCommand.ts b/Core/src/commands/guild/GuildElderCommand.ts index c05bb4c91..038ced7eb 100644 --- a/Core/src/commands/guild/GuildElderCommand.ts +++ b/Core/src/commands/guild/GuildElderCommand.ts @@ -65,6 +65,7 @@ async function isEligible(player: Player, promotedPlayer: Player, response: Draf */ async function acceptGuildElder(player: Player, promotedPlayer: Player, response: DraftBotPacket[]): Promise { await player.reload(); + await promotedPlayer.reload(); // Do all necessary checks again just in case something changed during the menu if (!await isEligible(player, promotedPlayer, response)) { return; @@ -116,7 +117,6 @@ export default class GuildElderCommand { })); } BlockingUtils.unblockPlayer(player.id, BlockingConstants.REASONS.GUILD_ELDER); - BlockingUtils.unblockPlayer(promotedPlayer.id, BlockingConstants.REASONS.GUILD_ELDER); }; const collectorPacket = new ReactionCollectorInstance( @@ -129,7 +129,6 @@ export default class GuildElderCommand { endCallback ) .block(player.id, BlockingConstants.REASONS.GUILD_ELDER) - .block(promotedPlayer.id, BlockingConstants.REASONS.GUILD_ELDER) .build(); response.push(collectorPacket); From f76976b5a5234da1be754a5ff2cb7653510f0a6d Mon Sep 17 00:00:00 2001 From: Ntalcme Date: Sun, 12 Jan 2025 13:08:42 +0100 Subject: [PATCH 08/10] Fix on packets. #2273 --- Core/src/commands/guild/GuildElderCommand.ts | 8 +-- .../src/commands/guild/GuildElderCommand.ts | 57 ++++++++----------- Lang/en/discordBuilder.json | 2 +- Lang/fr/discordBuilder.json | 4 +- .../commands/CommandGuildElderPacket.ts | 4 -- 5 files changed, 31 insertions(+), 44 deletions(-) diff --git a/Core/src/commands/guild/GuildElderCommand.ts b/Core/src/commands/guild/GuildElderCommand.ts index 038ced7eb..9e4122044 100644 --- a/Core/src/commands/guild/GuildElderCommand.ts +++ b/Core/src/commands/guild/GuildElderCommand.ts @@ -28,7 +28,7 @@ import {ReactionCollectorGuildElder} from "../../../../Lib/src/packets/interacti */ async function isEligible(player: Player, promotedPlayer: Player, response: DraftBotPacket[]): Promise { if (promotedPlayer === null) { - response.push(makePacket(CommandGuildElderFoundPlayerPacketRes, {foundPlayer: false})); + response.push(makePacket(CommandGuildElderFoundPlayerPacketRes, {})); return false; } let promotedGuild; @@ -41,17 +41,17 @@ async function isEligible(player: Player, promotedPlayer: Player, response: Draf const guild = await Guilds.getById(player.guildId); if (promotedGuild === null || promotedGuild.id !== player.guildId) { - response.push(makePacket(CommandGuildElderSameGuildPacketRes, {sameGuild: false})); + response.push(makePacket(CommandGuildElderSameGuildPacketRes, {})); return false; } if (promotedPlayer.id === player.id) { - response.push(makePacket(CommandGuildElderHimselfPacketRes, {himself: true})); + response.push(makePacket(CommandGuildElderHimselfPacketRes, {})); return false; } if (promotedPlayer.id === guild.elderId) { - response.push(makePacket(CommandGuildElderAlreadyElderPacketRes, {alreadyElder: true})); + response.push(makePacket(CommandGuildElderAlreadyElderPacketRes, {})); return false; } return true; diff --git a/Discord/src/commands/guild/GuildElderCommand.ts b/Discord/src/commands/guild/GuildElderCommand.ts index 9413c7904..aafa509b8 100644 --- a/Discord/src/commands/guild/GuildElderCommand.ts +++ b/Discord/src/commands/guild/GuildElderCommand.ts @@ -55,14 +55,12 @@ export async function handleCommandGuildElderFoundPlayerPacketRes(packet: Comman if (!interaction) { return; } - if (!packet.foundPlayer) { - await sendErrorMessage( - interaction.user, - interaction, - i18n.t("commands:guildElder.playerNotFound", {lng: interaction.userLanguage}), - {sendManner: SendManner.REPLY} - ); - } + await sendErrorMessage( + interaction.user, + interaction, + i18n.t("commands:guildElder.playerNotFound", {lng: interaction.userLanguage}), + {sendManner: SendManner.REPLY} + ); } export async function handleCommandGuildElderSameGuildPacketRes(packet: CommandGuildElderSameGuildPacketRes, context: PacketContext): Promise { @@ -70,14 +68,12 @@ export async function handleCommandGuildElderSameGuildPacketRes(packet: CommandG if (!interaction) { return; } - if (!packet.sameGuild) { - await sendErrorMessage( - interaction.user, - interaction, - i18n.t("commands:guildElder.notSameGuild", {lng: interaction.userLanguage}), - {sendManner: SendManner.REPLY} - ); - } + await sendErrorMessage( + interaction.user, + interaction, + i18n.t("commands:guildElder.notSameGuild", {lng: interaction.userLanguage}), + {sendManner: SendManner.REPLY} + ); } export async function handleCommandGuildElderHimselfPacketRes(packet: CommandGuildElderHimselfPacketRes, context: PacketContext): Promise { @@ -85,14 +81,12 @@ export async function handleCommandGuildElderHimselfPacketRes(packet: CommandGui if (!interaction) { return; } - if (packet.himself) { - await sendErrorMessage( - interaction.user, - interaction, - i18n.t("commands:guildElder.chiefError", {lng: interaction.userLanguage}), - {sendManner: SendManner.REPLY} - ); - } + await sendErrorMessage( + interaction.user, + interaction, + i18n.t("commands:guildElder.chiefError", {lng: interaction.userLanguage}), + {sendManner: SendManner.REPLY} + ); } export async function handleCommandGuildElderAlreadyElderPacketRes(packet: CommandGuildElderAlreadyElderPacketRes, context: PacketContext): Promise { @@ -100,16 +94,15 @@ export async function handleCommandGuildElderAlreadyElderPacketRes(packet: Comma if (!interaction) { return; } - if (packet.alreadyElder) { - await sendErrorMessage( - interaction.user, - interaction, - i18n.t("commands:guildElder.alreadyElder", {lng: interaction.userLanguage}), - {sendManner: SendManner.REPLY} - ); - } + await sendErrorMessage( + interaction.user, + interaction, + i18n.t("commands:guildElder.alreadyElder", {lng: interaction.userLanguage}), + {sendManner: SendManner.REPLY} + ); } + /** * Handle the response of the server after a guild elder, * this packet is only sent if the promotion is refused diff --git a/Lang/en/discordBuilder.json b/Lang/en/discordBuilder.json index b325a9d67..c52e72852 100644 --- a/Lang/en/discordBuilder.json +++ b/Lang/en/discordBuilder.json @@ -114,7 +114,7 @@ "name": "guildelder", "options": { "user": { - "description": "The user concerned by the command.", + "description": "The user who will be promoted as an elder.", "name": "user" } } diff --git a/Lang/fr/discordBuilder.json b/Lang/fr/discordBuilder.json index 637b9d41a..e70d38627 100644 --- a/Lang/fr/discordBuilder.json +++ b/Lang/fr/discordBuilder.json @@ -229,18 +229,16 @@ "description": "Récupérer la récompense journalière de la guilde.", "name": "bonusjournalierguilde" }, - "guildElder": { "description": "Promouvoir un membre de la guilde au rang d'aîné.", "name": "aineguilde", "options": { "user": { - "description": "L'utilisateur concerné par la commande.", + "description": "L'utilisateur qui sera promu en tant qu'aîné.", "name": "utilisateur" } } }, - "daily": { "description": "Utiliser votre objet équipé pour obtenir un bonus journalier.", "name": "bonusjournalier" diff --git a/Lib/src/packets/commands/CommandGuildElderPacket.ts b/Lib/src/packets/commands/CommandGuildElderPacket.ts index 1f8e50181..fdd226bf9 100644 --- a/Lib/src/packets/commands/CommandGuildElderPacket.ts +++ b/Lib/src/packets/commands/CommandGuildElderPacket.ts @@ -19,20 +19,16 @@ export class CommandGuildElderPacketReq extends DraftBotPacket { @sendablePacket(PacketDirection.BACK_TO_FRONT) export class CommandGuildElderSameGuildPacketRes extends DraftBotPacket { - sameGuild!: boolean; } @sendablePacket(PacketDirection.BACK_TO_FRONT) export class CommandGuildElderHimselfPacketRes extends DraftBotPacket { - himself!: boolean; } @sendablePacket(PacketDirection.BACK_TO_FRONT) export class CommandGuildElderAlreadyElderPacketRes extends DraftBotPacket { - alreadyElder!: boolean; } @sendablePacket(PacketDirection.BACK_TO_FRONT) export class CommandGuildElderFoundPlayerPacketRes extends DraftBotPacket { - foundPlayer!: boolean; } \ No newline at end of file From 511a7d1ae6a2743514c68812dfaf2adb3ff64179 Mon Sep 17 00:00:00 2001 From: Ntalcme Date: Sun, 12 Jan 2025 14:37:58 +0100 Subject: [PATCH 09/10] Fix on errors reply #2273 --- .../src/packetHandlers/handlers/CommandHandlers.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/Discord/src/packetHandlers/handlers/CommandHandlers.ts b/Discord/src/packetHandlers/handlers/CommandHandlers.ts index 53f671c59..5faa2c428 100644 --- a/Discord/src/packetHandlers/handlers/CommandHandlers.ts +++ b/Discord/src/packetHandlers/handlers/CommandHandlers.ts @@ -172,11 +172,7 @@ import { } from "../../../../Lib/src/packets/commands/CommandGuildElderPacket"; import { handleCommandGuildElderAcceptPacketRes, - handleCommandGuildElderAlreadyElderPacketRes, - handleCommandGuildElderFoundPlayerPacketRes, - handleCommandGuildElderHimselfPacketRes, - handleCommandGuildElderRefusePacketRes, - handleCommandGuildElderSameGuildPacketRes + handleCommandGuildElderRefusePacketRes } from "../../commands/guild/GuildElderCommand"; export default class CommandHandlers { @@ -306,22 +302,22 @@ export default class CommandHandlers { @packetHandler(CommandGuildElderSameGuildPacketRes) async guildElderSameGuildRes(packet: CommandGuildElderSameGuildPacketRes, context: PacketContext): Promise { - await handleCommandGuildElderSameGuildPacketRes(packet, context); + await handleClassicError(context, "commands:guildElder.notSameGuild"); } @packetHandler(CommandGuildElderHimselfPacketRes) async guildElderHimselfRes(packet: CommandGuildElderHimselfPacketRes, context: PacketContext): Promise { - await handleCommandGuildElderHimselfPacketRes(packet, context); + await handleClassicError(context, "commands:guildElder.chiefError"); } @packetHandler(CommandGuildElderAlreadyElderPacketRes) async guildElderAlreadyElderRes(packet: CommandGuildElderAlreadyElderPacketRes, context: PacketContext): Promise { - await handleCommandGuildElderAlreadyElderPacketRes(packet, context); + await handleClassicError(context, "commands:guildElder.alreadyElder"); } @packetHandler(CommandGuildElderFoundPlayerPacketRes) async guildElderFoundPlayerRes(packet: CommandGuildElderFoundPlayerPacketRes, context: PacketContext): Promise { - await handleCommandGuildElderFoundPlayerPacketRes(packet, context); + await handleClassicError(context, "commands:guildElder.playerNotFound"); } @packetHandler(CommandGuildElderRefusePacketRes) From 55b9ce05acd6d045e3cfd95760bc85151d2ea0ef Mon Sep 17 00:00:00 2001 From: Ntalcme Date: Sun, 12 Jan 2025 14:56:53 +0100 Subject: [PATCH 10/10] fix #2273 --- .../src/commands/guild/GuildElderCommand.ts | 61 +------------------ 1 file changed, 1 insertion(+), 60 deletions(-) diff --git a/Discord/src/commands/guild/GuildElderCommand.ts b/Discord/src/commands/guild/GuildElderCommand.ts index aafa509b8..78a60a25f 100644 --- a/Discord/src/commands/guild/GuildElderCommand.ts +++ b/Discord/src/commands/guild/GuildElderCommand.ts @@ -9,14 +9,9 @@ import {DiscordCollectorUtils} from "../../utils/DiscordCollectorUtils"; import {ReactionCollectorGuildElderData} from "../../../../Lib/src/packets/interaction/ReactionCollectorGuildElder"; import { CommandGuildElderAcceptPacketRes, - CommandGuildElderAlreadyElderPacketRes, - CommandGuildElderFoundPlayerPacketRes, - CommandGuildElderHimselfPacketRes, CommandGuildElderPacketReq, - CommandGuildElderRefusePacketRes, - CommandGuildElderSameGuildPacketRes + CommandGuildElderRefusePacketRes } from "../../../../Lib/src/packets/commands/CommandGuildElderPacket"; -import {sendErrorMessage, SendManner} from "../../utils/ErrorUtils"; import {ICommand} from "../ICommand"; import {SlashCommandBuilderGenerator} from "../SlashCommandBuilderGenerator"; import {DraftbotInteraction} from "../../messages/DraftbotInteraction"; @@ -49,60 +44,6 @@ export async function createGuildElderCollector(packet: ReactionCollectorCreatio await DiscordCollectorUtils.createAcceptRefuseCollector(interaction, embed, packet, context); } - -export async function handleCommandGuildElderFoundPlayerPacketRes(packet: CommandGuildElderFoundPlayerPacketRes, context: PacketContext): Promise { - const interaction = DiscordCache.getInteraction(context.discord!.interaction); - if (!interaction) { - return; - } - await sendErrorMessage( - interaction.user, - interaction, - i18n.t("commands:guildElder.playerNotFound", {lng: interaction.userLanguage}), - {sendManner: SendManner.REPLY} - ); -} - -export async function handleCommandGuildElderSameGuildPacketRes(packet: CommandGuildElderSameGuildPacketRes, context: PacketContext): Promise { - const interaction = DiscordCache.getInteraction(context.discord!.interaction); - if (!interaction) { - return; - } - await sendErrorMessage( - interaction.user, - interaction, - i18n.t("commands:guildElder.notSameGuild", {lng: interaction.userLanguage}), - {sendManner: SendManner.REPLY} - ); -} - -export async function handleCommandGuildElderHimselfPacketRes(packet: CommandGuildElderHimselfPacketRes, context: PacketContext): Promise { - const interaction = DiscordCache.getInteraction(context.discord!.interaction); - if (!interaction) { - return; - } - await sendErrorMessage( - interaction.user, - interaction, - i18n.t("commands:guildElder.chiefError", {lng: interaction.userLanguage}), - {sendManner: SendManner.REPLY} - ); -} - -export async function handleCommandGuildElderAlreadyElderPacketRes(packet: CommandGuildElderAlreadyElderPacketRes, context: PacketContext): Promise { - const interaction = DiscordCache.getInteraction(context.discord!.interaction); - if (!interaction) { - return; - } - await sendErrorMessage( - interaction.user, - interaction, - i18n.t("commands:guildElder.alreadyElder", {lng: interaction.userLanguage}), - {sendManner: SendManner.REPLY} - ); -} - - /** * Handle the response of the server after a guild elder, * this packet is only sent if the promotion is refused