Add a result webhook push for being able to log the result in a Discord channel.
This commit is contained in:
parent
b288cbb1f8
commit
804e7c7bec
3 changed files with 59 additions and 5 deletions
53
src/api.ts
53
src/api.ts
|
|
@ -1,6 +1,7 @@
|
|||
const axios = require("axios").default;
|
||||
import {
|
||||
QUOTE_URL,
|
||||
RESULT_WEBHOOK,
|
||||
DISCORD_WEBHOOK,
|
||||
DISCORD_API_BASE,
|
||||
DISCORD_CHANNEL_ID,
|
||||
|
|
@ -31,6 +32,7 @@ export const GET_QUOTE = async (count = 1): Promise<string> => {
|
|||
}
|
||||
|
||||
|
||||
|
||||
export const GET_MESSAGE = async (id: string): Promise<msg_meta> => {
|
||||
return axios.get(
|
||||
`${DISCORD_API_BASE}/channels/${DISCORD_CHANNEL_ID}/messages/${id}`,
|
||||
|
|
@ -61,15 +63,60 @@ export const GET_MESSAGE = async (id: string): Promise<msg_meta> => {
|
|||
|
||||
|
||||
|
||||
export const WEBHOOK_PUSH = async (embed: any): Promise<string> => {
|
||||
const WEBHOOK_POST = async (webhook: string, username: string, embed: any): Promise<object> => {
|
||||
console.log(2)
|
||||
return await axios.post(
|
||||
`${DISCORD_WEBHOOK}?wait=true`,
|
||||
{
|
||||
username: DISCORD_WEBHOOK_USERNAME,
|
||||
username: username,
|
||||
embeds: [embed]
|
||||
}
|
||||
)
|
||||
.then((response: any) => {
|
||||
return response.data.id;
|
||||
console.log(3)
|
||||
return response.data;
|
||||
}).catch((err:any) => {throw err});
|
||||
};
|
||||
|
||||
|
||||
|
||||
export const POST_NEW_BRACKET = async (embed: any) => {
|
||||
// @ts-ignore
|
||||
return (await WEBHOOK_POST(DISCORD_WEBHOOK, DISCORD_WEBHOOK_USERNAME, embed)).id
|
||||
}
|
||||
|
||||
|
||||
export const POST_WINNING_QUOTE = async (ctx: msg_meta, won: reaction|"TIE"|"NO_DATA") => {
|
||||
let result: string;
|
||||
console.log(1)
|
||||
switch (won) {
|
||||
case "NO_DATA":
|
||||
case "TIE":
|
||||
result = won;
|
||||
break;
|
||||
default:
|
||||
result = `<:${won.emoji.name}:${won.emoji.id}>`
|
||||
break;
|
||||
}
|
||||
console.log(4)
|
||||
WEBHOOK_POST(
|
||||
RESULT_WEBHOOK,
|
||||
"Bracket Result",
|
||||
{
|
||||
title: "Bracket Results",
|
||||
description: `Bracket Result: ${result}`,
|
||||
fields: [
|
||||
{
|
||||
name: `Quote A:`,
|
||||
value: ctx.quote_a.value,
|
||||
inline: false
|
||||
},
|
||||
{
|
||||
name: `Quote B:`,
|
||||
value: ctx.quote_b.value,
|
||||
inline: false
|
||||
}
|
||||
]
|
||||
}
|
||||
);
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue