BREAKING: changed all ids to "opendiscord:"
This commit is contained in:
@@ -4,21 +4,21 @@
|
||||
import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("openticket:general")
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("openticket:add-ticket-user"))
|
||||
opendiscord.actions.get("openticket:add-ticket-user").workers.add([
|
||||
new api.ODWorker("openticket:add-ticket-user",2,async (instance,params,source,cancel) => {
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:add-ticket-user"))
|
||||
opendiscord.actions.get("opendiscord:add-ticket-user").workers.add([
|
||||
new api.ODWorker("opendiscord:add-ticket-user",2,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason,data} = params
|
||||
if (channel.isThread()) throw new api.ODSystemError("Unable to add user to ticket! Open Ticket doesn't support threads!")
|
||||
|
||||
await opendiscord.events.get("onTicketUserAdd").emit([ticket,user,data,channel,reason])
|
||||
|
||||
//update ticket
|
||||
ticket.get("openticket:participants").value.push({type:"user",id:data.id})
|
||||
ticket.get("openticket:participants").refreshDatabase()
|
||||
ticket.get("openticket:busy").value = true
|
||||
ticket.get("opendiscord:participants").value.push({type:"user",id:data.id})
|
||||
ticket.get("opendiscord:participants").refreshDatabase()
|
||||
ticket.get("opendiscord:busy").value = true
|
||||
|
||||
//update channel permissions
|
||||
try{
|
||||
@@ -38,7 +38,7 @@ export const registerActions = async () => {
|
||||
const ticketMessage = await opendiscord.tickets.getTicketMessage(ticket)
|
||||
if (ticketMessage){
|
||||
try{
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
}catch(e){
|
||||
opendiscord.log("Unable to edit ticket message on ticket user adding!","error",[
|
||||
{key:"channel",value:"#"+channel.name},
|
||||
@@ -51,24 +51,24 @@ export const registerActions = async () => {
|
||||
}
|
||||
|
||||
//reply with new message
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("openticket:add-message").build(source,{guild,channel,user,ticket,reason,data})).message)
|
||||
ticket.get("openticket:busy").value = false
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:add-message").build(source,{guild,channel,user,ticket,reason,data})).message)
|
||||
ticket.get("opendiscord:busy").value = false
|
||||
await opendiscord.events.get("afterTicketUserAdded").emit([ticket,user,data,channel,reason])
|
||||
}),
|
||||
new api.ODWorker("openticket:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason,data} = params
|
||||
|
||||
//to logs
|
||||
if (generalConfig.data.system.logs.enabled && generalConfig.data.system.messages.adding.logs){
|
||||
const logChannel = opendiscord.posts.get("openticket:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("openticket:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"add",reason,additionalData:data}))
|
||||
const logChannel = opendiscord.posts.get("opendiscord:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"add",reason,additionalData:data}))
|
||||
}
|
||||
|
||||
//to dm
|
||||
const creator = await opendiscord.tickets.getTicketUser(ticket,"creator")
|
||||
if (creator && generalConfig.data.system.messages.adding.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("openticket:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"add",reason,additionalData:data}))
|
||||
if (creator && generalConfig.data.system.messages.adding.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"add",reason,additionalData:data}))
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",0,(instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",0,(instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,data} = params
|
||||
|
||||
opendiscord.log(user.displayName+" added "+data.displayName+" to a ticket!","info",[
|
||||
@@ -81,8 +81,8 @@ export const registerActions = async () => {
|
||||
])
|
||||
})
|
||||
])
|
||||
opendiscord.actions.get("openticket:add-ticket-user").workers.backupWorker = new api.ODWorker("openticket:cancel-busy",0,(instance,params) => {
|
||||
opendiscord.actions.get("opendiscord:add-ticket-user").workers.backupWorker = new api.ODWorker("opendiscord:cancel-busy",0,(instance,params) => {
|
||||
//set busy to false in case of crash or cancel
|
||||
params.ticket.get("openticket:busy").value = false
|
||||
params.ticket.get("opendiscord:busy").value = false
|
||||
})
|
||||
}
|
||||
+69
-69
@@ -4,35 +4,35 @@
|
||||
import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("openticket:general")
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("openticket:claim-ticket"))
|
||||
opendiscord.actions.get("openticket:claim-ticket").workers.add([
|
||||
new api.ODWorker("openticket:claim-ticket",2,async (instance,params,source,cancel) => {
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:claim-ticket"))
|
||||
opendiscord.actions.get("opendiscord:claim-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:claim-ticket",2,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason} = params
|
||||
if (channel.isThread()) throw new api.ODSystemError("Unable to claim ticket! Open Ticket doesn't support threads!")
|
||||
|
||||
await opendiscord.events.get("onTicketClaim").emit([ticket,user,channel,reason])
|
||||
|
||||
//update ticket
|
||||
ticket.get("openticket:claimed").value = true
|
||||
ticket.get("openticket:claimed-by").value = user.id
|
||||
ticket.get("openticket:claimed-on").value = new Date().getTime()
|
||||
ticket.get("openticket:busy").value = true
|
||||
ticket.get("opendiscord:claimed").value = true
|
||||
ticket.get("opendiscord:claimed-by").value = user.id
|
||||
ticket.get("opendiscord:claimed-on").value = new Date().getTime()
|
||||
ticket.get("opendiscord:busy").value = true
|
||||
|
||||
//update stats
|
||||
await opendiscord.stats.get("openticket:global").setStat("openticket:tickets-claimed",1,"increase")
|
||||
await opendiscord.stats.get("openticket:user").setStat("openticket:tickets-claimed",user.id,1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:global").setStat("opendiscord:tickets-claimed",1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:user").setStat("opendiscord:tickets-claimed",user.id,1,"increase")
|
||||
|
||||
//update category
|
||||
const rawClaimCategory = ticket.option.get("openticket:channel-categories-claimed").value.find((c) => c.user == user.id)
|
||||
const rawClaimCategory = ticket.option.get("opendiscord:channel-categories-claimed").value.find((c) => c.user == user.id)
|
||||
const claimCategory = (rawClaimCategory) ? rawClaimCategory.category : null
|
||||
if (claimCategory){
|
||||
try {
|
||||
channel.setParent(claimCategory,{lockPermissions:false})
|
||||
ticket.get("openticket:category-mode").value = "claimed"
|
||||
ticket.get("openticket:category").value = claimCategory
|
||||
ticket.get("opendiscord:category-mode").value = "claimed"
|
||||
ticket.get("opendiscord:category").value = claimCategory
|
||||
}catch(e){
|
||||
opendiscord.log("Unable to move ticket to 'claimed category'!","error",[
|
||||
{key:"channel",value:"#"+channel.name},
|
||||
@@ -47,7 +47,7 @@ export const registerActions = async () => {
|
||||
const ticketMessage = await opendiscord.tickets.getTicketMessage(ticket)
|
||||
if (ticketMessage){
|
||||
try{
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
}catch(e){
|
||||
opendiscord.log("Unable to edit ticket message on ticket claiming!","error",[
|
||||
{key:"channel",value:"#"+channel.name},
|
||||
@@ -60,24 +60,24 @@ export const registerActions = async () => {
|
||||
}
|
||||
|
||||
//reply with new message
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("openticket:claim-message").build(source,{guild,channel,user,ticket,reason})).message)
|
||||
ticket.get("openticket:busy").value = false
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:claim-message").build(source,{guild,channel,user,ticket,reason})).message)
|
||||
ticket.get("opendiscord:busy").value = false
|
||||
await opendiscord.events.get("afterTicketClaimed").emit([ticket,user,channel,reason])
|
||||
}),
|
||||
new api.ODWorker("openticket:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason} = params
|
||||
|
||||
//to logs
|
||||
if (generalConfig.data.system.logs.enabled && generalConfig.data.system.messages.claiming.logs){
|
||||
const logChannel = opendiscord.posts.get("openticket:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("openticket:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"claim",reason,additionalData:null}))
|
||||
const logChannel = opendiscord.posts.get("opendiscord:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"claim",reason,additionalData:null}))
|
||||
}
|
||||
|
||||
//to dm
|
||||
const creator = await opendiscord.tickets.getTicketUser(ticket,"creator")
|
||||
if (creator && generalConfig.data.system.messages.claiming.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("openticket:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"claim",reason,additionalData:null}))
|
||||
if (creator && generalConfig.data.system.messages.claiming.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"claim",reason,additionalData:null}))
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",0,(instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",0,(instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket} = params
|
||||
|
||||
opendiscord.log(user.displayName+" claimed a ticket!","info",[
|
||||
@@ -90,188 +90,188 @@ export const registerActions = async () => {
|
||||
])
|
||||
})
|
||||
])
|
||||
opendiscord.actions.get("openticket:claim-ticket").workers.backupWorker = new api.ODWorker("openticket:cancel-busy",0,(instance,params) => {
|
||||
opendiscord.actions.get("opendiscord:claim-ticket").workers.backupWorker = new api.ODWorker("opendiscord:cancel-busy",0,(instance,params) => {
|
||||
//set busy to false in case of crash or cancel
|
||||
params.ticket.get("openticket:busy").value = false
|
||||
params.ticket.get("opendiscord:busy").value = false
|
||||
})
|
||||
}
|
||||
|
||||
export const registerVerifyBars = async () => {
|
||||
//CLAIM TICKET TICKET MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:claim-ticket-ticket-message",opendiscord.builders.messages.getSafe("openticket:verifybar-ticket-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:claim-ticket-ticket-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:claim-ticket-ticket-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-ticket-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:claim-ticket-ticket-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.claim
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:claim-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:claim-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
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("openticket:claimed").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.claim"),layout:"simple"}))
|
||||
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("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start claiming ticket
|
||||
if (params.data == "reason"){
|
||||
//claim with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:claim-ticket-reason").build("ticket-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:claim-ticket-reason").build("ticket-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//claim without reason
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("openticket:claim-ticket").run("ticket-message",{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
await opendiscord.actions.get("opendiscord:claim-ticket").run("ticket-message",{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}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:claim-ticket-ticket-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-ticket-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:claim-ticket-ticket-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-ticket-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
})
|
||||
])
|
||||
|
||||
//CLAIM TICKET UNCLAIM MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:claim-ticket-unclaim-message",opendiscord.builders.messages.getSafe("openticket:verifybar-unclaim-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:claim-ticket-unclaim-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:claim-ticket-unclaim-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-unclaim-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:claim-ticket-unclaim-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.claim
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:claim-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:claim-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
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("openticket:claimed").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.claim"),layout:"simple"}))
|
||||
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("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start claiming ticket
|
||||
if (params.data == "reason"){
|
||||
//claim with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:claim-ticket-reason").build("unclaim-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:claim-ticket-reason").build("unclaim-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//claim without reason
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("openticket:claim-ticket").run("unclaim-message",{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:claim-message").build("unclaim-message",{guild,channel,user,ticket,reason:null}))
|
||||
await opendiscord.actions.get("opendiscord:claim-ticket").run("unclaim-message",{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:claim-message").build("unclaim-message",{guild,channel,user,ticket,reason:null}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:claim-ticket-unclaim-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-unclaim-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:claim-ticket-unclaim-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-unclaim-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
const {verifybarMessage} = params
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
const rawReason = (verifybarMessage && verifybarMessage.embeds[0] && verifybarMessage.embeds[0].fields[0]) ? verifybarMessage.embeds[0].fields[0].value : null
|
||||
const reason = (rawReason == null) ? null : rawReason.substring(3,rawReason.length-3)
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:unclaim-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:unclaim-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
})
|
||||
])
|
||||
}
|
||||
@@ -4,12 +4,12 @@
|
||||
import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("openticket:general")
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("openticket:clear-tickets"))
|
||||
opendiscord.actions.get("openticket:clear-tickets").workers.add([
|
||||
new api.ODWorker("openticket:clear-tickets",2,async (instance,params,source,cancel) => {
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:clear-tickets"))
|
||||
opendiscord.actions.get("opendiscord:clear-tickets").workers.add([
|
||||
new api.ODWorker("opendiscord:clear-tickets",2,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,filter,list} = params
|
||||
|
||||
await opendiscord.events.get("onTicketsClear").emit([list,user,channel,filter])
|
||||
@@ -18,21 +18,21 @@ export const registerActions = async () => {
|
||||
const ticketChannel = await opendiscord.tickets.getTicketChannel(ticket)
|
||||
if (!ticketChannel) return
|
||||
nameList.push("#"+ticketChannel.name)
|
||||
await opendiscord.actions.get("openticket:delete-ticket").run("clear",{guild,channel:ticketChannel,user,ticket,reason:"Cleared Ticket",sendMessage:true,withoutTranscript:false})
|
||||
await opendiscord.actions.get("opendiscord:delete-ticket").run("clear",{guild,channel:ticketChannel,user,ticket,reason:"Cleared Ticket",sendMessage:true,withoutTranscript:false})
|
||||
}
|
||||
instance.list = nameList
|
||||
await opendiscord.events.get("afterTicketsCleared").emit([list,user,channel,filter])
|
||||
}),
|
||||
new api.ODWorker("openticket:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,filter,list} = params
|
||||
|
||||
//to logs
|
||||
if (generalConfig.data.system.logs.enabled && generalConfig.data.system.messages.deleting.logs){
|
||||
const logChannel = opendiscord.posts.get("openticket:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("openticket:clear-logs").build(source,{guild,channel,user,filter,list:instance.list ?? []}))
|
||||
const logChannel = opendiscord.posts.get("opendiscord:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("opendiscord:clear-logs").build(source,{guild,channel,user,filter,list:instance.list ?? []}))
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",0,(instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",0,(instance,params,source,cancel) => {
|
||||
const {guild,user,filter,list} = params
|
||||
opendiscord.log(user.displayName+" cleared "+list.length+" tickets!","info",[
|
||||
{key:"user",value:user.username},
|
||||
|
||||
+75
-75
@@ -4,36 +4,36 @@
|
||||
import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("openticket:general")
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("openticket:close-ticket"))
|
||||
opendiscord.actions.get("openticket:close-ticket").workers.add([
|
||||
new api.ODWorker("openticket:close-ticket",2,async (instance,params,source,cancel) => {
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:close-ticket"))
|
||||
opendiscord.actions.get("opendiscord:close-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:close-ticket",2,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason} = params
|
||||
if (channel.isThread()) throw new api.ODSystemError("Unable to close ticket! Open Ticket doesn't support threads!")
|
||||
|
||||
await opendiscord.events.get("onTicketClose").emit([ticket,user,channel,reason])
|
||||
|
||||
//update ticket
|
||||
ticket.get("openticket:closed").value = true
|
||||
if (source == "autoclose") ticket.get("openticket:autoclosed").value = true
|
||||
ticket.get("openticket:open").value = false
|
||||
ticket.get("openticket:closed-by").value = user.id
|
||||
ticket.get("openticket:closed-on").value = new Date().getTime()
|
||||
ticket.get("openticket:busy").value = true
|
||||
ticket.get("opendiscord:closed").value = true
|
||||
if (source == "autoclose") ticket.get("opendiscord:autoclosed").value = true
|
||||
ticket.get("opendiscord:open").value = false
|
||||
ticket.get("opendiscord:closed-by").value = user.id
|
||||
ticket.get("opendiscord:closed-on").value = new Date().getTime()
|
||||
ticket.get("opendiscord:busy").value = true
|
||||
|
||||
//update stats
|
||||
await opendiscord.stats.get("openticket:global").setStat("openticket:tickets-closed",1,"increase")
|
||||
await opendiscord.stats.get("openticket:user").setStat("openticket:tickets-closed",user.id,1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:global").setStat("opendiscord:tickets-closed",1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:user").setStat("opendiscord:tickets-closed",user.id,1,"increase")
|
||||
|
||||
//update category
|
||||
const closeCategory = ticket.option.get("openticket:channel-category-closed").value
|
||||
const closeCategory = ticket.option.get("opendiscord:channel-category-closed").value
|
||||
if (closeCategory !== ""){
|
||||
try {
|
||||
channel.setParent(closeCategory,{lockPermissions:false})
|
||||
ticket.get("openticket:category-mode").value = "closed"
|
||||
ticket.get("openticket:category").value = closeCategory
|
||||
ticket.get("opendiscord:category-mode").value = "closed"
|
||||
ticket.get("opendiscord:category").value = closeCategory
|
||||
}catch(e){
|
||||
opendiscord.log("Unable to move ticket to 'closed category'!","error",[
|
||||
{key:"channel",value:"#"+channel.name},
|
||||
@@ -51,9 +51,9 @@ export const registerActions = async () => {
|
||||
allow:[],
|
||||
deny:["ViewChannel","SendMessages","ReadMessageHistory"]
|
||||
}]
|
||||
const globalAdmins = opendiscord.configs.get("openticket:general").data.globalAdmins
|
||||
const optionAdmins = ticket.option.get("openticket:admins").value
|
||||
const readonlyAdmins = ticket.option.get("openticket:admins-readonly").value
|
||||
const globalAdmins = opendiscord.configs.get("opendiscord:general").data.globalAdmins
|
||||
const optionAdmins = ticket.option.get("opendiscord:admins").value
|
||||
const readonlyAdmins = ticket.option.get("opendiscord:admins-readonly").value
|
||||
|
||||
globalAdmins.forEach((admin) => {
|
||||
permissions.push({
|
||||
@@ -82,7 +82,7 @@ export const registerActions = async () => {
|
||||
deny:["SendMessages","AddReactions","AttachFiles","SendPolls"]
|
||||
})
|
||||
})
|
||||
ticket.get("openticket:participants").value.forEach((participant) => {
|
||||
ticket.get("opendiscord:participants").value.forEach((participant) => {
|
||||
//all participants that aren't roles/admins => readonly (OR non-viewable when enabled)
|
||||
if (participant.type == "user"){
|
||||
if (generalConfig.data.system.removeParticipantsOnClose) permissions.push({
|
||||
@@ -105,7 +105,7 @@ export const registerActions = async () => {
|
||||
const ticketMessage = await opendiscord.tickets.getTicketMessage(ticket)
|
||||
if (ticketMessage){
|
||||
try{
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
}catch(e){
|
||||
opendiscord.log("Unable to edit ticket message on ticket closing!","error",[
|
||||
{key:"channel",value:"#"+channel.name},
|
||||
@@ -118,24 +118,24 @@ export const registerActions = async () => {
|
||||
}
|
||||
|
||||
//reply with new message
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("openticket:close-message").build(source,{guild,channel,user,ticket,reason})).message)
|
||||
ticket.get("openticket:busy").value = false
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:close-message").build(source,{guild,channel,user,ticket,reason})).message)
|
||||
ticket.get("opendiscord:busy").value = false
|
||||
await opendiscord.events.get("afterTicketClosed").emit([ticket,user,channel,reason])
|
||||
}),
|
||||
new api.ODWorker("openticket:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason} = params
|
||||
|
||||
//to logs
|
||||
if (generalConfig.data.system.logs.enabled && generalConfig.data.system.messages.closing.logs){
|
||||
const logChannel = opendiscord.posts.get("openticket:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("openticket:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"close",reason,additionalData:null}))
|
||||
const logChannel = opendiscord.posts.get("opendiscord:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"close",reason,additionalData:null}))
|
||||
}
|
||||
|
||||
//to dm
|
||||
const creator = await opendiscord.tickets.getTicketUser(ticket,"creator")
|
||||
if (creator && generalConfig.data.system.messages.closing.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("openticket:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"close",reason,additionalData:null}))
|
||||
if (creator && generalConfig.data.system.messages.closing.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"close",reason,additionalData:null}))
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",0,(instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",0,(instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket} = params
|
||||
|
||||
opendiscord.log(user.displayName+" closed a ticket!","info",[
|
||||
@@ -148,188 +148,188 @@ export const registerActions = async () => {
|
||||
])
|
||||
})
|
||||
])
|
||||
opendiscord.actions.get("openticket:close-ticket").workers.backupWorker = new api.ODWorker("openticket:cancel-busy",0,(instance,params) => {
|
||||
opendiscord.actions.get("opendiscord:close-ticket").workers.backupWorker = new api.ODWorker("opendiscord:cancel-busy",0,(instance,params) => {
|
||||
//set busy to false in case of crash or cancel
|
||||
params.ticket.get("openticket:busy").value = false
|
||||
params.ticket.get("opendiscord:busy").value = false
|
||||
})
|
||||
}
|
||||
|
||||
export const registerVerifyBars = async () => {
|
||||
//CLOSE TICKET TICKET MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:close-ticket-ticket-message",opendiscord.builders.messages.getSafe("openticket:verifybar-ticket-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:close-ticket-ticket-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:close-ticket-ticket-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-ticket-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:close-ticket-ticket-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.close
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:close-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:close-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
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("openticket:closed").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.close"),layout:"simple"}))
|
||||
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("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start closing ticket
|
||||
if (params.data == "reason"){
|
||||
//close with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:close-ticket-reason").build("ticket-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:close-ticket-reason").build("ticket-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//close without reason
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("openticket:close-ticket").run("ticket-message",{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
await opendiscord.actions.get("opendiscord:close-ticket").run("ticket-message",{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}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:close-ticket-ticket-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-ticket-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:close-ticket-ticket-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-ticket-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
})
|
||||
])
|
||||
|
||||
//CLOSE TICKET REOPEN MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:close-ticket-reopen-message",opendiscord.builders.messages.getSafe("openticket:verifybar-reopen-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:close-ticket-reopen-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:close-ticket-reopen-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-reopen-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:close-ticket-reopen-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.close
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:close-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:close-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
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("openticket:closed").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.close"),layout:"simple"}))
|
||||
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("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start closing ticket
|
||||
if (params.data == "reason"){
|
||||
//close with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:close-ticket-reason").build("reopen-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:close-ticket-reason").build("reopen-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//close without reason
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("openticket:close-ticket").run("reopen-message",{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:close-message").build("reopen-message",{guild,channel,user,ticket,reason:null}))
|
||||
await opendiscord.actions.get("opendiscord:close-ticket").run("reopen-message",{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:close-message").build("reopen-message",{guild,channel,user,ticket,reason:null}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:close-ticket-reopen-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-reopen-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:close-ticket-reopen-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-reopen-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
const {verifybarMessage} = params
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
const rawReason = (verifybarMessage && verifybarMessage.embeds[0] && verifybarMessage.embeds[0].fields[0]) ? verifybarMessage.embeds[0].fields[0].value : null
|
||||
const reason = (rawReason == null) ? null : rawReason.substring(3,rawReason.length-3)
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:reopen-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:reopen-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
})
|
||||
])
|
||||
}
|
||||
+49
-49
@@ -4,22 +4,22 @@
|
||||
import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("openticket:general")
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("openticket:create-ticket"))
|
||||
opendiscord.actions.get("openticket:create-ticket").workers.add([
|
||||
new api.ODWorker("openticket:create-ticket",3,async (instance,params,source,cancel) => {
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:create-ticket"))
|
||||
opendiscord.actions.get("opendiscord:create-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:create-ticket",3,async (instance,params,source,cancel) => {
|
||||
const {guild,user,answers,option} = params
|
||||
|
||||
await opendiscord.events.get("onTicketCreate").emit([user])
|
||||
await opendiscord.events.get("onTicketChannelCreation").emit([option,user])
|
||||
|
||||
//get channel properties
|
||||
const channelPrefix = option.get("openticket:channel-prefix").value
|
||||
const channelCategory = option.get("openticket:channel-category").value
|
||||
const channelBackupCategory = option.get("openticket:channel-category-backup").value
|
||||
const channelDescription = option.get("openticket:channel-description").value
|
||||
const channelPrefix = option.get("opendiscord:channel-prefix").value
|
||||
const channelCategory = option.get("opendiscord:channel-category").value
|
||||
const channelBackupCategory = option.get("opendiscord:channel-category-backup").value
|
||||
const channelDescription = option.get("opendiscord:channel-description").value
|
||||
const channelSuffix = opendiscord.options.suffix.getSuffixFromOption(option,user)
|
||||
const channelName = channelPrefix+channelSuffix
|
||||
|
||||
@@ -65,9 +65,9 @@ export const registerActions = async () => {
|
||||
allow:[],
|
||||
deny:["ViewChannel","SendMessages","ReadMessageHistory"]
|
||||
}]
|
||||
const globalAdmins = opendiscord.configs.get("openticket:general").data.globalAdmins
|
||||
const optionAdmins = option.get("openticket:admins").value
|
||||
const readonlyAdmins = option.get("openticket:admins-readonly").value
|
||||
const globalAdmins = opendiscord.configs.get("opendiscord:general").data.globalAdmins
|
||||
const optionAdmins = option.get("opendiscord:admins").value
|
||||
const readonlyAdmins = option.get("opendiscord:admins-readonly").value
|
||||
|
||||
globalAdmins.forEach((admin) => {
|
||||
permissions.push({
|
||||
@@ -127,40 +127,40 @@ export const registerActions = async () => {
|
||||
|
||||
//create ticket
|
||||
const ticket = new api.ODTicket(channel.id,option,[
|
||||
new api.ODTicketData("openticket:busy",false),
|
||||
new api.ODTicketData("openticket:ticket-message",null),
|
||||
new api.ODTicketData("openticket:participants",participants),
|
||||
new api.ODTicketData("openticket:channel-suffix",channelSuffix),
|
||||
new api.ODTicketData("opendiscord:busy",false),
|
||||
new api.ODTicketData("opendiscord:ticket-message",null),
|
||||
new api.ODTicketData("opendiscord:participants",participants),
|
||||
new api.ODTicketData("opendiscord:channel-suffix",channelSuffix),
|
||||
|
||||
new api.ODTicketData("openticket:open",true),
|
||||
new api.ODTicketData("openticket:opened-by",user.id),
|
||||
new api.ODTicketData("openticket:opened-on",new Date().getTime()),
|
||||
new api.ODTicketData("openticket:closed",false),
|
||||
new api.ODTicketData("openticket:closed-by",null),
|
||||
new api.ODTicketData("openticket:closed-on",null),
|
||||
new api.ODTicketData("openticket:claimed",false),
|
||||
new api.ODTicketData("openticket:claimed-by",null),
|
||||
new api.ODTicketData("openticket:claimed-on",null),
|
||||
new api.ODTicketData("openticket:pinned",false),
|
||||
new api.ODTicketData("openticket:pinned-by",null),
|
||||
new api.ODTicketData("openticket:pinned-on",null),
|
||||
new api.ODTicketData("openticket:for-deletion",false),
|
||||
new api.ODTicketData("opendiscord:open",true),
|
||||
new api.ODTicketData("opendiscord:opened-by",user.id),
|
||||
new api.ODTicketData("opendiscord:opened-on",new Date().getTime()),
|
||||
new api.ODTicketData("opendiscord:closed",false),
|
||||
new api.ODTicketData("opendiscord:closed-by",null),
|
||||
new api.ODTicketData("opendiscord:closed-on",null),
|
||||
new api.ODTicketData("opendiscord:claimed",false),
|
||||
new api.ODTicketData("opendiscord:claimed-by",null),
|
||||
new api.ODTicketData("opendiscord:claimed-on",null),
|
||||
new api.ODTicketData("opendiscord:pinned",false),
|
||||
new api.ODTicketData("opendiscord:pinned-by",null),
|
||||
new api.ODTicketData("opendiscord:pinned-on",null),
|
||||
new api.ODTicketData("opendiscord:for-deletion",false),
|
||||
|
||||
new api.ODTicketData("openticket:category",category),
|
||||
new api.ODTicketData("openticket:category-mode",categoryMode),
|
||||
new api.ODTicketData("opendiscord:category",category),
|
||||
new api.ODTicketData("opendiscord:category-mode",categoryMode),
|
||||
|
||||
new api.ODTicketData("openticket:autoclose-enabled",option.get("openticket:autoclose-enable-hours").value),
|
||||
new api.ODTicketData("openticket:autoclose-hours",(option.get("openticket:autoclose-enable-hours").value ? option.get("openticket:autoclose-hours").value : 0)),
|
||||
new api.ODTicketData("openticket:autoclosed",false),
|
||||
new api.ODTicketData("openticket:autodelete-enabled",option.get("openticket:autodelete-enable-days").value),
|
||||
new api.ODTicketData("openticket:autodelete-days",(option.get("openticket:autodelete-enable-days").value ? option.get("openticket:autodelete-days").value : 0)),
|
||||
new api.ODTicketData("opendiscord:autoclose-enabled",option.get("opendiscord:autoclose-enable-hours").value),
|
||||
new api.ODTicketData("opendiscord:autoclose-hours",(option.get("opendiscord:autoclose-enable-hours").value ? option.get("opendiscord:autoclose-hours").value : 0)),
|
||||
new api.ODTicketData("opendiscord:autoclosed",false),
|
||||
new api.ODTicketData("opendiscord:autodelete-enabled",option.get("opendiscord:autodelete-enable-days").value),
|
||||
new api.ODTicketData("opendiscord:autodelete-days",(option.get("opendiscord:autodelete-enable-days").value ? option.get("opendiscord:autodelete-days").value : 0)),
|
||||
|
||||
new api.ODTicketData("openticket:answers",answers)
|
||||
new api.ODTicketData("opendiscord:answers",answers)
|
||||
])
|
||||
|
||||
//manage stats
|
||||
await opendiscord.stats.get("openticket:global").setStat("openticket:tickets-created",1,"increase")
|
||||
await opendiscord.stats.get("openticket:user").setStat("openticket:tickets-created",user.id,1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:global").setStat("opendiscord:tickets-created",1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:user").setStat("opendiscord:tickets-created",user.id,1,"increase")
|
||||
|
||||
//manage bot permissions
|
||||
await opendiscord.events.get("onTicketPermissionsCreated").emit([option,opendiscord.permissions,channel,user])
|
||||
@@ -172,7 +172,7 @@ export const registerActions = async () => {
|
||||
instance.ticket = ticket
|
||||
opendiscord.tickets.add(ticket)
|
||||
}),
|
||||
new api.ODWorker("openticket:send-ticket-message",2,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:send-ticket-message",2,async (instance,params,source,cancel) => {
|
||||
const {guild,user,answers,option} = params
|
||||
const {ticket,channel} = instance
|
||||
|
||||
@@ -180,37 +180,37 @@ export const registerActions = async () => {
|
||||
|
||||
await opendiscord.events.get("onTicketMainMessageCreated").emit([ticket,channel,user])
|
||||
//check if ticket message is enabled
|
||||
if (!option.get("openticket:ticket-message-enabled").value) return
|
||||
if (!option.get("opendiscord:ticket-message-enabled").value) return
|
||||
try {
|
||||
const msg = await channel.send((await opendiscord.builders.messages.getSafe("openticket:ticket-message").build(source,{guild,channel,user,ticket})).message)
|
||||
const msg = await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build(source,{guild,channel,user,ticket})).message)
|
||||
|
||||
ticket.get("openticket:ticket-message").value = msg.id
|
||||
ticket.get("opendiscord:ticket-message").value = msg.id
|
||||
|
||||
//manage stats
|
||||
await opendiscord.stats.get("openticket:ticket").setStat("openticket:messages-sent",ticket.id.value,1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:ticket").setStat("opendiscord:messages-sent",ticket.id.value,1,"increase")
|
||||
|
||||
await opendiscord.events.get("afterTicketMainMessageCreated").emit([ticket,msg,channel,user])
|
||||
}catch(err){
|
||||
process.emit("uncaughtException",err)
|
||||
//something went wrong while sending the ticket message
|
||||
channel.send((await opendiscord.builders.messages.getSafe("openticket:error").build("other",{guild,channel,user,error:"Ticket Message: Creation Error!\n=> Ticket Is Still Created Succesfully",layout:"advanced"})).message)
|
||||
channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error").build("other",{guild,channel,user,error:"Ticket Message: Creation Error!\n=> Ticket Is Still Created Succesfully",layout:"advanced"})).message)
|
||||
}
|
||||
await opendiscord.events.get("afterTicketCreated").emit([ticket,user,channel])
|
||||
}),
|
||||
new api.ODWorker("openticket:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
const {guild,user,answers,option} = params
|
||||
const {ticket,channel} = instance
|
||||
|
||||
//to logs
|
||||
if (generalConfig.data.system.logs.enabled && generalConfig.data.system.messages.creation.logs){
|
||||
const logChannel = opendiscord.posts.get("openticket:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("openticket:ticket-created-logs").build(source,{guild,channel,user,ticket}))
|
||||
const logChannel = opendiscord.posts.get("opendiscord:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("opendiscord:ticket-created-logs").build(source,{guild,channel,user,ticket}))
|
||||
}
|
||||
|
||||
//to dm
|
||||
if (generalConfig.data.system.messages.creation.dm) await opendiscord.client.sendUserDm(user,await opendiscord.builders.messages.getSafe("openticket:ticket-created-dm").build(source,{guild,channel,user,ticket}))
|
||||
if (generalConfig.data.system.messages.creation.dm) await opendiscord.client.sendUserDm(user,await opendiscord.builders.messages.getSafe("opendiscord:ticket-created-dm").build(source,{guild,channel,user,ticket}))
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",0,(instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",0,(instance,params,source,cancel) => {
|
||||
const {guild,user,answers,option} = params
|
||||
const {ticket,channel} = instance
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("openticket:create-ticket-permissions"))
|
||||
opendiscord.actions.get("openticket:create-ticket-permissions").workers.add([
|
||||
new api.ODWorker("openticket:check-blacklist",4,(instance,params,source,cancel) => {
|
||||
if (!params.option.get("openticket:allow-blacklisted-users").value && opendiscord.blacklist.exists(params.user.id)){
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:create-ticket-permissions"))
|
||||
opendiscord.actions.get("opendiscord:create-ticket-permissions").workers.add([
|
||||
new api.ODWorker("opendiscord:check-blacklist",4,(instance,params,source,cancel) => {
|
||||
if (!params.option.get("opendiscord:allow-blacklisted-users").value && opendiscord.blacklist.exists(params.user.id)){
|
||||
instance.valid = false
|
||||
instance.reason = "blacklist"
|
||||
opendiscord.log(params.user.displayName+" tried to create a ticket but is blacklisted!","info",[
|
||||
@@ -19,8 +19,8 @@ export const registerActions = async () => {
|
||||
return cancel()
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:check-cooldown",3,(instance,params,source,cancel) => {
|
||||
const cooldown = opendiscord.cooldowns.get("openticket:option-cooldown_"+params.option.id.value)
|
||||
new api.ODWorker("opendiscord:check-cooldown",3,(instance,params,source,cancel) => {
|
||||
const cooldown = opendiscord.cooldowns.get("opendiscord:option-cooldown_"+params.option.id.value)
|
||||
if (cooldown && cooldown instanceof api.ODTimeoutCooldown && cooldown.use(params.user.id)){
|
||||
instance.valid = false
|
||||
instance.reason = "cooldown"
|
||||
@@ -36,13 +36,13 @@ export const registerActions = async () => {
|
||||
return cancel()
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:check-global-limits",2,(instance,params,source,cancel) => {
|
||||
const generalConfig = opendiscord.configs.get("openticket:general")
|
||||
new api.ODWorker("opendiscord:check-global-limits",2,(instance,params,source,cancel) => {
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
if (!generalConfig.data.system.limits.enabled) return
|
||||
|
||||
const allTickets = opendiscord.tickets.getAll()
|
||||
const globalTicketCount = allTickets.length
|
||||
const userTickets = opendiscord.tickets.getFiltered((ticket) => ticket.exists("openticket:opened-by") && (ticket.get("openticket:opened-by").value == params.user.id))
|
||||
const userTickets = opendiscord.tickets.getFiltered((ticket) => ticket.exists("opendiscord:opened-by") && (ticket.get("opendiscord:opened-by").value == params.user.id))
|
||||
const userTicketCount = userTickets.length
|
||||
|
||||
if (globalTicketCount >= generalConfig.data.system.limits.globalMaximum){
|
||||
@@ -67,15 +67,15 @@ export const registerActions = async () => {
|
||||
return cancel()
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:check-option-limits",1,(instance,params,source,cancel) => {
|
||||
if (!params.option.exists("openticket:limits-enabled") || !params.option.get("openticket:limits-enabled").value) return
|
||||
new api.ODWorker("opendiscord:check-option-limits",1,(instance,params,source,cancel) => {
|
||||
if (!params.option.exists("opendiscord:limits-enabled") || !params.option.get("opendiscord:limits-enabled").value) return
|
||||
|
||||
const allTickets = opendiscord.tickets.getFiltered((ticket) => ticket.option.id.value == params.option.id.value)
|
||||
const globalTicketCount = allTickets.length
|
||||
const userTickets = opendiscord.tickets.getFiltered((ticket) => ticket.option.id.value == params.option.id.value && ticket.exists("openticket:opened-by") && (ticket.get("openticket:opened-by").value == params.user.id))
|
||||
const userTickets = opendiscord.tickets.getFiltered((ticket) => ticket.option.id.value == params.option.id.value && ticket.exists("opendiscord:opened-by") && (ticket.get("opendiscord:opened-by").value == params.user.id))
|
||||
const userTicketCount = userTickets.length
|
||||
|
||||
if (globalTicketCount >= params.option.get("openticket:limits-maximum-global").value){
|
||||
if (globalTicketCount >= params.option.get("opendiscord:limits-maximum-global").value){
|
||||
instance.valid = false
|
||||
instance.reason = "option-limit"
|
||||
opendiscord.log(params.user.displayName+" tried to create a ticket, but reached the limit!","info",[
|
||||
@@ -85,7 +85,7 @@ export const registerActions = async () => {
|
||||
{key:"limit",value:"option"}
|
||||
])
|
||||
return cancel()
|
||||
}else if (userTicketCount >= params.option.get("openticket:limits-maximum-user").value){
|
||||
}else if (userTicketCount >= params.option.get("opendiscord:limits-maximum-user").value){
|
||||
instance.valid = false
|
||||
instance.reason = "option-user-limit"
|
||||
opendiscord.log(params.user.displayName+" tried to create a ticket, but reached the limit!","info",[
|
||||
@@ -97,7 +97,7 @@ export const registerActions = async () => {
|
||||
return cancel()
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:valid",0,(instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:valid",0,(instance,params,source,cancel) => {
|
||||
instance.valid = true
|
||||
instance.reason = null
|
||||
cancel()
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
const transcriptConfig = opendiscord.configs.get("openticket:transcripts")
|
||||
const transcriptConfig = opendiscord.configs.get("opendiscord:transcripts")
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("openticket:create-transcript"))
|
||||
opendiscord.actions.get("openticket:create-transcript").workers.add([
|
||||
new api.ODWorker("openticket:select-compiler",4,async (instance,params,source,cancel) => {
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:create-transcript"))
|
||||
opendiscord.actions.get("opendiscord:create-transcript").workers.add([
|
||||
new api.ODWorker("opendiscord:select-compiler",4,async (instance,params,source,cancel) => {
|
||||
const {channel,user,ticket} = params
|
||||
if (channel.type != discord.ChannelType.GuildText) return cancel()
|
||||
if (!transcriptConfig.data.general.enabled) return cancel()
|
||||
@@ -26,10 +26,10 @@ export const registerActions = async () => {
|
||||
instance.participants = participants
|
||||
|
||||
//select transcript compiler
|
||||
if (transcriptConfig.data.general.mode == "text") instance.compiler = opendiscord.transcripts.get("openticket:text-compiler")
|
||||
else if (transcriptConfig.data.general.mode == "html") instance.compiler = opendiscord.transcripts.get("openticket:html-compiler")
|
||||
if (transcriptConfig.data.general.mode == "text") instance.compiler = opendiscord.transcripts.get("opendiscord:text-compiler")
|
||||
else if (transcriptConfig.data.general.mode == "html") instance.compiler = opendiscord.transcripts.get("opendiscord:html-compiler")
|
||||
}),
|
||||
new api.ODWorker("openticket:init-transcript",3,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:init-transcript",3,async (instance,params,source,cancel) => {
|
||||
const {channel,user,ticket} = params
|
||||
if (channel.type != discord.ChannelType.GuildText) return cancel()
|
||||
if (!transcriptConfig.data.general.enabled) return cancel()
|
||||
@@ -41,7 +41,7 @@ export const registerActions = async () => {
|
||||
const result = await instance.compiler.init(ticket,channel,user)
|
||||
if (result.success && result.pendingMessage && transcriptConfig.data.general.enableChannel){
|
||||
//send init message to channel
|
||||
const post = opendiscord.posts.get("openticket:transcripts")
|
||||
const post = opendiscord.posts.get("opendiscord:transcripts")
|
||||
if (post){
|
||||
instance.pendingMessage = await post.send(result.pendingMessage)
|
||||
}
|
||||
@@ -59,7 +59,7 @@ export const registerActions = async () => {
|
||||
}
|
||||
await opendiscord.events.get("afterTranscriptInitiated").emit([opendiscord.transcripts,ticket,channel,user])
|
||||
}),
|
||||
new api.ODWorker("openticket:compile-transcript",2,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:compile-transcript",2,async (instance,params,source,cancel) => {
|
||||
const {channel,user,ticket} = params
|
||||
if (channel.type != discord.ChannelType.GuildText) return cancel()
|
||||
if (!instance.compiler){
|
||||
@@ -89,7 +89,7 @@ export const registerActions = async () => {
|
||||
}
|
||||
await opendiscord.events.get("afterTranscriptCompiled").emit([opendiscord.transcripts,ticket,channel,user])
|
||||
}),
|
||||
new api.ODWorker("openticket:ready-transcript",1,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:ready-transcript",1,async (instance,params,source,cancel) => {
|
||||
if (!instance.result){
|
||||
instance.success = false
|
||||
cancel()
|
||||
@@ -110,7 +110,7 @@ export const registerActions = async () => {
|
||||
instance.pendingMessage.message.edit(channelMessage.message)
|
||||
}else{
|
||||
//send ready message to channel
|
||||
const post = opendiscord.posts.get("openticket:transcripts")
|
||||
const post = opendiscord.posts.get("opendiscord:transcripts")
|
||||
if (post) await post.send(channelMessage)
|
||||
}
|
||||
}
|
||||
@@ -145,11 +145,11 @@ export const registerActions = async () => {
|
||||
})
|
||||
|
||||
//update stats
|
||||
await opendiscord.stats.get("openticket:global").setStat("openticket:transcripts-created",1,"increase")
|
||||
await opendiscord.stats.get("openticket:user").setStat("openticket:transcripts-created",params.user.id,1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:global").setStat("opendiscord:transcripts-created",1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:user").setStat("opendiscord:transcripts-created",params.user.id,1,"increase")
|
||||
await opendiscord.events.get("afterTranscriptCreated").emit([opendiscord.transcripts,instance.result.ticket,instance.result.channel,instance.result.user])
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",0,(instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",0,(instance,params,source,cancel) => {
|
||||
const {user,channel,ticket} = params
|
||||
opendiscord.log(user.displayName+" created a transcript!","info",[
|
||||
{key:"user",value:user.username},
|
||||
|
||||
+111
-111
@@ -4,26 +4,26 @@
|
||||
import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("openticket:general")
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("openticket:delete-ticket"))
|
||||
opendiscord.actions.get("openticket:delete-ticket").workers.add([
|
||||
new api.ODWorker("openticket:delete-ticket",3,async (instance,params,source,cancel) => {
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:delete-ticket"))
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:delete-ticket",3,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason} = params
|
||||
if (channel.isThread()) throw new api.ODSystemError("Unable to delete ticket! Open Ticket doesn't support threads!")
|
||||
|
||||
await opendiscord.events.get("onTicketDelete").emit([ticket,user,channel,reason])
|
||||
|
||||
//update ticket
|
||||
ticket.get("openticket:for-deletion").value = true
|
||||
ticket.get("openticket:busy").value = true
|
||||
ticket.get("opendiscord:for-deletion").value = true
|
||||
ticket.get("opendiscord:busy").value = true
|
||||
|
||||
//update ticket message
|
||||
const ticketMessage = await opendiscord.tickets.getTicketMessage(ticket)
|
||||
if (ticketMessage){
|
||||
try{
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
}catch(e){
|
||||
opendiscord.log("Unable to edit ticket message on ticket deletion!","error",[
|
||||
{key:"channel",value:"#"+channel.name},
|
||||
@@ -35,20 +35,20 @@ export const registerActions = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("openticket:delete-message").build(source,{guild,channel,user,ticket,reason})).message)
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:delete-message").build(source,{guild,channel,user,ticket,reason})).message)
|
||||
|
||||
//create transcript
|
||||
if (!params.withoutTranscript){
|
||||
const transcriptRes = await opendiscord.actions.get("openticket:create-transcript").run(source,{guild,channel,user,ticket})
|
||||
const transcriptRes = await opendiscord.actions.get("opendiscord:create-transcript").run(source,{guild,channel,user,ticket})
|
||||
//transcript failure
|
||||
if (typeof transcriptRes.success == "boolean" && !transcriptRes.success && transcriptRes.compiler){
|
||||
const {compiler} = transcriptRes
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("openticket:transcript-error").build(source,{guild,channel,user,ticket,compiler,reason:transcriptRes.errorReason ?? null})).message)
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:transcript-error").build(source,{guild,channel,user,ticket,compiler,reason:transcriptRes.errorReason ?? null})).message)
|
||||
.catch((reason) => opendiscord.log("Unable to send transcript failure to ticket channel!","error",[{key:"id",value:channel.id}]))
|
||||
|
||||
//undo deletion
|
||||
ticket.get("openticket:for-deletion").value = false
|
||||
ticket.get("openticket:busy").value = false
|
||||
ticket.get("opendiscord:for-deletion").value = false
|
||||
ticket.get("opendiscord:busy").value = false
|
||||
opendiscord.log("Canceled ticket deletion because of transcript system malfunction!","warning",[
|
||||
{key:"compiler",value:compiler.id.value},
|
||||
{key:"reason",value:transcriptRes.errorReason ?? "/"},
|
||||
@@ -58,8 +58,8 @@ export const registerActions = async () => {
|
||||
}
|
||||
|
||||
//update stats
|
||||
await opendiscord.stats.get("openticket:global").setStat("openticket:tickets-deleted",1,"increase")
|
||||
await opendiscord.stats.get("openticket:user").setStat("openticket:tickets-deleted",user.id,1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:global").setStat("opendiscord:tickets-deleted",1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:user").setStat("opendiscord:tickets-deleted",user.id,1,"increase")
|
||||
|
||||
//delete ticket from manager
|
||||
opendiscord.tickets.remove(ticket.id)
|
||||
@@ -67,21 +67,21 @@ export const registerActions = async () => {
|
||||
//delete permissions from manager
|
||||
await (await import("../data/framework/permissionLoader.js")).removeTicketPermissions(ticket)
|
||||
}),
|
||||
new api.ODWorker("openticket:discord-logs",2,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:discord-logs",2,async (instance,params,source,cancel) => {
|
||||
//logs before channel deletion => channel might still be used in log embeds
|
||||
const {guild,channel,user,ticket,reason} = params
|
||||
|
||||
//to logs
|
||||
if (generalConfig.data.system.logs.enabled && generalConfig.data.system.messages.deleting.logs){
|
||||
const logChannel = opendiscord.posts.get("openticket:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("openticket:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"delete",reason,additionalData:null}))
|
||||
const logChannel = opendiscord.posts.get("opendiscord:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"delete",reason,additionalData:null}))
|
||||
}
|
||||
|
||||
//to dm
|
||||
const creator = await opendiscord.tickets.getTicketUser(ticket,"creator")
|
||||
if (creator && generalConfig.data.system.messages.deleting.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("openticket:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"delete",reason,additionalData:null}))
|
||||
if (creator && generalConfig.data.system.messages.deleting.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"delete",reason,additionalData:null}))
|
||||
}),
|
||||
new api.ODWorker("openticket:delete-channel",1,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:delete-channel",1,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason} = params
|
||||
//delete channel & events
|
||||
await opendiscord.events.get("onTicketChannelDeletion").emit([ticket,channel,user])
|
||||
@@ -93,7 +93,7 @@ export const registerActions = async () => {
|
||||
|
||||
await opendiscord.events.get("afterTicketDeleted").emit([ticket,user,reason])
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",0,(instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",0,(instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket} = params
|
||||
|
||||
opendiscord.log(user.displayName+" deleted a ticket!","info",[
|
||||
@@ -107,360 +107,360 @@ export const registerActions = async () => {
|
||||
])
|
||||
})
|
||||
])
|
||||
opendiscord.actions.get("openticket:delete-ticket").workers.backupWorker = new api.ODWorker("openticket:cancel-busy",0,(instance,params) => {
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").workers.backupWorker = new api.ODWorker("opendiscord:cancel-busy",0,(instance,params) => {
|
||||
//set busy to false in case of crash or cancel
|
||||
params.ticket.get("openticket:busy").value = false
|
||||
params.ticket.get("openticket:for-deletion").value = false
|
||||
params.ticket.get("opendiscord:busy").value = false
|
||||
params.ticket.get("opendiscord:for-deletion").value = false
|
||||
})
|
||||
}
|
||||
|
||||
export const registerVerifyBars = async () => {
|
||||
//DELETE TICKET TICKET MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:delete-ticket-ticket-message",opendiscord.builders.messages.getSafe("openticket:verifybar-ticket-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:delete-ticket-ticket-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:delete-ticket-ticket-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-ticket-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:delete-ticket-ticket-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.delete
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:delete-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:delete-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
//return when busy
|
||||
if (ticket.get("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start deleting ticket
|
||||
if (params.data == "reason"){
|
||||
//delete with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:delete-ticket-reason").build("ticket-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:delete-ticket-reason").build("ticket-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//delete without reason
|
||||
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("openticket:delete-ticket").run("ticket-message",{guild,channel,user,ticket,reason:null,sendMessage:true,withoutTranscript:(params.data == "no-transcript")})
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run("ticket-message",{guild,channel,user,ticket,reason:null,sendMessage:true,withoutTranscript:(params.data == "no-transcript")})
|
||||
//update ticket (for ticket message) => no-await doesn't wait for the action to set this variable
|
||||
ticket.get("openticket:for-deletion").value = true
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
ticket.get("opendiscord:for-deletion").value = true
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:delete-ticket-ticket-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-ticket-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:delete-ticket-ticket-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-ticket-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
})
|
||||
])
|
||||
|
||||
//DELETE TICKET CLOSE MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:delete-ticket-close-message",opendiscord.builders.messages.getSafe("openticket:verifybar-close-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:delete-ticket-close-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:delete-ticket-close-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-close-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:delete-ticket-close-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.delete
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:delete-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:delete-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
//return when busy
|
||||
if (ticket.get("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start deleting ticket
|
||||
if (params.data == "reason"){
|
||||
//delete with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:delete-ticket-reason").build("close-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:delete-ticket-reason").build("close-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//delete without reason
|
||||
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("openticket:delete-ticket").run("close-message",{guild,channel,user,ticket,reason:null,sendMessage:false,withoutTranscript:(params.data == "no-transcript")})
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run("close-message",{guild,channel,user,ticket,reason:null,sendMessage:false,withoutTranscript:(params.data == "no-transcript")})
|
||||
//update ticket (for ticket message) => no-await doesn't wait for the action to set this variable
|
||||
ticket.get("openticket:for-deletion").value = true
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:delete-message").build("close-message",{guild,channel,user,ticket,reason:null}))
|
||||
ticket.get("opendiscord:for-deletion").value = true
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:delete-message").build("close-message",{guild,channel,user,ticket,reason:null}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:delete-ticket-close-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-close-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:delete-ticket-close-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-close-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
const {verifybarMessage} = params
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
const rawReason = (verifybarMessage && verifybarMessage.embeds[0] && verifybarMessage.embeds[0].fields[0]) ? verifybarMessage.embeds[0].fields[0].value : null
|
||||
const reason = (rawReason == null) ? null : rawReason.substring(3,rawReason.length-3)
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:close-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:close-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
})
|
||||
])
|
||||
|
||||
//DELETE TICKET REOPEN MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:delete-ticket-reopen-message",opendiscord.builders.messages.getSafe("openticket:verifybar-reopen-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:delete-ticket-reopen-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:delete-ticket-reopen-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-reopen-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:delete-ticket-reopen-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.delete
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:delete-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:delete-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
//return when busy
|
||||
if (ticket.get("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start deleting ticket
|
||||
if (params.data == "reason"){
|
||||
//delete with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:delete-ticket-reason").build("reopen-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:delete-ticket-reason").build("reopen-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//delete without reason
|
||||
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("openticket:delete-ticket").run("reopen-message",{guild,channel,user,ticket,reason:null,sendMessage:false,withoutTranscript:(params.data == "no-transcript")})
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run("reopen-message",{guild,channel,user,ticket,reason:null,sendMessage:false,withoutTranscript:(params.data == "no-transcript")})
|
||||
//update ticket (for ticket message) => no-await doesn't wait for the action to set this variable
|
||||
ticket.get("openticket:for-deletion").value = true
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:delete-message").build("reopen-message",{guild,channel,user,ticket,reason:null}))
|
||||
ticket.get("opendiscord:for-deletion").value = true
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:delete-message").build("reopen-message",{guild,channel,user,ticket,reason:null}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:delete-ticket-reopen-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-reopen-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:delete-ticket-reopen-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-reopen-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
const {verifybarMessage} = params
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
const rawReason = (verifybarMessage && verifybarMessage.embeds[0] && verifybarMessage.embeds[0].fields[0]) ? verifybarMessage.embeds[0].fields[0].value : null
|
||||
const reason = (rawReason == null) ? null : rawReason.substring(3,rawReason.length-3)
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:reopen-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:reopen-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
})
|
||||
])
|
||||
|
||||
//DELETE TICKET AUTOCLOSE MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:delete-ticket-autoclose-message",opendiscord.builders.messages.getSafe("openticket:verifybar-autoclose-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:delete-ticket-autoclose-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:delete-ticket-autoclose-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-autoclose-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:delete-ticket-autoclose-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.delete
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:delete-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:delete-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
//return when busy
|
||||
if (ticket.get("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start deleting ticket
|
||||
if (params.data == "reason"){
|
||||
//delete with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:delete-ticket-reason").build("autoclose-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:delete-ticket-reason").build("autoclose-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//delete without reason
|
||||
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("openticket:delete-ticket").run("autoclose-message",{guild,channel,user,ticket,reason:null,sendMessage:false,withoutTranscript:(params.data == "no-transcript")})
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run("autoclose-message",{guild,channel,user,ticket,reason:null,sendMessage:false,withoutTranscript:(params.data == "no-transcript")})
|
||||
//update ticket (for ticket message) => no-await doesn't wait for the action to set this variable
|
||||
ticket.get("openticket:for-deletion").value = true
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:delete-message").build("autoclose-message",{guild,channel,user,ticket,reason:null}))
|
||||
ticket.get("opendiscord:for-deletion").value = true
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:delete-message").build("autoclose-message",{guild,channel,user,ticket,reason:null}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:delete-ticket-autoclose-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-autoclose-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:delete-ticket-autoclose-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-autoclose-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
const {verifybarMessage} = params
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:autoclose-message").build("other",{guild,channel,user,ticket}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:autoclose-message").build("other",{guild,channel,user,ticket}))
|
||||
})
|
||||
])
|
||||
}
|
||||
@@ -3,75 +3,75 @@
|
||||
///////////////////////////////////////
|
||||
import {opendiscord, api, utilities} from "../index"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("openticket:general")
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
|
||||
export const registerButtonResponders = async () => {
|
||||
//TRANSCRIPT ERROR RETRY
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("openticket:transcript-error-retry",/^od:transcript-error-retry_([^_]+)/))
|
||||
opendiscord.responders.buttons.get("openticket:transcript-error-retry").workers.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("opendiscord:transcript-error-retry",/^od:transcript-error-retry_([^_]+)/))
|
||||
opendiscord.responders.buttons.get("opendiscord:transcript-error-retry").workers.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.delete
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:delete-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:delete-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
const originalSource = instance.interaction.customId.split("_")[1]
|
||||
if (originalSource != "slash" && originalSource != "text" && originalSource != "ticket-message" && originalSource != "reopen-message" && originalSource != "close-message" && originalSource != "other") return
|
||||
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
//return when busy
|
||||
if (ticket.get("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start deleting ticket (without reason)
|
||||
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("openticket:delete-ticket").run(originalSource,{guild,channel,user,ticket,reason:"Transcript Error (Retried)",sendMessage:false,withoutTranscript:false})
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run(originalSource,{guild,channel,user,ticket,reason:"Transcript Error (Retried)",sendMessage:false,withoutTranscript:false})
|
||||
//update ticket (for ticket message) => no-await doesn't wait for the action to set this variable
|
||||
ticket.get("openticket:for-deletion").value = true
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:delete-message").build("other",{guild,channel,user,ticket,reason:"Transcript Error (Retried)"}))
|
||||
ticket.get("opendiscord:for-deletion").value = true
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:delete-message").build("other",{guild,channel,user,ticket,reason:"Transcript Error (Retried)"}))
|
||||
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",-1,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",-1,async (instance,params,source,cancel) => {
|
||||
const {user,channel} = instance
|
||||
if (channel.isDMBased()) return
|
||||
opendiscord.log(user.displayName+" retried deleting a ticket with transcript!","info",[
|
||||
@@ -85,71 +85,71 @@ export const registerButtonResponders = async () => {
|
||||
])
|
||||
|
||||
//TRANSCRIPT ERROR CONTINUE
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("openticket:transcript-error-continue",/^od:transcript-error-continue_([^_]+)/))
|
||||
opendiscord.responders.buttons.get("openticket:transcript-error-continue").workers.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("opendiscord:transcript-error-continue",/^od:transcript-error-continue_([^_]+)/))
|
||||
opendiscord.responders.buttons.get("opendiscord:transcript-error-continue").workers.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.delete
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:delete-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:delete-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
const originalSource = instance.interaction.customId.split("_")[1]
|
||||
if (originalSource != "slash" && originalSource != "text" && originalSource != "ticket-message" && originalSource != "reopen-message" && originalSource != "close-message" && originalSource != "other") return
|
||||
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
//return when busy
|
||||
if (ticket.get("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start deleting ticket (without reason)
|
||||
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("openticket:delete-ticket").run(originalSource,{guild,channel,user,ticket,reason:"Transcript Error (Continued)",sendMessage:false,withoutTranscript:true})
|
||||
opendiscord.actions.get("opendiscord:delete-ticket").run(originalSource,{guild,channel,user,ticket,reason:"Transcript Error (Continued)",sendMessage:false,withoutTranscript:true})
|
||||
//update ticket (for ticket message) => no-await doesn't wait for the action to set this variable
|
||||
ticket.get("openticket:for-deletion").value = true
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:delete-message").build("other",{guild,channel,user,ticket,reason:"Transcript Error (Continued)"}))
|
||||
ticket.get("opendiscord:for-deletion").value = true
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:delete-message").build("other",{guild,channel,user,ticket,reason:"Transcript Error (Continued)"}))
|
||||
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",-1,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",-1,async (instance,params,source,cancel) => {
|
||||
const {user,channel} = instance
|
||||
if (channel.isDMBased()) return
|
||||
opendiscord.log(user.displayName+" continued deleting a ticket without transcript!","info",[
|
||||
|
||||
@@ -5,9 +5,9 @@ import {opendiscord, api, utilities} from "../index"
|
||||
|
||||
export const registerButtonResponders = async () => {
|
||||
//VERIFYBAR SUCCESS
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("openticket:verifybar-success",/^od:verifybar-success_([^_]+)/))
|
||||
opendiscord.responders.buttons.get("openticket:verifybar-success").workers.add(
|
||||
new api.ODWorker("openticket:handle-verifybar",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("opendiscord:verifybar-success",/^od:verifybar-success_([^_]+)/))
|
||||
opendiscord.responders.buttons.get("opendiscord:verifybar-success").workers.add(
|
||||
new api.ODWorker("opendiscord:handle-verifybar",0,async (instance,params,source,cancel) => {
|
||||
const id = instance.interaction.customId.split("_")[1]
|
||||
const customData = instance.interaction.customId.split("_")[2] as string|undefined
|
||||
|
||||
@@ -18,9 +18,9 @@ export const registerButtonResponders = async () => {
|
||||
)
|
||||
|
||||
//VERIFYBAR FAILURE
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("openticket:verifybar-failure",/^od:verifybar-failure_([^_]+)/))
|
||||
opendiscord.responders.buttons.get("openticket:verifybar-failure").workers.add(
|
||||
new api.ODWorker("openticket:handle-verifybar",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.responders.buttons.add(new api.ODButtonResponder("opendiscord:verifybar-failure",/^od:verifybar-failure_([^_]+)/))
|
||||
opendiscord.responders.buttons.get("opendiscord:verifybar-failure").workers.add(
|
||||
new api.ODWorker("opendiscord:handle-verifybar",0,async (instance,params,source,cancel) => {
|
||||
const id = instance.interaction.customId.split("_")[1]
|
||||
const customData = instance.interaction.customId.split("_")[2] as string|undefined
|
||||
|
||||
|
||||
+33
-33
@@ -4,12 +4,12 @@
|
||||
import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("openticket:general")
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("openticket:move-ticket"))
|
||||
opendiscord.actions.get("openticket:move-ticket").workers.add([
|
||||
new api.ODWorker("openticket:move-ticket",2,async (instance,params,source,cancel) => {
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:move-ticket"))
|
||||
opendiscord.actions.get("opendiscord:move-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:move-ticket",2,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason,data} = params
|
||||
if (channel.isThread()) throw new api.ODSystemError("Unable to move ticket! Open Ticket doesn't support threads!")
|
||||
|
||||
@@ -17,18 +17,18 @@ export const registerActions = async () => {
|
||||
ticket.option = data
|
||||
|
||||
//update stats
|
||||
await opendiscord.stats.get("openticket:global").setStat("openticket:tickets-moved",1,"increase")
|
||||
await opendiscord.stats.get("openticket:user").setStat("openticket:tickets-moved",user.id,1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:global").setStat("opendiscord:tickets-moved",1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:user").setStat("opendiscord:tickets-moved",user.id,1,"increase")
|
||||
|
||||
//get new channel properties
|
||||
const channelPrefix = ticket.option.get("openticket:channel-prefix").value
|
||||
const channelSuffix = ticket.get("openticket:channel-suffix").value
|
||||
const channelCategory = ticket.option.get("openticket:channel-category").value
|
||||
const channelBackupCategory = ticket.option.get("openticket:channel-category-backup").value
|
||||
const rawClaimCategory = ticket.option.get("openticket:channel-categories-claimed").value.find((c) => c.user == user.id)
|
||||
const channelPrefix = ticket.option.get("opendiscord:channel-prefix").value
|
||||
const channelSuffix = ticket.get("opendiscord:channel-suffix").value
|
||||
const channelCategory = ticket.option.get("opendiscord:channel-category").value
|
||||
const channelBackupCategory = ticket.option.get("opendiscord:channel-category-backup").value
|
||||
const rawClaimCategory = ticket.option.get("opendiscord:channel-categories-claimed").value.find((c) => c.user == user.id)
|
||||
const claimCategory = (rawClaimCategory) ? rawClaimCategory.category : null
|
||||
const closeCategory = ticket.option.get("openticket:channel-category-closed").value
|
||||
const channelDescription = ticket.option.get("openticket:channel-description").value
|
||||
const closeCategory = ticket.option.get("opendiscord:channel-category-closed").value
|
||||
const channelDescription = ticket.option.get("opendiscord:channel-description").value
|
||||
const channelName = channelPrefix+channelSuffix
|
||||
|
||||
//handle category
|
||||
@@ -38,7 +38,7 @@ export const registerActions = async () => {
|
||||
//use claim category
|
||||
category = claimCategory
|
||||
categoryMode = "claimed"
|
||||
}else if (closeCategory != "" && ticket.get("openticket:closed").value){
|
||||
}else if (closeCategory != "" && ticket.get("opendiscord:closed").value){
|
||||
//use close category
|
||||
category = closeCategory
|
||||
categoryMode = "closed"
|
||||
@@ -79,8 +79,8 @@ export const registerActions = async () => {
|
||||
if (channel.parentId != category) await utilities.timedAwait(channel.setParent(category,{lockPermissions:false}),2500,(err) => {
|
||||
opendiscord.log("Failed to change channel category on ticket move","error")
|
||||
})
|
||||
ticket.get("openticket:category-mode").value = categoryMode
|
||||
ticket.get("openticket:category").value = category
|
||||
ticket.get("opendiscord:category-mode").value = categoryMode
|
||||
ticket.get("opendiscord:category").value = category
|
||||
}catch(e){
|
||||
opendiscord.log("Unable to move ticket to 'moved category'!","error",[
|
||||
{key:"channel",value:"#"+channel.name},
|
||||
@@ -97,9 +97,9 @@ export const registerActions = async () => {
|
||||
allow:[],
|
||||
deny:["ViewChannel","SendMessages","ReadMessageHistory"]
|
||||
}]
|
||||
const globalAdmins = opendiscord.configs.get("openticket:general").data.globalAdmins
|
||||
const optionAdmins = ticket.option.get("openticket:admins").value
|
||||
const readonlyAdmins = ticket.option.get("openticket:admins-readonly").value
|
||||
const globalAdmins = opendiscord.configs.get("opendiscord:general").data.globalAdmins
|
||||
const optionAdmins = ticket.option.get("opendiscord:admins").value
|
||||
const readonlyAdmins = ticket.option.get("opendiscord:admins-readonly").value
|
||||
|
||||
globalAdmins.forEach((admin) => {
|
||||
permissions.push({
|
||||
@@ -129,7 +129,7 @@ export const registerActions = async () => {
|
||||
})
|
||||
})
|
||||
//transfer all old user-participants over to the new ticket (creator & participants)
|
||||
ticket.get("openticket:participants").value.forEach((p) => {
|
||||
ticket.get("opendiscord:participants").value.forEach((p) => {
|
||||
if (p.type == "user") permissions.push({
|
||||
type:discord.OverwriteType.Member,
|
||||
id:p.id,
|
||||
@@ -151,8 +151,8 @@ export const registerActions = async () => {
|
||||
const id = permission.id as string
|
||||
participants.push({type,id})
|
||||
})
|
||||
ticket.get("openticket:participants").value = participants
|
||||
ticket.get("openticket:participants").refreshDatabase()
|
||||
ticket.get("opendiscord:participants").value = participants
|
||||
ticket.get("opendiscord:participants").refreshDatabase()
|
||||
|
||||
//rename channel (and give error when crashed)
|
||||
const originalName = channel.name
|
||||
@@ -161,7 +161,7 @@ export const registerActions = async () => {
|
||||
opendiscord.log("Failed to rename channel on ticket move","error")
|
||||
})
|
||||
}catch(err){
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("openticket:error-channel-rename").build("ticket-move",{guild,channel,user,originalName,newName:channelName})).message)
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-move",{guild,channel,user,originalName,newName:channelName})).message)
|
||||
}
|
||||
try{
|
||||
if (channel.type == discord.ChannelType.GuildText) channel.setTopic(channelDescription)
|
||||
@@ -171,7 +171,7 @@ export const registerActions = async () => {
|
||||
const ticketMessage = await opendiscord.tickets.getTicketMessage(ticket)
|
||||
if (ticketMessage){
|
||||
try{
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
}catch(e){
|
||||
opendiscord.log("Unable to edit ticket message on ticket renaming!","error",[
|
||||
{key:"channel",value:"#"+channel.name},
|
||||
@@ -184,24 +184,24 @@ export const registerActions = async () => {
|
||||
}
|
||||
|
||||
//reply with new message
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("openticket:move-message").build(source,{guild,channel,user,ticket,reason,data})).message)
|
||||
ticket.get("openticket:busy").value = false
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:move-message").build(source,{guild,channel,user,ticket,reason,data})).message)
|
||||
ticket.get("opendiscord:busy").value = false
|
||||
await opendiscord.events.get("afterTicketMoved").emit([ticket,user,channel,reason])
|
||||
}),
|
||||
new api.ODWorker("openticket:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason,data} = params
|
||||
|
||||
//to logs
|
||||
if (generalConfig.data.system.logs.enabled && generalConfig.data.system.messages.moving.logs){
|
||||
const logChannel = opendiscord.posts.get("openticket:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("openticket:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"move",reason,additionalData:data}))
|
||||
const logChannel = opendiscord.posts.get("opendiscord:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"move",reason,additionalData:data}))
|
||||
}
|
||||
|
||||
//to dm
|
||||
const creator = await opendiscord.tickets.getTicketUser(ticket,"creator")
|
||||
if (creator && generalConfig.data.system.messages.moving.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("openticket:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"move",reason,additionalData:data}))
|
||||
if (creator && generalConfig.data.system.messages.moving.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"move",reason,additionalData:data}))
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",0,(instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",0,(instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket} = params
|
||||
|
||||
opendiscord.log(user.displayName+" moved a ticket!","info",[
|
||||
@@ -214,8 +214,8 @@ export const registerActions = async () => {
|
||||
])
|
||||
})
|
||||
])
|
||||
opendiscord.actions.get("openticket:move-ticket").workers.backupWorker = new api.ODWorker("openticket:cancel-busy",0,(instance,params) => {
|
||||
opendiscord.actions.get("opendiscord:move-ticket").workers.backupWorker = new api.ODWorker("opendiscord:cancel-busy",0,(instance,params) => {
|
||||
//set busy to false in case of crash or cancel
|
||||
params.ticket.get("openticket:busy").value = false
|
||||
params.ticket.get("opendiscord:busy").value = false
|
||||
})
|
||||
}
|
||||
+67
-67
@@ -4,26 +4,26 @@
|
||||
import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("openticket:general")
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("openticket:pin-ticket"))
|
||||
opendiscord.actions.get("openticket:pin-ticket").workers.add([
|
||||
new api.ODWorker("openticket:pin-ticket",2,async (instance,params,source,cancel) => {
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:pin-ticket"))
|
||||
opendiscord.actions.get("opendiscord:pin-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:pin-ticket",2,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason} = params
|
||||
if (channel.isThread()) throw new api.ODSystemError("Unable to pin ticket! Open Ticket doesn't support threads!")
|
||||
|
||||
await opendiscord.events.get("onTicketPin").emit([ticket,user,channel,reason])
|
||||
|
||||
//update ticket
|
||||
ticket.get("openticket:pinned").value = true
|
||||
ticket.get("openticket:pinned-by").value = user.id
|
||||
ticket.get("openticket:pinned-on").value = new Date().getTime()
|
||||
ticket.get("openticket:busy").value = true
|
||||
ticket.get("opendiscord:pinned").value = true
|
||||
ticket.get("opendiscord:pinned-by").value = user.id
|
||||
ticket.get("opendiscord:pinned-on").value = new Date().getTime()
|
||||
ticket.get("opendiscord:busy").value = true
|
||||
|
||||
//update stats
|
||||
await opendiscord.stats.get("openticket:global").setStat("openticket:tickets-pinned",1,"increase")
|
||||
await opendiscord.stats.get("openticket:user").setStat("openticket:tickets-pinned",user.id,1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:global").setStat("opendiscord:tickets-pinned",1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:user").setStat("opendiscord:tickets-pinned",user.id,1,"increase")
|
||||
|
||||
//move to top of category
|
||||
if (channel.parent){
|
||||
@@ -38,14 +38,14 @@ export const registerActions = async () => {
|
||||
opendiscord.log("Failed to rename channel on ticket pin","error")
|
||||
})
|
||||
}catch(err){
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("openticket:error-channel-rename").build("ticket-pin",{guild,channel,user,originalName,newName})).message)
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-pin",{guild,channel,user,originalName,newName})).message)
|
||||
}
|
||||
|
||||
//update ticket message
|
||||
const ticketMessage = await opendiscord.tickets.getTicketMessage(ticket)
|
||||
if (ticketMessage){
|
||||
try{
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
}catch(e){
|
||||
opendiscord.log("Unable to edit ticket message on ticket pinning!","error",[
|
||||
{key:"channel",value:"#"+channel.name},
|
||||
@@ -58,24 +58,24 @@ export const registerActions = async () => {
|
||||
}
|
||||
|
||||
//reply with new message
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("openticket:pin-message").build(source,{guild,channel,user,ticket,reason})).message)
|
||||
ticket.get("openticket:busy").value = false
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:pin-message").build(source,{guild,channel,user,ticket,reason})).message)
|
||||
ticket.get("opendiscord:busy").value = false
|
||||
await opendiscord.events.get("afterTicketPinned").emit([ticket,user,channel,reason])
|
||||
}),
|
||||
new api.ODWorker("openticket:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason} = params
|
||||
|
||||
//to logs
|
||||
if (generalConfig.data.system.logs.enabled && generalConfig.data.system.messages.pinning.logs){
|
||||
const logChannel = opendiscord.posts.get("openticket:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("openticket:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"pin",reason,additionalData:null}))
|
||||
const logChannel = opendiscord.posts.get("opendiscord:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"pin",reason,additionalData:null}))
|
||||
}
|
||||
|
||||
//to dm
|
||||
const creator = await opendiscord.tickets.getTicketUser(ticket,"creator")
|
||||
if (creator && generalConfig.data.system.messages.pinning.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("openticket:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"pin",reason,additionalData:null}))
|
||||
if (creator && generalConfig.data.system.messages.pinning.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"pin",reason,additionalData:null}))
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",0,(instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",0,(instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket} = params
|
||||
|
||||
opendiscord.log(user.displayName+" pinned a ticket!","info",[
|
||||
@@ -92,184 +92,184 @@ export const registerActions = async () => {
|
||||
|
||||
export const registerVerifyBars = async () => {
|
||||
//PIN TICKET TICKET MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:pin-ticket-ticket-message",opendiscord.builders.messages.getSafe("openticket:verifybar-ticket-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:pin-ticket-ticket-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:pin-ticket-ticket-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-ticket-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:pin-ticket-ticket-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.pin
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:pin-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:pin-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
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("openticket:pinned").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.pin"),layout:"simple"}))
|
||||
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()
|
||||
}
|
||||
//return when busy
|
||||
if (ticket.get("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start pinning ticket
|
||||
if (params.data == "reason"){
|
||||
//pin with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:pin-ticket-reason").build("ticket-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:pin-ticket-reason").build("ticket-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//pin without reason
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("openticket:pin-ticket").run("ticket-message",{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
await opendiscord.actions.get("opendiscord:pin-ticket").run("ticket-message",{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}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:pin-ticket-ticket-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-ticket-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:pin-ticket-ticket-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-ticket-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
})
|
||||
])
|
||||
|
||||
//PIN TICKET UNPIN MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:pin-ticket-unpin-message",opendiscord.builders.messages.getSafe("openticket:verifybar-unpin-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:pin-ticket-unpin-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:pin-ticket-unpin-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-unpin-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:pin-ticket-unpin-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.pin
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:pin-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:pin-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
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("openticket:pinned").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.pin"),layout:"simple"}))
|
||||
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()
|
||||
}
|
||||
//return when busy
|
||||
if (ticket.get("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start pinning ticket
|
||||
if (params.data == "reason"){
|
||||
//pin with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:pin-ticket-reason").build("unpin-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:pin-ticket-reason").build("unpin-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//pin without reason
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("openticket:pin-ticket").run("unpin-message",{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:pin-message").build("unpin-message",{guild,channel,user,ticket,reason:null}))
|
||||
await opendiscord.actions.get("opendiscord:pin-ticket").run("unpin-message",{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:pin-message").build("unpin-message",{guild,channel,user,ticket,reason:null}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:pin-ticket-unpin-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-unpin-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:pin-ticket-unpin-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-unpin-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
const {verifybarMessage} = params
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
const rawReason = (verifybarMessage && verifybarMessage.embeds[0] && verifybarMessage.embeds[0].fields[0]) ? verifybarMessage.embeds[0].fields[0].value : null
|
||||
const reason = (rawReason == null) ? null : rawReason.substring(3,rawReason.length-3)
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:unpin-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:unpin-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
})
|
||||
])
|
||||
opendiscord.actions.get("openticket:pin-ticket").workers.backupWorker = new api.ODWorker("openticket:cancel-busy",0,(instance,params) => {
|
||||
opendiscord.actions.get("opendiscord:pin-ticket").workers.backupWorker = new api.ODWorker("opendiscord:cancel-busy",0,(instance,params) => {
|
||||
//set busy to false in case of crash or cancel
|
||||
params.ticket.get("openticket:busy").value = false
|
||||
params.ticket.get("opendiscord:busy").value = false
|
||||
})
|
||||
}
|
||||
@@ -5,14 +5,14 @@ import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("openticket:reaction-role"))
|
||||
opendiscord.actions.get("openticket:reaction-role").workers.add([
|
||||
new api.ODWorker("openticket:reaction-role",2,async (instance,params,source,cancel) => {
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:reaction-role"))
|
||||
opendiscord.actions.get("opendiscord:reaction-role").workers.add([
|
||||
new api.ODWorker("opendiscord:reaction-role",2,async (instance,params,source,cancel) => {
|
||||
const {guild,user,option,overwriteMode} = params
|
||||
const role = opendiscord.roles.get(option.id)
|
||||
if (!role) throw new api.ODSystemError("ODAction(ot:reaction-role) => Unknown reaction role (ODRole)")
|
||||
instance.role = role
|
||||
const mode = (overwriteMode) ? overwriteMode : role.get("openticket:mode").value
|
||||
const mode = (overwriteMode) ? overwriteMode : role.get("opendiscord:mode").value
|
||||
|
||||
await opendiscord.events.get("onRoleUpdate").emit([user,role])
|
||||
|
||||
@@ -21,7 +21,7 @@ export const registerActions = async () => {
|
||||
if (!member) throw new api.ODSystemError("ODAction(ot:reaction-role) => User isn't a member of the server!")
|
||||
|
||||
//get all roles
|
||||
const roleIds = role.get("openticket:roles").value
|
||||
const roleIds = role.get("opendiscord:roles").value
|
||||
const roles: discord.Role[] = []
|
||||
for (const id of roleIds){
|
||||
const r = await opendiscord.client.fetchGuildRole(guild,id)
|
||||
@@ -55,7 +55,7 @@ export const registerActions = async () => {
|
||||
//get roles to remove on add
|
||||
if (result.find((r) => r.action == "added")){
|
||||
//get all remove roles
|
||||
const removeRoleIds = role.get("openticket:remove-roles-on-add").value
|
||||
const removeRoleIds = role.get("opendiscord:remove-roles-on-add").value
|
||||
const removeRoles: discord.Role[] = []
|
||||
for (const id of removeRoleIds){
|
||||
const r = await opendiscord.client.fetchGuildRole(guild,id)
|
||||
@@ -81,7 +81,7 @@ export const registerActions = async () => {
|
||||
instance.result = result
|
||||
await opendiscord.events.get("afterRolesUpdated").emit([user,role])
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",0,(instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",0,(instance,params,source,cancel) => {
|
||||
const {guild,user,option} = params
|
||||
opendiscord.log(user.displayName+" updated his roles!","info",[
|
||||
{key:"user",value:user.username},
|
||||
|
||||
@@ -4,23 +4,23 @@
|
||||
import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("openticket:general")
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("openticket:remove-ticket-user"))
|
||||
opendiscord.actions.get("openticket:remove-ticket-user").workers.add([
|
||||
new api.ODWorker("openticket:remove-ticket-user",2,async (instance,params,source,cancel) => {
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:remove-ticket-user"))
|
||||
opendiscord.actions.get("opendiscord:remove-ticket-user").workers.add([
|
||||
new api.ODWorker("opendiscord:remove-ticket-user",2,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason,data} = params
|
||||
if (channel.isThread()) throw new api.ODSystemError("Unable to remove user from ticket! Open Ticket doesn't support threads!")
|
||||
|
||||
await opendiscord.events.get("onTicketUserRemove").emit([ticket,user,data,channel,reason])
|
||||
|
||||
//update ticket
|
||||
const index = ticket.get("openticket:participants").value.findIndex((p) => p.type == "user" && p.id == data.id)
|
||||
const index = ticket.get("opendiscord:participants").value.findIndex((p) => p.type == "user" && p.id == data.id)
|
||||
if (index < 0) return cancel()
|
||||
ticket.get("openticket:participants").value.splice(index,1)
|
||||
ticket.get("openticket:participants").refreshDatabase()
|
||||
ticket.get("openticket:busy").value = true
|
||||
ticket.get("opendiscord:participants").value.splice(index,1)
|
||||
ticket.get("opendiscord:participants").refreshDatabase()
|
||||
ticket.get("opendiscord:busy").value = true
|
||||
|
||||
//update channel permissions
|
||||
try{
|
||||
@@ -33,7 +33,7 @@ export const registerActions = async () => {
|
||||
const ticketMessage = await opendiscord.tickets.getTicketMessage(ticket)
|
||||
if (ticketMessage){
|
||||
try{
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
}catch(e){
|
||||
opendiscord.log("Unable to edit ticket message on ticket user removal!","error",[
|
||||
{key:"channel",value:channel.id},
|
||||
@@ -45,24 +45,24 @@ export const registerActions = async () => {
|
||||
}
|
||||
|
||||
//reply with new message
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("openticket:remove-message").build(source,{guild,channel,user,ticket,reason,data})).message)
|
||||
ticket.get("openticket:busy").value = false
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:remove-message").build(source,{guild,channel,user,ticket,reason,data})).message)
|
||||
ticket.get("opendiscord:busy").value = false
|
||||
await opendiscord.events.get("afterTicketUserRemoved").emit([ticket,user,data,channel,reason])
|
||||
}),
|
||||
new api.ODWorker("openticket:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason,data} = params
|
||||
|
||||
//to logs
|
||||
if (generalConfig.data.system.logs.enabled && generalConfig.data.system.messages.removing.logs){
|
||||
const logChannel = opendiscord.posts.get("openticket:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("openticket:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"remove",reason,additionalData:data}))
|
||||
const logChannel = opendiscord.posts.get("opendiscord:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"remove",reason,additionalData:data}))
|
||||
}
|
||||
|
||||
//to dm
|
||||
const creator = await opendiscord.tickets.getTicketUser(ticket,"creator")
|
||||
if (creator && generalConfig.data.system.messages.removing.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("openticket:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"remove",reason,additionalData:data}))
|
||||
if (creator && generalConfig.data.system.messages.removing.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"remove",reason,additionalData:data}))
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",0,(instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",0,(instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,data} = params
|
||||
|
||||
opendiscord.log(user.displayName+" removed "+data.displayName+" from a ticket!","info",[
|
||||
@@ -75,8 +75,8 @@ export const registerActions = async () => {
|
||||
])
|
||||
})
|
||||
])
|
||||
opendiscord.actions.get("openticket:remove-ticket-user").workers.backupWorker = new api.ODWorker("openticket:cancel-busy",0,(instance,params) => {
|
||||
opendiscord.actions.get("opendiscord:remove-ticket-user").workers.backupWorker = new api.ODWorker("opendiscord:cancel-busy",0,(instance,params) => {
|
||||
//set busy to false in case of crash or cancel
|
||||
params.ticket.get("openticket:busy").value = false
|
||||
params.ticket.get("opendiscord:busy").value = false
|
||||
})
|
||||
}
|
||||
+15
-15
@@ -4,12 +4,12 @@
|
||||
import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("openticket:general")
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("openticket:rename-ticket"))
|
||||
opendiscord.actions.get("openticket:rename-ticket").workers.add([
|
||||
new api.ODWorker("openticket:rename-ticket",2,async (instance,params,source,cancel) => {
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:rename-ticket"))
|
||||
opendiscord.actions.get("opendiscord:rename-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:rename-ticket",2,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason,data} = params
|
||||
if (channel.isThread()) throw new api.ODSystemError("Unable to rename ticket! Open Ticket doesn't support threads!")
|
||||
|
||||
@@ -22,14 +22,14 @@ export const registerActions = async () => {
|
||||
opendiscord.log("Failed to rename channel on ticket rename","error")
|
||||
})
|
||||
}catch(err){
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("openticket:error-channel-rename").build("ticket-rename",{guild,channel,user,originalName,newName:data})).message)
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-rename",{guild,channel,user,originalName,newName:data})).message)
|
||||
}
|
||||
|
||||
//update ticket message
|
||||
const ticketMessage = await opendiscord.tickets.getTicketMessage(ticket)
|
||||
if (ticketMessage){
|
||||
try{
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
}catch(e){
|
||||
opendiscord.log("Unable to edit ticket message on ticket renaming!","error",[
|
||||
{key:"channel",value:"#"+channel.name},
|
||||
@@ -42,24 +42,24 @@ export const registerActions = async () => {
|
||||
}
|
||||
|
||||
//reply with new message
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("openticket:rename-message").build(source,{guild,channel,user,ticket,reason,data})).message)
|
||||
ticket.get("openticket:busy").value = false
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:rename-message").build(source,{guild,channel,user,ticket,reason,data})).message)
|
||||
ticket.get("opendiscord:busy").value = false
|
||||
await opendiscord.events.get("afterTicketRenamed").emit([ticket,user,channel,reason])
|
||||
}),
|
||||
new api.ODWorker("openticket:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason,data} = params
|
||||
|
||||
//to logs
|
||||
if (generalConfig.data.system.logs.enabled && generalConfig.data.system.messages.renaming.logs){
|
||||
const logChannel = opendiscord.posts.get("openticket:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("openticket:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"rename",reason,additionalData:data}))
|
||||
const logChannel = opendiscord.posts.get("opendiscord:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"rename",reason,additionalData:data}))
|
||||
}
|
||||
|
||||
//to dm
|
||||
const creator = await opendiscord.tickets.getTicketUser(ticket,"creator")
|
||||
if (creator && generalConfig.data.system.messages.renaming.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("openticket:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"rename",reason,additionalData:data}))
|
||||
if (creator && generalConfig.data.system.messages.renaming.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"rename",reason,additionalData:data}))
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",0,(instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",0,(instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket} = params
|
||||
|
||||
opendiscord.log(user.displayName+" renamed a ticket!","info",[
|
||||
@@ -72,8 +72,8 @@ export const registerActions = async () => {
|
||||
])
|
||||
})
|
||||
])
|
||||
opendiscord.actions.get("openticket:rename-ticket").workers.backupWorker = new api.ODWorker("openticket:cancel-busy",0,(instance,params) => {
|
||||
opendiscord.actions.get("opendiscord:rename-ticket").workers.backupWorker = new api.ODWorker("opendiscord:cancel-busy",0,(instance,params) => {
|
||||
//set busy to false in case of crash or cancel
|
||||
params.ticket.get("openticket:busy").value = false
|
||||
params.ticket.get("opendiscord:busy").value = false
|
||||
})
|
||||
}
|
||||
+103
-103
@@ -4,32 +4,32 @@
|
||||
import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("openticket:general")
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("openticket:reopen-ticket"))
|
||||
opendiscord.actions.get("openticket:reopen-ticket").workers.add([
|
||||
new api.ODWorker("openticket:reopen-ticket",2,async (instance,params,source,cancel) => {
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:reopen-ticket"))
|
||||
opendiscord.actions.get("opendiscord:reopen-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:reopen-ticket",2,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason} = params
|
||||
if (channel.isThread()) throw new api.ODSystemError("Unable to reopen ticket! Open Ticket doesn't support threads!")
|
||||
|
||||
await opendiscord.events.get("onTicketReopen").emit([ticket,user,channel,reason])
|
||||
|
||||
//update ticket
|
||||
ticket.get("openticket:closed").value = false
|
||||
ticket.get("openticket:open").value = true
|
||||
ticket.get("openticket:autoclosed").value = false
|
||||
ticket.get("openticket:closed-by").value = null
|
||||
ticket.get("openticket:closed-on").value = null
|
||||
ticket.get("openticket:busy").value = true
|
||||
ticket.get("opendiscord:closed").value = false
|
||||
ticket.get("opendiscord:open").value = true
|
||||
ticket.get("opendiscord:autoclosed").value = false
|
||||
ticket.get("opendiscord:closed-by").value = null
|
||||
ticket.get("opendiscord:closed-on").value = null
|
||||
ticket.get("opendiscord:busy").value = true
|
||||
|
||||
//update stats
|
||||
await opendiscord.stats.get("openticket:global").setStat("openticket:tickets-reopened",1,"increase")
|
||||
await opendiscord.stats.get("openticket:user").setStat("openticket:tickets-reopened",user.id,1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:global").setStat("opendiscord:tickets-reopened",1,"increase")
|
||||
await opendiscord.stats.get("opendiscord:user").setStat("opendiscord:tickets-reopened",user.id,1,"increase")
|
||||
|
||||
//update category
|
||||
const channelCategory = ticket.option.get("openticket:channel-category").value
|
||||
const channelBackupCategory = ticket.option.get("openticket:channel-category-backup").value
|
||||
const channelCategory = ticket.option.get("opendiscord:channel-category").value
|
||||
const channelBackupCategory = ticket.option.get("opendiscord:channel-category-backup").value
|
||||
if (channelCategory !== ""){
|
||||
//category enabled
|
||||
try {
|
||||
@@ -54,14 +54,14 @@ export const registerActions = async () => {
|
||||
}else{
|
||||
//use backup category
|
||||
channel.setParent(backupCategory,{lockPermissions:false})
|
||||
ticket.get("openticket:category-mode").value = "backup"
|
||||
ticket.get("openticket:category").value = backupCategory.id
|
||||
ticket.get("opendiscord:category-mode").value = "backup"
|
||||
ticket.get("opendiscord:category").value = backupCategory.id
|
||||
}
|
||||
}else{
|
||||
//use default category
|
||||
channel.setParent(normalCategory,{lockPermissions:false})
|
||||
ticket.get("openticket:category-mode").value = "normal"
|
||||
ticket.get("openticket:category").value = normalCategory.id
|
||||
ticket.get("opendiscord:category-mode").value = "normal"
|
||||
ticket.get("opendiscord:category").value = normalCategory.id
|
||||
}
|
||||
}
|
||||
}catch(e){
|
||||
@@ -73,8 +73,8 @@ export const registerActions = async () => {
|
||||
}
|
||||
}else{
|
||||
channel.setParent(null,{lockPermissions:false})
|
||||
ticket.get("openticket:category-mode").value = null
|
||||
ticket.get("openticket:category").value = null
|
||||
ticket.get("opendiscord:category-mode").value = null
|
||||
ticket.get("opendiscord:category").value = null
|
||||
}
|
||||
|
||||
//update permissions
|
||||
@@ -84,9 +84,9 @@ export const registerActions = async () => {
|
||||
allow:[],
|
||||
deny:["ViewChannel","SendMessages","ReadMessageHistory"]
|
||||
}]
|
||||
const globalAdmins = opendiscord.configs.get("openticket:general").data.globalAdmins
|
||||
const optionAdmins = ticket.option.get("openticket:admins").value
|
||||
const readonlyAdmins = ticket.option.get("openticket:admins-readonly").value
|
||||
const globalAdmins = opendiscord.configs.get("opendiscord:general").data.globalAdmins
|
||||
const optionAdmins = ticket.option.get("opendiscord:admins").value
|
||||
const readonlyAdmins = ticket.option.get("opendiscord:admins-readonly").value
|
||||
|
||||
globalAdmins.forEach((admin) => {
|
||||
permissions.push({
|
||||
@@ -115,7 +115,7 @@ export const registerActions = async () => {
|
||||
deny:["SendMessages","AddReactions","AttachFiles","SendPolls"]
|
||||
})
|
||||
})
|
||||
ticket.get("openticket:participants").value.forEach((participant) => {
|
||||
ticket.get("opendiscord:participants").value.forEach((participant) => {
|
||||
//all participants that aren't roles/admins
|
||||
if (participant.type == "user"){
|
||||
permissions.push({
|
||||
@@ -132,7 +132,7 @@ export const registerActions = async () => {
|
||||
const ticketMessage = await opendiscord.tickets.getTicketMessage(ticket)
|
||||
if (ticketMessage){
|
||||
try{
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
}catch(e){
|
||||
opendiscord.log("Unable to edit ticket message on ticket reopening!","error",[
|
||||
{key:"channel",value:"#"+channel.name},
|
||||
@@ -144,24 +144,24 @@ export const registerActions = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("openticket:reopen-message").build(source,{guild,channel,user,ticket,reason})).message)
|
||||
ticket.get("openticket:busy").value = false
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:reopen-message").build(source,{guild,channel,user,ticket,reason})).message)
|
||||
ticket.get("opendiscord:busy").value = false
|
||||
await opendiscord.events.get("afterTicketReopened").emit([ticket,user,channel,reason])
|
||||
}),
|
||||
new api.ODWorker("openticket:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason} = params
|
||||
|
||||
//to logs
|
||||
if (generalConfig.data.system.logs.enabled && generalConfig.data.system.messages.reopening.logs){
|
||||
const logChannel = opendiscord.posts.get("openticket:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("openticket:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"reopen",reason,additionalData:null}))
|
||||
const logChannel = opendiscord.posts.get("opendiscord:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"reopen",reason,additionalData:null}))
|
||||
}
|
||||
|
||||
//to dm
|
||||
const creator = await opendiscord.tickets.getTicketUser(ticket,"creator")
|
||||
if (creator && generalConfig.data.system.messages.reopening.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("openticket:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"reopen",reason,additionalData:null}))
|
||||
if (creator && generalConfig.data.system.messages.reopening.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"reopen",reason,additionalData:null}))
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",0,(instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",0,(instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket} = params
|
||||
|
||||
opendiscord.log(user.displayName+" reopened a ticket!","info",[
|
||||
@@ -178,272 +178,272 @@ export const registerActions = async () => {
|
||||
|
||||
export const registerVerifyBars = async () => {
|
||||
//REOPEN TICKET TICKET MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:reopen-ticket-ticket-message",opendiscord.builders.messages.getSafe("openticket:verifybar-ticket-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:reopen-ticket-ticket-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:reopen-ticket-ticket-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-ticket-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:reopen-ticket-ticket-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.reopen
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:reopen-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:reopen-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
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("openticket:closed").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.reopen"),layout:"simple"}))
|
||||
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("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start reopening ticket
|
||||
if (params.data == "reason"){
|
||||
//reopen with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:reopen-ticket-reason").build("ticket-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:reopen-ticket-reason").build("ticket-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//reopen without reason
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("openticket:reopen-ticket").run("ticket-message",{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
await opendiscord.actions.get("opendiscord:reopen-ticket").run("ticket-message",{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}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:reopen-ticket-ticket-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-ticket-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:reopen-ticket-ticket-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-ticket-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
})
|
||||
])
|
||||
|
||||
//REOPEN TICKET CLOSE MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:reopen-ticket-close-message",opendiscord.builders.messages.getSafe("openticket:verifybar-close-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:reopen-ticket-close-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:reopen-ticket-close-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-close-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:reopen-ticket-close-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.reopen
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:reopen-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:reopen-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
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("openticket:closed").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.reopen"),layout:"simple"}))
|
||||
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("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start reopening ticket
|
||||
if (params.data == "reason"){
|
||||
//reopen with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:reopen-ticket-reason").build("close-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:reopen-ticket-reason").build("close-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//reopen without reason
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("openticket:reopen-ticket").run("close-message",{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:reopen-message").build("close-message",{guild,channel,user,ticket,reason:null}))
|
||||
await opendiscord.actions.get("opendiscord:reopen-ticket").run("close-message",{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:reopen-message").build("close-message",{guild,channel,user,ticket,reason:null}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:reopen-ticket-close-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-close-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:reopen-ticket-close-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-close-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
const {verifybarMessage} = params
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
const rawReason = (verifybarMessage && verifybarMessage.embeds[0] && verifybarMessage.embeds[0].fields[0]) ? verifybarMessage.embeds[0].fields[0].value : null
|
||||
const reason = (rawReason == null) ? null : rawReason.substring(3,rawReason.length-3)
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:close-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:close-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
})
|
||||
])
|
||||
|
||||
//REOPEN TICKET AUTOCLOSE MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:reopen-ticket-autoclose-message",opendiscord.builders.messages.getSafe("openticket:verifybar-autoclose-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:reopen-ticket-autoclose-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:reopen-ticket-autoclose-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-autoclose-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:reopen-ticket-autoclose-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.reopen
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:reopen-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:reopen-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
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("openticket:closed").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.reopen"),layout:"simple"}))
|
||||
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("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start reopening ticket
|
||||
if (params.data == "reason"){
|
||||
//reopen with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:reopen-ticket-reason").build("autoclose-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:reopen-ticket-reason").build("autoclose-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//reopen without reason
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("openticket:reopen-ticket").run("autoclose-message",{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:reopen-message").build("autoclose-message",{guild,channel,user,ticket,reason:null}))
|
||||
await opendiscord.actions.get("opendiscord:reopen-ticket").run("autoclose-message",{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:reopen-message").build("autoclose-message",{guild,channel,user,ticket,reason:null}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:reopen-ticket-autoclose-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-autoclose-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:reopen-ticket-autoclose-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-autoclose-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
const {verifybarMessage} = params
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:autoclose-message").build("other",{guild,channel,user,ticket}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:autoclose-message").build("other",{guild,channel,user,ticket}))
|
||||
})
|
||||
])
|
||||
opendiscord.actions.get("openticket:reopen-ticket").workers.backupWorker = new api.ODWorker("openticket:cancel-busy",0,(instance,params) => {
|
||||
opendiscord.actions.get("opendiscord:reopen-ticket").workers.backupWorker = new api.ODWorker("opendiscord:cancel-busy",0,(instance,params) => {
|
||||
//set busy to false in case of crash or cancel
|
||||
params.ticket.get("openticket:busy").value = false
|
||||
params.ticket.get("opendiscord:busy").value = false
|
||||
})
|
||||
}
|
||||
@@ -4,26 +4,26 @@
|
||||
import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("openticket:general")
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("openticket:unclaim-ticket"))
|
||||
opendiscord.actions.get("openticket:unclaim-ticket").workers.add([
|
||||
new api.ODWorker("openticket:unclaim-ticket",2,async (instance,params,source,cancel) => {
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:unclaim-ticket"))
|
||||
opendiscord.actions.get("opendiscord:unclaim-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:unclaim-ticket",2,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason} = params
|
||||
if (channel.isThread()) throw new api.ODSystemError("Unable to unclaim ticket! Open Ticket doesn't support threads!")
|
||||
|
||||
await opendiscord.events.get("onTicketUnclaim").emit([ticket,user,channel,reason])
|
||||
|
||||
//update ticket
|
||||
ticket.get("openticket:claimed").value = false
|
||||
ticket.get("openticket:claimed-by").value = null
|
||||
ticket.get("openticket:claimed-on").value = null
|
||||
ticket.get("openticket:busy").value = true
|
||||
ticket.get("opendiscord:claimed").value = false
|
||||
ticket.get("opendiscord:claimed-by").value = null
|
||||
ticket.get("opendiscord:claimed-on").value = null
|
||||
ticket.get("opendiscord:busy").value = true
|
||||
|
||||
//update category
|
||||
const channelCategory = ticket.option.get("openticket:channel-category").value
|
||||
const channelBackupCategory = ticket.option.get("openticket:channel-category-backup").value
|
||||
const channelCategory = ticket.option.get("opendiscord:channel-category").value
|
||||
const channelBackupCategory = ticket.option.get("opendiscord:channel-category-backup").value
|
||||
if (channelCategory !== ""){
|
||||
//category enabled
|
||||
try {
|
||||
@@ -48,14 +48,14 @@ export const registerActions = async () => {
|
||||
}else{
|
||||
//use backup category
|
||||
channel.setParent(backupCategory,{lockPermissions:false})
|
||||
ticket.get("openticket:category-mode").value = "backup"
|
||||
ticket.get("openticket:category").value = backupCategory.id
|
||||
ticket.get("opendiscord:category-mode").value = "backup"
|
||||
ticket.get("opendiscord:category").value = backupCategory.id
|
||||
}
|
||||
}else{
|
||||
//use default category
|
||||
channel.setParent(normalCategory,{lockPermissions:false})
|
||||
ticket.get("openticket:category-mode").value = "normal"
|
||||
ticket.get("openticket:category").value = normalCategory.id
|
||||
ticket.get("opendiscord:category-mode").value = "normal"
|
||||
ticket.get("opendiscord:category").value = normalCategory.id
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,15 +68,15 @@ export const registerActions = async () => {
|
||||
}
|
||||
}else{
|
||||
channel.setParent(null,{lockPermissions:false})
|
||||
ticket.get("openticket:category-mode").value = null
|
||||
ticket.get("openticket:category").value = null
|
||||
ticket.get("opendiscord:category-mode").value = null
|
||||
ticket.get("opendiscord:category").value = null
|
||||
}
|
||||
|
||||
//update ticket message
|
||||
const ticketMessage = await opendiscord.tickets.getTicketMessage(ticket)
|
||||
if (ticketMessage){
|
||||
try{
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
}catch(e){
|
||||
opendiscord.log("Unable to edit ticket message on ticket unclaiming!","error",[
|
||||
{key:"channel",value:"#"+channel.name},
|
||||
@@ -89,24 +89,24 @@ export const registerActions = async () => {
|
||||
}
|
||||
|
||||
//reply with new message
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("openticket:unclaim-message").build(source,{guild,channel,user,ticket,reason})).message)
|
||||
ticket.get("openticket:busy").value = false
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:unclaim-message").build(source,{guild,channel,user,ticket,reason})).message)
|
||||
ticket.get("opendiscord:busy").value = false
|
||||
await opendiscord.events.get("afterTicketUnclaimed").emit([ticket,user,channel,reason])
|
||||
}),
|
||||
new api.ODWorker("openticket:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason} = params
|
||||
|
||||
//to logs
|
||||
if (generalConfig.data.system.logs.enabled && generalConfig.data.system.messages.claiming.logs){
|
||||
const logChannel = opendiscord.posts.get("openticket:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("openticket:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"unclaim",reason,additionalData:null}))
|
||||
const logChannel = opendiscord.posts.get("opendiscord:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"unclaim",reason,additionalData:null}))
|
||||
}
|
||||
|
||||
//to dm
|
||||
const creator = await opendiscord.tickets.getTicketUser(ticket,"creator")
|
||||
if (creator && generalConfig.data.system.messages.claiming.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("openticket:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"unclaim",reason,additionalData:null}))
|
||||
if (creator && generalConfig.data.system.messages.claiming.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"unclaim",reason,additionalData:null}))
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",0,(instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",0,(instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket} = params
|
||||
|
||||
opendiscord.log(user.displayName+" unclaimed a ticket!","info",[
|
||||
@@ -123,184 +123,184 @@ export const registerActions = async () => {
|
||||
|
||||
export const registerVerifyBars = async () => {
|
||||
//UNCLAIM TICKET TICKET MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:unclaim-ticket-ticket-message",opendiscord.builders.messages.getSafe("openticket:verifybar-ticket-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:unclaim-ticket-ticket-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:unclaim-ticket-ticket-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-ticket-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:unclaim-ticket-ticket-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.unclaim
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:unclaim-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:unclaim-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
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("openticket:claimed").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.unclaim"),layout:"simple"}))
|
||||
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("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start unclaiming ticket
|
||||
if (params.data == "reason"){
|
||||
//unclaim with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:unclaim-ticket-reason").build("ticket-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:unclaim-ticket-reason").build("ticket-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//unclaim without reason
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("openticket:unclaim-ticket").run("ticket-message",{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
await opendiscord.actions.get("opendiscord:unclaim-ticket").run("ticket-message",{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}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:unclaim-ticket-ticket-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-ticket-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:unclaim-ticket-ticket-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-ticket-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
})
|
||||
])
|
||||
|
||||
//UNCLAIM TICKET CLAIM MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:unclaim-ticket-claim-message",opendiscord.builders.messages.getSafe("openticket:verifybar-claim-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:unclaim-ticket-claim-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:unclaim-ticket-claim-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-claim-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:unclaim-ticket-claim-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.unclaim
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:unclaim-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:unclaim-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
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("openticket:claimed").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.unclaim"),layout:"simple"}))
|
||||
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("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start unclaiming ticket
|
||||
if (params.data == "reason"){
|
||||
//unclaim with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:unclaim-ticket-reason").build("claim-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:unclaim-ticket-reason").build("claim-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//unclaim without reason
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("openticket:unclaim-ticket").run("claim-message",{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:unclaim-message").build("claim-message",{guild,channel,user,ticket,reason:null}))
|
||||
await opendiscord.actions.get("opendiscord:unclaim-ticket").run("claim-message",{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:unclaim-message").build("claim-message",{guild,channel,user,ticket,reason:null}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:unclaim-ticket-claim-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-claim-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:unclaim-ticket-claim-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-claim-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
const {verifybarMessage} = params
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
const rawReason = (verifybarMessage && verifybarMessage.embeds[0] && verifybarMessage.embeds[0].fields[0]) ? verifybarMessage.embeds[0].fields[0].value : null
|
||||
const reason = (rawReason == null) ? null : rawReason.substring(3,rawReason.length-3)
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:claim-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:claim-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
})
|
||||
])
|
||||
opendiscord.actions.get("openticket:unclaim-ticket").workers.backupWorker = new api.ODWorker("openticket:cancel-busy",0,(instance,params) => {
|
||||
opendiscord.actions.get("opendiscord:unclaim-ticket").workers.backupWorker = new api.ODWorker("opendiscord:cancel-busy",0,(instance,params) => {
|
||||
//set busy to false in case of crash or cancel
|
||||
params.ticket.get("openticket:busy").value = false
|
||||
params.ticket.get("opendiscord:busy").value = false
|
||||
})
|
||||
}
|
||||
+65
-65
@@ -4,22 +4,22 @@
|
||||
import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("openticket:general")
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("openticket:unpin-ticket"))
|
||||
opendiscord.actions.get("openticket:unpin-ticket").workers.add([
|
||||
new api.ODWorker("openticket:unpin-ticket",2,async (instance,params,source,cancel) => {
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:unpin-ticket"))
|
||||
opendiscord.actions.get("opendiscord:unpin-ticket").workers.add([
|
||||
new api.ODWorker("opendiscord:unpin-ticket",2,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason} = params
|
||||
if (channel.isThread()) throw new api.ODSystemError("Unable to unpin ticket! Open Ticket doesn't support threads!")
|
||||
|
||||
await opendiscord.events.get("onTicketUnpin").emit([ticket,user,channel,reason])
|
||||
|
||||
//update ticket
|
||||
ticket.get("openticket:pinned").value = false
|
||||
ticket.get("openticket:pinned-by").value = null
|
||||
ticket.get("openticket:pinned-on").value = null
|
||||
ticket.get("openticket:busy").value = true
|
||||
ticket.get("opendiscord:pinned").value = false
|
||||
ticket.get("opendiscord:pinned-by").value = null
|
||||
ticket.get("opendiscord:pinned-on").value = null
|
||||
ticket.get("opendiscord:busy").value = true
|
||||
|
||||
//rename channel (and give error when crashed)
|
||||
const originalName = channel.name
|
||||
@@ -30,7 +30,7 @@ export const registerActions = async () => {
|
||||
opendiscord.log("Failed to rename channel on ticket unpin","error")
|
||||
})
|
||||
}catch(err){
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("openticket:error-channel-rename").build("ticket-unpin",{guild,channel,user,originalName,newName})).message)
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-unpin",{guild,channel,user,originalName,newName})).message)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ export const registerActions = async () => {
|
||||
const ticketMessage = await opendiscord.tickets.getTicketMessage(ticket)
|
||||
if (ticketMessage){
|
||||
try{
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
ticketMessage.edit((await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket})).message)
|
||||
}catch(e){
|
||||
opendiscord.log("Unable to edit ticket message on ticket unpinning!","error",[
|
||||
{key:"channel",value:"#"+channel.name},
|
||||
@@ -51,24 +51,24 @@ export const registerActions = async () => {
|
||||
}
|
||||
|
||||
//reply with new message
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("openticket:unpin-message").build(source,{guild,channel,user,ticket,reason})).message)
|
||||
ticket.get("openticket:busy").value = false
|
||||
if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:unpin-message").build(source,{guild,channel,user,ticket,reason})).message)
|
||||
ticket.get("opendiscord:busy").value = false
|
||||
await opendiscord.events.get("afterTicketUnpinned").emit([ticket,user,channel,reason])
|
||||
}),
|
||||
new api.ODWorker("openticket:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,reason} = params
|
||||
|
||||
//to logs
|
||||
if (generalConfig.data.system.logs.enabled && generalConfig.data.system.messages.pinning.logs){
|
||||
const logChannel = opendiscord.posts.get("openticket:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("openticket:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"unpin",reason,additionalData:null}))
|
||||
const logChannel = opendiscord.posts.get("opendiscord:logs")
|
||||
if (logChannel) logChannel.send(await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-logs").build(source,{guild,channel,user,ticket,mode:"unpin",reason,additionalData:null}))
|
||||
}
|
||||
|
||||
//to dm
|
||||
const creator = await opendiscord.tickets.getTicketUser(ticket,"creator")
|
||||
if (creator && generalConfig.data.system.messages.pinning.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("openticket:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"unpin",reason,additionalData:null}))
|
||||
if (creator && generalConfig.data.system.messages.pinning.dm) await opendiscord.client.sendUserDm(creator,await opendiscord.builders.messages.getSafe("opendiscord:ticket-action-dm").build(source,{guild,channel,user,ticket,mode:"unpin",reason,additionalData:null}))
|
||||
}),
|
||||
new api.ODWorker("openticket:logs",0,(instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:logs",0,(instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket} = params
|
||||
|
||||
opendiscord.log(user.displayName+" unpinned a ticket!","info",[
|
||||
@@ -85,184 +85,184 @@ export const registerActions = async () => {
|
||||
|
||||
export const registerVerifyBars = async () => {
|
||||
//UNPIN TICKET TICKET MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:unpin-ticket-ticket-message",opendiscord.builders.messages.getSafe("openticket:verifybar-ticket-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:unpin-ticket-ticket-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:unpin-ticket-ticket-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-ticket-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:unpin-ticket-ticket-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.unpin
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:unpin-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:unpin-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
//return when not pinned
|
||||
if (!ticket.get("openticket:pinned").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.unpin"),layout:"simple"}))
|
||||
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("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start unpining ticket
|
||||
if (params.data == "reason"){
|
||||
//unpin with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:unpin-ticket-reason").build("ticket-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:unpin-ticket-reason").build("ticket-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//unpin without reason
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("openticket:unpin-ticket").run("ticket-message",{guild,channel,user,ticket,reason:null,sendMessage:true})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
await opendiscord.actions.get("opendiscord:unpin-ticket").run("ticket-message",{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}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:unpin-ticket-ticket-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-ticket-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:unpin-ticket-ticket-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-ticket-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:ticket-message").build("other",{guild,channel,user,ticket}))
|
||||
})
|
||||
])
|
||||
|
||||
//UNPIN TICKET PIN MESSAGE
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("openticket:unpin-ticket-pin-message",opendiscord.builders.messages.getSafe("openticket:verifybar-pin-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("openticket:unpin-ticket-pin-message").success.add([
|
||||
new api.ODWorker("openticket:permissions",1,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.add(new api.ODVerifyBar("opendiscord:unpin-ticket-pin-message",opendiscord.builders.messages.getSafe("opendiscord:verifybar-pin-message"),!generalConfig.data.system.disableVerifyBars))
|
||||
opendiscord.verifybars.get("opendiscord:unpin-ticket-pin-message").success.add([
|
||||
new api.ODWorker("opendiscord:permissions",1,async (instance,params,source,cancel) => {
|
||||
const permissionMode = generalConfig.data.system.permissions.unpin
|
||||
|
||||
if (permissionMode == "none"){
|
||||
//no permissions
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,permissions:["support"]}))
|
||||
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()
|
||||
}else return
|
||||
}else{
|
||||
if (!instance.guild || !instance.member){
|
||||
//error
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #1",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,error:"Permission Error: Not in Server #2",layout:"advanced"}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error").build("button",{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("openticket:error-no-permissions").build("button",{guild:instance.guild,channel:instance.channel,user:instance.user,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 return
|
||||
}
|
||||
}),
|
||||
new api.ODWorker("openticket:unpin-ticket",0,async (instance,params,source,cancel) => {
|
||||
new api.ODWorker("opendiscord:unpin-ticket",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
//return when not pinned
|
||||
if (!ticket.get("openticket:pinned").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error").build("button",{guild,channel,user,error:opendiscord.languages.getTranslation("errors.actionInvalid.unpin"),layout:"simple"}))
|
||||
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("openticket:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
if (ticket.get("opendiscord:busy").value){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-busy").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
//start unpinning ticket
|
||||
if (params.data == "reason"){
|
||||
//unpin with reason
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("openticket:unpin-ticket-reason").build("pin-message",{guild,channel,user,ticket}))
|
||||
instance.modal(await opendiscord.builders.modals.getSafe("opendiscord:unpin-ticket-reason").build("pin-message",{guild,channel,user,ticket}))
|
||||
}else{
|
||||
//unpin without reason
|
||||
await instance.defer("update",false)
|
||||
await opendiscord.actions.get("openticket:unpin-ticket").run("pin-message",{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:unpin-message").build("pin-message",{guild,channel,user,ticket,reason:null}))
|
||||
await opendiscord.actions.get("opendiscord:unpin-ticket").run("pin-message",{guild,channel,user,ticket,reason:null,sendMessage:false})
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:unpin-message").build("pin-message",{guild,channel,user,ticket,reason:null}))
|
||||
}
|
||||
})
|
||||
])
|
||||
opendiscord.verifybars.get("openticket:unpin-ticket-pin-message").failure.add([
|
||||
new api.ODWorker("openticket:back-to-pin-message",0,async (instance,params,source,cancel) => {
|
||||
opendiscord.verifybars.get("opendiscord:unpin-ticket-pin-message").failure.add([
|
||||
new api.ODWorker("opendiscord:back-to-pin-message",0,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user} = instance
|
||||
const {verifybarMessage} = params
|
||||
if (!guild){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-not-in-guild").build("button",{channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-not-in-guild").build("button",{channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
const ticket = opendiscord.tickets.get(channel.id)
|
||||
if (!ticket || channel.isDMBased()){
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
instance.reply(await opendiscord.builders.messages.getSafe("opendiscord:error-ticket-unknown").build("button",{guild,channel,user}))
|
||||
return cancel()
|
||||
}
|
||||
|
||||
const rawReason = (verifybarMessage && verifybarMessage.embeds[0] && verifybarMessage.embeds[0].fields[0]) ? verifybarMessage.embeds[0].fields[0].value : null
|
||||
const reason = (rawReason == null) ? null : rawReason.substring(3,rawReason.length-3)
|
||||
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("openticket:pin-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
await instance.update(await opendiscord.builders.messages.getSafe("opendiscord:pin-message").build("other",{guild,channel,user,ticket,reason}))
|
||||
})
|
||||
])
|
||||
opendiscord.actions.get("openticket:unpin-ticket").workers.backupWorker = new api.ODWorker("openticket:cancel-busy",0,(instance,params) => {
|
||||
opendiscord.actions.get("opendiscord:unpin-ticket").workers.backupWorker = new api.ODWorker("opendiscord:cancel-busy",0,(instance,params) => {
|
||||
//set busy to false in case of crash or cancel
|
||||
params.ticket.get("openticket:busy").value = false
|
||||
params.ticket.get("opendiscord:busy").value = false
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user