From a50c63b679e6b09412e1a9baa1424e8244fce6ec Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sun, 29 Aug 2021 14:56:29 -0600 Subject: [PATCH] Refactor getQuote to return the Quote object --- src/utils/quotes.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/utils/quotes.ts b/src/utils/quotes.ts index 8c7f22c..ad886ec 100644 --- a/src/utils/quotes.ts +++ b/src/utils/quotes.ts @@ -11,17 +11,20 @@ export async function getQuote(gID: string, count = 1) { let history = await loadUsedQuotes(gID); // Populate the quotes list - let quotes: string[] = []; + let quotes: quote[] = []; 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); + history.push(quote.text); }; } while (quotes.length < count); - history.push(...quotes) - await saveUsedQuotes(gID, history); return quotes;