diff --git a/src/buttons/view_open_tickets.ts b/src/buttons/view_open_tickets.ts new file mode 100644 index 0000000..9fbe264 --- /dev/null +++ b/src/buttons/view_open_tickets.ts @@ -0,0 +1,24 @@ +import ButtonCommand from "../classes/ButtonCommand"; + +export default new ButtonCommand({ + checkType:"EQUALS", + execute(interaction){ + interaction.fetchActiveThreads(interaction.guild_id) + .then(r => r.json()) + .then(({threads:activeTickets}) => { + let openTickets = { + private:activeTickets.filter(c => c.name && c.name.startsWith("🔒")), + public:activeTickets.filter(c => c.name && c.name.startsWith("🔓")), + unknown:activeTickets.filter(c => c.name && (!c.name.startsWith("🔓") && !c.name.startsWith("🔒"))) + } + + const threadsAvailable = `Here are a list of active support tickets:\n${openTickets.public.length > 0?`\n**Public :unlock:**\n${openTickets.public.map(c => `<#${c.id}> (${c.name?.split(" - ")[1]})`).join("\n")}`:``}${openTickets.private.length > 0?`\n**Private :lock:**\n${openTickets.private.map(c => `<#${c.id}> (${c.name?.split(" - ")[1]})`).join("\n")}`:``}${openTickets.unknown.length >0?`\n**Unknown :grey_question:**\n${openTickets.unknown.map(c => `<#${c.id}> (${c.name?.split(" - ")[1] || c.name})`).join("\n")}`:``}`; + const noThreadsAvailable = `❌ There are no open tickets available`; + + interaction.reply({ + content:activeTickets.length > 0?threadsAvailable:noThreadsAvailable, + ephemeral:true + }); + }) + } +}) \ No newline at end of file diff --git a/src/commands/setup_ticket_button.ts b/src/commands/setup_ticket_button.ts index bcf91b8..66505ca 100644 --- a/src/commands/setup_ticket_button.ts +++ b/src/commands/setup_ticket_button.ts @@ -7,7 +7,7 @@ export default new Command({ "ephemeral":true }).then(() => { interaction.sendMessage(interaction.internalBot.config.supportChannelId, { - content:"**Check for your issue**\nBefore opening a ticket, check the thread menu <:threadmenu:895475842010988584> and search/scroll through the __**Archived**__ tab/button at the top of the thread menu.\n\n**If you can't find your issue**\n\n*Open Public Support Ticket* : Allows everyone to view your ticket and provide support.\n\n*Open Private Support Ticket* : Allows everyone to view your ticket, but only staff members can provide support.\n\n*`/ticket` Slash Command* : Run in any other channel to open a support ticket supplied with a specific topic.\n\n**Want to help others?**\nOpen the thread menu <:threadmenu:895475842010988584> and search/scroll through the __**Active**__ threads for people needing help. Please only join a thread if you intend to provide support.", + content:"**Check for your issue**\nBefore opening a ticket, check the thread menu <:threadmenu:895475842010988584> and search/scroll through the __**Archived**__ tab/button at the top of the thread menu.\n\n**If you can't find your issue**\n\n*Open Public Support Ticket* : Allows everyone to view your ticket and provide support.\n\n*Open Private Support Ticket* : Allows everyone to view your ticket, but only staff members can provide support.\n\n*`/ticket` Slash Command* : Run in any other channel to open a support ticket supplied with a specific topic.\n\n**Want to help others?**\nClick the *View Open Tickets* button below and look under the **Public :unlock:** tickets. Feel free to view any thread, but please only join a thread if you intend to provide support.", components:[ { type:1, @@ -29,6 +29,15 @@ export default new Command({ "emoji":{ "name":"🔒" } + }, + { + "custom_id":`view_open_tickets`, + "label":"View Open Tickets", + "type":2, + "style":1, + "emoji":{ + "name":"🗒️" + } } ] } diff --git a/src/index.ts b/src/index.ts index 64fcb72..44bbf5d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -195,6 +195,18 @@ app.use("/interactions", (req, res, next) => { .catch(reject) }) } + req.body.fetchActiveThreads = (guildId:string) => { + return new Promise((resolve, reject) => { + fetch(`${discord_api}/guilds/${guildId}/threads/active`, { + "method":"GET", + headers:{ + "authorization":`Bot ${config.bot_token}` + } + }) + .then(resolve) + .catch(reject) + }) + } if(interaction.type == InteractionType.MESSAGE_COMPONENT){ req.body.update = (msg:InteractionResponse) => { if(msg.ephemeral) diff --git a/typings/index.d.ts b/typings/index.d.ts index 846c510..a555ee8 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -91,6 +91,7 @@ export interface Interaction { sendMessage(channelId:string, msg:Message), joinThread(channelId:string):Promise, lockThread(channelId:string):Promise, + fetchActiveThreads(guildId:string):Promise, packageBuilder:{ builder:Builder, store:Builder,