diff --git a/Core/src/commands/guild/GuildElderCommand.ts b/Core/src/commands/guild/GuildElderCommand.ts new file mode 100644 index 000000000..038ced7eb --- /dev/null +++ b/Core/src/commands/guild/GuildElderCommand.ts @@ -0,0 +1,136 @@ +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, + CommandGuildElderAlreadyElderPacketRes, + CommandGuildElderFoundPlayerPacketRes, + CommandGuildElderHimselfPacketRes, + CommandGuildElderPacketReq, + CommandGuildElderRefusePacketRes, + CommandGuildElderSameGuildPacketRes +} 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 {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"; +import {ReactionCollectorGuildElder} from "../../../../Lib/src/packets/interaction/ReactionCollectorGuildElder"; + +/** + * 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(CommandGuildElderFoundPlayerPacketRes, {foundPlayer: 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(CommandGuildElderSameGuildPacketRes, {sameGuild: false})); + return false; + } + + if (promotedPlayer.id === player.id) { + response.push(makePacket(CommandGuildElderHimselfPacketRes, {himself: true})); + return false; + } + + if (promotedPlayer.id === guild.elderId) { + response.push(makePacket(CommandGuildElderAlreadyElderPacketRes, {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(); + await promotedPlayer.reload(); + // Do all necessary checks again just in case something changed during the menu + 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({keycloakId: packet.askedPlayerKeycloakId}, player); + + if (!await isEligible(player, promotedPlayer, response)) { + return; + } + const guildName = (await Guilds.getById(player.guildId)).name; + + const collector = new ReactionCollectorGuildElder( + guildName, + 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/Discord/src/commands/guild/GuildElderCommand.ts b/Discord/src/commands/guild/GuildElderCommand.ts new file mode 100644 index 000000000..9413c7904 --- /dev/null +++ b/Discord/src/commands/guild/GuildElderCommand.ts @@ -0,0 +1,187 @@ +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, + CommandGuildElderAlreadyElderPacketRes, + CommandGuildElderFoundPlayerPacketRes, + CommandGuildElderHimselfPacketRes, + CommandGuildElderPacketReq, + CommandGuildElderRefusePacketRes, + CommandGuildElderSameGuildPacketRes +} 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, + guildName: data.guildName + }) + ); + + 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; + } + if (!packet.foundPlayer) { + 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; + } + 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) { + 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; + } + 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, + guildName: packet.guildName + }), 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..53f671c59 100644 --- a/Discord/src/packetHandlers/handlers/CommandHandlers.ts +++ b/Discord/src/packetHandlers/handlers/CommandHandlers.ts @@ -162,6 +162,22 @@ import { handleCommandUnlockRefusePacketRes } from "../../commands/player/UnlockCommand"; import {handleClassicError} from "../../utils/ErrorUtils"; +import { + CommandGuildElderAcceptPacketRes, + CommandGuildElderAlreadyElderPacketRes, + CommandGuildElderFoundPlayerPacketRes, + CommandGuildElderHimselfPacketRes, + CommandGuildElderRefusePacketRes, + CommandGuildElderSameGuildPacketRes +} from "../../../../Lib/src/packets/commands/CommandGuildElderPacket"; +import { + handleCommandGuildElderAcceptPacketRes, + handleCommandGuildElderAlreadyElderPacketRes, + handleCommandGuildElderFoundPlayerPacketRes, + handleCommandGuildElderHimselfPacketRes, + handleCommandGuildElderRefusePacketRes, + handleCommandGuildElderSameGuildPacketRes +} from "../../commands/guild/GuildElderCommand"; export default class CommandHandlers { @packetHandler(CommandPingPacketRes) @@ -288,6 +304,36 @@ export default class CommandHandlers { await handleCommandGuildKickAcceptPacketRes(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) + 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..67a78f8c3 100644 --- a/Lang/fr/commands.json +++ b/Lang/fr/commands.json @@ -82,6 +82,20 @@ "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": { + "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é.", + "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/commands/CommandGuildElderPacket.ts b/Lib/src/packets/commands/CommandGuildElderPacket.ts new file mode 100644 index 000000000..1f8e50181 --- /dev/null +++ b/Lib/src/packets/commands/CommandGuildElderPacket.ts @@ -0,0 +1,38 @@ +import {DraftBotPacket, PacketDirection, sendablePacket} from "../DraftBotPacket"; + +@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; +} + +@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 diff --git a/Lib/src/packets/interaction/ReactionCollectorGuildElder.ts b/Lib/src/packets/interaction/ReactionCollectorGuildElder.ts new file mode 100644 index 000000000..2887b05b1 --- /dev/null +++ b/Lib/src/packets/interaction/ReactionCollectorGuildElder.ts @@ -0,0 +1,40 @@ +import { + ReactionCollector, + ReactionCollectorAcceptReaction, + ReactionCollectorCreationPacket, + ReactionCollectorData, + ReactionCollectorRefuseReaction +} 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(guildName: string, promotedKeycloakId: string) { + super(); + this.guildName = guildName; + this.promotedKeycloakId = promotedKeycloakId; + } + + creationPacket(id: string, endTime: number): ReactionCollectorCreationPacket { + return { + id, + endTime, + reactions: [ + this.buildReaction(ReactionCollectorAcceptReaction, {}), + this.buildReaction(ReactionCollectorRefuseReaction, {}) + ], + data: this.buildData(ReactionCollectorGuildElderData, { + guildName: this.guildName, + promotedKeycloakId: this.promotedKeycloakId + }) + }; + } +} \ No newline at end of file