summaryrefslogtreecommitdiff
path: root/commands/quote.js
diff options
context:
space:
mode:
Diffstat (limited to 'commands/quote.js')
-rw-r--r--commands/quote.js50
1 files changed, 22 insertions, 28 deletions
diff --git a/commands/quote.js b/commands/quote.js
index 149fe37..37f5714 100644
--- a/commands/quote.js
+++ b/commands/quote.js
@@ -1,7 +1,7 @@
/** **************************************
*
* Quote: 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
@@ -17,39 +17,33 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* *************************************/
-module.exports.run = async (client, message) => {
- const Discord = require('discord.js');
-
- let NewQuote;
-
- function GetNewQuote(quoteNum = -1) {
- NewQuote = new Discord.MessageEmbed();
-
- let quo = require('../storage/quotes.json').quotes;
+module.exports.run = async (client, message, args) => {
+ const quoteDB = require('../models/quote');
+ const { MessageEmbed } = require('discord.js');
+ let quoteID = args[0];
+
+ if (quoteID === undefined) {
+ const quoteList = await quoteDB.findAll({ attributes: ['id'] })
+ const random = crypto.getRandomValues(new Uint32Array(1));
+ quoteID = quoteList[random[0] % quoteList.length].id;
+ }
- if (quoteNum == -1) {
- quoteNum = Math.floor(Math.random() * 1000) % quo.length;
- quo=quo[quoteNum];
- }
+ const quote = await quoteDB.findOne({ where: { id: quoteID } })
- const author = quo.author;
- const authorImage = quo.authorImage;
- const quote = quo.quote;
- const year = quo.year;
- const url = quo.url;
- NewQuote.setAuthor(author, authorImage);
- NewQuote.setColor('#1fd619');
- NewQuote.setDescription(quote);
- NewQuote.setFooter('- ' + year);
- NewQuote.setURL(url);
+ if (quote) {
+ const quoteEmbed = new MessageEmbed()
+ .setAuthor({ name: quote.author, iconURL: quote.authorImage })
+ .setDescription(quote.quote)
+ .setColor('#1fd619')
+ .setFooter('- ' + quote.year);
- return NewQuote;
+ await message.reply({ content: 'Alright, here\'s your quote.', embeds: [quoteEmbed] })
+ } else {
+ message.reply('Cannot find quote, specify the correct quote id.');
}
- const newquote = GetNewQuote();
- message.reply('Alright, here\'s your quote.');
- message.channel.send(newquote);
+
};
exports.conf = {