From 5fde8a07b649a445413167d91af23cd5d5c9ff11 Mon Sep 17 00:00:00 2001 From: Raphael Date: Mon, 24 Nov 2025 16:02:03 +0100 Subject: [PATCH] feat(commands/administration): Adding the start of the welcome command --- src/commands/administration/join.ts | 150 ++++++++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 src/commands/administration/join.ts diff --git a/src/commands/administration/join.ts b/src/commands/administration/join.ts new file mode 100644 index 0000000..f36d573 --- /dev/null +++ b/src/commands/administration/join.ts @@ -0,0 +1,150 @@ +import { + SlashCommandBuilder, + CommandInteraction, + ActionRowBuilder, + ChannelSelectMenuBuilder, + ChannelType, + ModalBuilder, + TextInputBuilder, + MessageFlags, + ButtonStyle, + ButtonBuilder, + ChannelSelectMenuInteraction, + GuildBasedChannel, + TextInputStyle, +} from 'discord.js'; +import { prisma } from '@lib/prisma'; +import emoji from '../../../assets/emoji.json' assert { type: 'json' }; + +export default { + data: new SlashCommandBuilder() + .setName('welcome') + .setDescription('Configuration of the welcome system') + .addStringOption((option) => + option + .setName('action') + .setDescription('What is the action you to perform') + .setRequired(true) + .addChoices( + { + name: 'Show', + value: 'welcome_show', + }, + { + name: 'Join', + value: 'welcome_join', + }, + { + name: 'Leave', + value: 'welcome_leave', + }, + ), + ), + + async execute(interaction: CommandInteraction) { + if (!(interaction.guild)) { + await interaction.reply({ + content: `${emoji.answer.error} | This command can only be used in a guild`, + flags: MessageFlags.Ephemeral, + }); + return; + } + + const choice: string = interaction.options.getString('action', true); + + switch (choice) { + case 'welcome_join': { + const joinSelectMenu: ChannelSelectMenuBuilder = new ChannelSelectMenuBuilder() + .setCustomId('join_select_channel') + .setPlaceholder('Choose a channel to send the join notification') + .addChannelTypes(ChannelType.GuildText); + const joinDisable = new ButtonBuilder() + .setCustomId('join_no_channel') + .setLabel('Disabled') + .setStyle(ButtonStyle.Danger); + await interaction.reply({ + content: 'Select the channel where the join message will be send:', + components: [ + new ActionRowBuilder().addComponents(joinSelectMenu), + new ActionRowBuilder().addComponents(joinDisable), + ], + flags: MessageFlags.Ephemeral, + }); + const joinReply: ChannelSelectMenuInteraction = await interaction.channel?.awaitMessageComponent({ + filter: i => i.user.id === interaction.user.id && (i.customId === 'join_select_channel' || i.customId === 'join_no_channel'), + time: 60_000, + }); + if (joinReply.customId == 'join_no_channel') { + await prisma.guild.update({ + where: { + id: interaction.guild.id, + }, + data: { + welcomeEnabled: false, + }, + }); + await interaction.editReply({ + content: `${emoji.answer.yes} | The joining message is now **disabled**`, + components: [], + }); + } + else { + const joinChannel: string = joinReply!.values[0]; + const modal: ModalBuilder = new ModalBuilder() + .setCustomId('join_modal') + .setTitle('Join Form'); + const joinInput: TextInputBuilder = new TextInputBuilder() + .setCustomId('join_msg') + .setRequired(true) + .setLabel('The new message for joinning user') + .setStyle(TextInputStyle.Short); + const placeholdersDisplay = new TextInputBuilder() + .setCustomId('placeholder') + .setRequired(false) + .setStyle(TextInputStyle.Paragraph) + .setLabel('The placeholders allowed for this message') + .setValue( + '{user.mention} → mentions the user\n' + + '{user.name} → username\n' + + '{user.tag} → username#0000\n' + + '{guild.name} → server name\n', + ); + modal.addComponents( + new ActionRowBuilder().addComponents(joinInput), + new ActionRowBuilder().addComponents(placeholdersDisplay), + ); + await joinReply!.showModal(modal); + + const modalSubmit = await joinReply!.awaitModalSubmit({ + filter: i => i.user.id === interaction.user.id && i.customId === 'join_modal', + time: 120_000, + }); + const newJoinMsg: string = modalSubmit.fields.getTextInputValue('join_msg'); + const finalChannel: GuildBasedChannel | null = interaction.guild.channels.cache.get(joinChannel!); + if (!finalChannel || !finalChannel.isTextBased()) { + return modalSubmit.reply({ + content: `${emoji.answer.error} | The channel collected is invalid`, + flags: MessageFlags.Ephemeral, + }); + } + + await prisma.guild.update({ + where: { + id: interaction.guild.id, + }, + data: { + welcomeEnabled: true, + welcomeMessage: newJoinMsg, + welcomeChannel: finalChannel.id, + }, + }); + + await modalSubmit.reply({ + content: `${emoji.answer.yes} | The joining message is now **enabled**`, + flags: MessageFlags.Ephemeral, + }); + } + } + } + }, +};