Finished Message States & Overhauled Verifybars
This commit is contained in:
+188
-71
@@ -3,8 +3,11 @@
|
||||
///////////////////////////////////////
|
||||
import {opendiscord, api, utilities} from "../index.js"
|
||||
import * as discord from "discord.js"
|
||||
import * as actionUtils from "../actions/utilities.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
const lang = opendiscord.languages
|
||||
const interactiveMsgState = opendiscord.states.get("opendiscord:interactive-message")
|
||||
|
||||
export async function registerCommandResponders(){
|
||||
//CLAIM COMMAND RESPONDER
|
||||
@@ -13,46 +16,36 @@ export async function registerCommandResponders(){
|
||||
new api.ODWorker("opendiscord:claim",0,async (instance,params,origin,cancel) => {
|
||||
const {guild,channel,user,member} = instance
|
||||
|
||||
//check permissions
|
||||
const permsResult = await opendiscord.permissions.checkCommandPerms(generalConfig.data.system.permissions.claim,"support",user,member,channel,guild)
|
||||
if (!permsResult.hasPerms){
|
||||
if (permsResult.reason == "not-in-server") await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
else await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-no-permissions").build(origin,{guild,channel,user,permissions:["support"]}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//check is in guild/server
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//check if ticket exists
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//return when already claimed
|
||||
if (ticket.get("opendiscord:claimed").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.claim"),layout:"simple"}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//return when busy
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
const claimUser = instance.options.getUser("user",false) ?? user
|
||||
const reason = instance.options.getString("reason",false)
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"claim")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketUnclaimed = await actionUtils.replyTicketMustBeUnclaimed(instance,origin,ticket)
|
||||
if (!isTicketUnclaimed) return cancel()
|
||||
|
||||
//start claiming ticket
|
||||
await instance.defer(false)
|
||||
const reason = instance.options.getString("reason",false)
|
||||
const claimUser = instance.options.getUser("user",false) ?? user
|
||||
await opendiscord.actions.get("opendiscord:claim-ticket").run(origin,{guild,channel,user:claimUser,ticket,reason,sendMessage:false})
|
||||
await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:claim-message").build(origin,{guild,channel,user:claimUser,ticket,reason}))
|
||||
|
||||
//send message & set state
|
||||
const sentMsg = await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:claim-message").build(origin,{guild,channel,user:claimUser,ticket,reason}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"claim-message",
|
||||
messageOrigin:origin,
|
||||
messageAuthor:claimUser.id,
|
||||
messageReason:reason
|
||||
},sentMsg.ephemeral)
|
||||
}),
|
||||
new api.ODWorker("opendiscord:logs",-1,(instance,params,origin,cancel) => {
|
||||
opendiscord.log(instance.user.displayName+" used the 'claim' command!","info",[
|
||||
@@ -70,50 +63,174 @@ export async function registerButtonResponders(){
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("opendiscord:claim-ticket",/^od:claim-ticket/))
|
||||
opendiscord.responders.buttons.get("opendiscord:claim-ticket").workers.add(
|
||||
new api.ODWorker("opendiscord:claim-ticket",0,async (instance,params,origin,cancel) => {
|
||||
const originalOrigin = instance.interaction.customId.split("_")[1] as Exclude<api.ODActionManagerIdMappings["opendiscord:claim-ticket"]["origin"],"slash"|"text">
|
||||
const {guild,channel,user,message} = instance
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"claim")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
if (originalOrigin == "ticket-message") await opendiscord.verifybars.get("opendiscord:claim-ticket-ticket-message").activate(instance)
|
||||
else if (originalOrigin == "unclaim-message") await opendiscord.verifybars.get("opendiscord:claim-ticket-unclaim-message").activate(instance)
|
||||
else await instance.defer("update",false)
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/claim")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketUnclaimed = await actionUtils.replyTicketMustBeUnclaimed(instance,origin,ticket)
|
||||
if (!isTicketUnclaimed) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const verifybar = opendiscord.verifybars.get("opendiscord:claim-ticket")
|
||||
const originalUser = ((state.data.messageAuthor) ? await opendiscord.client.fetchUser(state.data.messageAuthor) : user) ?? user
|
||||
const originalReason = state.data.messageReason ?? null
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//send verifybar
|
||||
if (generalConfig.data.system.disableVerifyBars){
|
||||
//verifybar disabled, directly run response
|
||||
await verifybar.activate(instance,"accept")
|
||||
|
||||
}else if (originalMsgType == "ticket-message"){
|
||||
//ticket message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:claim-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:ticket-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "unclaim-message"){
|
||||
//unclaim message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:claim-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:unclaim-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user:originalUser,ticket,reason:originalReason}))
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export async function registerVerifyBars(){
|
||||
//CLAIM TICKET
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:claim-ticket"))
|
||||
opendiscord.verifybars.get("opendiscord:claim-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:claim-ticket",0,async (instance,params,origin,cancel) => {
|
||||
const {user,member,channel,guild,message} = instance
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"claim")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/claim")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketUnclaimed = await actionUtils.replyTicketMustBeUnclaimed(instance,origin,ticket)
|
||||
if (!isTicketUnclaimed) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const originalUser = ((state.data.messageAuthor) ? await opendiscord.client.fetchUser(state.data.messageAuthor) : user) ?? user
|
||||
const originalReason = state.data.messageReason ?? null
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//start claiming ticket
|
||||
if (params.selectedButtonId == "cancel"){
|
||||
//CANCEL
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "unclaim-message"){
|
||||
//unclaim message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:unclaim-message").build("verifybar",{guild,channel,user:originalUser,ticket,reason:originalReason}))
|
||||
}
|
||||
}else if (params.selectedButtonId == "accept"){
|
||||
//CLAIM TICKET
|
||||
await instance.defer("update",false)
|
||||
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await opendiscord.actions.get("opendiscord:claim-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "unclaim-message"){
|
||||
//converted to claim message
|
||||
await opendiscord.actions.get("opendiscord:claim-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
const sentMsg = await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:claim-message").build("verifybar",{guild,channel,user,ticket,reason:null}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"claim-message",
|
||||
messageOrigin:origin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:null
|
||||
},sentMsg.ephemeral)
|
||||
}
|
||||
}else if (params.selectedButtonId == "accept-with-reason"){
|
||||
//CLAIM WITH REASON (MODAL)
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:claim-ticket-reason").build("other",{guild,channel,user,ticket,message}))
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
export async function registerModalResponders(){
|
||||
//CLAIM WITH REASON MODAL RESPONDER
|
||||
opendiscord.responders.modals.add(new api.ODModalResponder("opendiscord:claim-ticket-reason",/^od:claim-ticket-reason_/))
|
||||
opendiscord.responders.modals.add(new api.ODModalResponder("opendiscord:claim-ticket-reason",/^od:claim-ticket-reason\|([^|]+)\|([^|]+)/))
|
||||
opendiscord.responders.modals.get("opendiscord:claim-ticket-reason").workers.add([
|
||||
new api.ODWorker("opendiscord:claim-ticket-reason",0,async (instance,params,origin,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!channel) return
|
||||
if (!guild){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build(origin,{channel,user:instance.user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(instance.interaction.customId.split("_")[1])
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return
|
||||
}
|
||||
|
||||
const originalOrigin = instance.interaction.customId.split("_")[2] as Exclude<api.ODActionManagerIdMappings["opendiscord:claim-ticket"]["origin"],"slash"|"text">
|
||||
const reason = instance.values.getTextField("reason",true)
|
||||
|
||||
//claim with reason
|
||||
if (originalOrigin == "ticket-message"){
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:claim-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
}else if (originalOrigin == "unclaim-message"){
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:claim-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:claim-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
}else{
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:claim-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:true})
|
||||
}
|
||||
const {guild,user} = instance
|
||||
|
||||
const match = /^od:claim-ticket-reason\|([^|]+)\|([^|]+)/.exec(instance.interaction.customId)
|
||||
if (!match) return cancel()
|
||||
const channel = await opendiscord.client.fetchTextChannel(match[1])
|
||||
const message = await opendiscord.client.fetchChannelMessage(match[1],match[2])
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"claim")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || !channel || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/claim")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketUnclaimed = await actionUtils.replyTicketMustBeUnclaimed(instance,origin,ticket)
|
||||
if (!isTicketUnclaimed) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const reason = instance.values.getTextField("reason",true)
|
||||
const originalMsgOrigin = state.data.messageOrigin
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//start claiming ticket
|
||||
await instance.defer("update",false)
|
||||
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await opendiscord.actions.get("opendiscord:claim-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
|
||||
}else if (originalMsgType == "unclaim-message"){
|
||||
//converted to claim message
|
||||
await opendiscord.actions.get("opendiscord:claim-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
const sentMsg = await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:claim-message").build(originalMsgType,{guild,channel,user,ticket,reason}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"claim-message",
|
||||
messageOrigin:originalMsgOrigin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:reason
|
||||
},sentMsg.ephemeral)
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
+45
-19
@@ -3,8 +3,10 @@
|
||||
///////////////////////////////////////
|
||||
import {opendiscord, api, utilities} from "../index.js"
|
||||
import * as discord from "discord.js"
|
||||
import * as actionUtils from "../actions/utilities.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
const clearMsgState = opendiscord.states.get("opendiscord:clear-message")
|
||||
|
||||
export async function registerCommandResponders(){
|
||||
//CLEAR COMMAND RESPONDER
|
||||
@@ -29,7 +31,7 @@ export async function registerCommandResponders(){
|
||||
|
||||
const tempFilter = instance.options.getString("filter",false)
|
||||
const filter = (tempFilter) ? tempFilter.toLowerCase() as api.ODTicketClearFilter : "all"
|
||||
const list: string[] = []
|
||||
const channelNameList: string[] = []
|
||||
const ticketList = opendiscord.tickets.getAll().filter((ticket) => {
|
||||
if (filter == "all") return true
|
||||
else if (filter == "open" && ticket.get("opendiscord:open").value) return true
|
||||
@@ -43,12 +45,17 @@ export async function registerCommandResponders(){
|
||||
})
|
||||
for (const ticket of ticketList){
|
||||
const ticketChannel = await opendiscord.tickets.getTicketChannel(ticket)
|
||||
if (ticketChannel) list.push("#"+ticketChannel.name)
|
||||
if (ticketChannel) channelNameList.push("#"+ticketChannel.name)
|
||||
}
|
||||
|
||||
//reply with clear verify
|
||||
await instance.defer(true)
|
||||
await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:clear-verify-message").build(origin,{guild,channel,user,filter,list}))
|
||||
const sentMsg = await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:clear-verify-message").build(origin,{guild,channel,user,filter,list:channelNameList,inProgress:false}))
|
||||
if (sentMsg.success) await clearMsgState.setMsgState({channel,message:sentMsg.message,user},{
|
||||
messageOrigin:origin,
|
||||
clearFilter:filter,
|
||||
clearChannelNameList:channelNameList
|
||||
},sentMsg.ephemeral)
|
||||
}),
|
||||
new api.ODWorker("opendiscord:logs",-1,(instance,params,origin,cancel) => {
|
||||
opendiscord.log(instance.user.displayName+" used the 'clear' command!","info",[
|
||||
@@ -63,26 +70,45 @@ export async function registerCommandResponders(){
|
||||
|
||||
export async function registerButtonResponders(){
|
||||
//CLEAR CONTINUE BUTTON RESPONDER
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("opendiscord:clear-continue",/^od:clear-continue_/))
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("opendiscord:clear-continue","od:clear-continue"))
|
||||
opendiscord.responders.buttons.get("opendiscord:clear-continue").workers.add(
|
||||
new api.ODWorker("opendiscord:clear-continue",0,async (instance,params,origin,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild || channel.isDMBased()) return
|
||||
const originalOrigin = instance.interaction.customId.split("_")[1] as api.ODActionManagerIdMappings["opendiscord:clear-tickets"]["origin"]
|
||||
const filter = instance.interaction.customId.split("_")[2] as api.ODTicketClearFilter
|
||||
const {guild,channel,user,message} = instance
|
||||
|
||||
//check message state
|
||||
const state = await clearMsgState.getMsgState({channel,message,user})
|
||||
if (!state){
|
||||
//TODO TRANSLATION!!!
|
||||
await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build(origin,{guild,channel,user,error:"This interaction is no longer valid or has expired. Use the command `{0}` instead. It is normal to receive this error after a major Open Ticket update.".replace("{0}","/clear"),layout:"simple",customTitle:"Message State Expired"}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"clear")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || !channel || channel.isDMBased()) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const originalUser = ((state.userId) ? await opendiscord.client.fetchUser(state.userId) : user) ?? user
|
||||
const originalOrigin = state.data.messageOrigin
|
||||
const originalClearFilter = state.data.clearFilter
|
||||
const originalClearChannelNameList = state.data.clearChannelNameList
|
||||
|
||||
//start ticket clear
|
||||
await instance.defer("update",true)
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:clear-verify-message").build(originalOrigin,{guild,channel,user:originalUser,filter:originalClearFilter,list:originalClearChannelNameList,inProgress:true}))
|
||||
|
||||
const list: string[] = []
|
||||
const ticketList = opendiscord.tickets.getAll().filter((ticket) => {
|
||||
if (filter == "all") return true
|
||||
else if (filter == "open" && ticket.get("opendiscord:open").value) return true
|
||||
else if (filter == "closed" && ticket.get("opendiscord:closed").value) return true
|
||||
else if (filter == "claimed" && ticket.get("opendiscord:claimed").value) return true
|
||||
else if (filter == "pinned" && ticket.get("opendiscord:pinned").value) return true
|
||||
else if (filter == "unclaimed" && !ticket.get("opendiscord:claimed").value) return true
|
||||
else if (filter == "unpinned" && !ticket.get("opendiscord:pinned").value) return true
|
||||
else if (filter == "autoclosed" && ticket.get("opendiscord:closed").value) return true
|
||||
if (originalClearFilter == "all") return true
|
||||
else if (originalClearFilter == "open" && ticket.get("opendiscord:open").value) return true
|
||||
else if (originalClearFilter == "closed" && ticket.get("opendiscord:closed").value) return true
|
||||
else if (originalClearFilter == "claimed" && ticket.get("opendiscord:claimed").value) return true
|
||||
else if (originalClearFilter == "pinned" && ticket.get("opendiscord:pinned").value) return true
|
||||
else if (originalClearFilter == "unclaimed" && !ticket.get("opendiscord:claimed").value) return true
|
||||
else if (originalClearFilter == "unpinned" && !ticket.get("opendiscord:pinned").value) return true
|
||||
else if (originalClearFilter == "autoclosed" && ticket.get("opendiscord:closed").value) return true
|
||||
else return false
|
||||
})
|
||||
for (const ticket of ticketList){
|
||||
@@ -90,8 +116,8 @@ export async function registerButtonResponders(){
|
||||
if (ticketChannel) list.push("#"+ticketChannel.name)
|
||||
}
|
||||
|
||||
await opendiscord.actions.get("opendiscord:clear-tickets").run(originalOrigin,{guild,channel,user,filter,list:ticketList})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:clear-message").build(originalOrigin,{guild,channel,user,filter,list}))
|
||||
await opendiscord.actions.get("opendiscord:clear-tickets").run(originalOrigin,{guild,channel,user,filter:originalClearFilter,list:ticketList})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:clear-message").build(originalOrigin,{guild,channel,user,filter:originalClearFilter,list}))
|
||||
})
|
||||
)
|
||||
}
|
||||
+194
-81
@@ -3,9 +3,11 @@
|
||||
///////////////////////////////////////
|
||||
import {opendiscord, api, utilities} from "../index.js"
|
||||
import * as discord from "discord.js"
|
||||
import * as actionUtils from "../actions/utilities.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
const lang = opendiscord.languages
|
||||
const interactiveMsgState = opendiscord.states.get("opendiscord:interactive-message")
|
||||
|
||||
export async function registerCommandResponders(){
|
||||
//CLOSE COMMAND RESPONDER
|
||||
@@ -14,57 +16,38 @@ export async function registerCommandResponders(){
|
||||
new api.ODWorker("opendiscord:close",0,async (instance,params,origin,cancel) => {
|
||||
const {user,member,channel,guild} = instance
|
||||
|
||||
//check permissions
|
||||
const permsResult = await opendiscord.permissions.checkCommandPerms(generalConfig.data.system.permissions.close,"support",user,member,channel,guild)
|
||||
if (!permsResult.hasPerms){
|
||||
if (permsResult.reason == "not-in-server") await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
else await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-no-permissions").build(origin,{guild,channel,user,permissions:["support"]}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//check is in guild/server
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//check if ticket exists
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//return when already closed
|
||||
if (ticket.get("opendiscord:closed").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.close"),layout:"simple"}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//return when busy
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//return when not allowed because of missing messages
|
||||
if (!permsResult.isAdmin && (!generalConfig.data.system.allowCloseBeforeMessage || !generalConfig.data.system.allowCloseBeforeAdminMessage)){
|
||||
const analysis = await opendiscord.transcripts.collector.ticketUserMessagesAnalysis(ticket,guild,channel)
|
||||
if (analysis && !generalConfig.data.system.allowCloseBeforeMessage && analysis.totalMessages < 1){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{guild,channel,user,layout:"simple",error:lang.getTranslation("errors.descriptions.closeBeforeMessage"),customTitle:lang.getTranslation("errors.titles.noPermissions")}))
|
||||
return cancel()
|
||||
}
|
||||
if (analysis && !generalConfig.data.system.allowCloseBeforeAdminMessage && analysis.adminMessages < 1){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{guild,channel,user,layout:"simple",error:lang.getTranslation("errors.descriptions.closeBeforeAdminMessage"),customTitle:lang.getTranslation("errors.titles.noPermissions")}))
|
||||
return cancel()
|
||||
}
|
||||
}
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"close")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketOpen = await actionUtils.replyTicketMustBeOpen(instance,origin,ticket)
|
||||
if (!isTicketOpen) return cancel()
|
||||
|
||||
const messagesHaveBeenSent = await actionUtils.replyMessageMustBeSentBeforeClose(instance,origin,ticket,"close")
|
||||
if (!messagesHaveBeenSent) return cancel()
|
||||
|
||||
//start closing ticket
|
||||
await instance.defer(false)
|
||||
const reason = instance.options.getString("reason",false)
|
||||
await opendiscord.actions.get("opendiscord:close-ticket").run(origin,{guild,channel,user,ticket,reason,sendMessage:false})
|
||||
await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:close-message").build(origin,{guild,channel,user,ticket,reason}))
|
||||
|
||||
//send message & set state
|
||||
const sentMsg = await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:close-message").build(origin,{guild,channel,user,ticket,reason}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"close-message",
|
||||
messageOrigin:origin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:reason
|
||||
},sentMsg.ephemeral)
|
||||
}),
|
||||
new api.ODWorker("opendiscord:logs",-1,(instance,params,origin,cancel) => {
|
||||
opendiscord.log(instance.user.displayName+" used the 'close' command!","info",[
|
||||
@@ -77,55 +60,185 @@ export async function registerCommandResponders(){
|
||||
])
|
||||
}
|
||||
|
||||
export const registerButtonResponders = async () => {
|
||||
export async function registerButtonResponders(){
|
||||
//CLOSE TICKET BUTTON RESPONDER
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("opendiscord:close-ticket",/^od:close-ticket_/))
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("opendiscord:close-ticket",/^od:close-ticket/))
|
||||
opendiscord.responders.buttons.get("opendiscord:close-ticket").workers.add(
|
||||
new api.ODWorker("opendiscord:close-ticket",0,async (instance,params,origin,cancel) => {
|
||||
const originalOrigin = instance.interaction.customId.split("_")[1] as Exclude<api.ODActionManagerIdMappings["opendiscord:close-ticket"]["origin"],"slash"|"text"|"autoclose">
|
||||
const {guild,channel,message,user,member} = instance
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"close")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
if (originalOrigin == "ticket-message") await opendiscord.verifybars.get("opendiscord:close-ticket-ticket-message").activate(instance)
|
||||
else if (originalOrigin == "reopen-message") await opendiscord.verifybars.get("opendiscord:close-ticket-reopen-message").activate(instance)
|
||||
else await instance.defer("update",false)
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/close")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketOpen = await actionUtils.replyTicketMustBeOpen(instance,origin,ticket)
|
||||
if (!isTicketOpen) return cancel()
|
||||
|
||||
const messagesHaveBeenSent = await actionUtils.replyMessageMustBeSentBeforeClose(instance,origin,ticket,"close")
|
||||
if (!messagesHaveBeenSent) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const verifybar = opendiscord.verifybars.get("opendiscord:close-ticket")
|
||||
const originalUser = ((state.data.messageAuthor) ? await opendiscord.client.fetchUser(state.data.messageAuthor) : user) ?? user
|
||||
const originalReason = state.data.messageReason ?? null
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//send verifybar
|
||||
if (generalConfig.data.system.disableVerifyBars){
|
||||
//verifybar disabled, directly run response
|
||||
await verifybar.activate(instance,"accept")
|
||||
|
||||
}else if (originalMsgType == "ticket-message"){
|
||||
//ticket message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:close-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:ticket-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "reopen-message"){
|
||||
//reopen message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:close-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:reopen-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user:originalUser,ticket,reason:originalReason}))
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export async function registerVerifyBars(){
|
||||
//CLOSE TICKET VERIFYBAR
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:close-ticket"))
|
||||
opendiscord.verifybars.get("opendiscord:close-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:close-ticket",0,async (instance,params,origin,cancel) => {
|
||||
const {user,member,channel,guild,message} = instance
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"close")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/close")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketOpen = await actionUtils.replyTicketMustBeOpen(instance,origin,ticket)
|
||||
if (!isTicketOpen) return cancel()
|
||||
|
||||
const messagesHaveBeenSent = await actionUtils.replyMessageMustBeSentBeforeClose(instance,origin,ticket,"close")
|
||||
if (!messagesHaveBeenSent) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const originalUser = ((state.data.messageAuthor) ? await opendiscord.client.fetchUser(state.data.messageAuthor) : user) ?? user
|
||||
const originalReason = state.data.messageReason ?? null
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//start closing ticket
|
||||
if (params.selectedButtonId == "cancel"){
|
||||
//CANCEL
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "reopen-message"){
|
||||
//reopen message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:reopen-message").build("verifybar",{guild,channel,user:originalUser,ticket,reason:originalReason}))
|
||||
}
|
||||
}else if (params.selectedButtonId == "accept"){
|
||||
//CLOSE TICKET
|
||||
await instance.defer("update",false)
|
||||
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await opendiscord.actions.get("opendiscord:close-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "reopen-message"){
|
||||
//converted to close message
|
||||
await opendiscord.actions.get("opendiscord:close-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
const sentMsg = await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:close-message").build("verifybar",{guild,channel,user,ticket,reason:null}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"close-message",
|
||||
messageOrigin:origin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:null
|
||||
},sentMsg.ephemeral)
|
||||
}
|
||||
}else if (params.selectedButtonId == "accept-with-reason"){
|
||||
//CLOSE WITH REASON (MODAL)
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:close-ticket-reason").build("other",{guild,channel,user,ticket,message}))
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
export async function registerModalResponders(){
|
||||
//CLOSE WITH REASON MODAL RESPONDER
|
||||
opendiscord.responders.modals.add(new api.ODModalResponder("opendiscord:close-ticket-reason",/^od:close-ticket-reason_/))
|
||||
opendiscord.responders.modals.add(new api.ODModalResponder("opendiscord:close-ticket-reason",/^od:close-ticket-reason\|([^|]+)\|([^|]+)/))
|
||||
opendiscord.responders.modals.get("opendiscord:close-ticket-reason").workers.add([
|
||||
new api.ODWorker("opendiscord:close-ticket-reason",0,async (instance,params,origin,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!channel) return
|
||||
if (!guild){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build(origin,{channel,user:instance.user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(instance.interaction.customId.split("_")[1])
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return
|
||||
}
|
||||
const {guild,user} = instance
|
||||
|
||||
const originalOrigin = instance.interaction.customId.split("_")[2] as Exclude<api.ODActionManagerIdMappings["opendiscord:close-ticket"]["origin"],"slash"|"text"|"autoclose">
|
||||
const reason = instance.values.getTextField("reason",true)
|
||||
|
||||
//close with reason
|
||||
if (originalOrigin == "ticket-message"){
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:close-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
}else if (originalOrigin == "reopen-message"){
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:close-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:close-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
}else{
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:close-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:true})
|
||||
}
|
||||
const match = /^od:close-ticket-reason\|([^|]+)\|([^|]+)/.exec(instance.interaction.customId)
|
||||
if (!match) return cancel()
|
||||
const channel = await opendiscord.client.fetchTextChannel(match[1])
|
||||
const message = await opendiscord.client.fetchChannelMessage(match[1],match[2])
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"close")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || !channel || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/close")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketOpen = await actionUtils.replyTicketMustBeOpen(instance,origin,ticket)
|
||||
if (!isTicketOpen) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const reason = instance.values.getTextField("reason",true)
|
||||
const originalMsgOrigin = state.data.messageOrigin
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//start closing ticket
|
||||
await instance.defer("update",false)
|
||||
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await opendiscord.actions.get("opendiscord:close-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
|
||||
}else if (originalMsgType == "reopen-message"){
|
||||
//converted to close message
|
||||
await opendiscord.actions.get("opendiscord:close-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
const sentMsg = await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:close-message").build(originalMsgType,{guild,channel,user,ticket,reason}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"close-message",
|
||||
messageOrigin:originalMsgOrigin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:reason
|
||||
},sentMsg.ephemeral)
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
+209
-87
@@ -3,9 +3,11 @@
|
||||
///////////////////////////////////////
|
||||
import {opendiscord, api, utilities} from "../index.js"
|
||||
import * as discord from "discord.js"
|
||||
import * as actionUtils from "../actions/utilities.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
const lang = opendiscord.languages
|
||||
const interactiveMsgState = opendiscord.states.get("opendiscord:interactive-message")
|
||||
|
||||
export async function registerCommandResponders(){
|
||||
//DELETE COMMAND RESPONDER
|
||||
@@ -14,50 +16,27 @@ export async function registerCommandResponders(){
|
||||
new api.ODWorker("opendiscord:delete",0,async (instance,params,origin,cancel) => {
|
||||
const {user,member,channel,guild} = instance
|
||||
|
||||
//check permissions
|
||||
const permsResult = await opendiscord.permissions.checkCommandPerms(generalConfig.data.system.permissions.delete,"support",user,member,channel,guild)
|
||||
if (!permsResult.hasPerms){
|
||||
if (permsResult.reason == "not-in-server") await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
else await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-no-permissions").build(origin,{guild,channel,user,permissions:["support"]}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//check is in guild/server
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//check if ticket exists
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//return when busy
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"delete")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
//return when not allowed because of missing messages
|
||||
if (!permsResult.isAdmin && (!generalConfig.data.system.allowCloseBeforeMessage || !generalConfig.data.system.allowCloseBeforeAdminMessage)){
|
||||
const analysis = await opendiscord.transcripts.collector.ticketUserMessagesAnalysis(ticket,guild,channel)
|
||||
if (analysis && !generalConfig.data.system.allowCloseBeforeMessage && analysis.totalMessages < 1){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{guild,channel,user,layout:"simple",error:lang.getTranslation("errors.descriptions.closeBeforeMessage"),customTitle:lang.getTranslation("errors.titles.noPermissions")}))
|
||||
return cancel()
|
||||
}
|
||||
if (analysis && !generalConfig.data.system.allowCloseBeforeAdminMessage && analysis.adminMessages < 1){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{guild,channel,user,layout:"simple",error:lang.getTranslation("errors.descriptions.closeBeforeAdminMessage"),customTitle:lang.getTranslation("errors.titles.noPermissions")}))
|
||||
return cancel()
|
||||
}
|
||||
}
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketOpen = await actionUtils.replyTicketMustBeOpen(instance,origin,ticket)
|
||||
if (!isTicketOpen) return cancel()
|
||||
|
||||
const reason = instance.options.getString("reason",false)
|
||||
const withoutTranscript = instance.options.getBoolean("notranscript",false) ?? false
|
||||
const messagesHaveBeenSent = await actionUtils.replyMessageMustBeSentBeforeClose(instance,origin,ticket,"delete")
|
||||
if (!messagesHaveBeenSent) return cancel()
|
||||
|
||||
//don't allow deleteWithoutTranscript to non-global-admins when enabled
|
||||
const withoutTranscript = instance.options.getBoolean("notranscript",false) ?? false
|
||||
if (withoutTranscript && generalConfig.data.system.adminOnlyDeleteWithoutTranscript){
|
||||
if (!opendiscord.permissions.hasPermissions("support",await opendiscord.permissions.getPermissions(instance.user,instance.channel,instance.guild,{allowChannelRoleScope:false,allowChannelUserScope:false,allowGlobalRoleScope:true,allowGlobalUserScope:true}))){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
@@ -67,6 +46,7 @@ export async function registerCommandResponders(){
|
||||
|
||||
//start deleting ticket
|
||||
await instance.defer(false)
|
||||
const reason = instance.options.getString("reason",false)
|
||||
await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:delete-message").build(origin,{guild,channel,user,ticket,reason}))
|
||||
await opendiscord.actions.get("opendiscord:delete-ticket").run(origin,{guild,channel,user,ticket,reason,sendMessage:false,withoutTranscript})
|
||||
}),
|
||||
@@ -86,65 +66,207 @@ export async function registerButtonResponders(){
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("opendiscord:delete-ticket",/^od:delete-ticket/))
|
||||
opendiscord.responders.buttons.get("opendiscord:delete-ticket").workers.add(
|
||||
new api.ODWorker("opendiscord:delete-ticket",0,async (instance,params,origin,cancel) => {
|
||||
const originalOrigin = instance.interaction.customId.split("_")[1] as Exclude<api.ODActionManagerIdMappings["opendiscord:delete-ticket"]["origin"],"slash"|"text"|"autodelete"|"clear">
|
||||
const {guild,channel,message,user,member} = instance
|
||||
|
||||
if (originalOrigin == "ticket-message") await opendiscord.verifybars.get("opendiscord:delete-ticket-ticket-message").activate(instance)
|
||||
else if (originalOrigin == "close-message") await opendiscord.verifybars.get("opendiscord:delete-ticket-close-message").activate(instance)
|
||||
else if (originalOrigin == "reopen-message") await opendiscord.verifybars.get("opendiscord:delete-ticket-reopen-message").activate(instance)
|
||||
else if (originalOrigin == "autoclose-message") await opendiscord.verifybars.get("opendiscord:delete-ticket-autoclose-message").activate(instance)
|
||||
else await instance.defer("update",false)
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"delete")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/delete")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const messagesHaveBeenSent = await actionUtils.replyMessageMustBeSentBeforeClose(instance,origin,ticket,"delete")
|
||||
if (!messagesHaveBeenSent) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const verifybar = opendiscord.verifybars.get("opendiscord:delete-ticket")
|
||||
const originalUser = ((state.data.messageAuthor) ? await opendiscord.client.fetchUser(state.data.messageAuthor) : user) ?? user
|
||||
const originalReason = state.data.messageReason ?? null
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//send verifybar
|
||||
if (generalConfig.data.system.disableVerifyBars){
|
||||
//verifybar disabled, directly run response
|
||||
await verifybar.activate(instance,"accept")
|
||||
|
||||
}else if (originalMsgType == "ticket-message"){
|
||||
//ticket message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:delete-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:ticket-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "close-message"){
|
||||
//close message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:delete-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:close-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user:originalUser,ticket,reason:originalReason}))
|
||||
}else if (originalMsgType == "reopen-message"){
|
||||
//reopen message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:delete-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:reopen-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user:originalUser,ticket,reason:originalReason}))
|
||||
}else if (originalMsgType == "autoclose-message"){
|
||||
//autoclose message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:delete-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:autoclose-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user:originalUser,ticket}))
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export async function registerVerifyBars(){
|
||||
//DELETE TICKET
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:delete-ticket"))
|
||||
opendiscord.verifybars.get("opendiscord:delete-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:delete-ticket",0,async (instance,params,origin,cancel) => {
|
||||
const {user,member,channel,guild,message} = instance
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"delete")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/delete")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const messagesHaveBeenSent = await actionUtils.replyMessageMustBeSentBeforeClose(instance,origin,ticket,"delete")
|
||||
if (!messagesHaveBeenSent) return cancel()
|
||||
|
||||
//don't allow deleteWithoutTranscript to non-global-admins when enabled
|
||||
const withoutTranscript = (params.selectedButtonId == "accept-without-transcript")
|
||||
if (withoutTranscript && generalConfig.data.system.adminOnlyDeleteWithoutTranscript){
|
||||
if (!opendiscord.permissions.hasPermissions("support",await opendiscord.permissions.getPermissions(instance.user,instance.channel,instance.guild,{allowChannelRoleScope:false,allowChannelUserScope:false,allowGlobalRoleScope:true,allowGlobalUserScope:true}))){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
return cancel()
|
||||
}
|
||||
}
|
||||
|
||||
//fetch state details
|
||||
const originalUser = ((state.data.messageAuthor) ? await opendiscord.client.fetchUser(state.data.messageAuthor) : user) ?? user
|
||||
const originalReason = state.data.messageReason ?? null
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//start deleting ticket
|
||||
if (params.selectedButtonId == "cancel"){
|
||||
//CANCEL
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "close-message"){
|
||||
//close message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:close-message").build("verifybar",{guild,channel,user:originalUser,ticket,reason:originalReason}))
|
||||
}else if (originalMsgType == "reopen-message"){
|
||||
//reopen message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:reopen-message").build("verifybar",{guild,channel,user:originalUser,ticket,reason:originalReason}))
|
||||
}else if (originalMsgType == "autoclose-message"){
|
||||
//autoclose message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:autoclose-message").build("verifybar",{guild,channel,user:originalUser,ticket}))
|
||||
}
|
||||
}else if (params.selectedButtonId == "accept" || params.selectedButtonId == "accept-without-transcript"){
|
||||
//DELETE TICKET
|
||||
await instance.defer("update",false)
|
||||
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:true,withoutTranscript})
|
||||
ticket.get("opendiscord:for-deletion").value = true //disable ticket message buttons
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
|
||||
}else if (originalMsgType == "close-message"){
|
||||
//converted to delete message
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false,withoutTranscript})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:delete-message").build(originalMsgType,{guild,channel,user,ticket,reason:null}))
|
||||
|
||||
}else if (originalMsgType == "reopen-message"){
|
||||
//converted to delete message
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false,withoutTranscript})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:delete-message").build(originalMsgType,{guild,channel,user,ticket,reason:null}))
|
||||
|
||||
}else if (originalMsgType == "autoclose-message"){
|
||||
//converted to delete message
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false,withoutTranscript})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:delete-message").build(originalMsgType,{guild,channel,user,ticket,reason:null}))
|
||||
|
||||
}
|
||||
}else if (params.selectedButtonId == "accept-with-reason"){
|
||||
//DELETE WITH REASON (MODAL)
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:delete-ticket-reason").build("other",{guild,channel,user,ticket,message}))
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
export async function registerModalResponders(){
|
||||
//REOPEN WITH REASON MODAL RESPONDER
|
||||
opendiscord.responders.modals.add(new api.ODModalResponder("opendiscord:delete-ticket-reason",/^od:delete-ticket-reason_/))
|
||||
//DELETE WITH REASON MODAL RESPONDER
|
||||
opendiscord.responders.modals.add(new api.ODModalResponder("opendiscord:delete-ticket-reason",/^od:delete-ticket-reason\|([^|]+)\|([^|]+)/))
|
||||
opendiscord.responders.modals.get("opendiscord:delete-ticket-reason").workers.add([
|
||||
new api.ODWorker("opendiscord:delete-ticket-reason",0,async (instance,params,origin,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!channel) return
|
||||
if (!guild){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build(origin,{channel,user:instance.user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(instance.interaction.customId.split("_")[1])
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return
|
||||
}
|
||||
const {guild,user} = instance
|
||||
|
||||
const originalOrigin = instance.interaction.customId.split("_")[2] as Exclude<api.ODActionManagerIdMappings["opendiscord:delete-ticket"]["origin"],"slash"|"text"|"autodelete"|"clear">
|
||||
const match = /^od:delete-ticket-reason\|([^|]+)\|([^|]+)/.exec(instance.interaction.customId)
|
||||
if (!match) return cancel()
|
||||
const channel = await opendiscord.client.fetchTextChannel(match[1])
|
||||
const message = await opendiscord.client.fetchChannelMessage(match[1],match[2])
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"delete")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || !channel || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/delete")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const reason = instance.values.getTextField("reason",true)
|
||||
const originalMsgOrigin = state.data.messageOrigin
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//delete with reason
|
||||
if (originalOrigin == "ticket-message"){
|
||||
await instance.defer("update",false)
|
||||
//don't await DELETE action => else it will update the message after the channel has been deleted
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:true,withoutTranscript:false})
|
||||
//update ticket (for ticket message) => no-await doesn't wait for the action to set this variable
|
||||
ticket.get("opendiscord:for-deletion").value = true
|
||||
//start deleting ticket
|
||||
//don't await DELETE action => else it will update the message after the channel has been deleted
|
||||
await instance.defer("update",false)
|
||||
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run(originalMsgType,{guild,channel,user,ticket,reason,sendMessage:true,withoutTranscript:false})
|
||||
ticket.get("opendiscord:for-deletion").value = true //disable ticket message buttons
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
}else if (originalOrigin == "close-message"){
|
||||
await instance.defer("update",false)
|
||||
//don't await DELETE action => else it will update the message after the channel has been deleted
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:false,withoutTranscript:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:delete-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
}else if (originalOrigin == "reopen-message"){
|
||||
await instance.defer("update",false)
|
||||
//don't await DELETE action => else it will update the message after the channel has been deleted
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:false,withoutTranscript:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:delete-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
}else if (originalOrigin == "autoclose-message"){
|
||||
await instance.defer("update",false)
|
||||
//don't await DELETE action => else it will update the message after the channel has been deleted
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:false,withoutTranscript:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:delete-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
}else{
|
||||
await instance.defer("update",false)
|
||||
//don't await DELETE action => else it will update the message after the channel has been deleted
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:true,withoutTranscript:false})
|
||||
|
||||
}else if (originalMsgType == "close-message"){
|
||||
//converted to delete message
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run(originalMsgType,{guild,channel,user,ticket,reason,sendMessage:false,withoutTranscript:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:delete-message").build(originalMsgType,{guild,channel,user,ticket,reason}))
|
||||
|
||||
}else if (originalMsgType == "reopen-message"){
|
||||
//converted to delete message
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run(originalMsgType,{guild,channel,user,ticket,reason,sendMessage:false,withoutTranscript:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:delete-message").build(originalMsgType,{guild,channel,user,ticket,reason}))
|
||||
|
||||
}else if (originalMsgType == "autoclose-message"){
|
||||
//converted to delete message
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run(originalMsgType,{guild,channel,user,ticket,reason,sendMessage:false,withoutTranscript:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:delete-message").build(originalMsgType,{guild,channel,user,ticket,reason}))
|
||||
|
||||
}
|
||||
})
|
||||
])
|
||||
|
||||
+187
-102
@@ -3,88 +3,48 @@
|
||||
///////////////////////////////////////
|
||||
import {opendiscord, api, utilities} from "../index.js"
|
||||
import * as discord from "discord.js"
|
||||
import * as actionUtils from "../actions/utilities.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
const lang = opendiscord.languages
|
||||
const interactiveMsgState = opendiscord.states.get("opendiscord:interactive-message")
|
||||
|
||||
export async function registerCommandResponders(){
|
||||
//PIN COMMAND RESPONDER
|
||||
opendiscord.responders.commands.add(new api.ODCommandResponder("opendiscord:pin",generalConfig.data.prefix,"pin"))
|
||||
opendiscord.responders.commands.get("opendiscord:pin").workers.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,origin,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.pin
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:[]}))
|
||||
return cancel()
|
||||
}else if (permissionMode == "everyone") return
|
||||
else if (permissionMode == "admin"){
|
||||
if (!opendiscord.permissions.hasPermissions("support",await opendiscord.permissions.getPermissions(instance.user,instance.channel,instance.guild))){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-no-permissions").build(origin,{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
return cancel()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build(origin,{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
return cancel()
|
||||
}
|
||||
const role = await opendiscord.client.fetchGuildRole(instance.guild,permissionMode)
|
||||
if (!role){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build(origin,{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
return cancel()
|
||||
}
|
||||
if (!role.members.has(instance.member.id)){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-no-permissions").build(origin,{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:[]}))
|
||||
return cancel()
|
||||
}else return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("opendiscord:pin",0,async (instance,params,origin,cancel) => {
|
||||
const {guild,channel,user,member} = instance
|
||||
|
||||
//check permissions
|
||||
const permsResult = await opendiscord.permissions.checkCommandPerms(generalConfig.data.system.permissions.pin,"support",user,member,channel,guild)
|
||||
if (!permsResult.hasPerms){
|
||||
if (permsResult.reason == "not-in-server") await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
else await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-no-permissions").build(origin,{guild,channel,user,permissions:["support"]}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//check is in guild/server
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//check if ticket exists
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//return when already pinned
|
||||
if (ticket.get("opendiscord:pinned").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.pin"),layout:"simple"}))
|
||||
return cancel()
|
||||
}
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"pin")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketUnpinned = await actionUtils.replyTicketMustBeUnpinned(instance,origin,ticket)
|
||||
if (!isTicketUnpinned) return cancel()
|
||||
|
||||
//return when busy
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
const reason = instance.options.getString("reason",false)
|
||||
|
||||
//start pinning ticket
|
||||
await instance.defer(false)
|
||||
const reason = instance.options.getString("reason",false)
|
||||
await opendiscord.actions.get("opendiscord:pin-ticket").run(origin,{guild,channel,user,ticket,reason,sendMessage:false})
|
||||
await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:pin-message").build(origin,{guild,channel,user,ticket,reason}))
|
||||
|
||||
//send message & set state
|
||||
const sentMsg = await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:pin-message").build(origin,{guild,channel,user,ticket,reason}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"pin-message",
|
||||
messageOrigin:origin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:reason
|
||||
},sentMsg.ephemeral)
|
||||
}),
|
||||
new api.ODWorker("opendiscord:logs",-1,(instance,params,origin,cancel) => {
|
||||
opendiscord.log(instance.user.displayName+" used the 'pin' command!","info",[
|
||||
@@ -102,50 +62,175 @@ export async function registerButtonResponders(){
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("opendiscord:pin-ticket",/^od:pin-ticket/))
|
||||
opendiscord.responders.buttons.get("opendiscord:pin-ticket").workers.add(
|
||||
new api.ODWorker("opendiscord:pin-ticket",0,async (instance,params,origin,cancel) => {
|
||||
const originalOrigin = instance.interaction.customId.split("_")[1] as Exclude<api.ODActionManagerIdMappings["opendiscord:pin-ticket"]["origin"],"slash"|"text">
|
||||
const {guild,channel,user,message} = instance
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"pin")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
if (originalOrigin == "ticket-message") await opendiscord.verifybars.get("opendiscord:pin-ticket-ticket-message").activate(instance)
|
||||
else if (originalOrigin == "unpin-message") await opendiscord.verifybars.get("opendiscord:pin-ticket-unpin-message").activate(instance)
|
||||
else await instance.defer("update",false)
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/pin")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketUnpinned = await actionUtils.replyTicketMustBeUnpinned(instance,origin,ticket)
|
||||
if (!isTicketUnpinned) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const verifybar = opendiscord.verifybars.get("opendiscord:pin-ticket")
|
||||
const originalUser = ((state.data.messageAuthor) ? await opendiscord.client.fetchUser(state.data.messageAuthor) : user) ?? user
|
||||
const originalReason = state.data.messageReason ?? null
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//send verifybar
|
||||
if (generalConfig.data.system.disableVerifyBars){
|
||||
//verifybar disabled, directly run response
|
||||
await verifybar.activate(instance,"accept")
|
||||
|
||||
}else if (originalMsgType == "ticket-message"){
|
||||
//ticket message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:pin-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:ticket-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "unpin-message"){
|
||||
//unpin message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:pin-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:unpin-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user:originalUser,ticket,reason:originalReason}))
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
export async function registerVerifyBars(){
|
||||
//PIN TICKET
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:pin-ticket"))
|
||||
opendiscord.verifybars.get("opendiscord:pin-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:pin-ticket",0,async (instance,params,origin,cancel) => {
|
||||
const {user,member,channel,guild,message} = instance
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"pin")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/pin")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketUnpinned = await actionUtils.replyTicketMustBeUnpinned(instance,origin,ticket)
|
||||
if (!isTicketUnpinned) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const originalUser = ((state.data.messageAuthor) ? await opendiscord.client.fetchUser(state.data.messageAuthor) : user) ?? user
|
||||
const originalReason = state.data.messageReason ?? null
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//start pinning ticket
|
||||
if (params.selectedButtonId == "cancel"){
|
||||
//CANCEL
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "unpin-message"){
|
||||
//unpin message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:unpin-message").build("verifybar",{guild,channel,user:originalUser,ticket,reason:originalReason}))
|
||||
}
|
||||
}else if (params.selectedButtonId == "accept"){
|
||||
//PIN TICKET
|
||||
await instance.defer("update",false)
|
||||
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await opendiscord.actions.get("opendiscord:pin-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "unpin-message"){
|
||||
//converted to pin message
|
||||
await opendiscord.actions.get("opendiscord:pin-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
const sentMsg = await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:pin-message").build("verifybar",{guild,channel,user,ticket,reason:null}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"pin-message",
|
||||
messageOrigin:origin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:null
|
||||
},sentMsg.ephemeral)
|
||||
}
|
||||
}else if (params.selectedButtonId == "accept-with-reason"){
|
||||
//PIN WITH REASON (MODAL)
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:pin-ticket-reason").build("other",{guild,channel,user,ticket,message}))
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
export async function registerModalResponders(){
|
||||
//PIN WITH REASON MODAL RESPONDER
|
||||
opendiscord.responders.modals.add(new api.ODModalResponder("opendiscord:pin-ticket-reason",/^od:pin-ticket-reason_/))
|
||||
opendiscord.responders.modals.add(new api.ODModalResponder("opendiscord:pin-ticket-reason",/^od:pin-ticket-reason\|([^|]+)\|([^|]+)/))
|
||||
opendiscord.responders.modals.get("opendiscord:pin-ticket-reason").workers.add([
|
||||
new api.ODWorker("opendiscord:pin-ticket-reason",0,async (instance,params,origin,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!channel) return
|
||||
if (!guild){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build(origin,{channel,user:instance.user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(instance.interaction.customId.split("_")[1])
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return
|
||||
}
|
||||
|
||||
const originalOrigin = instance.interaction.customId.split("_")[2] as Exclude<api.ODActionManagerIdMappings["opendiscord:pin-ticket"]["origin"],"slash"|"text">
|
||||
const reason = instance.values.getTextField("reason",true)
|
||||
|
||||
//pin with reason
|
||||
if (originalOrigin == "ticket-message"){
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:pin-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
}else if (originalOrigin == "unpin-message"){
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:pin-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:pin-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
}else{
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:pin-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:true})
|
||||
}
|
||||
const {guild,user} = instance
|
||||
|
||||
const match = /^od:pin-ticket-reason\|([^|]+)\|([^|]+)/.exec(instance.interaction.customId)
|
||||
if (!match) return cancel()
|
||||
const channel = await opendiscord.client.fetchTextChannel(match[1])
|
||||
const message = await opendiscord.client.fetchChannelMessage(match[1],match[2])
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"pin")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || !channel || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/pin")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketUnpinned = await actionUtils.replyTicketMustBeUnpinned(instance,origin,ticket)
|
||||
if (!isTicketUnpinned) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const reason = instance.values.getTextField("reason",true)
|
||||
const originalMsgOrigin = state.data.messageOrigin
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//start pinning ticket
|
||||
await instance.defer("update",false)
|
||||
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await opendiscord.actions.get("opendiscord:pin-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
|
||||
}else if (originalMsgType == "unpin-message"){
|
||||
//converted to pin message
|
||||
await opendiscord.actions.get("opendiscord:pin-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
const sentMsg = await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:pin-message").build(originalMsgType,{guild,channel,user,ticket,reason}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"pin-message",
|
||||
messageOrigin:originalMsgOrigin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:reason
|
||||
},sentMsg.ephemeral)
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
+212
-73
@@ -3,8 +3,11 @@
|
||||
///////////////////////////////////////
|
||||
import {opendiscord, api, utilities} from "../index.js"
|
||||
import * as discord from "discord.js"
|
||||
import * as actionUtils from "../actions/utilities.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
const lang = opendiscord.languages
|
||||
const interactiveMsgState = opendiscord.states.get("opendiscord:interactive-message")
|
||||
|
||||
export async function registerCommandResponders(){
|
||||
//REOPEN COMMAND RESPONDER
|
||||
@@ -13,45 +16,35 @@ export async function registerCommandResponders(){
|
||||
new api.ODWorker("opendiscord:reopen",0,async (instance,params,origin,cancel) => {
|
||||
const {guild,channel,user,member} = instance
|
||||
|
||||
//check permissions
|
||||
const permsResult = await opendiscord.permissions.checkCommandPerms(generalConfig.data.system.permissions.reopen,"support",user,member,channel,guild)
|
||||
if (!permsResult.hasPerms){
|
||||
if (permsResult.reason == "not-in-server") await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
else await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-no-permissions").build(origin,{guild,channel,user,permissions:["support"]}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//check is in guild/server
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//check if ticket exists
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//return when not closed
|
||||
if (!ticket.get("opendiscord:closed").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.reopen"),layout:"simple"}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//return when busy
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
const reason = instance.options.getString("reason",false)
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"reopen")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketClosed = await actionUtils.replyTicketMustBeClosed(instance,origin,ticket)
|
||||
if (!isTicketClosed) return cancel()
|
||||
|
||||
//start reopening ticket
|
||||
await instance.defer(false)
|
||||
const reason = instance.options.getString("reason",false)
|
||||
await opendiscord.actions.get("opendiscord:reopen-ticket").run(origin,{guild,channel,user,ticket,reason,sendMessage:false})
|
||||
await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:reopen-message").build(origin,{guild,channel,user,ticket,reason}))
|
||||
|
||||
//send message & set state
|
||||
const sentMsg = await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:reopen-message").build(origin,{guild,channel,user,ticket,reason}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"reopen-message",
|
||||
messageOrigin:origin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:reason
|
||||
},sentMsg.ephemeral)
|
||||
}),
|
||||
new api.ODWorker("opendiscord:logs",-1,(instance,params,origin,cancel) => {
|
||||
opendiscord.log(instance.user.displayName+" used the 'reopen' command!","info",[
|
||||
@@ -69,55 +62,201 @@ export async function registerButtonResponders(){
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("opendiscord:reopen-ticket",/^od:reopen-ticket/))
|
||||
opendiscord.responders.buttons.get("opendiscord:reopen-ticket").workers.add(
|
||||
new api.ODWorker("opendiscord:reopen-ticket",0,async (instance,params,origin,cancel) => {
|
||||
const originalOrigin = instance.interaction.customId.split("_")[1] as Exclude<api.ODActionManagerIdMappings["opendiscord:reopen-ticket"]["origin"],"slash"|"text">
|
||||
const {guild,channel,message,user,member} = instance
|
||||
|
||||
if (originalOrigin == "ticket-message") await opendiscord.verifybars.get("opendiscord:reopen-ticket-ticket-message").activate(instance)
|
||||
else if (originalOrigin == "close-message") await opendiscord.verifybars.get("opendiscord:reopen-ticket-close-message").activate(instance)
|
||||
else if (originalOrigin == "autoclose-message") await opendiscord.verifybars.get("opendiscord:reopen-ticket-autoclose-message").activate(instance)
|
||||
else await instance.defer("update",false)
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"reopen")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/reopen")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketClosed = await actionUtils.replyTicketMustBeClosed(instance,origin,ticket)
|
||||
if (!isTicketClosed) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const verifybar = opendiscord.verifybars.get("opendiscord:reopen-ticket")
|
||||
const originalUser = ((state.data.messageAuthor) ? await opendiscord.client.fetchUser(state.data.messageAuthor) : user) ?? user
|
||||
const originalReason = state.data.messageReason ?? null
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//send verifybar
|
||||
if (generalConfig.data.system.disableVerifyBars){
|
||||
//verifybar disabled, directly run response
|
||||
await verifybar.activate(instance,"accept")
|
||||
|
||||
}else if (originalMsgType == "ticket-message"){
|
||||
//ticket message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:reopen-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:ticket-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "close-message"){
|
||||
//close message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:reopen-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:close-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user:originalUser,ticket,reason:originalReason}))
|
||||
}else if (originalMsgType == "autoclose-message"){
|
||||
//autoclose message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:reopen-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:autoclose-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user:originalUser,ticket}))
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export async function registerVerifyBars(){
|
||||
//REOPEN TICKET
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:reopen-ticket"))
|
||||
opendiscord.verifybars.get("opendiscord:reopen-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:reopen-ticket",0,async (instance,params,origin,cancel) => {
|
||||
const {user,member,channel,guild,message} = instance
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"reopen")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/reopen")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketClosed = await actionUtils.replyTicketMustBeClosed(instance,origin,ticket)
|
||||
if (!isTicketClosed) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const originalUser = ((state.data.messageAuthor) ? await opendiscord.client.fetchUser(state.data.messageAuthor) : user) ?? user
|
||||
const originalReason = state.data.messageReason ?? null
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//start reopening ticket
|
||||
if (params.selectedButtonId == "cancel"){
|
||||
//CANCEL
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "close-message"){
|
||||
//close message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:close-message").build("verifybar",{guild,channel,user:originalUser,ticket,reason:originalReason}))
|
||||
}else if (originalMsgType == "autoclose-message"){
|
||||
//autoclose message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:autoclose-message").build("verifybar",{guild,channel,user:originalUser,ticket}))
|
||||
}
|
||||
}else if (params.selectedButtonId == "accept"){
|
||||
//REOPEN TICKET
|
||||
await instance.defer("update",false)
|
||||
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await opendiscord.actions.get("opendiscord:reopen-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "close-message"){
|
||||
//converted to reopen message
|
||||
await opendiscord.actions.get("opendiscord:reopen-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
const sentMsg = await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:reopen-message").build("verifybar",{guild,channel,user,ticket,reason:null}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"reopen-message",
|
||||
messageOrigin:origin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:null
|
||||
},sentMsg.ephemeral)
|
||||
}else if (originalMsgType == "autoclose-message"){
|
||||
//converted to reopen message
|
||||
await opendiscord.actions.get("opendiscord:reopen-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
const sentMsg = await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:reopen-message").build("verifybar",{guild,channel,user,ticket,reason:null}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"reopen-message",
|
||||
messageOrigin:origin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:null
|
||||
},sentMsg.ephemeral)
|
||||
}
|
||||
}else if (params.selectedButtonId == "accept-with-reason"){
|
||||
//REOPEN WITH REASON (MODAL)
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:reopen-ticket-reason").build("other",{guild,channel,user,ticket,message}))
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
export async function registerModalResponders(){
|
||||
//REOPEN WITH REASON MODAL RESPONDER
|
||||
opendiscord.responders.modals.add(new api.ODModalResponder("opendiscord:reopen-ticket-reason",/^od:reopen-ticket-reason_/))
|
||||
opendiscord.responders.modals.add(new api.ODModalResponder("opendiscord:reopen-ticket-reason",/^od:reopen-ticket-reason\|([^|]+)\|([^|]+)/))
|
||||
opendiscord.responders.modals.get("opendiscord:reopen-ticket-reason").workers.add([
|
||||
new api.ODWorker("opendiscord:reopen-ticket-reason",0,async (instance,params,origin,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!channel) return
|
||||
if (!guild){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build(origin,{channel,user:instance.user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(instance.interaction.customId.split("_")[1])
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return
|
||||
}
|
||||
const {guild,user} = instance
|
||||
|
||||
const originalOrigin = instance.interaction.customId.split("_")[2] as Exclude<api.ODActionManagerIdMappings["opendiscord:reopen-ticket"]["origin"],"slash"|"text">
|
||||
const reason = instance.values.getTextField("reason",true)
|
||||
|
||||
//reopen with reason
|
||||
if (originalOrigin == "ticket-message"){
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:reopen-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
}else if (originalOrigin == "close-message"){
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:reopen-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:reopen-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
}else if (originalOrigin == "autoclose-message"){
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:reopen-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:reopen-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
}else{
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:reopen-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:true})
|
||||
}
|
||||
const match = /^od:reopen-ticket-reason\|([^|]+)\|([^|]+)/.exec(instance.interaction.customId)
|
||||
if (!match) return cancel()
|
||||
const channel = await opendiscord.client.fetchTextChannel(match[1])
|
||||
const message = await opendiscord.client.fetchChannelMessage(match[1],match[2])
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"reopen")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || !channel || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/reopen")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketClosed = await actionUtils.replyTicketMustBeClosed(instance,origin,ticket)
|
||||
if (!isTicketClosed) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const reason = instance.values.getTextField("reason",true)
|
||||
const originalMsgOrigin = state.data.messageOrigin
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//start reopening ticket
|
||||
await instance.defer("update",false)
|
||||
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await opendiscord.actions.get("opendiscord:reopen-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
|
||||
}else if (originalMsgType == "close-message"){
|
||||
//converted to reopen message
|
||||
await opendiscord.actions.get("opendiscord:reopen-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
const sentMsg = await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:reopen-message").build(originalMsgType,{guild,channel,user,ticket,reason}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"reopen-message",
|
||||
messageOrigin:originalMsgOrigin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:reason
|
||||
},sentMsg.ephemeral)
|
||||
}else if (originalMsgType == "autoclose-message"){
|
||||
//converted to reopen message
|
||||
await opendiscord.actions.get("opendiscord:reopen-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
const sentMsg = await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:reopen-message").build(originalMsgType,{guild,channel,user,ticket,reason}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"reopen-message",
|
||||
messageOrigin:originalMsgOrigin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:reason
|
||||
},sentMsg.ephemeral)
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
+183
-65
@@ -3,8 +3,11 @@
|
||||
///////////////////////////////////////
|
||||
import {opendiscord, api, utilities} from "../index.js"
|
||||
import * as discord from "discord.js"
|
||||
import * as actionUtils from "../actions/utilities.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
const lang = opendiscord.languages
|
||||
const interactiveMsgState = opendiscord.states.get("opendiscord:interactive-message")
|
||||
|
||||
export async function registerCommandResponders(){
|
||||
//UNCLAIM COMMAND RESPONDER
|
||||
@@ -13,45 +16,35 @@ export async function registerCommandResponders(){
|
||||
new api.ODWorker("opendiscord:unclaim",0,async (instance,params,origin,cancel) => {
|
||||
const {user,member,channel,guild} = instance
|
||||
|
||||
//check permissions
|
||||
const permsResult = await opendiscord.permissions.checkCommandPerms(generalConfig.data.system.permissions.unclaim,"support",user,member,channel,guild)
|
||||
if (!permsResult.hasPerms){
|
||||
if (permsResult.reason == "not-in-server") await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
else await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-no-permissions").build(origin,{guild,channel,user,permissions:["support"]}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//check is in guild/Server
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//check if ticket exists
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//return when not claimed
|
||||
if (!ticket.get("opendiscord:claimed").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.unclaim"),layout:"simple"}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//return when busy
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
const reason = instance.options.getString("reason",false)
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"unclaim")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketClaimed = await actionUtils.replyTicketMustBeClaimed(instance,origin,ticket)
|
||||
if (!isTicketClaimed) return cancel()
|
||||
|
||||
//start unclaiming ticket
|
||||
await instance.defer(false)
|
||||
const reason = instance.options.getString("reason",false)
|
||||
await opendiscord.actions.get("opendiscord:unclaim-ticket").run(origin,{guild,channel,user,ticket,reason,sendMessage:false})
|
||||
await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:unclaim-message").build(origin,{guild,channel,user,ticket,reason}))
|
||||
|
||||
//send message & set state
|
||||
const sentMsg = await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:unclaim-message").build(origin,{guild,channel,user,ticket,reason}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"unclaim-message",
|
||||
messageOrigin:origin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:reason
|
||||
},sentMsg.ephemeral)
|
||||
}),
|
||||
new api.ODWorker("opendiscord:logs",-1,(instance,params,origin,cancel) => {
|
||||
opendiscord.log(instance.user.displayName+" used the 'unclaim' command!","info",[
|
||||
@@ -69,48 +62,173 @@ export async function registerButtonResponders(){
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("opendiscord:unclaim-ticket",/^od:unclaim-ticket/))
|
||||
opendiscord.responders.buttons.get("opendiscord:unclaim-ticket").workers.add(
|
||||
new api.ODWorker("opendiscord:unclaim-ticket",0,async (instance,params,origin,cancel) => {
|
||||
const originalOrigin = instance.interaction.customId.split("_")[1] as Exclude<api.ODActionManagerIdMappings["opendiscord:unclaim-ticket"]["origin"],"slash"|"text">
|
||||
const {guild,channel,user,message} = instance
|
||||
|
||||
if (originalOrigin == "ticket-message") await opendiscord.verifybars.get("opendiscord:unclaim-ticket-ticket-message").activate(instance)
|
||||
else if (originalOrigin == "claim-message") await opendiscord.verifybars.get("opendiscord:unclaim-ticket-claim-message").activate(instance)
|
||||
else await instance.defer("update",false)
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"unclaim")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/unclaim")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketClaimed = await actionUtils.replyTicketMustBeClaimed(instance,origin,ticket)
|
||||
if (!isTicketClaimed) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const verifybar = opendiscord.verifybars.get("opendiscord:unclaim-ticket")
|
||||
const originalUser = ((state.data.messageAuthor) ? await opendiscord.client.fetchUser(state.data.messageAuthor) : user) ?? user
|
||||
const originalReason = state.data.messageReason ?? null
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//send verifybar
|
||||
if (generalConfig.data.system.disableVerifyBars){
|
||||
//verifybar disabled, directly run response
|
||||
await verifybar.activate(instance,"accept")
|
||||
|
||||
}else if (originalMsgType == "ticket-message"){
|
||||
//ticket message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:unclaim-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:ticket-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "claim-message"){
|
||||
//claim message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:unclaim-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:claim-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user:originalUser,ticket,reason:originalReason}))
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export async function registerVerifyBars(){
|
||||
//UNCLAIM TICKET
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:unclaim-ticket"))
|
||||
opendiscord.verifybars.get("opendiscord:unclaim-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:unclaim-ticket",0,async (instance,params,origin,cancel) => {
|
||||
const {user,member,channel,guild,message} = instance
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"unclaim")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/unclaim")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketClaimed = await actionUtils.replyTicketMustBeClaimed(instance,origin,ticket)
|
||||
if (!isTicketClaimed) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const originalUser = ((state.data.messageAuthor) ? await opendiscord.client.fetchUser(state.data.messageAuthor) : user) ?? user
|
||||
const originalReason = state.data.messageReason ?? null
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//start unclaiming ticket
|
||||
if (params.selectedButtonId == "cancel"){
|
||||
//CANCEL
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "claim-message"){
|
||||
//claim message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:claim-message").build("verifybar",{guild,channel,user:originalUser,ticket,reason:originalReason}))
|
||||
}
|
||||
}else if (params.selectedButtonId == "accept"){
|
||||
//UNCLAIM TICKET
|
||||
await instance.defer("update",false)
|
||||
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await opendiscord.actions.get("opendiscord:unclaim-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "claim-message"){
|
||||
//converted to unclaim message
|
||||
await opendiscord.actions.get("opendiscord:unclaim-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
const sentMsg = await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:unclaim-message").build("verifybar",{guild,channel,user,ticket,reason:null}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"unclaim-message",
|
||||
messageOrigin:origin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:null
|
||||
},sentMsg.ephemeral)
|
||||
}
|
||||
}else if (params.selectedButtonId == "accept-with-reason"){
|
||||
//UNCLAIM WITH REASON (MODAL)
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:unclaim-ticket-reason").build("other",{guild,channel,user,ticket,message}))
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
export async function registerModalResponders(){
|
||||
//UNCLAIM WITH REASON MODAL RESPONDER
|
||||
opendiscord.responders.modals.add(new api.ODModalResponder("opendiscord:unclaim-ticket-reason",/^od:unclaim-ticket-reason_/))
|
||||
opendiscord.responders.modals.add(new api.ODModalResponder("opendiscord:unclaim-ticket-reason",/^od:unclaim-ticket-reason\|([^|]+)\|([^|]+)/))
|
||||
opendiscord.responders.modals.get("opendiscord:unclaim-ticket-reason").workers.add([
|
||||
new api.ODWorker("opendiscord:unclaim-ticket-reason",0,async (instance,params,origin,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!channel) return
|
||||
if (!guild){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build(origin,{channel,user:instance.user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(instance.interaction.customId.split("_")[1])
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return
|
||||
}
|
||||
const {guild,user} = instance
|
||||
|
||||
const match = /^od:unclaim-ticket-reason\|([^|]+)\|([^|]+)/.exec(instance.interaction.customId)
|
||||
if (!match) return cancel()
|
||||
const channel = await opendiscord.client.fetchTextChannel(match[1])
|
||||
const message = await opendiscord.client.fetchChannelMessage(match[1],match[2])
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"unclaim")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || !channel || channel.isDMBased()) return cancel()
|
||||
|
||||
const originalOrigin = instance.interaction.customId.split("_")[2] as Exclude<api.ODActionManagerIdMappings["opendiscord:unclaim-ticket"]["origin"],"slash"|"text">
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/unclaim")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketClaimed = await actionUtils.replyTicketMustBeClaimed(instance,origin,ticket)
|
||||
if (!isTicketClaimed) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const reason = instance.values.getTextField("reason",true)
|
||||
const originalMsgOrigin = state.data.messageOrigin
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//unclaim with reason
|
||||
if (originalOrigin == "ticket-message"){
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:unclaim-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:true})
|
||||
//start claiming ticket
|
||||
await instance.defer("update",false)
|
||||
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await opendiscord.actions.get("opendiscord:unclaim-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
}else if (originalOrigin == "claim-message"){
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:unclaim-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:unclaim-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
}else{
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:unclaim-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:true})
|
||||
|
||||
}else if (originalMsgType == "claim-message"){
|
||||
//converted to unclaim message
|
||||
await opendiscord.actions.get("opendiscord:unclaim-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
const sentMsg = await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:unclaim-message").build(originalMsgType,{guild,channel,user,ticket,reason}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"unclaim-message",
|
||||
messageOrigin:originalMsgOrigin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:reason
|
||||
},sentMsg.ephemeral)
|
||||
}
|
||||
})
|
||||
])
|
||||
|
||||
+184
-66
@@ -3,8 +3,11 @@
|
||||
///////////////////////////////////////
|
||||
import {opendiscord, api, utilities} from "../index.js"
|
||||
import * as discord from "discord.js"
|
||||
import * as actionUtils from "../actions/utilities.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
const lang = opendiscord.languages
|
||||
const interactiveMsgState = opendiscord.states.get("opendiscord:interactive-message")
|
||||
|
||||
export async function registerCommandResponders(){
|
||||
//UNPIN COMMAND RESPONDER
|
||||
@@ -12,46 +15,36 @@ export async function registerCommandResponders(){
|
||||
opendiscord.responders.commands.get("opendiscord:unpin").workers.add([
|
||||
new api.ODWorker("opendiscord:unpin",0,async (instance,params,origin,cancel) => {
|
||||
const {user,member,channel,guild} = instance
|
||||
|
||||
//check permissions
|
||||
const permsResult = await opendiscord.permissions.checkCommandPerms(generalConfig.data.system.permissions.unpin,"support",user,member,channel,guild)
|
||||
if (!permsResult.hasPerms){
|
||||
if (permsResult.reason == "not-in-server") await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
else await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-no-permissions").build(origin,{guild,channel,user,permissions:["support"]}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//check is in guild/Server
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//check if ticket exists
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//return when not pinned yet
|
||||
if (!ticket.get("opendiscord:pinned").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.unpin"),layout:"simple"}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//return when busy
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
const reason = instance.options.getString("reason",false)
|
||||
|
||||
//start unpinning ticket
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"unpin")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketPinned = await actionUtils.replyTicketMustBePinned(instance,origin,ticket)
|
||||
if (!isTicketPinned) return cancel()
|
||||
|
||||
//start unpining ticket
|
||||
await instance.defer(false)
|
||||
const reason = instance.options.getString("reason",false)
|
||||
await opendiscord.actions.get("opendiscord:unpin-ticket").run(origin,{guild,channel,user,ticket,reason,sendMessage:false})
|
||||
await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:unpin-message").build(origin,{guild,channel,user,ticket,reason}))
|
||||
|
||||
//send message & set state
|
||||
const sentMsg = await instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:unpin-message").build(origin,{guild,channel,user,ticket,reason}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"unpin-message",
|
||||
messageOrigin:origin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:reason
|
||||
},sentMsg.ephemeral)
|
||||
}),
|
||||
new api.ODWorker("opendiscord:logs",-1,(instance,params,origin,cancel) => {
|
||||
opendiscord.log(instance.user.displayName+" used the 'unpin' command!","info",[
|
||||
@@ -69,48 +62,173 @@ export async function registerButtonResponders(){
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("opendiscord:unpin-ticket",/^od:unpin-ticket/))
|
||||
opendiscord.responders.buttons.get("opendiscord:unpin-ticket").workers.add(
|
||||
new api.ODWorker("opendiscord:unpin-ticket",0,async (instance,params,origin,cancel) => {
|
||||
const originalOrigin = instance.interaction.customId.split("_")[1] as Exclude<api.ODActionManagerIdMappings["opendiscord:unpin-ticket"]["origin"],"slash"|"text">
|
||||
const {guild,channel,user,message} = instance
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"unpin")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
if (originalOrigin == "ticket-message") await opendiscord.verifybars.get("opendiscord:unpin-ticket-ticket-message").activate(instance)
|
||||
else if (originalOrigin == "pin-message") await opendiscord.verifybars.get("opendiscord:unpin-ticket-pin-message").activate(instance)
|
||||
else await instance.defer("update",false)
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/unpin")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketPinned = await actionUtils.replyTicketMustBePinned(instance,origin,ticket)
|
||||
if (!isTicketPinned) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const verifybar = opendiscord.verifybars.get("opendiscord:unpin-ticket")
|
||||
const originalUser = ((state.data.messageAuthor) ? await opendiscord.client.fetchUser(state.data.messageAuthor) : user) ?? user
|
||||
const originalReason = state.data.messageReason ?? null
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//send verifybar
|
||||
if (generalConfig.data.system.disableVerifyBars){
|
||||
//verifybar disabled, directly run response
|
||||
await verifybar.activate(instance,"accept")
|
||||
|
||||
}else if (originalMsgType == "ticket-message"){
|
||||
//ticket message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:unpin-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:ticket-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "pin-message"){
|
||||
//pin message verifybar
|
||||
const modifiedMsg = opendiscord.components.modifiers.get("opendiscord:unpin-ticket-verifybar").modify(opendiscord.builders.messages.getSafe("opendiscord:pin-message"),originalMsgType,{guild,channel,user,verifybar})
|
||||
await instance.update(await modifiedMsg.build("verifybar",{guild,channel,user:originalUser,ticket,reason:originalReason}))
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export async function registerVerifyBars(){
|
||||
//UNPIN TICKET
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:unpin-ticket"))
|
||||
opendiscord.verifybars.get("opendiscord:unpin-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:unpin-ticket",0,async (instance,params,origin,cancel) => {
|
||||
const {user,member,channel,guild,message} = instance
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"unpin")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || channel.isDMBased()) return cancel()
|
||||
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/unpin")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketPinned = await actionUtils.replyTicketMustBePinned(instance,origin,ticket)
|
||||
if (!isTicketPinned) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const originalUser = ((state.data.messageAuthor) ? await opendiscord.client.fetchUser(state.data.messageAuthor) : user) ?? user
|
||||
const originalReason = state.data.messageReason ?? null
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//start unpinning ticket
|
||||
if (params.selectedButtonId == "cancel"){
|
||||
//CANCEL
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "pin-message"){
|
||||
//pin message
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:pin-message").build("verifybar",{guild,channel,user:originalUser,ticket,reason:originalReason}))
|
||||
}
|
||||
}else if (params.selectedButtonId == "accept"){
|
||||
//UNPIN TICKET
|
||||
await instance.defer("update",false)
|
||||
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await opendiscord.actions.get("opendiscord:unpin-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("verifybar",{guild,channel,user,ticket}))
|
||||
}else if (originalMsgType == "pin-message"){
|
||||
//converted to unpin message
|
||||
await opendiscord.actions.get("opendiscord:unpin-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
const sentMsg = await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:unpin-message").build("verifybar",{guild,channel,user,ticket,reason:null}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"unpin-message",
|
||||
messageOrigin:origin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:null
|
||||
},sentMsg.ephemeral)
|
||||
}
|
||||
}else if (params.selectedButtonId == "accept-with-reason"){
|
||||
//UNPIN WITH REASON (MODAL)
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:unpin-ticket-reason").build("other",{guild,channel,user,ticket,message}))
|
||||
}
|
||||
})
|
||||
])
|
||||
}
|
||||
|
||||
export async function registerModalResponders(){
|
||||
//UNPIN WITH REASON MODAL RESPONDER
|
||||
opendiscord.responders.modals.add(new api.ODModalResponder("opendiscord:unpin-ticket-reason",/^od:unpin-ticket-reason_/))
|
||||
opendiscord.responders.modals.add(new api.ODModalResponder("opendiscord:unpin-ticket-reason",/^od:unpin-ticket-reason\|([^|]+)\|([^|]+)/))
|
||||
opendiscord.responders.modals.get("opendiscord:unpin-ticket-reason").workers.add([
|
||||
new api.ODWorker("opendiscord:unpin-ticket-reason",0,async (instance,params,origin,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!channel) return
|
||||
if (!guild){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build(origin,{channel,user:instance.user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(instance.interaction.customId.split("_")[1])
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return
|
||||
}
|
||||
const {guild,user} = instance
|
||||
|
||||
const match = /^od:unpin-ticket-reason\|([^|]+)\|([^|]+)/.exec(instance.interaction.customId)
|
||||
if (!match) return cancel()
|
||||
const channel = await opendiscord.client.fetchTextChannel(match[1])
|
||||
const message = await opendiscord.client.fetchChannelMessage(match[1],match[2])
|
||||
|
||||
//responder checks
|
||||
const hasPerms = await actionUtils.replyHasPermissions(instance,origin,"unpin")
|
||||
if (!hasPerms) return cancel()
|
||||
|
||||
const isInGuild = await actionUtils.replyIsInGuild(instance,origin)
|
||||
if (!isInGuild || !guild || !channel || channel.isDMBased()) return cancel()
|
||||
|
||||
const originalOrigin = instance.interaction.customId.split("_")[2] as Exclude<api.ODActionManagerIdMappings["opendiscord:unpin-ticket"]["origin"],"slash"|"text">
|
||||
const state = await actionUtils.replyInteractiveMessageState(instance,origin,channel,message,"/unpin")
|
||||
if (!state) return cancel()
|
||||
|
||||
const ticket = await actionUtils.replyIsTicket(instance,origin)
|
||||
if (!ticket) return cancel()
|
||||
|
||||
const isAvailable = await actionUtils.replyTicketIsAvailable(instance,origin,ticket)
|
||||
if (!isAvailable) return cancel()
|
||||
|
||||
const isTicketPinned = await actionUtils.replyTicketMustBePinned(instance,origin,ticket)
|
||||
if (!isTicketPinned) return cancel()
|
||||
|
||||
//fetch state details
|
||||
const reason = instance.values.getTextField("reason",true)
|
||||
const originalMsgOrigin = state.data.messageOrigin
|
||||
const originalMsgType = state.data.messageType
|
||||
|
||||
//unpin with reason
|
||||
if (originalOrigin == "ticket-message"){
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:unpin-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:true})
|
||||
//start pinning ticket
|
||||
await instance.defer("update",false)
|
||||
|
||||
if (originalMsgType == "ticket-message"){
|
||||
//ticket message
|
||||
await opendiscord.actions.get("opendiscord:unpin-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
}else if (originalOrigin == "pin-message"){
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:unpin-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:unpin-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
}else{
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("opendiscord:unpin-ticket").run(originalOrigin,{guild,channel,user,ticket,reason,sendMessage:true})
|
||||
|
||||
}else if (originalMsgType == "pin-message"){
|
||||
//converted to unpin message
|
||||
await opendiscord.actions.get("opendiscord:unpin-ticket").run(originalMsgType,{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
const sentMsg = await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:unpin-message").build(originalMsgType,{guild,channel,user,ticket,reason}))
|
||||
if (sentMsg.success) await interactiveMsgState.setMsgState({channel,message:sentMsg.message},{
|
||||
messageType:"unpin-message",
|
||||
messageOrigin:originalMsgOrigin,
|
||||
messageAuthor:user.id,
|
||||
messageReason:reason
|
||||
},sentMsg.ephemeral)
|
||||
}
|
||||
})
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user