Add code and config template.
This commit is contained in:
parent
e0684b963e
commit
ade3be9447
4 changed files with 98 additions and 0 deletions
11
src/config.template.ts
Normal file
11
src/config.template.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
// The number of seconds between each push, this must be a minimum of 300
|
||||||
|
export const DELAY: number = 24 * 60 * 60
|
||||||
|
|
||||||
|
|
||||||
|
// The twitch.center URL for the quotes list, this endpoint must return a
|
||||||
|
// plaintext response with newline characters separating each quote
|
||||||
|
export const QUOTE_URL: string = ``;
|
||||||
|
|
||||||
|
|
||||||
|
// The Discord webhook URL that we are sending the quotes to.
|
||||||
|
export const DISCORD_WEBHOOK: string = ``;
|
||||||
44
src/main.ts
Normal file
44
src/main.ts
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
//
|
||||||
|
// main.ts
|
||||||
|
//
|
||||||
|
// Written by: Tyler Akins (2019/12/31)
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
import { GET_RANDOM_QUOTE } from "./utils/api";
|
||||||
|
import { WEBHOOK_PUSH } from "./utils/webhook";
|
||||||
|
import { DELAY } from "./config";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const MAIN = async () => {
|
||||||
|
const args = process.argv;
|
||||||
|
|
||||||
|
|
||||||
|
if (args.includes("--single")) {
|
||||||
|
console.log(`* Emitting a quote`)
|
||||||
|
let quote = await GET_RANDOM_QUOTE();
|
||||||
|
await WEBHOOK_PUSH(quote);
|
||||||
|
process.exit(0);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
if (args.includes("--repeat")) {
|
||||||
|
|
||||||
|
if (DELAY < 30) {
|
||||||
|
console.log("Can't have a delay < 30 seconds.");
|
||||||
|
process.exit(1);
|
||||||
|
};
|
||||||
|
|
||||||
|
setInterval(
|
||||||
|
async () => {
|
||||||
|
console.log(`* Emitting a quote`)
|
||||||
|
await WEBHOOK_PUSH(await GET_RANDOM_QUOTE());
|
||||||
|
},
|
||||||
|
DELAY * 1000
|
||||||
|
);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
MAIN();
|
||||||
18
src/utils/api.ts
Normal file
18
src/utils/api.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
//
|
||||||
|
// api.ts
|
||||||
|
//
|
||||||
|
// Written by: Tyler Akins (2019/12/31)
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
import * as requests from "request-promise-native"
|
||||||
|
import { QUOTE_URL } from "../config";
|
||||||
|
|
||||||
|
|
||||||
|
export const GET_RANDOM_QUOTE = async (): Promise<string> => {
|
||||||
|
let response = await requests.get(QUOTE_URL);
|
||||||
|
|
||||||
|
let quotes = response.split("\n")
|
||||||
|
|
||||||
|
return quotes[Math.floor(Math.random() * quotes.length)];
|
||||||
|
};
|
||||||
25
src/utils/webhook.ts
Normal file
25
src/utils/webhook.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
//
|
||||||
|
// webhook.ts
|
||||||
|
//
|
||||||
|
// Written by: Tyler Akins (2019/12/31)
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
|
import * as requests from "request-promise-native";
|
||||||
|
import { DISCORD_WEBHOOK } from "../config";
|
||||||
|
|
||||||
|
|
||||||
|
export const WEBHOOK_PUSH = async (quote: string): Promise<boolean> => {
|
||||||
|
return await requests.post({
|
||||||
|
uri: DISCORD_WEBHOOK,
|
||||||
|
body: {
|
||||||
|
content: quote
|
||||||
|
},
|
||||||
|
qs: {
|
||||||
|
wait: true
|
||||||
|
},
|
||||||
|
json: true
|
||||||
|
})
|
||||||
|
.then(() => {return true})
|
||||||
|
.catch(() => {return false});
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue