aboutsummaryrefslogtreecommitdiff
path: root/commands/addquote.js
diff options
context:
space:
mode:
authorAndrew Lee <andrew@alee14.me>2025-01-11 11:55:18 -0500
committerAndrew Lee <andrew@alee14.me>2025-01-11 11:55:18 -0500
commitf5de90ba89146008af78c16e798e216efccf0c50 (patch)
tree75f2bb7cee8bacce3f92c2b1bc468c7831b3429e /commands/addquote.js
parent83dcca0a0279ce6415a3e9d153c13d91284369b0 (diff)
downloadAleeBot-f5de90ba89146008af78c16e798e216efccf0c50.tar.gz
AleeBot-f5de90ba89146008af78c16e798e216efccf0c50.tar.bz2
AleeBot-f5de90ba89146008af78c16e798e216efccf0c50.zip
Ability to add quotes, web interface, pending quotes
Diffstat (limited to 'commands/addquote.js')
-rw-r--r--commands/addquote.js198
1 files changed, 129 insertions, 69 deletions
diff --git a/commands/addquote.js b/commands/addquote.js
index 5f2b9bc..52f7b21 100644
--- a/commands/addquote.js
+++ b/commands/addquote.js
@@ -17,105 +17,164 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* *************************************/
-const quoteDB = require('../models/quote');
+const { pendingQuote } = require('../models/quote');
const { MessageEmbed } = require("discord.js");
-module.exports.run = async (client, message, args) => {
- if (!['242775871059001344'].includes(message.author.id)) return message.reply('**This command is disabled due to a new system being implemented.**');
- try {
- let newAuthor;
- let newAuthorImage;
- let newQuote;
- let newYear;
-
- let quoteOriginator;
+module.exports.run = async (client, message) => {
+ try {
+ let newAuthor, newAuthorImage, newQuote, newYear;
let isSetupRunning = false;
const setupProcess = [
- 'Provide the name of the author.',
- 'Submit the image of the author\nYou need to use a picture link that ends in .jpg 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.'
- ]
-
- let setupMessage = "Welcome to the AleeBot Quote Setup!\n"
- setupMessage += "Please follow these rules when submitting quotes\n"
- setupMessage += "```1. Do not use profanity or offensive language.\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"
+ 'Provide the name of the author:',
+ 'Submit the image of the author:\nYou need to use a picture link that ends in .jpg 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,
+ });
+ }
- let counter = 0
+ let setupMessage = "Welcome to the AleeBot Quote Setup!\n";
+ setupMessage += "Please follow these rules when submitting quotes:\n";
+ setupMessage += "```1. Do not use profanity or offensive language.\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";
if (isSetupRunning) {
- return await message.reply('You are already setting up the quote.');
+ return await message.reply('You are already setting up a quote.');
}
- const filter = m => m.author.id === message.author.id
+
+ const filter = (m) => m.author.id === message.author.id;
isSetupRunning = true;
- await message.reply(':arrow_left: Check your DMs to continue.')
- await message.author.send(setupMessage);
- await message.author.send(setupProcess[counter++]);
+ await message.reply(':arrow_left: Check DMs to continue.');
+
+ const dmChannel = await message.author.createDM();
+ await dmChannel.send(setupMessage);
+ await dmChannel.send(setupProcess[0]);
- const collector = message.channel.createMessageCollector({
+ let counter = 1;
+ const collector = dmChannel.createMessageCollector({
filter,
max: setupProcess.length,
- time: 1000 * 60
+ time: 1000 * 120
});
- collector.on('collect', message => {
- console.log(`Collected ${message.content} from ${message.author.tag}`)
- if (setupProcess.length > setupProcess.length + 1) {
- message.author.send(setupProcess[counter++]);
+ collector.on('collect', async () => {
+ if (counter < setupProcess.length) {
+ await dmChannel.send(setupProcess[counter++]);
}
});
- collector.on('end', collected => {
- if (collected.size === 0 && collected.size < 2) {
- message.author.send('Quote setup was not completed, rerun the command.')
+ collector.on('end', async (collected) => {
+ if (collected.size < setupProcess.length) {
+ dmChannel.send('Quote setup was not completed. Please rerun the command.');
} else {
- let quoteContent = [];
-
- collected.forEach((message) => {
- quoteContent.push(message.content)
- })
-
- newAuthor = quoteContent[0]
- newAuthorImage = quoteContent[1]
- newQuote = quoteContent[2]
- newYear = quoteContent[3]
+ const quoteContent = collected.map((m) => m.content);
+ newAuthor = quoteContent[0];
+ newAuthorImage = quoteContent[1];
+ 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')
+ .setDescription('Are you happy with this quote?\nThis quote will be sent for manual approval automatically in 2 minutes.')
.addField('Author', newAuthor)
.addField('Author Image (URL)', newAuthorImage)
.addField('Quote', newQuote)
- .addField('Year', newYear);
+ .addField('Year', newYear)
+ .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 * 120
+ });
+
+ 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.');
+ const imageResponse = await dmChannel.awaitMessages({ filter, max: 1, time: 60000 });
+ if (imageResponse.size) newAuthorImage = imageResponse.first().content;
+ await dmChannel.send('Updated author URL.');
+ 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;
+ }
+
+ const updatedEmbed = 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 2 minutes.')
+ .addField('Author', newAuthor)
+ .addField('Author Image (URL)', newAuthorImage)
+ .addField('Quote', newQuote)
+ .addField('Year', newYear)
+ .setColor('#1fd619');
+
+ await messageReact.edit({embeds: [updatedEmbed]});
+ });
+
+ reactionCollector.on('end', async (collected, reason) => {
+ if (reason === 'cancelled') {
+ isSetupRunning = false;
+ dmChannel.send('Cancelling quote setup.');
+ } else if (reason === 'completed') {
+ dmChannel.send('Sending this quote for manual approval.');
+ isSetupRunning = false;
+ await createQuote();
+ } else {
+ dmChannel.send('You have not responded. Sending this quote for manual approval.');
+ isSetupRunning = false;
+ await createQuote();
+ }
+ });
- message.author.send({embeds:[setupEmbed]})
- quoteOriginator = message.author.tag
- console.log(`This quote has been originated from ${quoteOriginator}`)
- isSetupRunning = false;
}
-
});
-
- /*await quoteDB.create({
- author: newAuthor,
- authorImage: newAuthorImage,
- quote: newQuote,
- year: newYear,
- });*/
-
- //let messageReact = await message.author.send({embeds: [setupEmbed]});
- /*await messageReact.react('🧑');
- await messageReact.react('📷');
- await messageReact.react('🖋️');
- await messageReact.react('📅');*/
-
} catch (error) {
- console.log(error)
+ console.error(error);
}
};
@@ -123,6 +182,7 @@ exports.conf = {
aliases: [],
guildOnly: true,
};
+
exports.help = {
name: 'addquote',
description: 'Adds a quote to the database.',