Add code to make the stuff work
This commit is contained in:
parent
a18b73fe52
commit
3d9feabe88
15 changed files with 517 additions and 0 deletions
28
src/utils/quotes.ts
Normal file
28
src/utils/quotes.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { readFileSync, writeFileSync } from "fs";
|
||||
import { config } from "../main";
|
||||
import axios from "axios";
|
||||
|
||||
export async function getQuote(count = 1) {
|
||||
let r = await axios.get(
|
||||
config.quote.api_base,
|
||||
{ params: { token: config.quote.token } }
|
||||
);
|
||||
let quoteList = r.data.split(`\n`);
|
||||
let history: string[] = JSON.parse(readFileSync(config.server.quote_history, `utf-8`));
|
||||
|
||||
// Populate the quotes list
|
||||
let quotes: string[] = [];
|
||||
do {
|
||||
let quote = quoteList[Math.floor(Math.random() * quoteList.length)];
|
||||
|
||||
if (!quotes.includes(quote) && !history.includes(quote)) {
|
||||
quotes.push(quote);
|
||||
};
|
||||
} while (quotes.length < count);
|
||||
|
||||
history.push(...quotes)
|
||||
|
||||
writeFileSync(config.server.quote_history, JSON.stringify(history));
|
||||
|
||||
return quotes;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue