diff --git a/src/actions/moveTicket.ts b/src/actions/moveTicket.ts index a5d3a64..591aef6 100644 --- a/src/actions/moveTicket.ts +++ b/src/actions/moveTicket.ts @@ -29,7 +29,6 @@ export const registerActions = async () => { 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 - const channelName = channelPrefix+channelSuffix //handle category let category: string|null = null @@ -155,17 +154,18 @@ export const registerActions = async () => { 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(channelName),2500,(err) => { + 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:channelName})).message) + await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:error-channel-rename").build("ticket-move",{guild,channel,user,originalName,newName:newName})).message) } - try{ - if (channel.type == discord.ChannelType.GuildText) channel.setTopic(channelTopic) - }catch{} //update ticket message const ticketMessage = await opendiscord.tickets.getTicketMessage(ticket) @@ -173,7 +173,7 @@ export const registerActions = async () => { try{ 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",[ + opendiscord.log("Unable to edit ticket message on ticket moving!","error",[ {key:"channel",value:"#"+channel.name}, {key:"channelid",value:channel.id,hidden:true}, {key:"messageid",value:ticketMessage.id}, diff --git a/src/actions/updateTicketPriority.ts b/src/actions/updateTicketPriority.ts index 50c16d0..de328a7 100644 --- a/src/actions/updateTicketPriority.ts +++ b/src/actions/updateTicketPriority.ts @@ -14,7 +14,7 @@ export const registerActions = async () => { if (channel.isThread() || !(channel instanceof discord.TextChannel)) throw new api.ODSystemError("Unable to set priority of ticket! Open Ticket doesn't support threads!") const oldPriority = opendiscord.priorities.getFromPriorityLevel(ticket.get("opendiscord:priority").value) - await opendiscord.events.get("onTicketPriorityChange").emit([ticket,user,channel,oldPriority,newPriority]) + await opendiscord.events.get("onTicketPriorityChange").emit([ticket,user,channel,oldPriority,newPriority,reason]) //update ticket ticket.get("opendiscord:busy").value = true @@ -37,7 +37,7 @@ export const registerActions = async () => { //reply with new message if (params.sendMessage) await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:priority-set").build(source,{guild,channel,user,ticket,priority:newPriority,reason})).message) ticket.get("opendiscord:busy").value = false - await opendiscord.events.get("afterTicketPriorityChanged").emit([ticket,user,channel,oldPriority,newPriority]) + await opendiscord.events.get("afterTicketPriorityChanged").emit([ticket,user,channel,oldPriority,newPriority,reason]) //update channel topic await opendiscord.actions.get("opendiscord:update-ticket-topic").run("ticket-action",{guild,channel,user,ticket,sendMessage:false,newTopic:null}) @@ -58,4 +58,8 @@ export const registerActions = async () => { ]) }) ]) + opendiscord.actions.get("opendiscord:update-ticket-priority").workers.backupWorker = new api.ODWorker("opendiscord:cancel-busy",0,(instance,params) => { + //set busy to false in case of crash or cancel + params.ticket.get("opendiscord:busy").value = false + }) } \ No newline at end of file diff --git a/src/actions/updateTicketTopic.ts b/src/actions/updateTicketTopic.ts index f01637b..d974166 100644 --- a/src/actions/updateTicketTopic.ts +++ b/src/actions/updateTicketTopic.ts @@ -24,6 +24,7 @@ export const registerActions = async () => { const closed = ticket.get("opendiscord:closed").value const claimedBy = ticket.get("opendiscord:claimed-by").value const pinned = ticket.get("opendiscord:pinned").value + const creator = ticket.get("opendiscord:opened-by").value ?? opendiscord.client.client.user.id //handle channel topic const channelTopics: string[] = [] @@ -34,7 +35,7 @@ export const registerActions = async () => { if (generalConfig.data.system.channelTopic.showClosed) channelTopics.push("**Status:** "+(closed ? "Closed" : "Opened")) //TODO TRANSLATION!!! if (generalConfig.data.system.channelTopic.showClaimed) channelTopics.push("**Claimed By:** "+(claimedBy ? discord.userMention(claimedBy) : "No-one")) //TODO TRANSLATION!!! if (generalConfig.data.system.channelTopic.showPinned) channelTopics.push("**Pinned:** "+(pinned ? "Yes" : "No")) //TODO TRANSLATION!!! - if (generalConfig.data.system.channelTopic.showCreator) channelTopics.push("**Creator:** "+discord.userMention(user.id)) //TODO TRANSLATION!!! + if (generalConfig.data.system.channelTopic.showCreator) channelTopics.push("**Creator:** "+discord.userMention(creator)) //TODO TRANSLATION!!! if (generalConfig.data.system.channelTopic.showParticipants) channelTopics.push("**Participants:** "+ticket.get("opendiscord:participants").value.map((p) => (p.type == "user") ? discord.userMention(p.id) : discord.roleMention(p.id)).join(", ")) //TODO TRANSLATION!!! //update channel @@ -61,4 +62,8 @@ export const registerActions = async () => { ]) }) ]) + opendiscord.actions.get("opendiscord:update-ticket-topic").workers.backupWorker = new api.ODWorker("opendiscord:cancel-busy",0,(instance,params) => { + //set busy to false in case of crash or cancel + params.ticket.get("opendiscord:busy").value = false + }) } \ No newline at end of file