0
0
Fork 0

Refactor getQuote to return the Quote object

This commit is contained in:
Oliver-Akins 2021-08-29 14:56:29 -06:00
parent fb0bdc779e
commit a50c63b679

View file

@ -11,17 +11,20 @@ export async function getQuote(gID: string, count = 1) {
let history = await loadUsedQuotes(gID); let history = await loadUsedQuotes(gID);
// Populate the quotes list // Populate the quotes list
let quotes: string[] = []; let quotes: quote[] = [];
do { do {
let quote = quoteList[Math.floor(Math.random() * quoteList.length)]; let quote: quote = {
text: quoteList[Math.floor(Math.random() * quoteList.length)],
votes: 0,
win_streak: 0,
};
if (!quotes.includes(quote) && !history.includes(quote)) { if (!quotes.includes(quote) && !history.includes(quote.text)) {
quotes.push(quote); quotes.push(quote);
history.push(quote.text);
}; };
} while (quotes.length < count); } while (quotes.length < count);
history.push(...quotes)
await saveUsedQuotes(gID, history); await saveUsedQuotes(gID, history);
return quotes; return quotes;