Add the ability to have the tie alert go to a thread of the quote bracket message
This commit is contained in:
parent
d8df5caa76
commit
49c1b848b6
1 changed files with 42 additions and 4 deletions
|
|
@ -6,7 +6,8 @@ import axios from "axios";
|
|||
export default {
|
||||
method: `GET`, path: `/{guild_id}/bracket/isTied`,
|
||||
async handler(request: Request, h: ResponseToolkit) {
|
||||
let gID = request.params.guild_id;
|
||||
let { guild_id: gID } = request.params;
|
||||
let { try_thread } = request.query;
|
||||
|
||||
let r = await request.server.inject({
|
||||
url: `/${gID}/bracket/winners`,
|
||||
|
|
@ -15,6 +16,7 @@ export default {
|
|||
let data = JSON.parse(r.payload);
|
||||
|
||||
if (data.count >= 2) {
|
||||
let bracket = db[gID].bracket;
|
||||
|
||||
// Construct the primary body of the message
|
||||
let content = `The bracket currently has a tie between:\n> ${data.winners.join('\n~~------------------------------------~~\n> ')}`;
|
||||
|
|
@ -26,16 +28,52 @@ export default {
|
|||
content += `\n\n**All of these quotes will advance if the tie isn't broken.**`;
|
||||
};
|
||||
|
||||
// Define the query params that are needed all the time
|
||||
let params: execute_webhook_query_params = { wait: true };
|
||||
|
||||
// Check if the user is wanting to use a thread notification
|
||||
if (try_thread === `true` && config.guilds[gID].bot_token) {
|
||||
try {
|
||||
await axios.get(
|
||||
`${DISCORD_API_URI}/channels/${bracket.msg}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bot ${config.guilds[gID].bot_token}`
|
||||
}
|
||||
}
|
||||
);
|
||||
params.thread_id = bracket.msg;
|
||||
} catch (err) {
|
||||
try {
|
||||
await axios.post(
|
||||
`${DISCORD_API_URI}/channels/${bracket.channel}/messages/${bracket.msg}/threads`,
|
||||
{
|
||||
name: config.guilds[gID].thread_name ?? `Quote Bracket Discussion`,
|
||||
auto_archive_duration: 1440,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bot ${config.guilds[gID].bot_token}`
|
||||
}
|
||||
}
|
||||
).then(response => {
|
||||
params.thread_id = bracket.msg
|
||||
});
|
||||
} catch (err) {};
|
||||
};
|
||||
};
|
||||
|
||||
// Add link if we know what channel the message was posted in
|
||||
if (db[gID].bracket.channel) {
|
||||
content += `\n\n[Jump To Bracket](https://discord.com/channels/${gID}/${db[gID].bracket.channel}/${db[gID].bracket.msg})`
|
||||
let use_jump_link = config.guilds[gID].include_jump_link_for_threads ?? true;
|
||||
if (db[gID].bracket.channel && (use_jump_link && params.thread_id)) {
|
||||
content += `\n\n[Jump To Bracket](https://discord.com/channels/${gID}/${bracket.channel}/${bracket.msg})`
|
||||
};
|
||||
|
||||
let wh = db[gID].webhook;
|
||||
let r = await axios.post(
|
||||
`${DISCORD_API_URI}/webhooks/${wh.id}/${wh.token}`,
|
||||
{ content },
|
||||
{ params: { wait: true } }
|
||||
{ params }
|
||||
);
|
||||
return h.response(r.data).code(r.status);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue