Started with channel topic auto-update action
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
///////////////////////////////////////
|
||||
//TICKET TOPIC SYSTEM
|
||||
///////////////////////////////////////
|
||||
import {opendiscord, api, utilities} from "../index"
|
||||
import * as discord from "discord.js"
|
||||
|
||||
const generalConfig = opendiscord.configs.get("opendiscord:general")
|
||||
|
||||
export const registerActions = async () => {
|
||||
opendiscord.actions.add(new api.ODAction("opendiscord:update-ticket-topic"))
|
||||
opendiscord.actions.get("opendiscord:update-ticket-topic").workers.add([
|
||||
new api.ODWorker("opendiscord:update-ticket-topic",2,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,newTopic} = params
|
||||
if (channel.isThread() || !(channel instanceof discord.TextChannel)) throw new api.ODSystemError("Unable to set topic of ticket! Open Ticket doesn't support threads!")
|
||||
|
||||
//update ticket
|
||||
ticket.get("opendiscord:busy").value = true
|
||||
if (newTopic) ticket.get("opendiscord:topic").value = newTopic
|
||||
|
||||
//handle channel topic
|
||||
const channelTopics: string[] = []
|
||||
if (generalConfig.data.system.channelTopic.showOptionName) channelTopics.push(ticket.option.get("opendiscord:name").value)
|
||||
if (generalConfig.data.system.channelTopic.showOptionDescription) channelTopics.push(ticket.option.get("opendiscord:description").value)
|
||||
if (generalConfig.data.system.channelTopic.showOptionTopic) channelTopics.push(ticket.get("opendiscord:topic").value)
|
||||
if (generalConfig.data.system.channelTopic.showPriority) channelTopics.push("**Priority:** "+opendiscord.priorities.get("opendiscord:none").renderDisplayName()) //TODO TRANSLATION!!!
|
||||
if (generalConfig.data.system.channelTopic.showClosed) channelTopics.push("**Status:** Opened") //TODO TRANSLATION!!!
|
||||
if (generalConfig.data.system.channelTopic.showClaimed) channelTopics.push("**Claimed By:** No-one") //TODO TRANSLATION!!!
|
||||
if (generalConfig.data.system.channelTopic.showPinned) channelTopics.push("**Pinned:** No") //TODO TRANSLATION!!!
|
||||
if (generalConfig.data.system.channelTopic.showCreator) channelTopics.push("**Creator:** "+discord.userMention(user.id)) //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
|
||||
channel.setTopic(channelTopics.join(" • "),"Topic Changed")
|
||||
|
||||
//reply with new message
|
||||
if (params.sendMessage && newTopic) await channel.send((await opendiscord.builders.messages.getSafe("opendiscord:topic-set").build(source,{guild,channel,user,ticket,topic:newTopic})).message)
|
||||
ticket.get("opendiscord:busy").value = false
|
||||
}),
|
||||
new api.ODWorker("opendiscord:discord-logs",1,async (instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket} = params
|
||||
}),
|
||||
new api.ODWorker("opendiscord:logs",0,(instance,params,source,cancel) => {
|
||||
const {guild,channel,user,ticket,newTopic} = params
|
||||
|
||||
if (newTopic) opendiscord.log(user.displayName+" changed the topic of a ticket!","info",[
|
||||
{key:"user",value:user.username},
|
||||
{key:"userid",value:user.id,hidden:true},
|
||||
{key:"channel",value:"#"+channel.name},
|
||||
{key:"channelid",value:channel.id,hidden:true},
|
||||
{key:"topic",value:newTopic},
|
||||
{key:"method",value:source}
|
||||
])
|
||||
})
|
||||
])
|
||||
}
|
||||
@@ -111,7 +111,13 @@ export interface ODActionManagerIds_Default {
|
||||
params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,filter:ODTicketClearFilter,list:ODTicket[]},
|
||||
result:{list:string[]},
|
||||
workers:"opendiscord:clear-tickets"|"opendiscord:discord-logs"|"opendiscord:logs"
|
||||
}
|
||||
},
|
||||
"opendiscord:update-ticket-topic":{
|
||||
source:"slash"|"text"|"ticket-action"|"other",
|
||||
params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,newTopic:string|null,sendMessage:boolean},
|
||||
result:{},
|
||||
workers:"opendiscord:update-ticket-topic"|"opendiscord:discord-logs"|"opendiscord:logs"
|
||||
},
|
||||
}
|
||||
|
||||
/**## ODActionManager_Default `default_class`
|
||||
|
||||
@@ -296,7 +296,7 @@ export interface ODEmbedManagerIds_Default {
|
||||
"opendiscord:autoclose-disable":{source:"slash"|"text"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,reason:string|null},workers:"opendiscord:autoclose-disable"},
|
||||
"opendiscord:autodelete-disable":{source:"slash"|"text"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,reason:string|null},workers:"opendiscord:autodelete-disable"},
|
||||
|
||||
"opendiscord:topic-set":{source:"slash"|"text"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,topic:string},workers:"opendiscord:topic-set"},
|
||||
"opendiscord:topic-set":{source:"slash"|"text"|"ticket-action"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,topic:string},workers:"opendiscord:topic-set"},
|
||||
"opendiscord:priority-set":{source:"slash"|"text"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,priority:ODPriorityLevel,reason:string|null},workers:"opendiscord:priority-set"},
|
||||
"opendiscord:priority-get":{source:"slash"|"text"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,priority:ODPriorityLevel},workers:"opendiscord:priority-get"},
|
||||
}
|
||||
@@ -434,7 +434,7 @@ export interface ODMessageManagerIds_Default {
|
||||
"opendiscord:autoclose-disable":{source:"slash"|"text"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,reason:string|null},workers:"opendiscord:autoclose-disable"},
|
||||
"opendiscord:autodelete-disable":{source:"slash"|"text"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,reason:string|null},workers:"opendiscord:autodelete-disable"},
|
||||
|
||||
"opendiscord:topic-set":{source:"slash"|"text"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,topic:string},workers:"opendiscord:topic-set"},
|
||||
"opendiscord:topic-set":{source:"slash"|"text"|"ticket-action"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,topic:string},workers:"opendiscord:topic-set"},
|
||||
"opendiscord:priority-set":{source:"slash"|"text"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,priority:ODPriorityLevel,reason:string|null},workers:"opendiscord:priority-set"},
|
||||
"opendiscord:priority-get":{source:"slash"|"text"|"other",params:{guild:discord.Guild,channel:discord.GuildTextBasedChannel,user:discord.User,ticket:ODTicket,priority:ODPriorityLevel},workers:"opendiscord:priority-get"},
|
||||
}
|
||||
|
||||
@@ -757,6 +757,7 @@ const main = async () => {
|
||||
await (await import("./actions/removeTicketUser.js")).registerActions()
|
||||
await (await import("./actions/reactionRole.js")).registerActions()
|
||||
await (await import("./actions/clearTickets.js")).registerActions()
|
||||
await (await import("./actions/updateTicketTopic.js")).registerActions()
|
||||
}
|
||||
await opendiscord.events.get("onActionLoad").emit([opendiscord.actions])
|
||||
await opendiscord.events.get("afterActionsLoaded").emit([opendiscord.actions])
|
||||
|
||||
Reference in New Issue
Block a user