diff options
| author | Andrew Lee <andrew@alee14.me> | 2025-01-11 11:55:18 -0500 |
|---|---|---|
| committer | Andrew Lee <andrew@alee14.me> | 2025-01-11 11:55:18 -0500 |
| commit | f5de90ba89146008af78c16e798e216efccf0c50 (patch) | |
| tree | 75f2bb7cee8bacce3f92c2b1bc468c7831b3429e /commands | |
| parent | 83dcca0a0279ce6415a3e9d153c13d91284369b0 (diff) | |
| download | AleeBot-f5de90ba89146008af78c16e798e216efccf0c50.tar.gz AleeBot-f5de90ba89146008af78c16e798e216efccf0c50.tar.bz2 AleeBot-f5de90ba89146008af78c16e798e216efccf0c50.zip | |
Ability to add quotes, web interface, pending quotes
Diffstat (limited to 'commands')
| -rw-r--r-- | commands/about.js | 3 | ||||
| -rw-r--r-- | commands/addquote.js | 198 | ||||
| -rw-r--r-- | commands/quote.js | 4 | ||||
| -rw-r--r-- | commands/setup.js | 6 |
4 files changed, 134 insertions, 77 deletions
diff --git a/commands/about.js b/commands/about.js index 7272b6a..0ae756d 100644 --- a/commands/about.js +++ b/commands/about.js @@ -17,7 +17,6 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. * * *************************************/ -const {MessageButton} = require("discord.js"); module.exports.run = async (client, message) => { const { MessageEmbed, MessageButton, MessageActionRow } = require('discord.js'); @@ -30,7 +29,7 @@ module.exports.run = async (client, message) => { .addField('About AleeBot', 'AleeBot is an all-in-one bot that\'s made from the Discord.JS API!') .addField('License', 'GNU General Public License v3.0') .addField('Contributors', Contributors) - .setFooter('© Copyright 2017-2023 Andrew Lee Projects') + .setFooter('© Copyright 2017-2025 Andrew Lee Projects') .setColor('#1fd619'); let Buttons = new MessageActionRow() 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.', diff --git a/commands/quote.js b/commands/quote.js index 37f5714..02699cd 100644 --- a/commands/quote.js +++ b/commands/quote.js @@ -18,7 +18,7 @@ * * *************************************/ module.exports.run = async (client, message, args) => { - const quoteDB = require('../models/quote'); + const { quote: quoteDB } = require('../models/quote'); const { MessageEmbed } = require('discord.js'); let quoteID = args[0]; @@ -38,7 +38,7 @@ module.exports.run = async (client, message, args) => { .setColor('#1fd619') .setFooter('- ' + quote.year); - await message.reply({ content: 'Alright, here\'s your quote.', embeds: [quoteEmbed] }) + 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 5c2f232..380e85e 100644 --- a/commands/setup.js +++ b/commands/setup.js @@ -20,14 +20,12 @@ module.exports.run = async (client, message) => { if (!['242775871059001344', message.guild.ownerId].includes(message.author.id)) return message.reply(':warning: You must be a server owner or be the creator of the bot to access this command.'); - message.reply('Look at your DMs.'); - //message.reply("This feature is coming soon. Stay tuned!"); + message.reply(':arrow_left: Check DMs to continue.'); const Discord = require('discord.js'); const setupEmbed = new Discord.MessageEmbed() .setTitle('AleeBot Setup', client.user.avatarURL()) .setDescription('Select the options') - .addField('Chat Logs', 'channelid', true) - .addField('Joining & Leaving Logs', 'placeholder', true) + .addField('Logging', 'channelid', true) .addField('Broadcast', 'placeholder', true) .addField('Broadcast', 'placeholder', true); |
