diff options
| author | Andrew Lee <andrew@alee14.me> | 2025-02-25 23:15:04 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-25 23:15:04 -0500 |
| commit | 44f7f14736aaf77858ee71c80abeb3c13343d3c2 (patch) | |
| tree | 47dc895e50fa95b52a894bf0806e1a6c1edc8818 /commands/addquote.js | |
| parent | 9519602e73a53931be10438dcd990becea7989d9 (diff) | |
| parent | 5777f96394444dab18a81d6f085ac81df3e62008 (diff) | |
| download | AleeBot-44f7f14736aaf77858ee71c80abeb3c13343d3c2.tar.gz AleeBot-44f7f14736aaf77858ee71c80abeb3c13343d3c2.tar.bz2 AleeBot-44f7f14736aaf77858ee71c80abeb3c13343d3c2.zip | |
Merge pull request #36 from Alee14/beta
2.13 Release
Diffstat (limited to 'commands/addquote.js')
| -rw-r--r-- | commands/addquote.js | 251 |
1 files changed, 206 insertions, 45 deletions
diff --git a/commands/addquote.js b/commands/addquote.js index 04df3f4..6eae015 100644 --- a/commands/addquote.js +++ b/commands/addquote.js @@ -1,7 +1,7 @@ -/**************************************** - * +/** ************************************** + * * AddQuote: Command for AleeBot - * Copyright (C) 2017-2020 Alee Productions + * Copyright (C) 2017-2021 Alee Productions * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,46 +15,207 @@ * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. - * + * * *************************************/ -module.exports.run = async (client, message, args) => { - /* - const moment = require('moment'); - const log = message => { - - console.log(`[${moment().format('YYYY-MM-DD HH:mm:ss')}] ${message}`); - - }; - const fs = require('fs'); - if(!args[0]) return message.reply(`Usage: ab:addquote [author] [authorImage] [quote] [year]`); - - let quotes = JSON.parse(fs.readFileSync("./storage/quotes.json", "utf8")); - - quotes = { - author: args[0], - authorImage: args[1], - quote: args[2], - year: args[3] - }; - - fs.writeFile("./storage/quotes.json", JSON.stringify(quotes), (err) =>{ - if (err) log(err) - }) - - message.reply(`You just added a new quote!`); - log(`[i] A quote has been added to quotes.json...`) -*/ - message.reply('Command is broken for now'); - }; - - exports.conf = { - aliases: [], - guildOnly: true, - }; - exports.help = { - name: 'addquote', - description: 'Sets the guild prefix.', - usage: 'addquote [author] [authorImage] [quote] [year]', - category: '- Quote Commands', - }; - +const { pendingQuote } = require('../models/quote'); +const { MessageEmbed } = require("discord.js"); + +const setupUsers = new Set(); + +module.exports.run = async (client, message) => { + try { + let newAuthor, newAuthorImage, newQuote, newYear; + + if (setupUsers.has(message.author.id)) { + return await message.reply('You are already setting up a quote.'); + } + + setupUsers.add(message.author.id); + + const setupProcess = [ + 'Provide the name of the author:', + 'Submit the image of the author:\nYou can use an attachment or a link that ends in .jpg/.jpeg or .png (like those from IMGUR or Google Images), and the picture should be either 128x128 pixels or 512x512 pixels in size.', + 'Enter the quote:', + 'Specify the year from which the quote originates:' + ]; + + async function createQuote() { + await pendingQuote.create({ + author: newAuthor, + authorImage: newAuthorImage, + quote: newQuote, + year: newYear, + submitterAuthor: message.author.username, + submitterID: message.author.id + }); + } + + 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"; + + const filter = (m) => m.author.id === message.author.id; + + await message.reply(':arrow_left: Check DMs to continue.'); + + const dmChannel = await message.author.createDM(); + await dmChannel.send(setupMessage); + await dmChannel.send(setupProcess[0]); + + let counter = 1; + const collector = dmChannel.createMessageCollector({ + filter, + max: setupProcess.length, + time: 1000 * 1200 + }); + + collector.on('collect', async (msg) => { + if (counter === 2) { // Collecting author image + const attachment = msg.attachments.first(); + if (attachment) { + const fileExtension = attachment.name.split('.').pop().toLowerCase(); + if (['jpg', 'png', 'jpeg'].includes(fileExtension)) { + newAuthorImage = attachment.url.toString(); // Use the attachment's URL directly + } else { + await dmChannel.send('Invalid file type. Please attach a .jpg or .png image.'); + collector.stop(); + return; + } + } else if (msg.content.startsWith('http') && (msg.content.endsWith('.jpg') || msg.content.endsWith('.jpeg') || msg.content.endsWith('.png'))) { + newAuthorImage = msg.content; + } else { + await dmChannel.send('Invalid input. Please provide an image URL or attach an image file.'); + collector.stop(); + return; + } + } + + if (counter < setupProcess.length) { + await dmChannel.send(setupProcess[counter++]); + } + }); + + collector.on('end', async (collected) => { + if (collected.size < setupProcess.length) { + dmChannel.send('Quote setup was not completed. Please rerun the command.'); + setupUsers.delete(message.author.id); + } else { + const quoteContent = collected.map((m) => m.content); + newAuthor = quoteContent[0]; + if (!newAuthorImage) { + newAuthorImage = quoteContent[1] || 'N/A'; + } + newQuote = quoteContent[2]; + newYear = quoteContent[3]; + + const setupEmbed = new MessageEmbed() + .setAuthor('AleeBot Quote Setup', client.user.avatarURL()) + .setDescription('Are you happy with this quote?\nThis quote will be sent for manual approval automatically in 20 minutes.') + .addField('Author', newAuthor || 'N/A') + .addField('Author Image (URL)', newAuthorImage || 'N/A') + .addField('Quote', newQuote || 'N/A') + .addField('Year', newYear || 'N/A') + .setColor('#1fd619'); + + let messageReact = await dmChannel.send({embeds: [setupEmbed]}); + await messageReact.react('🧑'); + await messageReact.react('📷'); + await messageReact.react('🖋️'); + await messageReact.react('📅'); + await messageReact.react('✅'); + await messageReact.react('❌'); + + const reactionFilter = (reaction, user) => { + return ['🧑', '📷', '🖋️', '📅', '✅', '❌'].includes(reaction.emoji.name) && user.id === message.author.id; + }; + + const reactionCollector = messageReact.createReactionCollector({ + filter: reactionFilter, + time: 1000 * 1200 + }); + + reactionCollector.on('collect', async (reaction) => { + switch (reaction.emoji.name) { + case '🧑': + await dmChannel.send('You selected the author. Please provide the name of the author.'); + const authorResponse = await dmChannel.awaitMessages({ filter, max: 1, time: 60000 }); + if (authorResponse.size) newAuthor = authorResponse.first().content; + await dmChannel.send('Updated author name.'); + break; + case '📷': + await dmChannel.send('You selected the author image. Please provide the image URL or attach an image file.'); + const imageResponse = await dmChannel.awaitMessages({ filter, max: 1, time: 60000 }); + const attachment = imageResponse.first().attachments.first(); + if (attachment) { + const fileExtension = attachment.name.split('.').pop().toLowerCase(); + if (['jpg', 'png', 'jpeg'].includes(fileExtension)) { + newAuthorImage = attachment.url.toString(); // Use the attachment's URL directly + } else { + await dmChannel.send('Invalid file type. Please attach a .jpg or .png image.'); + } + } else if (imageResponse.first().content.startsWith('http') && (imageResponse.first().content.endsWith('.jpg') || imageResponse.first().content.endsWith('.jpeg') || imageResponse.first().content.endsWith('.png'))) { + newAuthorImage = imageResponse.first().content; + } else { + await dmChannel.send('Invalid input. Please provide an image URL or attach an image file.'); + } + await dmChannel.send('Updated author image.'); + break; + case '🖋️': + await dmChannel.send('You selected the quote. Please provide the quote.'); + const quoteResponse = await dmChannel.awaitMessages({ filter, max: 1, time: 60000 }); + if (quoteResponse.size) newQuote = quoteResponse.first().content; + await dmChannel.send('Updated quote.'); + break; + case '📅': + await dmChannel.send('You selected the year. Please provide the year.'); + const yearResponse = await dmChannel.awaitMessages({ filter, max: 1, time: 60000 }); + if (yearResponse.size) newYear = yearResponse.first().content; + await dmChannel.send('Updated year.'); + break; + case '✅': + reactionCollector.stop('completed'); + break; + case '❌': + reactionCollector.stop('cancelled'); + break; + } + + await messageReact.edit({embeds: [setupEmbed]}); + }); + + reactionCollector.on('end', async (collected, reason) => { + if (reason === 'cancelled') { + dmChannel.send('Cancelling quote setup.'); + } else if (reason === 'completed') { + dmChannel.send('Sending this quote for manual approval.'); + await createQuote(); + } else { + dmChannel.send('You have not responded. Sending this quote for manual approval.'); + await createQuote(); + } + setupUsers.delete(message.author.id); + }); + } + }); + } catch (error) { + await message.author.send('An error occurred while setting up the quote. Please rerun the command.'); + setupUsers.delete(message.author.id); + console.error(error); + } +}; + +exports.conf = { + aliases: [], + guildOnly: true, +}; + +exports.help = { + name: 'addquote', + description: 'Adds a quote to the database.', + usage: 'addquote', + category: '- Quote Commands', +}; + |
