1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
|
/** **************************************
*
* AddQuote: Command for AleeBot
* 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
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* *************************************/
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 = message.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 = message.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',
};
|