mirror of
https://github.com/Team-Neptune/Korral-Interactions.git
synced 2024-11-23 04:39:39 +00:00
Add 'View Open Tickets' button to setup_ticket_button command (#14)
* add Interaction#fetchActiveThreads * Add button to view open tickets on setup_ticket_button command * Update message on setup_ticket_button command
This commit is contained in:
parent
0ec77c31a9
commit
c188940da4
24
src/buttons/view_open_tickets.ts
Normal file
24
src/buttons/view_open_tickets.ts
Normal file
@ -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
|
||||
});
|
||||
})
|
||||
}
|
||||
})
|
@ -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":"🗒️"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
12
src/index.ts
12
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)
|
||||
|
1
typings/index.d.ts
vendored
1
typings/index.d.ts
vendored
@ -91,6 +91,7 @@ export interface Interaction {
|
||||
sendMessage(channelId:string, msg:Message),
|
||||
joinThread(channelId:string):Promise<Response>,
|
||||
lockThread(channelId:string):Promise<Response>,
|
||||
fetchActiveThreads(guildId:string):Promise<Response>,
|
||||
packageBuilder:{
|
||||
builder:Builder,
|
||||
store:Builder,
|
||||
|
Loading…
Reference in New Issue
Block a user