Refactor getQuote to return the Quote object
This commit is contained in:
parent
fb0bdc779e
commit
a50c63b679
1 changed files with 8 additions and 5 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue