summaryrefslogtreecommitdiff
path: root/commands
diff options
context:
space:
mode:
authorAndrew Lee <andrew@alee14.me>2025-01-11 18:02:05 -0500
committerAndrew Lee <andrew@alee14.me>2025-01-11 18:02:05 -0500
commit7e65ae0e135098acad76b8081f34478b4efc077f (patch)
treeb7efc060fca4257a875a5a3e525e2733b6579040 /commands
parentf5de90ba89146008af78c16e798e216efccf0c50 (diff)
downloadAleeBot-7e65ae0e135098acad76b8081f34478b4efc077f.tar.gz
AleeBot-7e65ae0e135098acad76b8081f34478b4efc077f.tar.bz2
AleeBot-7e65ae0e135098acad76b8081f34478b4efc077f.zip
Cleaned up some code, author image now support attachments
Diffstat (limited to 'commands')
-rw-r--r--commands/addquote.js87
-rw-r--r--commands/quote.js4
-rw-r--r--commands/setup.js3
3 files changed, 59 insertions, 35 deletions
diff --git a/commands/addquote.js b/commands/addquote.js
index 52f7b21..f13d3c9 100644
--- a/commands/addquote.js
+++ b/commands/addquote.js
@@ -20,14 +20,21 @@
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;
- let isSetupRunning = false;
+
+ 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 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.',
+ '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:'
];
@@ -38,23 +45,38 @@ module.exports.run = async (client, message) => {
authorImage: newAuthorImage,
quote: newQuote,
year: newYear,
+ submitterAuthor: message.author.username,
+ submitterID: message.author.id
});
}
+ async function imageCheck(message) {
+ const attachment = message.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.');
+ return await imageCheck(message);
+ }
+ } else if (msg.content.startsWith('http') && (message.content.endsWith('.jpg') || message.content.endsWith('.jpeg') || message.content.endsWith('.png'))) {
+ newAuthorImage = msg.content; // Use the provided URL
+ } else {
+ await dmChannel.send('Invalid input. Please provide an image URL or attach an image file.');
+ return await imageCheck(message);
+ }
+ }
+
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 += "```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";
- if (isSetupRunning) {
- return await message.reply('You are already setting up a quote.');
- }
-
const filter = (m) => m.author.id === message.author.id;
- isSetupRunning = true;
await message.reply(':arrow_left: Check DMs to continue.');
const dmChannel = await message.author.createDM();
@@ -65,10 +87,14 @@ module.exports.run = async (client, message) => {
const collector = dmChannel.createMessageCollector({
filter,
max: setupProcess.length,
- time: 1000 * 120
+ time: 1000 * 1200
});
- collector.on('collect', async () => {
+ collector.on('collect', async (msg) => {
+ if (counter === 2) { // Collecting author image
+ await imageCheck(msg);
+ }
+
if (counter < setupProcess.length) {
await dmChannel.send(setupProcess[counter++]);
}
@@ -77,20 +103,23 @@ module.exports.run = async (client, message) => {
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];
- newAuthorImage = quoteContent[1];
+ 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 2 minutes.')
- .addField('Author', newAuthor)
- .addField('Author Image (URL)', newAuthorImage)
- .addField('Quote', newQuote)
- .addField('Year', newYear)
+ .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]});
@@ -107,7 +136,7 @@ module.exports.run = async (client, message) => {
const reactionCollector = messageReact.createReactionCollector({
filter: reactionFilter,
- time: 1000 * 120
+ time: 1000 * 1200
});
reactionCollector.on('collect', async (reaction) => {
@@ -119,10 +148,10 @@ module.exports.run = async (client, message) => {
await dmChannel.send('Updated author name.');
break;
case '📷':
- await dmChannel.send('You selected the author image. Please provide the image URL.');
+ 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 });
- if (imageResponse.size) newAuthorImage = imageResponse.first().content;
- await dmChannel.send('Updated author URL.');
+ await imageCheck(imageResponse.first());
+ await dmChannel.send('Updated author image.');
break;
case '🖋️':
await dmChannel.send('You selected the quote. Please provide the quote.');
@@ -144,36 +173,26 @@ module.exports.run = async (client, message) => {
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]});
+ await messageReact.edit({embeds: [setupEmbed]});
});
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();
}
+ setupUsers.delete(message.author.id);
});
-
}
});
} catch (error) {
+ message.author.send('An error occurred while setting up the quote. Please try again.');
+ setupUsers.delete(message.author.id);
console.error(error);
}
};
diff --git a/commands/quote.js b/commands/quote.js
index 02699cd..0d67b66 100644
--- a/commands/quote.js
+++ b/commands/quote.js
@@ -38,6 +38,10 @@ module.exports.run = async (client, message, args) => {
.setColor('#1fd619')
.setFooter('- ' + quote.year);
+ if (quote.url) {
+ quoteEmbed.setURL(quote.url);
+ }
+
await message.reply({ embeds: [quoteEmbed] })
} else {
message.reply('Cannot find quote, specify the correct quote id.');
diff --git a/commands/setup.js b/commands/setup.js
index 380e85e..c797f7d 100644
--- a/commands/setup.js
+++ b/commands/setup.js
@@ -27,7 +27,8 @@ module.exports.run = async (client, message) => {
.setDescription('Select the options')
.addField('Logging', 'channelid', true)
.addField('Broadcast', 'placeholder', true)
- .addField('Broadcast', 'placeholder', true);
+ .addField('Quote of the Day', 'placeholder', true)
+ .addField('QOTD Channel', 'channelid', true);
message.author.send({embeds: [setupEmbed]});
};