(v4.2.0) Reworked ticket category logic

This commit is contained in:
DJj123dj
2026-05-15 12:30:14 +02:00
parent 0c45a0ad6a
commit 15ff345948
13 changed files with 258 additions and 215 deletions
+127
View File
@@ -0,0 +1,127 @@
///////////////////////////////////////
//CALCULATE TICKET CATEGORY SYSTEM
///////////////////////////////////////
import {opendiscord, api, utilities} from "../index.js"
import * as discord from "discord.js"
const generalConfig = opendiscord.configs.get("opendiscord:general")
export async function registerActions(){
opendiscord.actions.add(new api.ODAction("opendiscord:calculate-ticket-category"))
opendiscord.actions.get("opendiscord:calculate-ticket-category").workers.add([
new api.ODWorker("opendiscord:default-category",2,async (instance,params,origin,cancel) => {
//handle default category
const {guild,user,channel,option,ticket,currentCategoryId} = params
const defaultCategoryId = option.get("opendiscord:channel-category").value
if (!defaultCategoryId){
//default category is disabled
instance.newCategoryId = null
instance.newCategoryMode = null
instance.newCategory = null
instance.shouldChangeCategory = (instance.newCategoryId !== currentCategoryId)
}else{
const defaultCategory = await opendiscord.client.fetchGuildCategoryChannel(guild,defaultCategoryId)
if (defaultCategory){
//default category is enabled
instance.newCategoryId = defaultCategoryId
instance.newCategoryMode = "default"
instance.newCategory = defaultCategory
instance.shouldChangeCategory = (instance.newCategoryId !== currentCategoryId)
}else{
//default category is not found (do not switch categories)
opendiscord.log("Unable to find ticket category '"+defaultCategoryId+"' #1","error",[
{key:"categoryid",value:defaultCategoryId},
{key:"type",value:"default"}
])
instance.newCategoryId = null
instance.newCategoryMode = null
instance.newCategory = null
instance.shouldChangeCategory = false
}
}
}),
new api.ODWorker("opendiscord:close-category",1,async (instance,params,origin,cancel) => {
//handle close category
const {guild,user,channel,option,ticket,currentCategoryId} = params
if (!ticket) return
if (!ticket.get("opendiscord:closed").value) return
const closeCategoryId = option.get("opendiscord:channel-category-closed").value
if (!closeCategoryId) return
const closeCategory = await opendiscord.client.fetchGuildCategoryChannel(guild,closeCategoryId)
if (closeCategory){
//close category is enabled
instance.newCategoryId = closeCategoryId
instance.newCategoryMode = "close"
instance.newCategory = closeCategory
instance.shouldChangeCategory = (instance.newCategoryId !== currentCategoryId)
}else{
//close category is not found (do not switch categories)
opendiscord.log("Unable to find ticket category '"+closeCategoryId+"' #2","error",[
{key:"categoryid",value:closeCategoryId},
{key:"type",value:"close"}
])
instance.newCategoryId = null
instance.newCategoryMode = null
instance.newCategory = null
instance.shouldChangeCategory = false
}
}),
new api.ODWorker("opendiscord:claim-category",0,async (instance,params,origin,cancel) => {
//handle claim category
const {guild,user,channel,option,ticket,currentCategoryId} = params
if (!ticket) return
if (!ticket.get("opendiscord:claimed").value) return
const claimedCategoryIds = option.get("opendiscord:channel-categories-claimed").value
const claimCategoryId = claimedCategoryIds.find((c) => c.user == user.id)?.category
if (!claimCategoryId) return
const claimCategory = await opendiscord.client.fetchGuildCategoryChannel(guild,claimCategoryId)
if (claimCategory){
//claim category is enabled
instance.newCategoryId = claimCategoryId
instance.newCategoryMode = "claim"
instance.newCategory = claimCategory
instance.shouldChangeCategory = (instance.newCategoryId !== currentCategoryId)
}else{
//claim category is not found (do not switch categories)
opendiscord.log("Unable to find ticket category '"+claimCategoryId+"' #3","error",[
{key:"categoryid",value:claimCategoryId},
{key:"type",value:"claim"}
])
instance.newCategoryId = null
instance.newCategoryMode = null
instance.newCategory = null
instance.shouldChangeCategory = false
}
}),
new api.ODWorker("opendiscord:backup-category",-100,async (instance,params,origin,cancel) => {
//handle backup category
const {guild,user,channel,option,ticket,currentCategoryId} = params
if (!instance.newCategory || !instance.newCategoryId || !instance.shouldChangeCategory) return
if (instance.newCategory.children.cache.size < 50) return
const backupCategoryId = option.get("opendiscord:channel-category-backup").value
if (!backupCategoryId) return
const backupCategory = await opendiscord.client.fetchGuildCategoryChannel(guild,backupCategoryId)
if (backupCategory){
//backup category is enabled
instance.newCategoryId = backupCategoryId
instance.newCategoryMode = "backup"
instance.newCategory = backupCategory
instance.shouldChangeCategory = (instance.newCategoryId !== currentCategoryId)
}else{
//backup category is not found (do not switch categories)
opendiscord.log("Unable to find ticket category '"+backupCategoryId+"' #4","error",[
{key:"categoryid",value:backupCategoryId},
{key:"type",value:"backup"}
])
instance.newCategoryId = null
instance.newCategoryMode = null
instance.newCategory = null
instance.shouldChangeCategory = false
}
})
])
}
+14 -11
View File
@@ -26,22 +26,25 @@ export async function registerActions(){
await opendiscord.statistics.get("opendiscord:global").setStat("opendiscord:tickets-claimed",1,"increase") await opendiscord.statistics.get("opendiscord:global").setStat("opendiscord:tickets-claimed",1,"increase")
await opendiscord.statistics.get("opendiscord:user").setStat("opendiscord:tickets-claimed",user.id,1,"increase") await opendiscord.statistics.get("opendiscord:user").setStat("opendiscord:tickets-claimed",user.id,1,"increase")
//update category //calculate & update category
if (typeof params.allowCategoryChange == "boolean" ? params.allowCategoryChange : true){ if (typeof params.allowCategoryChange == "boolean" ? params.allowCategoryChange : true){
const rawClaimCategory = ticket.option.get("opendiscord:channel-categories-claimed").value.find((c) => c.user == user.id) const categoryResult = await opendiscord.actions.get("opendiscord:calculate-ticket-category").run("claim-ticket",{guild,user,option:ticket.option,channel,ticket,currentCategoryId:channel.parentId})
const claimCategory = (rawClaimCategory) ? rawClaimCategory.category : null if (categoryResult && categoryResult.shouldChangeCategory && typeof categoryResult.newCategoryId !== "undefined" && typeof categoryResult.newCategoryMode !== "undefined" && typeof categoryResult.newCategory !== "undefined"){
if (claimCategory){ const originalCategoryName = channel.parent?.name ?? "<unknown>"
const newCategoryName = categoryResult.newCategory?.name ?? "<unknown>"
try{ try{
channel.setParent(claimCategory,{lockPermissions:false}) await utilities.timedAwait(channel.setParent(categoryResult.newCategoryId,{lockPermissions:false}),3000,(err) => {
ticket.get("opendiscord:category-mode").value = "claimed" process.emit("uncaughtException",new Error("Error: Unable to change channel parent: "+err))
ticket.get("opendiscord:category").value = claimCategory })
}catch(e){ ticket.get("opendiscord:category-mode").value = categoryResult.newCategoryMode
opendiscord.log("Unable to move ticket to 'claimed category'!","error",[ ticket.get("opendiscord:category").value = categoryResult.newCategoryId
}catch(err){
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-category").build("ticket-claim",{guild,channel,user,originalCategory:originalCategoryName,newCategory:newCategoryName})).message)
opendiscord.log("Unable to move ticket to claimed category.","error",[
{key:"channel",value:"#"+channel.name}, {key:"channel",value:"#"+channel.name},
{key:"channelid",value:channel.id,hidden:true}, {key:"channelid",value:channel.id,hidden:true},
{key:"categoryid",value:claimCategory} {key:"categoryid",value:categoryResult.newCategoryId ?? "/"}
]) ])
opendiscord.debugfile.writeErrorMessage(new api.ODError(e,"uncaughtException"))
} }
} }
} }
+14 -10
View File
@@ -34,21 +34,25 @@ export async function registerActions(){
await opendiscord.statistics.get("opendiscord:global").setStat("opendiscord:tickets-closed",1,"increase") await opendiscord.statistics.get("opendiscord:global").setStat("opendiscord:tickets-closed",1,"increase")
await opendiscord.statistics.get("opendiscord:user").setStat("opendiscord:tickets-closed",user.id,1,"increase") await opendiscord.statistics.get("opendiscord:user").setStat("opendiscord:tickets-closed",user.id,1,"increase")
//update category //calculate & update category
if (typeof params.allowCategoryChange == "boolean" ? params.allowCategoryChange : true){ if (typeof params.allowCategoryChange == "boolean" ? params.allowCategoryChange : true){
const closeCategory = ticket.option.get("opendiscord:channel-category-closed").value const categoryResult = await opendiscord.actions.get("opendiscord:calculate-ticket-category").run("close-ticket",{guild,user,option:ticket.option,channel,ticket,currentCategoryId:channel.parentId})
if (closeCategory !== ""){ if (categoryResult && categoryResult.shouldChangeCategory && typeof categoryResult.newCategoryId !== "undefined" && typeof categoryResult.newCategoryMode !== "undefined" && typeof categoryResult.newCategory !== "undefined"){
const originalCategoryName = channel.parent?.name ?? "<unknown>"
const newCategoryName = categoryResult.newCategory?.name ?? "<unknown>"
try{ try{
channel.setParent(closeCategory,{lockPermissions:false}) await utilities.timedAwait(channel.setParent(categoryResult.newCategoryId,{lockPermissions:false}),3000,(err) => {
ticket.get("opendiscord:category-mode").value = "closed" process.emit("uncaughtException",new Error("Error: Unable to change channel parent: "+err))
ticket.get("opendiscord:category").value = closeCategory })
}catch(e){ ticket.get("opendiscord:category-mode").value = categoryResult.newCategoryMode
opendiscord.log("Unable to move ticket to 'closed category'!","error",[ ticket.get("opendiscord:category").value = categoryResult.newCategoryId
}catch(err){
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-category").build("ticket-close",{guild,channel,user,originalCategory:originalCategoryName,newCategory:newCategoryName})).message)
opendiscord.log("Unable to move ticket to closed category.","error",[
{key:"channel",value:"#"+channel.name}, {key:"channel",value:"#"+channel.name},
{key:"channelid",value:channel.id,hidden:true}, {key:"channelid",value:channel.id,hidden:true},
{key:"categoryid",value:closeCategory} {key:"categoryid",value:categoryResult.newCategoryId ?? "/"}
]) ])
opendiscord.debugfile.writeErrorMessage(new api.ODError(e,"uncaughtException"))
} }
} }
} }
+8 -39
View File
@@ -19,46 +19,15 @@ export async function registerActions(){
//get channel properties //get channel properties
const channelPrefix = option.get("opendiscord:channel-prefix").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 channelTopicText = option.get("opendiscord:channel-topic").value const channelTopicText = option.get("opendiscord:channel-topic").value
const channelSuffix = await opendiscord.options.suffix.getSuffixFromOption(option,user,guild) const channelSuffix = await opendiscord.options.suffix.getSuffixFromOption(option,user,guild)
const channelName = channelPrefix+channelSuffix const channelName = channelPrefix+channelSuffix
//handle category //calculate category
let category: string|null = null const categoryResult = await opendiscord.actions.get("opendiscord:calculate-ticket-category").run("create-ticket",{guild,user,option,channel:null,ticket:null,currentCategoryId:null})
let categoryMode: "backup"|"normal"|null = null if (!categoryResult) return opendiscord.log("Ticket Creation Error: Unable to calculate ticket category.","error")
if (channelCategory != ""){ const ticketCategoryId = (categoryResult.shouldChangeCategory && typeof categoryResult.newCategoryId !== "undefined") ? categoryResult.newCategoryId : undefined
//category enabled const ticketCategoryMode = (categoryResult.shouldChangeCategory && typeof categoryResult.newCategoryMode !== "undefined") ? categoryResult.newCategoryMode : undefined
const normalCategory = await opendiscord.client.fetchGuildCategoryChannel(guild,channelCategory)
if (!normalCategory){
//default category was not found
opendiscord.log("Ticket Creation Error: Unable to find category! #1","error",[
{key:"categoryid",value:channelCategory},
{key:"backup",value:"false"}
])
}else{
//default category was found
if (normalCategory.children.cache.size >= 50 && channelBackupCategory != ""){
//use backup category
const backupCategory = await opendiscord.client.fetchGuildCategoryChannel(guild,channelBackupCategory)
if (!backupCategory){
//default category was not found
opendiscord.log("Ticket Creation Error: Unable to find category! #2","error",[
{key:"categoryid",value:channelBackupCategory},
{key:"backup",value:"true"}
])
}else{
category = backupCategory.id
categoryMode = "backup"
}
}else{
//use default category
category = normalCategory.id
categoryMode = "normal"
}
}
}
//handle permissions //handle permissions
const permissions: discord.OverwriteResolvable[] = [{ const permissions: discord.OverwriteResolvable[] = [{
@@ -135,7 +104,7 @@ export async function registerActions(){
name:channelName, name:channelName,
nsfw:false, nsfw:false,
topic:(channelTopics.length > 0) ? channelTopics.join(" • ") : undefined, topic:(channelTopics.length > 0) ? channelTopics.join(" • ") : undefined,
parent:category, parent:ticketCategoryId,
reason:"Ticket Created By "+user.displayName, reason:"Ticket Created By "+user.displayName,
permissionOverwrites:permissions, permissionOverwrites:permissions,
rateLimitPerUser:slowMode rateLimitPerUser:slowMode
@@ -168,8 +137,8 @@ export async function registerActions(){
new api.ODTicketData("opendiscord:pinned-on",null), new api.ODTicketData("opendiscord:pinned-on",null),
new api.ODTicketData("opendiscord:for-deletion",false), new api.ODTicketData("opendiscord:for-deletion",false),
new api.ODTicketData("opendiscord:category",category), new api.ODTicketData("opendiscord:category",ticketCategoryId ?? null),
new api.ODTicketData("opendiscord:category-mode",categoryMode), new api.ODTicketData("opendiscord:category-mode",ticketCategoryMode ?? null),
new api.ODTicketData("opendiscord:autoclose-enabled",option.get("opendiscord:autoclose-enable-hours").value), 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:autoclose-hours",(option.get("opendiscord:autoclose-enable-hours").value ? option.get("opendiscord:autoclose-hours").value : 0)),
+14 -58
View File
@@ -23,70 +23,26 @@ export async function registerActions(){
//get new channel properties //get new channel properties
const channelPrefix = ticket.option.get("opendiscord:channel-prefix").value const channelPrefix = ticket.option.get("opendiscord:channel-prefix").value
const channelSuffix = ticket.get("opendiscord:channel-suffix").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("opendiscord:channel-category-closed").value
const channelTopic = ticket.option.get("opendiscord:channel-topic").value
//handle category
let category: string|null = null
let categoryMode: "backup"|"normal"|"closed"|"claimed"|null = null
if (claimCategory){
//use claim category
category = claimCategory
categoryMode = "claimed"
}else if (closeCategory != "" && ticket.get("opendiscord:closed").value){
//use close category
category = closeCategory
categoryMode = "closed"
}else if (channelCategory != ""){
//category enabled
const normalCategory = await opendiscord.client.fetchGuildCategoryChannel(guild,channelCategory)
if (!normalCategory){
//default category was not found
opendiscord.log("Ticket Move Error: Unable to find category! #1","error",[
{key:"categoryid",value:channelCategory},
{key:"backup",value:"false"}
])
}else{
//default category was found
if (normalCategory.children.cache.size >= 50 && channelBackupCategory != ""){
//use backup category
const backupCategory = await opendiscord.client.fetchGuildCategoryChannel(guild,channelBackupCategory)
if (!backupCategory){
//default category was not found
opendiscord.log("Ticket Move Error: Unable to find category! #2","error",[
{key:"categoryid",value:channelBackupCategory},
{key:"backup",value:"true"}
])
}else{
category = backupCategory.id
categoryMode = "backup"
}
}else{
//use default category
category = normalCategory.id
categoryMode = "normal"
}
}
}
//calculate & update category
const categoryResult = await opendiscord.actions.get("opendiscord:calculate-ticket-category").run("move-ticket",{guild,user,option:ticket.option,channel,ticket,currentCategoryId:channel.parentId})
if (categoryResult && categoryResult.shouldChangeCategory && typeof categoryResult.newCategoryId !== "undefined" && typeof categoryResult.newCategoryMode !== "undefined" && typeof categoryResult.newCategory !== "undefined"){
const originalCategoryName = channel.parent?.name ?? "<unknown>"
const newCategoryName = categoryResult.newCategory?.name ?? "<unknown>"
try{ try{
//only move category when not the same. await utilities.timedAwait(channel.setParent(categoryResult.newCategoryId,{lockPermissions:false}),3000,(err) => {
if (channel.parentId != category) await utilities.timedAwait(channel.setParent(category,{lockPermissions:false}),2500,(err) => { process.emit("uncaughtException",new Error("Error: Unable to change channel parent: "+err))
opendiscord.log("Failed to change channel category on ticket move","error")
}) })
ticket.get("opendiscord:category-mode").value = categoryMode ticket.get("opendiscord:category-mode").value = categoryResult.newCategoryMode
ticket.get("opendiscord:category").value = category ticket.get("opendiscord:category").value = categoryResult.newCategoryId
}catch(e){ }catch(err){
opendiscord.log("Unable to move ticket to 'moved category'!","error",[ await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-category").build("ticket-move",{guild,channel,user,originalCategory:originalCategoryName,newCategory:newCategoryName})).message)
opendiscord.log("Unable to move ticket to moved category.","error",[
{key:"channel",value:"#"+channel.name}, {key:"channel",value:"#"+channel.name},
{key:"channelid",value:channel.id,hidden:true}, {key:"channelid",value:channel.id,hidden:true},
{key:"categoryid",value:category ?? "/"} {key:"categoryid",value:categoryResult.newCategoryId ?? "/"}
]) ])
opendiscord.debugfile.writeErrorMessage(new api.ODError(e,"uncaughtException")) }
} }
//handle permissions //handle permissions
+14 -43
View File
@@ -39,55 +39,26 @@ export async function registerActions(){
await opendiscord.statistics.get("opendiscord:global").setStat("opendiscord:tickets-reopened",1,"increase") await opendiscord.statistics.get("opendiscord:global").setStat("opendiscord:tickets-reopened",1,"increase")
await opendiscord.statistics.get("opendiscord:user").setStat("opendiscord:tickets-reopened",user.id,1,"increase") await opendiscord.statistics.get("opendiscord:user").setStat("opendiscord:tickets-reopened",user.id,1,"increase")
//update category //calculate & update category
if (typeof params.allowCategoryChange == "boolean" ? params.allowCategoryChange : true){ if (typeof params.allowCategoryChange == "boolean" ? params.allowCategoryChange : true){
const channelCategory = ticket.option.get("opendiscord:channel-category").value const categoryResult = await opendiscord.actions.get("opendiscord:calculate-ticket-category").run("reopen-ticket",{guild,user,option:ticket.option,channel,ticket,currentCategoryId:channel.parentId})
const channelBackupCategory = ticket.option.get("opendiscord:channel-category-backup").value if (categoryResult && categoryResult.shouldChangeCategory && typeof categoryResult.newCategoryId !== "undefined" && typeof categoryResult.newCategoryMode !== "undefined" && typeof categoryResult.newCategory !== "undefined"){
if (channelCategory !== ""){ const originalCategoryName = channel.parent?.name ?? "<unknown>"
//category enabled const newCategoryName = categoryResult.newCategory?.name ?? "<unknown>"
try{ try{
const normalCategory = await opendiscord.client.fetchGuildCategoryChannel(guild,channelCategory) await utilities.timedAwait(channel.setParent(categoryResult.newCategoryId,{lockPermissions:false}),3000,(err) => {
if (!normalCategory){ process.emit("uncaughtException",new Error("Error: Unable to change channel parent: "+err))
//default category was not found })
opendiscord.log("Ticket Reopening Error: Unable to find category! #1","error",[ ticket.get("opendiscord:category-mode").value = categoryResult.newCategoryMode
{key:"categoryid",value:channelCategory}, ticket.get("opendiscord:category").value = categoryResult.newCategoryId
{key:"backup",value:"false"} }catch(err){
]) await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-category").build("ticket-reopen",{guild,channel,user,originalCategory:originalCategoryName,newCategory:newCategoryName})).message)
}else{ opendiscord.log("Unable to move ticket to reopened category.","error",[
//default category was found
if (normalCategory.children.cache.size >= 49 && channelBackupCategory != ""){
//use backup category
const backupCategory = await opendiscord.client.fetchGuildCategoryChannel(guild,channelBackupCategory)
if (!backupCategory){
//default category was not found
opendiscord.log("Ticket Reopening Error: Unable to find category! #2","error",[
{key:"categoryid",value:channelBackupCategory},
{key:"backup",value:"true"}
])
}else{
//use backup category
channel.setParent(backupCategory,{lockPermissions:false})
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("opendiscord:category-mode").value = "normal"
ticket.get("opendiscord:category").value = normalCategory.id
}
}
}catch(e){
opendiscord.log("Unable to move ticket to 'reopened category'!","error",[
{key:"channel",value:"#"+channel.name}, {key:"channel",value:"#"+channel.name},
{key:"channelid",value:channel.id,hidden:true}, {key:"channelid",value:channel.id,hidden:true},
{key:"categoryid",value:categoryResult.newCategoryId ?? "/"}
]) ])
opendiscord.debugfile.writeErrorMessage(new api.ODError(e,"uncaughtException"))
} }
}else{
channel.setParent(null,{lockPermissions:false})
ticket.get("opendiscord:category-mode").value = null
ticket.get("opendiscord:category").value = null
} }
} }
+15 -45
View File
@@ -22,56 +22,26 @@ export async function registerActions(){
ticket.get("opendiscord:claimed-on").value = null ticket.get("opendiscord:claimed-on").value = null
ticket.get("opendiscord:busy").value = true ticket.get("opendiscord:busy").value = true
//update category //calculate & update category
if (typeof params.allowCategoryChange == "boolean" ? params.allowCategoryChange : true){ if (typeof params.allowCategoryChange == "boolean" ? params.allowCategoryChange : true){
const channelCategory = ticket.option.get("opendiscord:channel-category").value const categoryResult = await opendiscord.actions.get("opendiscord:calculate-ticket-category").run("unclaim-ticket",{guild,user,option:ticket.option,channel,ticket,currentCategoryId:channel.parentId})
const channelBackupCategory = ticket.option.get("opendiscord:channel-category-backup").value if (categoryResult && categoryResult.shouldChangeCategory && typeof categoryResult.newCategoryId !== "undefined" && typeof categoryResult.newCategoryMode !== "undefined" && typeof categoryResult.newCategory !== "undefined"){
if (channelCategory !== ""){ const originalCategoryName = channel.parent?.name ?? "<unknown>"
//category enabled const newCategoryName = categoryResult.newCategory?.name ?? "<unknown>"
try{ try{
const normalCategory = await opendiscord.client.fetchGuildCategoryChannel(guild,channelCategory) await utilities.timedAwait(channel.setParent(categoryResult.newCategoryId,{lockPermissions:false}),3000,(err) => {
if (!normalCategory){ process.emit("uncaughtException",new Error("Error: Unable to change channel parent: "+err))
//default category was not found })
opendiscord.log("Ticket Unclaiming Error: Unable to find category! #1","error",[ ticket.get("opendiscord:category-mode").value = categoryResult.newCategoryMode
{key:"categoryid",value:channelCategory}, ticket.get("opendiscord:category").value = categoryResult.newCategoryId
{key:"backup",value:"false"} }catch(err){
]) await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-category").build("ticket-unclaim",{guild,channel,user,originalCategory:originalCategoryName,newCategory:newCategoryName})).message)
}else{ opendiscord.log("Unable to move ticket to unclaimed category.","error",[
//default category was found
if (normalCategory.children.cache.size >= 49 && channelBackupCategory != ""){
//use backup category
const backupCategory = await opendiscord.client.fetchGuildCategoryChannel(guild,channelBackupCategory)
if (!backupCategory){
//default category was not found
opendiscord.log("Ticket Unclaiming Error: Unable to find category! #2","error",[
{key:"categoryid",value:channelBackupCategory},
{key:"backup",value:"true"}
])
}else{
//use backup category
channel.setParent(backupCategory,{lockPermissions:false})
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("opendiscord:category-mode").value = "normal"
ticket.get("opendiscord:category").value = normalCategory.id
}
}
}catch(e){
opendiscord.log("Unable to move ticket to 'unclaimed category'!","error",[
{key:"channel",value:"#"+channel.name}, {key:"channel",value:"#"+channel.name},
{key:"channelid",value:channel.id,hidden:true} {key:"channelid",value:channel.id,hidden:true},
{key:"categoryid",value:categoryResult.newCategoryId ?? "/"}
]) ])
opendiscord.debugfile.writeErrorMessage(new api.ODError(e,"uncaughtException"))
} }
}else{
channel.setParent(null,{lockPermissions:false})
ticket.get("opendiscord:category-mode").value = null
ticket.get("opendiscord:category").value = null
} }
} }
+25 -1
View File
@@ -336,7 +336,7 @@ const errorEmbeds = () => {
instance.setTitle(utilities.emojiTitle("❌",lang.getTranslation("errors.titles.channelRename"))) instance.setTitle(utilities.emojiTitle("❌",lang.getTranslation("errors.titles.channelRename")))
instance.setAuthor(user.displayName,user.displayAvatarURL()) instance.setAuthor(user.displayName,user.displayAvatarURL())
instance.setDescription(lang.getTranslation("errors.descriptions.channelRename")) instance.setDescription(lang.getTranslation("errors.descriptions.channelRename"))
instance.setFooter(lang.getTranslationWithParams("errors.descriptions.channelRenameOrigin",[method])) instance.setFooter(lang.getTranslationWithParams("errors.descriptions.channelRenameSource",[method]))
instance.addFields( instance.addFields(
{name:lang.getTranslation("params.uppercase.originalName")+":",value:"```#"+originalName+"```",inline:false}, {name:lang.getTranslation("params.uppercase.originalName")+":",value:"```#"+originalName+"```",inline:false},
{name:lang.getTranslation("params.uppercase.newName")+":",value:"```#"+newName+"```",inline:false} {name:lang.getTranslation("params.uppercase.newName")+":",value:"```#"+newName+"```",inline:false}
@@ -344,6 +344,30 @@ const errorEmbeds = () => {
}) })
) )
//ERROR CHANNEL CATEGORY
embeds.add(new api.ODEmbed("opendiscord:error-channel-category"))
embeds.get("opendiscord:error-channel-category").workers.add(
new api.ODWorker("opendiscord:error-channel-category",0,async (instance,params,origin) => {
const {channel,user,originalCategory,newCategory} = params
const method = (origin == "ticket-create" || origin == "ticket-close" || origin == "ticket-reopen" || origin == "ticket-claim" || origin == "ticket-unclaim" || origin == "ticket-move") ? origin : getMethodFromOrigin(origin)
instance.setColor(generalConfig.data.system.useRedErrorEmbeds ? "Red" : generalConfig.data.mainColor)
//TODO TRANSLATION!!!
instance.setTitle(utilities.emojiTitle("❌","Unable To Change Category"))
instance.setAuthor(user.displayName,user.displayAvatarURL())
//TODO TRANSLATION!!!
instance.setDescription("Due to Discord rate limits, the channel category could not be changed immediately. It will be changed automatically within 10 minutes if the bot remains online.")
instance.setFooter(lang.getTranslationWithParams("errors.descriptions.channelRenameSource",[method]))
instance.addFields(
//TODO TRANSLATION!!!
{name:"Original Category"+":",value:"```"+originalCategory+"```",inline:false},
//TODO TRANSLATION!!!
{name:"New Category"+":",value:"```"+newCategory+"```",inline:false}
)
})
)
//ERROR TICKET BUSY //ERROR TICKET BUSY
embeds.add(new api.ODEmbed("opendiscord:error-ticket-busy")) embeds.add(new api.ODEmbed("opendiscord:error-ticket-busy"))
embeds.get("opendiscord:error-ticket-busy").workers.add( embeds.get("opendiscord:error-ticket-busy").workers.add(
+10
View File
@@ -178,6 +178,16 @@ const errorMessages = () => {
}) })
) )
//ERROR CHANNEL CATEGORY
messages.add(new api.ODMessage("opendiscord:error-channel-category"))
messages.get("opendiscord:error-channel-category").workers.add(
new api.ODWorker("opendiscord:error-channel-category",0,async (instance,params,origin) => {
const {guild,channel,user,originalCategory,newCategory} = params
instance.addEmbed(await embeds.getSafe("opendiscord:error-channel-category").build(origin,{guild,channel,user,originalCategory,newCategory}))
instance.setEphemeral(true)
})
)
//ERROR TICKET BUSY //ERROR TICKET BUSY
messages.add(new api.ODMessage("opendiscord:error-ticket-busy")) messages.add(new api.ODMessage("opendiscord:error-ticket-busy"))
messages.get("opendiscord:error-ticket-busy").workers.add( messages.get("opendiscord:error-ticket-busy").workers.add(
+1 -1
View File
@@ -39,7 +39,7 @@ export interface ODTicketIdMappings extends ODTicketIdConstraint {
"opendiscord:for-deletion":ODTicketData<boolean>, "opendiscord:for-deletion":ODTicketData<boolean>,
"opendiscord:category":ODTicketData<string|null>, "opendiscord:category":ODTicketData<string|null>,
"opendiscord:category-mode":ODTicketData<null|"normal"|"closed"|"backup"|"claimed">, "opendiscord:category-mode":ODTicketData<string|null>,
"opendiscord:autoclose-enabled":ODTicketData<boolean>, "opendiscord:autoclose-enabled":ODTicketData<boolean>,
"opendiscord:autoclose-hours":ODTicketData<number>, "opendiscord:autoclose-hours":ODTicketData<number>,
+6
View File
@@ -128,6 +128,12 @@ export interface ODActionManagerIdMappings extends api.ODActionManagerIdConstrai
result:{}, result:{},
workers:"opendiscord:transfer-ticket"|"opendiscord:discord-logs"|"opendiscord:logs" workers:"opendiscord:transfer-ticket"|"opendiscord:discord-logs"|"opendiscord:logs"
}, },
"opendiscord:calculate-ticket-category":{
origin:"create-ticket"|"close-ticket"|"reopen-ticket"|"claim-ticket"|"unclaim-ticket"|"move-ticket"|"other",
params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel|null,user:discord.User,option:ODTicketOption,ticket:ODTicket|null,currentCategoryId:string|null},
result:{newCategoryId:string|null,newCategoryMode:string|null,newCategory:discord.CategoryChannel|null,shouldChangeCategory:boolean},
workers:"opendiscord:default-category"|"opendiscord:close-category"|"opendiscord:claim-category"|"opendiscord:backup-category"
},
} }
///////////////////////////// /////////////////////////////
+2
View File
@@ -82,6 +82,7 @@ export interface ODEmbedManagerIdMappings extends api.ODEmbedManagerIdConstraint
"opendiscord:error-panel-unknown":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"other",params:{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User},workers:"opendiscord:error-panel-unknown"}, "opendiscord:error-panel-unknown":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"other",params:{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User},workers:"opendiscord:error-panel-unknown"},
"opendiscord:error-not-in-guild":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"other",params:{channel:discord.TextBasedChannel,user:discord.User},workers:"opendiscord:error-not-in-guild"}, "opendiscord:error-not-in-guild":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"other",params:{channel:discord.TextBasedChannel,user:discord.User},workers:"opendiscord:error-not-in-guild"},
"opendiscord:error-channel-rename":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"ticket-pin"|"ticket-unpin"|"ticket-rename"|"ticket-move"|"ticket-priority"|"ticket-transfer"|"other",params:{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User,originalName:string,newName:string},workers:"opendiscord:error-channel-rename"}, "opendiscord:error-channel-rename":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"ticket-pin"|"ticket-unpin"|"ticket-rename"|"ticket-move"|"ticket-priority"|"ticket-transfer"|"other",params:{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User,originalName:string,newName:string},workers:"opendiscord:error-channel-rename"},
"opendiscord:error-channel-category":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"ticket-create"|"ticket-close"|"ticket-reopen"|"ticket-claim"|"ticket-unclaim"|"ticket-move"|"other",params:{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User,originalCategory:string,newCategory:string},workers:"opendiscord:error-channel-category"},
"opendiscord:error-ticket-busy":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"other",params:{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User},workers:"opendiscord:error-ticket-busy"}, "opendiscord:error-ticket-busy":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"other",params:{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User},workers:"opendiscord:error-ticket-busy"},
"opendiscord:help-menu":{origin:"text"|"slash"|"button"|"other",params:{mode:"slash"|"text",page:number},workers:"opendiscord:help-menu"}, "opendiscord:help-menu":{origin:"text"|"slash"|"button"|"other",params:{mode:"slash"|"text",page:number},workers:"opendiscord:help-menu"},
@@ -164,6 +165,7 @@ export interface ODMessageManagerIdMappings extends api.ODMessageManagerIdConstr
"opendiscord:error-panel-unknown":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"other",params:{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User},workers:"opendiscord:error-panel-unknown"}, "opendiscord:error-panel-unknown":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"other",params:{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User},workers:"opendiscord:error-panel-unknown"},
"opendiscord:error-not-in-guild":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"other",params:{channel:discord.TextBasedChannel,user:discord.User},workers:"opendiscord:error-not-in-guild"}, "opendiscord:error-not-in-guild":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"other",params:{channel:discord.TextBasedChannel,user:discord.User},workers:"opendiscord:error-not-in-guild"},
"opendiscord:error-channel-rename":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"ticket-pin"|"ticket-unpin"|"ticket-rename"|"ticket-move"|"ticket-priority"|"ticket-transfer"|"other",params:{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User,originalName:string,newName:string},workers:"opendiscord:error-channel-rename"}, "opendiscord:error-channel-rename":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"ticket-pin"|"ticket-unpin"|"ticket-rename"|"ticket-move"|"ticket-priority"|"ticket-transfer"|"other",params:{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User,originalName:string,newName:string},workers:"opendiscord:error-channel-rename"},
"opendiscord:error-channel-category":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"ticket-create"|"ticket-close"|"ticket-reopen"|"ticket-claim"|"ticket-unclaim"|"ticket-move"|"other",params:{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User,originalCategory:string,newCategory:string},workers:"opendiscord:error-channel-category"},
"opendiscord:error-ticket-busy":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"other",params:{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User},workers:"opendiscord:error-ticket-busy"}, "opendiscord:error-ticket-busy":{origin:"slash"|"text"|"button"|"dropdown"|"modal"|"other",params:{guild:discord.Guild|null,channel:discord.TextBasedChannel,user:discord.User},workers:"opendiscord:error-ticket-busy"},
"opendiscord:help-menu":{origin:"slash"|"text"|"button"|"other",params:{mode:"slash"|"text",page:number},workers:"opendiscord:help-menu"}, "opendiscord:help-menu":{origin:"slash"|"text"|"button"|"other",params:{mode:"slash"|"text",page:number},workers:"opendiscord:help-menu"},
+1
View File
@@ -781,6 +781,7 @@ const main = async () => {
opendiscord.log("Loading actions...","system") opendiscord.log("Loading actions...","system")
if (opendiscord.sharedFuses.getFuse("actionsLoading")){ if (opendiscord.sharedFuses.getFuse("actionsLoading")){
await (await import("./actions/createTicketPermissions.js")).registerActions() await (await import("./actions/createTicketPermissions.js")).registerActions()
await (await import("./actions/calculateTicketCategory.js")).registerActions()
await (await import("./actions/createTranscript.js")).registerActions() await (await import("./actions/createTranscript.js")).registerActions()
await (await import("./actions/createTicket.js")).registerActions() await (await import("./actions/createTicket.js")).registerActions()
await (await import("./actions/closeTicket.js")).registerActions() await (await import("./actions/closeTicket.js")).registerActions()