BREAKING: changed all ids to "opendiscord:"

This commit is contained in:
DJj123dj
2025-02-01 10:29:35 +01:00
parent 29f8e1452c
commit 6acbf74846
101 changed files with 3736 additions and 3739 deletions
+69 -69
View File
@@ -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}))
})
])
}