diff options
Diffstat (limited to 'bot/src/commands')
| -rw-r--r-- | bot/src/commands/quote.js | 141 | ||||
| -rw-r--r-- | bot/src/commands/settings.js | 22 |
2 files changed, 138 insertions, 25 deletions
diff --git a/bot/src/commands/quote.js b/bot/src/commands/quote.js index eaac975..60e35b9 100644 --- a/bot/src/commands/quote.js +++ b/bot/src/commands/quote.js @@ -1,35 +1,132 @@ -import { SlashCommandBuilder, EmbedBuilder } from 'discord.js'; -import { quote as quoteDB } from '../models/quote.js'; +import { + SlashCommandBuilder, + EmbedBuilder, + MessageFlags, + ModalBuilder, + TextInputBuilder, + TextInputStyle, ActionRowBuilder +} from 'discord.js'; +import { pendingQuote, quote as quoteDB } from '../models/quote.js'; +import { abEmbedColour } from '../storage/consts.js'; +// import { setTimeout as wait } from 'node:timers/promises'; +// +// let setupMessage = 'Welcome to the AleeBot Quote Setup!\n'; +// setupMessage += 'Please follow these rules when submitting quotes:\n'; +// setupMessage += '```1. No offensive content (NSFW, Racism, etc).\n'; +// setupMessage += '2. Do not send any personal information.\n'; +// setupMessage += '3. Only send noteworthy quotes.```\n'; +// setupMessage += 'We reserve the right to reject any quotes that do not meet our criteria.\n'; + export default { data: new SlashCommandBuilder() .setName('quote') .setDescription('It gives you a quote.') - .addNumberOption(option => - option - .setName('id') - .setDescription('Enter the quote ID to get a specific quote.')), + .addSubcommand(subcommand => + subcommand + .setName('get') + .setDescription('Gives you a quote.') + .addNumberOption(option => + option + .setName('id') + .setDescription('Enter the quote ID to get a specific quote.'))) + .addSubcommand(subcommand => + subcommand + .setName('add') + .setDescription('Got a quote? Add it here!')), async execute(interaction) { - let quoteID = interaction.options.getNumber('id'); + if (interaction.options.getSubcommand() === 'add') { + const modal = new ModalBuilder() + .setCustomId(`newQuote-${interaction.user.id}`) + .setTitle('New Quote for AleeBot'); + + const author = new TextInputBuilder() + .setCustomId('author') + .setLabel('Provide the name of the author') + .setMaxLength(50) + .setPlaceholder('Name') + .setStyle(TextInputStyle.Short); + + const authorImage = new TextInputBuilder() + .setCustomId('authorImage') + .setLabel('Submit the image of the author') + .setMaxLength(100) + .setPlaceholder('Image URL (512x512) or (128x128)') + .setStyle(TextInputStyle.Short); + + const quote = new TextInputBuilder() + .setCustomId('quote') + .setLabel('Enter the quote') + .setMaxLength(200) + .setPlaceholder('Quote') + .setStyle(TextInputStyle.Paragraph); + + const year = new TextInputBuilder() + .setCustomId('year') + .setLabel('Specify the year which the quote originates') + .setMaxLength(4) + .setPlaceholder('Year') + .setStyle(TextInputStyle.Short); + + const firstActionRow = new ActionRowBuilder().addComponents(author); + const secondActionRow = new ActionRowBuilder().addComponents(authorImage); + const thirdActionRow = new ActionRowBuilder().addComponents(quote); + const fourthActionRow = new ActionRowBuilder().addComponents(year); + + modal.addComponents(firstActionRow, secondActionRow, thirdActionRow, fourthActionRow); - if (!quoteID) { - const quoteList = await quoteDB.findAll({ attributes: ['id'] }); - const random = crypto.getRandomValues(new Uint32Array(1)); - quoteID = quoteList[random[0] % quoteList.length].id; + await interaction.showModal(modal); + + const filter = (interaction) => interaction.customId === `newQuote-${interaction.user.id}`; + + interaction.awaitModalSubmit({ filter, time: 1000 * 1200 }) + .then(async (modalInteraction) => { + const author = modalInteraction.fields.getTextInputValue('author'); + const authorImage = modalInteraction.fields.getTextInputValue('authorImage'); + const quote = modalInteraction.fields.getTextInputValue('quote'); + const year = modalInteraction.fields.getTextInputValue('year'); + + await pendingQuote.create({ + author: author, + authorImage: authorImage, + quote: quote, + year: year, + submitterAuthor: modalInteraction.user.username, + submitterID: modalInteraction.user.id + }).catch((err) => { + console.error(err); + return modalInteraction.reply({ content: 'Something went wrong.', flags: MessageFlags.Ephemeral }); + }); + + return modalInteraction.reply({content: 'Sending this quote for manual approval.', flags: MessageFlags.Ephemeral}); + }) + .catch((err) => { + console.error(err); + }); } - const quote = await quoteDB.findOne({ where: { id: quoteID } }); + if (interaction.options.getSubcommand() === 'get') { + let quoteID = interaction.options.getNumber('id'); + + if (!quoteID) { + const quoteList = await quoteDB.findAll({ attributes: ['id'] }); + const random = crypto.getRandomValues(new Uint32Array(1)); + quoteID = quoteList[random[0] % quoteList.length].id; + } + + const quote = await quoteDB.findOne({ where: { id: quoteID } }); - if (quote) { - let userSubmitter = await interaction.client.users.fetch(quote.submitter); - const quoteEmbed = new EmbedBuilder() - .setAuthor({ name: quote.author, iconURL: quote.authorImage }) - .setDescription(quote.quote) - .setColor('#1fd619') - .setFooter({ text: `- ${quote.year}\nSubmitted by ${userSubmitter.username}` }); + if (quote) { + let userSubmitter = await interaction.client.users.fetch(quote.submitter); + const quoteEmbed = new EmbedBuilder() + .setAuthor({ name: quote.author, iconURL: quote.authorImage }) + .setDescription(quote.quote) + .setColor(abEmbedColour) + .setFooter({ text: `- ${quote.year}\nSubmitted by ${userSubmitter.username}` }); - return await interaction.reply({ embeds: [quoteEmbed] }); - } else { - return await interaction.reply('Cannot find quote, specify the correct quote id.'); + return await interaction.reply({ embeds: [quoteEmbed] }); + } else { + return await interaction.reply({ content: 'Cannot find quote. Specify the correct quote ID.', flags: MessageFlags.Ephemeral}); + } } } }; diff --git a/bot/src/commands/settings.js b/bot/src/commands/settings.js index a04d1c2..5d32a67 100644 --- a/bot/src/commands/settings.js +++ b/bot/src/commands/settings.js @@ -1,10 +1,26 @@ -import { SlashCommandBuilder } from 'discord.js'; +import { MessageFlags, PermissionFlagsBits, SlashCommandBuilder } from 'discord.js'; export default { data: new SlashCommandBuilder() .setName('settings') - .setDescription('User settings for AleeBot.'), + .setDescription('User settings for AleeBot.') + .addSubcommand(subcommand => + subcommand + .setName('guild') + .setDescription('Change settings for the guild.')) + .addSubcommand(subcommand => + subcommand + .setName('user') + .setDescription('Change settings for the user.')), async execute(interaction) { - return await interaction.reply(`**PONG!** :ping_pong: ${Math.round(interaction.client.ws.ping)} ms`); + if (interaction.options.getSubcommand() === 'guild') { + if (!interaction.member.permissions.has(PermissionFlagsBits.ManageGuild)) return await interaction.reply({ content: 'You do not have the permission to manage this guild.', flags: MessageFlags.Ephemeral }); + + return await interaction.reply('recieved'); + } + + if (interaction.options.getSubcommand() === 'user') { + return; + } } }; |
