From dfd93257751392696acbdfd0d42f5eb9ec96ee92 Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sun, 19 Sep 2021 01:44:48 -0600 Subject: [PATCH] Split the thread behaviour for the tie alerts into an enum intead of multiple booleans. --- src/endpoints/management/is_tied.ts | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/endpoints/management/is_tied.ts b/src/endpoints/management/is_tied.ts index 233dac3..8421f83 100644 --- a/src/endpoints/management/is_tied.ts +++ b/src/endpoints/management/is_tied.ts @@ -7,7 +7,7 @@ export default { method: `GET`, path: `/{guild_id}/bracket/isTied`, async handler(request: Request, h: ResponseToolkit) { 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({ url: `/${gID}/bracket/winners`, @@ -35,7 +35,7 @@ export default { let params: execute_webhook_query_params = { wait: true }; // 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 { await axios.get( `${DISCORD_API_URI}/channels/${bracket.msg}`, @@ -67,18 +67,18 @@ export default { }; // 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 - && ( - !try_thread - || ( - use_jump_link - || !params.thread_id - ) - ) - ) { - content += `\n\n[Jump To Bracket](https://discord.com/channels/${gID}/${bracket.channel}/${bracket.msg})` + if (db[gID].bracket.channel) { + switch (thread_behaviour) { + case "channel": + case "thread": + content += `\n\n[Jump To Bracket](https://discord.com/channels/${gID}/${bracket.channel}/${bracket.msg})`; + break; + case "thread_no_jump_link": + if (!params.thread_id) { + content += `\n\n[Jump To Bracket](https://discord.com/channels/${gID}/${bracket.channel}/${bracket.msg})`; + }; + break; + }; }; let wh = db[gID].webhook;