(v4.2.0) Reworked ticket channel name logic
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
///////////////////////////////////////
|
||||
//CALCULATE TICKET NAME 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-name"))
|
||||
opendiscord.actions.get("opendiscord:calculate-ticket-name").workers.add([
|
||||
new api.ODWorker("opendiscord:calculate-ticket-name",0,async (instance,params,origin,cancel) => {
|
||||
const {guild,user,channel,option,ticket,currentChannelName} = params
|
||||
|
||||
//calculate base channel name
|
||||
const channelPrefix = option.get("opendiscord:channel-prefix").value
|
||||
const channelSuffix = (ticket) ? ticket.get("opendiscord:channel-suffix").value : (await opendiscord.options.suffix.getSuffixFromOption(option,user,guild) ?? "unknown")
|
||||
const channelRenamed = (ticket && ticket.exists("opendiscord:channel-renamed")) ? ticket.get("opendiscord:channel-renamed").value : null
|
||||
const baseChannelName = (channelRenamed) ? channelRenamed : channelPrefix+channelSuffix
|
||||
|
||||
//calculate status emojis
|
||||
const pinEmoji = (ticket && ticket.get("opendiscord:pinned").value) ? generalConfig.data.system.pinEmoji : ""
|
||||
const priorityEmoji = (ticket) ? (opendiscord.priorities.getFromPriorityLevel(ticket.get("opendiscord:priority").value).channelEmoji ?? "") : ""
|
||||
|
||||
instance.newChannelName = pinEmoji+priorityEmoji+baseChannelName
|
||||
instance.newChannelSuffix = channelSuffix
|
||||
instance.shouldChangeName = (instance.newChannelName !== currentChannelName)
|
||||
})
|
||||
])
|
||||
}
|
||||
@@ -18,11 +18,14 @@ export async function registerActions(){
|
||||
await opendiscord.events.get("onTicketChannelCreation").emit([option,user])
|
||||
|
||||
//get channel properties
|
||||
const channelPrefix = option.get("opendiscord:channel-prefix").value
|
||||
const channelTopicText = option.get("opendiscord:channel-topic").value
|
||||
const channelSuffix = await opendiscord.options.suffix.getSuffixFromOption(option,user,guild)
|
||||
const channelName = channelPrefix+channelSuffix
|
||||
|
||||
//calculate channel name
|
||||
const channelNameResult = await opendiscord.actions.get("opendiscord:calculate-ticket-name").run("create-ticket",{guild,user,option,channel:null,ticket:null,currentChannelName:null})
|
||||
if (!channelNameResult) return opendiscord.log("Ticket Creation Error: Unable to calculate ticket name.","error")
|
||||
const channelName = (channelNameResult.shouldChangeName && typeof channelNameResult.newChannelName !== "undefined") ? channelNameResult.newChannelName : "ot-unnamed-ticket"
|
||||
const channelSuffix = (typeof channelNameResult.newChannelSuffix !== "undefined") ? channelNameResult.newChannelSuffix : "unknown"
|
||||
|
||||
//calculate category
|
||||
const categoryResult = await opendiscord.actions.get("opendiscord:calculate-ticket-category").run("create-ticket",{guild,user,option,channel:null,ticket:null,currentCategoryId:null})
|
||||
if (!categoryResult) return opendiscord.log("Ticket Creation Error: Unable to calculate ticket category.","error")
|
||||
@@ -118,6 +121,7 @@ export async function registerActions(){
|
||||
new api.ODTicketData("opendiscord:ticket-message",null),
|
||||
new api.ODTicketData("opendiscord:participants",participants),
|
||||
new api.ODTicketData("opendiscord:channel-suffix",channelSuffix),
|
||||
new api.ODTicketData("opendiscord:channel-renamed",null),
|
||||
new api.ODTicketData("opendiscord:previous-creators",[]),
|
||||
|
||||
new api.ODTicketData("opendiscord:open",true),
|
||||
|
||||
+16
-16
@@ -20,10 +20,6 @@ export async function registerActions(){
|
||||
await opendiscord.statistics.get("opendiscord:global").setStat("opendiscord:tickets-moved",1,"increase")
|
||||
await opendiscord.statistics.get("opendiscord:user").setStat("opendiscord:tickets-moved",user.id,1,"increase")
|
||||
|
||||
//get new channel properties
|
||||
const channelPrefix = ticket.option.get("opendiscord:channel-prefix").value
|
||||
const channelSuffix = ticket.get("opendiscord:channel-suffix").value
|
||||
|
||||
//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"){
|
||||
@@ -109,18 +105,22 @@ export async function registerActions(){
|
||||
ticket.get("opendiscord:participants").value = participants
|
||||
ticket.get("opendiscord:participants").refreshDatabase()
|
||||
|
||||
//rename channel (and give error when crashed)
|
||||
const pinEmoji = ticket.get("opendiscord:pinned").value ? generalConfig.data.system.pinEmoji : ""
|
||||
const priorityEmoji = opendiscord.priorities.getFromPriorityLevel(ticket.get("opendiscord:priority").value).channelEmoji ?? ""
|
||||
|
||||
const originalName = channel.name
|
||||
const newName = pinEmoji+priorityEmoji+utilities.trimEmojis(channelPrefix+channelSuffix)
|
||||
try{
|
||||
await utilities.timedAwait(channel.setName(newName),2500,(err) => {
|
||||
opendiscord.log("Failed to rename channel on ticket move","error")
|
||||
})
|
||||
}catch(err){
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-move",{guild,channel,user,originalName,newName:newName})).message)
|
||||
//calculate channel name
|
||||
const channelNameResult = await opendiscord.actions.get("opendiscord:calculate-ticket-name").run("move-ticket",{guild,user,option:ticket.option,channel,ticket,currentChannelName:channel.name})
|
||||
if (channelNameResult && channelNameResult.shouldChangeName && typeof channelNameResult.newChannelName !== "undefined"){
|
||||
const originalName = channel.name
|
||||
const newName = channelNameResult.newChannelName
|
||||
try{
|
||||
await utilities.timedAwait(channel.setName(newName),2500,(err) => {
|
||||
opendiscord.log("Failed to rename channel on ticket move","error")
|
||||
})
|
||||
}catch(err){
|
||||
opendiscord.log("Unable to rename channel while moving ticket! Waiting until ratelimit expires...","warning",[
|
||||
{key:"oldName",value:originalName},
|
||||
{key:"newName",value:newName}
|
||||
])
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-move",{guild,channel,user,originalName,newName})).message)
|
||||
}
|
||||
}
|
||||
|
||||
//update ticket message
|
||||
|
||||
+16
-12
@@ -31,18 +31,22 @@ export async function registerActions(){
|
||||
await channel.setPosition(0,{reason:"Ticket Pinned!"})
|
||||
}
|
||||
|
||||
//rename channel (and give error when crashed)
|
||||
const pinEmoji = ticket.get("opendiscord:pinned").value ? generalConfig.data.system.pinEmoji : ""
|
||||
const priorityEmoji = opendiscord.priorities.getFromPriorityLevel(ticket.get("opendiscord:priority").value).channelEmoji ?? ""
|
||||
|
||||
const originalName = channel.name
|
||||
const newName = pinEmoji+priorityEmoji+utilities.trimEmojis(channel.name)
|
||||
try{
|
||||
await utilities.timedAwait(channel.setName(newName),2500,(err) => {
|
||||
opendiscord.log("Failed to rename channel on ticket pin","error")
|
||||
})
|
||||
}catch(err){
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-pin",{guild,channel,user,originalName,newName})).message)
|
||||
//calculate channel name
|
||||
const channelNameResult = await opendiscord.actions.get("opendiscord:calculate-ticket-name").run("pin-ticket",{guild,user,option:ticket.option,channel,ticket,currentChannelName:channel.name})
|
||||
if (channelNameResult && channelNameResult.shouldChangeName && typeof channelNameResult.newChannelName !== "undefined"){
|
||||
const originalName = channel.name
|
||||
const newName = channelNameResult.newChannelName
|
||||
try{
|
||||
await utilities.timedAwait(channel.setName(newName),2500,(err) => {
|
||||
opendiscord.log("Failed to rename channel on ticket pin","error")
|
||||
})
|
||||
}catch(err){
|
||||
opendiscord.log("Unable to rename channel while pinning ticket! Waiting until ratelimit expires...","warning",[
|
||||
{key:"oldName",value:originalName},
|
||||
{key:"newName",value:newName}
|
||||
])
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-pin",{guild,channel,user,originalName,newName})).message)
|
||||
}
|
||||
}
|
||||
|
||||
//update ticket message
|
||||
|
||||
+18
-11
@@ -15,18 +15,25 @@ export async function registerActions(){
|
||||
|
||||
await opendiscord.events.get("onTicketRename").emit([ticket,user,channel,reason])
|
||||
|
||||
//rename channel (and give error when crashed)
|
||||
const pinEmoji = ticket.get("opendiscord:pinned").value ? generalConfig.data.system.pinEmoji : ""
|
||||
const priorityEmoji = opendiscord.priorities.getFromPriorityLevel(ticket.get("opendiscord:priority").value).channelEmoji ?? ""
|
||||
//update ticket
|
||||
ticket.get("opendiscord:channel-renamed").value = data
|
||||
|
||||
const originalName = channel.name
|
||||
const newName = pinEmoji+priorityEmoji+utilities.trimEmojis(data)
|
||||
try{
|
||||
await utilities.timedAwait(channel.setName(newName),2500,(err) => {
|
||||
opendiscord.log("Failed to rename channel on ticket rename","error")
|
||||
})
|
||||
}catch(err){
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-rename",{guild,channel,user,originalName,newName:data})).message)
|
||||
//calculate channel name
|
||||
const channelNameResult = await opendiscord.actions.get("opendiscord:calculate-ticket-name").run("rename-ticket",{guild,user,option:ticket.option,channel,ticket,currentChannelName:channel.name})
|
||||
if (channelNameResult && channelNameResult.shouldChangeName && typeof channelNameResult.newChannelName !== "undefined"){
|
||||
const originalName = channel.name
|
||||
const newName = channelNameResult.newChannelName
|
||||
try{
|
||||
await utilities.timedAwait(channel.setName(newName),2500,(err) => {
|
||||
opendiscord.log("Failed to rename channel on ticket rename","error")
|
||||
})
|
||||
}catch(err){
|
||||
opendiscord.log("Unable to rename channel while renaming ticket! Waiting until ratelimit expires...","warning",[
|
||||
{key:"oldName",value:originalName},
|
||||
{key:"newName",value:newName}
|
||||
])
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-rename",{guild,channel,user,originalName,newName})).message)
|
||||
}
|
||||
}
|
||||
|
||||
//update ticket message
|
||||
|
||||
@@ -36,10 +36,6 @@ export async function registerActions(){
|
||||
await opendiscord.statistics.get("opendiscord:global").setStat("opendiscord:tickets-transferred",1,"increase")
|
||||
await opendiscord.statistics.get("opendiscord:user").setStat("opendiscord:tickets-transferred",user.id,1,"increase")
|
||||
|
||||
//get new channel properties
|
||||
const channelPrefix = ticket.option.get("opendiscord:channel-prefix").value
|
||||
const channelSuffix = ticket.get("opendiscord:channel-suffix").value
|
||||
|
||||
//handle permissions
|
||||
const permissions: discord.OverwriteResolvable[] = [{
|
||||
type:discord.OverwriteType.Role,
|
||||
@@ -93,18 +89,22 @@ export async function registerActions(){
|
||||
opendiscord.log("Failed to reset channel permissions on ticket transfer!","error")
|
||||
}
|
||||
|
||||
//rename channel (and give error when crashed)
|
||||
const pinEmoji = ticket.get("opendiscord:pinned").value ? generalConfig.data.system.pinEmoji : ""
|
||||
const priorityEmoji = opendiscord.priorities.getFromPriorityLevel(ticket.get("opendiscord:priority").value).channelEmoji ?? ""
|
||||
|
||||
const originalName = channel.name
|
||||
const newName = pinEmoji+priorityEmoji+utilities.trimEmojis(channelPrefix+channelSuffix)
|
||||
try{
|
||||
await utilities.timedAwait(channel.setName(newName),2500,(err) => {
|
||||
opendiscord.log("Failed to rename channel on ticket transfer","error")
|
||||
})
|
||||
}catch(err){
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-transfer",{guild,channel,user,originalName,newName:newName})).message)
|
||||
//calculate channel name
|
||||
const channelNameResult = await opendiscord.actions.get("opendiscord:calculate-ticket-name").run("transfer-ticket",{guild,user,option:ticket.option,channel,ticket,currentChannelName:channel.name})
|
||||
if (channelNameResult && channelNameResult.shouldChangeName && typeof channelNameResult.newChannelName !== "undefined"){
|
||||
const originalName = channel.name
|
||||
const newName = channelNameResult.newChannelName
|
||||
try{
|
||||
await utilities.timedAwait(channel.setName(newName),2500,(err) => {
|
||||
opendiscord.log("Failed to rename channel on ticket transfer","error")
|
||||
})
|
||||
}catch(err){
|
||||
opendiscord.log("Unable to rename channel while transferring ticket! Waiting until ratelimit expires...","warning",[
|
||||
{key:"oldName",value:originalName},
|
||||
{key:"newName",value:newName}
|
||||
])
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-transfer",{guild,channel,user,originalName,newName})).message)
|
||||
}
|
||||
}
|
||||
|
||||
//update ticket message
|
||||
|
||||
+16
-12
@@ -22,18 +22,22 @@ export async function registerActions(){
|
||||
ticket.get("opendiscord:pinned-on").value = null
|
||||
ticket.get("opendiscord:busy").value = true
|
||||
|
||||
//rename channel (and give error when crashed)
|
||||
const pinEmoji = ticket.get("opendiscord:pinned").value ? generalConfig.data.system.pinEmoji : ""
|
||||
const priorityEmoji = opendiscord.priorities.getFromPriorityLevel(ticket.get("opendiscord:priority").value).channelEmoji ?? ""
|
||||
|
||||
const originalName = channel.name
|
||||
const newName = pinEmoji+priorityEmoji+utilities.trimEmojis(channel.name)
|
||||
try{
|
||||
await utilities.timedAwait(channel.setName(newName),2500,(err) => {
|
||||
opendiscord.log("Failed to rename channel on ticket unpin","error")
|
||||
})
|
||||
}catch(err){
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-unpin",{guild,channel,user,originalName,newName})).message)
|
||||
//calculate channel name
|
||||
const channelNameResult = await opendiscord.actions.get("opendiscord:calculate-ticket-name").run("unpin-ticket",{guild,user,option:ticket.option,channel,ticket,currentChannelName:channel.name})
|
||||
if (channelNameResult && channelNameResult.shouldChangeName && typeof channelNameResult.newChannelName !== "undefined"){
|
||||
const originalName = channel.name
|
||||
const newName = channelNameResult.newChannelName
|
||||
try{
|
||||
await utilities.timedAwait(channel.setName(newName),2500,(err) => {
|
||||
opendiscord.log("Failed to rename channel on ticket unpin","error")
|
||||
})
|
||||
}catch(err){
|
||||
opendiscord.log("Unable to rename channel while unpinning ticket! Waiting until ratelimit expires...","warning",[
|
||||
{key:"oldName",value:originalName},
|
||||
{key:"newName",value:newName}
|
||||
])
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-unpin",{guild,channel,user,originalName,newName})).message)
|
||||
}
|
||||
}
|
||||
|
||||
//update ticket message
|
||||
|
||||
@@ -20,18 +20,22 @@ export async function registerActions(){
|
||||
ticket.get("opendiscord:busy").value = true
|
||||
if (newPriority) ticket.get("opendiscord:priority").value = newPriority.priority
|
||||
|
||||
//rename channel (and give error when crashed)
|
||||
const pinEmoji = ticket.get("opendiscord:pinned").value ? generalConfig.data.system.pinEmoji : ""
|
||||
const priorityEmoji = newPriority.channelEmoji ?? ""
|
||||
|
||||
const originalName = channel.name
|
||||
const newName = pinEmoji+priorityEmoji+utilities.trimEmojis(channel.name)
|
||||
try{
|
||||
await utilities.timedAwait(channel.setName(newName),2500,(err) => {
|
||||
opendiscord.log("Failed to rename channel on ticket priority update","error")
|
||||
})
|
||||
}catch(err){
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-priority",{guild,channel,user,originalName,newName})).message)
|
||||
//calculate channel name
|
||||
const channelNameResult = await opendiscord.actions.get("opendiscord:calculate-ticket-name").run("priority-change",{guild,user,option:ticket.option,channel,ticket,currentChannelName:channel.name})
|
||||
if (channelNameResult && channelNameResult.shouldChangeName && typeof channelNameResult.newChannelName !== "undefined"){
|
||||
const originalName = channel.name
|
||||
const newName = channelNameResult.newChannelName
|
||||
try{
|
||||
await utilities.timedAwait(channel.setName(newName),2500,(err) => {
|
||||
opendiscord.log("Failed to rename channel on priority change","error")
|
||||
})
|
||||
}catch(err){
|
||||
opendiscord.log("Unable to rename channel while updating ticket priority! Waiting until ratelimit expires...","warning",[
|
||||
{key:"oldName",value:originalName},
|
||||
{key:"newName",value:newName}
|
||||
])
|
||||
await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-priority",{guild,channel,user,originalName,newName})).message)
|
||||
}
|
||||
}
|
||||
|
||||
//reply with new message
|
||||
|
||||
@@ -19,6 +19,7 @@ export interface ODTicketIdMappings extends ODTicketIdConstraint {
|
||||
"opendiscord:ticket-message":ODTicketData<string|null>,
|
||||
"opendiscord:participants":ODTicketData<{type:"role"|"user",id:string}[]>,
|
||||
"opendiscord:channel-suffix":ODTicketData<string>,
|
||||
"opendiscord:channel-renamed":ODTicketData<string|null>,
|
||||
"opendiscord:previous-creators":ODTicketData<string[]>,
|
||||
|
||||
"opendiscord:open":ODTicketData<boolean>,
|
||||
|
||||
@@ -134,6 +134,12 @@ export interface ODActionManagerIdMappings extends api.ODActionManagerIdConstrai
|
||||
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"
|
||||
},
|
||||
"opendiscord:calculate-ticket-name":{
|
||||
origin:"create-ticket"|"close-ticket"|"reopen-ticket"|"claim-ticket"|"unclaim-ticket"|"move-ticket"|"pin-ticket"|"unpin-ticket"|"rename-ticket"|"transfer-ticket"|"priority-change"|"other",
|
||||
params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel|null,user:discord.User,option:ODTicketOption,ticket:ODTicket|null,currentChannelName:string|null},
|
||||
result:{newChannelName:string,newChannelSuffix:string,shouldChangeName:boolean},
|
||||
workers:"opendiscord:calculate-ticket-name"
|
||||
},
|
||||
}
|
||||
|
||||
/////////////////////////////
|
||||
|
||||
@@ -783,6 +783,7 @@ const main = async () => {
|
||||
if (opendiscord.sharedFuses.getFuse("actionsLoading")){
|
||||
await (await import("./actions/createTicketPermissions.js")).registerActions()
|
||||
await (await import("./actions/calculateTicketCategory.js")).registerActions()
|
||||
await (await import("./actions/calculateTicketName.js")).registerActions()
|
||||
await (await import("./actions/createTranscript.js")).registerActions()
|
||||
await (await import("./actions/createTicket.js")).registerActions()
|
||||
await (await import("./actions/closeTicket.js")).registerActions()
|
||||
|
||||
Reference in New Issue
Block a user