0
0
Fork 0

Split the thread behaviour for the tie alerts into an enum intead of multiple booleans.

This commit is contained in:
Oliver-Akins 2021-09-19 01:44:48 -06:00
parent c0a1f4be2e
commit dfd9325775

View file

@ -7,7 +7,7 @@ export default {
method: `GET`, path: `/{guild_id}/bracket/isTied`, method: `GET`, path: `/{guild_id}/bracket/isTied`,
async handler(request: Request, h: ResponseToolkit) { async handler(request: Request, h: ResponseToolkit) {
let { guild_id: gID } = request.params; let { guild_id: gID } = request.params;
let try_thread = request.query?.try_thread === `true`; let thread_behaviour = config.guilds[gID].tie_reminder;
let r = await request.server.inject({ let r = await request.server.inject({
url: `/${gID}/bracket/winners`, url: `/${gID}/bracket/winners`,
@ -35,7 +35,7 @@ export default {
let params: execute_webhook_query_params = { wait: true }; let params: execute_webhook_query_params = { wait: true };
// Check if the user is wanting to use a thread notification // Check if the user is wanting to use a thread notification
if (try_thread && config.guilds[gID].bot_token) { if ((thread_behaviour !== "channel") && config.guilds[gID].bot_token) {
try { try {
await axios.get( await axios.get(
`${DISCORD_API_URI}/channels/${bracket.msg}`, `${DISCORD_API_URI}/channels/${bracket.msg}`,
@ -67,18 +67,18 @@ export default {
}; };
// Add link if we know what channel the message was posted in // Add link if we know what channel the message was posted in
let use_jump_link = config.guilds[gID].include_jump_link_for_threads ?? true; if (db[gID].bracket.channel) {
if ( switch (thread_behaviour) {
db[gID].bracket.channel case "channel":
&& ( case "thread":
!try_thread content += `\n\n[Jump To Bracket](https://discord.com/channels/${gID}/${bracket.channel}/${bracket.msg})`;
|| ( break;
use_jump_link case "thread_no_jump_link":
|| !params.thread_id if (!params.thread_id) {
) content += `\n\n[Jump To Bracket](https://discord.com/channels/${gID}/${bracket.channel}/${bracket.msg})`;
) };
) { break;
content += `\n\n[Jump To Bracket](https://discord.com/channels/${gID}/${bracket.channel}/${bracket.msg})` };
}; };
let wh = db[gID].webhook; let wh = db[gID].webhook;