Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // this file is for the giveaway command
- const { SlashCommandBuilder, EmbedBuilder, ModalBuilder, TextInputBuilder, ButtonBuilder, TextInputStyle, ActionRowBuilder, ButtonStyle, ComponentType } = require('discord.js');
- const winners = "Winners are chosen at random by Pip from the list of people who registered for the giveaway. When a winner is chosen, YOU MUST follow through with the exchange, regardless of who wins the item. If you anticipate that you will be unable to do so for any reason, DO NOT create a giveaway.\n\n You may choose to have multiple winners for your giveaway. If you do, the first winner announced must get preference for the item they want. For example, if you are giving away three sets of dice, the first winner chosen will get to choose which set they want first. The second winner will get the remaining item. If you have more than two items, the third winner will get the remaining item, and so on. It is recommended that you only use this functionality when the items are similar, to prevent someone from winning an item they weren't interested in. If you have multiple items of different types (like a game and a set of dice, or two different games), you should create separate giveaways for each item.\n"
- const validity = "Items must be related in some way to tabletop gaming. They can be time sensitive (like convention tickets) or physical items (like dice, games, or books). You may only giveaway monetary items such as gift cards if you have gotten permission to do so from a member of administration. You may NOT EVER give away cash, whether it be physical or through a service like Venmo or Paypal. This is to limit the risk of scams within the community.\n\nPlease keep your giveaway items family friendly. If you're unsure if your item is valid, reach out to a moderator before creating a giveaway.\n"
- const timing = "Giveaways must be scheduled at least 24 hours in advance to allow ample time for participation. This is not important for most things, but please keep this rule in mind for time-sensitive items like convention tickets. Giveaways always end and winners are announced at 8am on the day you choose. If you have a time-sensitive item, please make sure the end date is at least 24 hours before the item is to be used.\n\nGiveaways may be scheduled up to any number of days in advance, but please try to keep the end date within a reasonable timeframe. For non-time sensitive items we recommend 7 days, and for time-sensitive items we recommend 30 days to allow participants time to plan ahead for events.\n"
- const exchange = "Handoffs must take place at a Cardboard Society meetup unless otherwise agreed upon by the winner and the giver. If you are unable to attend a meetup, please reach out to a moderator before creating a giveaway to discuss alternative arrangements. All giveaways are local to the chapter in which you are holding the giveaway. If you are a member of multiple chapters, please make sure you are creating the giveaway in the correct chapter."
- const digitals = "Digital item giveaways are allowed, but you must communicate limitations about that item in the 'details' section of the following form. For example, if you are giving away a Steam code for the game Tabletop Sim, you must specify that the code can only be used with a valid Steam account. If you have any questions about what is allowed, please reach out to a moderator before creating a giveaway."
- const confirmation = "If you have read and understand the above rules, please click the 'Accept' button below to fill out the form. Otherwise feel free to click 'Dismiss message' below to remove the message, or ignore it and it will eventually delete itself. If you need to cancel a giveaway once it has begun or if you have any questions, please reach out to a moderator before creating a giveaway."
- async function wrongDate(interaction) {
- try {
- const customId = Date.now() + interaction.user.id;
- // send ephemeral message that the date is incorrect with button to try again
- const confirmButton = new ButtonBuilder()
- .setCustomId(customId)
- .setStyle(ButtonStyle.Primary)
- .setLabel('Try again');
- const actionRow = new ActionRowBuilder()
- .addComponents(confirmButton);
- const retryMessage = await interaction.reply({ content: 'The date you entered is not in the correct format. Please click the button to try again.', components: [actionRow], ephemeral: true });
- // create a collector for the try again button
- const retryCollector = await retryMessage.createMessageComponentCollector({ componentType: ComponentType.Button, time: 1000 * 60 * 3 });
- // when the button is pressed
- retryCollector.on('collect', async buttonInteraction => {
- console.log("button pressed");
- if (buttonInteraction.customId === customId) {
- console.log("retrying");
- retryCollector.stop();
- buttonInteraction.messageData = interaction.messageData;
- await createGiveaway(buttonInteraction);
- };
- });
- } catch (error) {
- console.error(error);
- }
- };
- async function createGiveaway(interaction) {
- try {
- const customId = Date.now() + interaction.user.id;
- // create modal to get details
- const Modal = new ModalBuilder()
- .setCustomId(customId)
- .setTitle('Create a giveaway');
- const item = new TextInputBuilder()
- .setCustomId('item' + customId)
- .setPlaceholder('What are you giving away?')
- .setLabel('Item')
- .setStyle(TextInputStyle.Short)
- .setRequired(true);
- const details = new TextInputBuilder()
- .setCustomId('details' + customId)
- .setPlaceholder('Do you have more details about the item?')
- .setLabel('Details')
- .setStyle(TextInputStyle.Paragraph)
- .setRequired(false);
- const endDate = new TextInputBuilder()
- .setCustomId('endDate' + customId)
- .setMinLength(10)
- .setMaxLength(10)
- .setPlaceholder('dd/mm/yyyy')
- .setLabel('End Date')
- .setStyle(TextInputStyle.Short)
- .setRequired(true);
- if (interaction.messageData) {
- item.setValue(interaction.messageData.item);
- details.setValue(interaction.messageData.details);
- console.log("data exists");
- }
- console.log("oopsy fucky wucky");
- const itemActionRow = new ActionRowBuilder()
- .addComponents(item);
- const detailsActionRow = new ActionRowBuilder()
- .addComponents(details);
- const durationActionRow = new ActionRowBuilder()
- .addComponents(endDate);
- Modal.addComponents([itemActionRow, detailsActionRow, durationActionRow]);
- console.log("showing modal");
- await interaction.showModal(Modal);
- console.log("modal shown");
- //collect modal response
- await interaction.awaitModalSubmit({time: 1000 * 60 * 15}).then(async response => {
- if (response.customId !== customId) return;
- response.messageData = {};
- response.messageData.item = response.fields.getTextInputValue('item' + customId);
- response.messageData.details = response.fields.getTextInputValue('details' + customId);
- response.messageData.endDate = response.fields.getTextInputValue('endDate' + customId);
- // check that the date follows the format dd/mm/yyyy
- const dateRegex = /^\d{2}\/\d{2}\/\d{4}$/;
- if (!dateRegex.test(response.messageData.endDate)) {
- await wrongDate(response);
- return;
- }
- });
- // create giveaway embed
- // send giveaway message
- // create scheduled task to announce winner(s)
- // send winner(s) message
- } catch (error) {
- console.error(error);
- }
- };
- module.exports = {
- data: new SlashCommandBuilder()
- .setName('giveaway')
- .setDescription('Create a giveaway'),
- async execute(interaction) {
- const customId = Date.now() + interaction.user.id;
- // send an embed with information about the giveaway command
- const giveawayEmbed = new EmbedBuilder()
- .setColor('1663f3')
- .setTitle('Giveaway Information')
- .setDescription('Please read the following information before creating a giveaway.')
- .addFields(
- { name: 'The Winners', value: winners, inline: false },
- { name: 'The Items', value: validity, inline: false },
- { name: 'The Timing', value: timing, inline: false },
- { name: 'The Exchange', value: exchange, inline: false },
- { name: 'The Digitals', value: digitals, inline: false },
- { name: 'Confirmation', value: confirmation, inline: false },
- )
- .setFooter({ text: 'Generated by Pip'});
- const confirmButton = new ButtonBuilder()
- .setCustomId('confirm' + customId)
- .setStyle(ButtonStyle.Success)
- .setLabel('Accept');
- const actionRow = new ActionRowBuilder()
- .addComponents(confirmButton);
- const termsEmbedResponse = await interaction.reply({ embeds: [giveawayEmbed], components: [actionRow], ephemeral: true });
- // create a collector for the confirm button
- const collector = await termsEmbedResponse.createMessageComponentCollector({ componentType: ComponentType.Button, time: 1000 * 60 * 15 });
- // when the button is pressed
- collector.on('collect', async buttonInteraction => {
- if (buttonInteraction.customId === 'confirm' + customId) {
- collector.stop();
- const newInteraction = buttonInteraction;
- createGiveaway(newInteraction);
- }
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement