Untitled

 avatar
unknown
plain_text
4 months ago
9.3 kB
10
Indexable
const {
  Client,
  ChatInputCommandInteraction,
  SlashCommandBuilder,
  EmbedBuilder,
  ActionRowBuilder,
  ButtonBuilder,
  ButtonStyle,
  ComponentType,
  StringSelectMenuBuilder,
} = require('discord.js');
const gamesData = require('../../Templates/gameTMP.json'); // Adjust the path if necessary
const { getLanguage } = require('../../Utils/getLanguage');

module.exports = {
  data: new SlashCommandBuilder()
    .setName('create_event')
    .setDescription('📅 Create a new event step by step.'),

  /**
   * Executes the command logic.
   * @param {ChatInputCommandInteraction} interaction
   * @param {Client} client
   */
  async execute(interaction, client) {
    await interaction.deferReply({ ephemeral: true });
    const { user } = interaction;

    const translations = await getLanguage(interaction, true);

    // Notify user to check DMs
    const notificationEmbed = new EmbedBuilder()
      .setTitle('Event Creation')
      .setDescription('Check your DMs to start creating your event! 📩')
      .setColor('Aqua');

    await interaction.editReply({ embeds: [notificationEmbed] });

    try {
      const dmChannel = await user.createDM();
      // Ask for event type
      const eventTypeEmbed = new EmbedBuilder()
        .setTitle('Choose Event Type')
        .setDescription(
          'Please select the type of event you want to create from the options below:'
        )
        .addFields(
          {
            name: '🎮 Gaming',
            value: 'Events related to games like WoW, FFXIV, etc.',
          },
          { name: '📊 General Polls', value: 'Surveys or voting events.' },
          { name: '🛠 Custom Events', value: 'Create a fully custom event.' }
        )
        .setColor('Blue')
        .setFooter({
          text: 'Select an option to proceed.',
          iconURL: user.displayAvatarURL(),
        })
        .setTimestamp();

      const eventTypeButtons = new ActionRowBuilder().addComponents(
        new ButtonBuilder()
          .setCustomId('gaming_event')
          .setLabel('🎮 Gaming')
          .setStyle(ButtonStyle.Primary),
        new ButtonBuilder()
          .setCustomId('general_poll')
          .setLabel('📊 General Poll')
          .setStyle(ButtonStyle.Secondary),
        new ButtonBuilder()
          .setCustomId('custom_event')
          .setLabel('🛠 Custom Event')
          .setStyle(ButtonStyle.Success)
      );

      await dmChannel.send({
        embeds: [eventTypeEmbed],
        components: [eventTypeButtons],
      });

      // Button collector for event type selection
      const collector = dmChannel.createMessageComponentCollector({
        componentType: ComponentType.Button,
        time: 60000,
      });
      const variableData = {
        Type: '',
        templateID: '',
        Title: '',
        Description: '',
      };

      collector.on('collect', async (buttonInteraction) => {
        await buttonInteraction.deferUpdate();

        let responseEmbed;

        if (buttonInteraction.customId === 'gaming_event') {
          // Prepare game list for dropdown
          variableData.Type = 'Gaming'; // Save type
          const gameOptions = gamesData.map((game) => ({
            emoji: `${game.templateEmoji}`,
            label: `${game.templateID} - ${game.templateName}`,
            value: `${game.templateID}`,
          }));

          // Show game selection dropdown
          responseEmbed = new EmbedBuilder()
            .setTitle('Gaming Event Selected')
            .setDescription(
              'You chose **Gaming**. Select a game from the list below:'
            )
            .setColor('Green');

          // Add game list as fields in the embed
          gamesData.forEach((game) => {
            responseEmbed.addFields({
              name: `\u200B`,
              value: `**${game.templateID}** - ${game.templateEmoji} ${game.templateName}`, // Add other details if needed
              inline: true, // Optional: display fields inline
            });
          });

          const selectMenu = new ActionRowBuilder().addComponents(
            new StringSelectMenuBuilder()
              .setCustomId('game_select')
              .setPlaceholder('Choose your game')
              .addOptions(gameOptions)
          );

          await dmChannel.send({
            embeds: [responseEmbed],
            components: [selectMenu],
          });
        } else if (buttonInteraction.customId === 'general_poll') {
          responseEmbed = new EmbedBuilder()
            .setTitle('General Poll Selected')
            .setDescription(
              'You chose **General Poll**. Let’s set up your poll questions and options.'
            )
            .setColor('Green');
        } else if (buttonInteraction.customId === 'custom_event') {
          responseEmbed = new EmbedBuilder()
            .setTitle('Custom Event Selected')
            .setDescription(
              'You chose **Custom Event**. Let’s build your custom event step by step.'
            )
            .setColor('Green');
        }

        collector.stop(); // Proceed to the next steps based on the selection

        const templateCollector = dmChannel.createMessageComponentCollector({
          componentType: ComponentType.StringSelect,
          time: 60000,
        });

        templateCollector.on('collect', async (dropDownInteraction) => {
          await dropDownInteraction.deferReply();
          variableData.templateID = dropDownInteraction.values[0];
          templateCollector.stop();

          const titleEmbed = new EmbedBuilder()
            .setTitle('Event Title')
            .setDescription(
              'Please provide a title for your event. Respond with your desired title below.'
            )
            .setColor('Blue');

          await dropDownInteraction.editReply({ embeds: [titleEmbed] });

          const titleCollector = dmChannel.createMessageCollector({
            filter: (m) =>
              m.author.id === user.id && m.channel.id === dmChannel.id,
            time: 60000,
            max: 1,
          });

          titleCollector.on('collect', async (message) => {
            variableData.Title = message.content;
            titleCollector.stop();

            const descriptionEmbed = new EmbedBuilder()
              .setTitle('Event Description')
              .setDescription(
                'Please provide a description for your event. Respond with your desired description below.'
              )
              .setColor('Blue');

            await dmChannel.send({ embeds: [descriptionEmbed] });

            const descriptionCollector = dmChannel.createMessageCollector({
              filter: (m) =>
                m.author.id === user.id && m.channel.id === dmChannel.id,
              time: 60000,
              max: 1,
            });

            descriptionCollector.on('collect', async (message) => {
              variableData.Description = message.content;
              descriptionCollector.stop();
            });

            descriptionCollector.on('end', (_, reason) => {
              if (reason === 'time') {
                const timeoutEmbed = new EmbedBuilder()
                  .setTitle('Session Expired')
                  .setDescription(
                    'You took too long to respond. Please try again.'
                  )
                  .setColor('Red');

                dmChannel.send({ embeds: [timeoutEmbed] });
              }
            });
          });

          titleCollector.on('end', (_, reason) => {
            if (reason === 'time') {
              const timeoutEmbed = new EmbedBuilder()
                .setTitle('Session Expired')
                .setDescription(
                  'You took too long to respond. Please try again.'
                )
                .setColor('Red');

              dmChannel.send({ embeds: [timeoutEmbed] });
            }
          });
        });

        templateCollector.on('end', (_, reason) => {
          if (reason === 'time') {
            const timeoutEmbed = new EmbedBuilder()
              .setTitle('Session Expired')
              .setDescription('You took too long to respond. Please try again.')
              .setColor('Red');

            dmChannel.send({ embeds: [timeoutEmbed] });
          }
        });
      });

      collector.on('end', (_, reason) => {
        if (reason === 'time') {
          const timeoutEmbed = new EmbedBuilder()
            .setTitle('Session Expired')
            .setDescription('You took too long to respond. Please try again.')
            .setColor('Red');

          dmChannel.send({ embeds: [timeoutEmbed] });
        }
      });
    } catch (error) {
      const errorEmbed = new EmbedBuilder()
        .setTitle('Error')
        .setDescription(
          'I was unable to send you a DM. Please check your settings and try again.'
        )
        .setColor('Red');

      await interaction.editReply({ embeds: [errorEmbed] });
    }
  },
};
Editor is loading...
Leave a Comment