BREAKING: changed openticket to opendiscord in API

This commit is contained in:
DJj123dj
2025-02-01 10:22:27 +01:00
parent ce242741cd
commit 29f8e1452c
103 changed files with 2160 additions and 2175 deletions
+18 -18
View File
@@ -1,26 +1,26 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
const generalConfig = openticket.configs.get("openticket:general")
const generalConfig = opendiscord.configs.get("openticket:general")
export const loadAllConfigCheckers = async () => {
openticket.checkers.add(new api.ODChecker("openticket:general",openticket.checkers.storage,0,openticket.configs.get("openticket:general"),defaultGeneralStructure))
openticket.checkers.add(new api.ODChecker("openticket:options",openticket.checkers.storage,1,openticket.configs.get("openticket:options"),defaultOptionsStructure))
openticket.checkers.add(new api.ODChecker("openticket:panels",openticket.checkers.storage,0,openticket.configs.get("openticket:panels"),defaultPanelsStructure))
openticket.checkers.add(new api.ODChecker("openticket:questions",openticket.checkers.storage,2,openticket.configs.get("openticket:questions"),defaultQuestionsStructure))
openticket.checkers.add(new api.ODChecker("openticket:transcripts",openticket.checkers.storage,0,openticket.configs.get("openticket:transcripts"),defaultTranscriptsStructure))
opendiscord.checkers.add(new api.ODChecker("openticket:general",opendiscord.checkers.storage,0,opendiscord.configs.get("openticket:general"),defaultGeneralStructure))
opendiscord.checkers.add(new api.ODChecker("openticket:options",opendiscord.checkers.storage,1,opendiscord.configs.get("openticket:options"),defaultOptionsStructure))
opendiscord.checkers.add(new api.ODChecker("openticket:panels",opendiscord.checkers.storage,0,opendiscord.configs.get("openticket:panels"),defaultPanelsStructure))
opendiscord.checkers.add(new api.ODChecker("openticket:questions",opendiscord.checkers.storage,2,opendiscord.configs.get("openticket:questions"),defaultQuestionsStructure))
opendiscord.checkers.add(new api.ODChecker("openticket:transcripts",opendiscord.checkers.storage,0,opendiscord.configs.get("openticket:transcripts"),defaultTranscriptsStructure))
}
export const loadAllConfigCheckerFunctions = async () => {
openticket.checkers.functions.add(new api.ODCheckerFunction("openticket:unused-options",defaultUnusedOptionsFunction))
openticket.checkers.functions.add(new api.ODCheckerFunction("openticket:unused-questions",defaultUnusedQuestionsFunction))
openticket.checkers.functions.add(new api.ODCheckerFunction("openticket:dropdown-options",defaultDropdownOptionsFunction))
opendiscord.checkers.functions.add(new api.ODCheckerFunction("openticket:unused-options",defaultUnusedOptionsFunction))
opendiscord.checkers.functions.add(new api.ODCheckerFunction("openticket:unused-questions",defaultUnusedQuestionsFunction))
opendiscord.checkers.functions.add(new api.ODCheckerFunction("openticket:dropdown-options",defaultDropdownOptionsFunction))
}
export const loadAllConfigCheckerTranslations = async () => {
if ((generalConfig && generalConfig.data.system && generalConfig.data.system.useTranslatedConfigChecker) ? generalConfig.data.system.useTranslatedConfigChecker : false){
registerDefaultCheckerSystemTranslations(openticket.checkers.translation,openticket.languages) //translate checker system text
registerDefaultCheckerMessageTranslations(openticket.checkers.translation,openticket.languages) //translate checker messages
registerDefaultCheckerCustomTranslations(openticket.checkers.translation,openticket.languages) //translate custom checker messages
registerDefaultCheckerSystemTranslations(opendiscord.checkers.translation,opendiscord.languages) //translate checker system text
registerDefaultCheckerMessageTranslations(opendiscord.checkers.translation,opendiscord.languages) //translate checker messages
registerDefaultCheckerCustomTranslations(opendiscord.checkers.translation,opendiscord.languages) //translate custom checker messages
}
}
@@ -170,7 +170,7 @@ const createPanelEmbedStructure = (id:api.ODValidId) => {
}
function loadFromEnv(){
const generalConfig = openticket.configs.get("openticket:general")
const generalConfig = opendiscord.configs.get("openticket:general")
if (generalConfig.data && generalConfig.data.tokenFromENV && typeof generalConfig.data.tokenFromENV == "boolean") return generalConfig.data.tokenFromENV
else return false
}
@@ -185,7 +185,7 @@ export const defaultGeneralStructure = new api.ODCheckerObjectStructure("opentic
const lt = checker.locationTraceDeref(locationTrace)
if (typeof value != "string") return false
else if (value != "open-ticket-"+openticket.versions.get("openticket:version").toString()){
else if (value != "open-ticket-"+opendiscord.versions.get("openticket:version").toString()){
checker.createMessage("openticket:invalid-version","warning","The version specified in your config is invalid! Make sure you have updated it to the latest version!",lt,null,[],locationId,locationDocs)
return false
}else return true
@@ -201,7 +201,7 @@ export const defaultGeneralStructure = new api.ODCheckerObjectStructure("opentic
const lt = checker.locationTraceDeref(locationTrace)
if (typeof value != "string") return false
else if (!openticket.defaults.getDefault("languageList").includes(value)){
else if (!opendiscord.defaults.getDefault("languageList").includes(value)){
checker.createMessage("openticket:invalid-language","error","This is an invalid language!",lt,null,[],locationId,locationDocs)
return false
}else return true
@@ -582,10 +582,10 @@ export const defaultDropdownOptionsFunction = (manager:api.ODCheckerManager, fun
const panelList: string[] = manager.storage.get("openticket","panel-ids")
if (!panelList) return {valid:true,messages:[]}
const panelConfig = openticket.configs.get("openticket:panels")
const panelConfig = opendiscord.configs.get("openticket:panels")
if (!panelConfig) return {valid:true,messages:[]}
const optionConfig = openticket.configs.get("openticket:options")
const optionConfig = opendiscord.configs.get("openticket:options")
if (!optionConfig) return {valid:true,messages:[]}
const final: api.ODCheckerMessage[] = []
+98 -98
View File
@@ -1,13 +1,13 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
import * as discord from "discord.js"
const generalConfig = openticket.configs.get("openticket:general")
const globalDatabase = openticket.databases.get("openticket:global")
const userDatabase = openticket.databases.get("openticket:users")
const ticketDatabase = openticket.databases.get("openticket:tickets")
const statsDatabase = openticket.databases.get("openticket:stats")
const optionDatabase = openticket.databases.get("openticket:options")
const mainServer = openticket.client.mainServer
const generalConfig = opendiscord.configs.get("openticket:general")
const globalDatabase = opendiscord.databases.get("openticket:global")
const userDatabase = opendiscord.databases.get("openticket:users")
const ticketDatabase = opendiscord.databases.get("openticket:tickets")
const statsDatabase = opendiscord.databases.get("openticket:stats")
const optionDatabase = opendiscord.databases.get("openticket:options")
const mainServer = opendiscord.client.mainServer
export const loadAllCode = async () => {
if (!generalConfig || !mainServer || !globalDatabase || !userDatabase || !ticketDatabase || !statsDatabase || !optionDatabase) return
@@ -22,46 +22,46 @@ export const loadAllCode = async () => {
export const loadCommandErrorHandlingCode = async () => {
//COMMAND ERROR HANDLING
openticket.code.add(new api.ODCode("openticket:command-error-handling",14,() => {
opendiscord.code.add(new api.ODCode("openticket:command-error-handling",14,() => {
//invalid/missing options
openticket.client.textCommands.onError(async (error) => {
opendiscord.client.textCommands.onError(async (error) => {
if (error.msg.channel.type == discord.ChannelType.GroupDM) return
if (error.type == "invalid_option"){
error.msg.channel.send((await openticket.builders.messages.getSafe("openticket:error-option-invalid").build("text",{guild:error.msg.guild,channel:error.msg.channel,user:error.msg.author,error})).message)
error.msg.channel.send((await opendiscord.builders.messages.getSafe("openticket:error-option-invalid").build("text",{guild:error.msg.guild,channel:error.msg.channel,user:error.msg.author,error})).message)
}else if (error.type == "missing_option"){
error.msg.channel.send((await openticket.builders.messages.getSafe("openticket:error-option-missing").build("text",{guild:error.msg.guild,channel:error.msg.channel,user:error.msg.author,error})).message)
error.msg.channel.send((await opendiscord.builders.messages.getSafe("openticket:error-option-missing").build("text",{guild:error.msg.guild,channel:error.msg.channel,user:error.msg.author,error})).message)
}else if (error.type == "unknown_command" && generalConfig.data.system.sendErrorOnUnknownCommand){
error.msg.channel.send((await openticket.builders.messages.getSafe("openticket:error-unknown-command").build("text",{guild:error.msg.guild,channel:error.msg.channel,user:error.msg.author,error})).message)
error.msg.channel.send((await opendiscord.builders.messages.getSafe("openticket:error-unknown-command").build("text",{guild:error.msg.guild,channel:error.msg.channel,user:error.msg.author,error})).message)
}
})
//responder timeout
openticket.responders.commands.setTimeoutErrorCallback(async (instance,source) => {
instance.reply(await openticket.builders.messages.getSafe("openticket:error-responder-timeout").build(source,{guild:instance.guild,channel:instance.channel,user:instance.user}))
opendiscord.responders.commands.setTimeoutErrorCallback(async (instance,source) => {
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-responder-timeout").build(source,{guild:instance.guild,channel:instance.channel,user:instance.user}))
},null)
openticket.responders.buttons.setTimeoutErrorCallback(async (instance,source) => {
instance.reply(await openticket.builders.messages.getSafe("openticket:error-responder-timeout").build(source,{guild:instance.guild,channel:instance.channel,user:instance.user}))
opendiscord.responders.buttons.setTimeoutErrorCallback(async (instance,source) => {
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-responder-timeout").build(source,{guild:instance.guild,channel:instance.channel,user:instance.user}))
},null)
openticket.responders.dropdowns.setTimeoutErrorCallback(async (instance,source) => {
instance.reply(await openticket.builders.messages.getSafe("openticket:error-responder-timeout").build(source,{guild:instance.guild,channel:instance.channel,user:instance.user}))
opendiscord.responders.dropdowns.setTimeoutErrorCallback(async (instance,source) => {
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-responder-timeout").build(source,{guild:instance.guild,channel:instance.channel,user:instance.user}))
},null)
openticket.responders.modals.setTimeoutErrorCallback(async (instance,source) => {
opendiscord.responders.modals.setTimeoutErrorCallback(async (instance,source) => {
if (!instance.channel){
instance.reply({id:new api.ODId("looks-like-we-got-an-error-here"), ephemeral:true, message:{
content:":x: **Something went wrong while replying to this modal!**"
}})
return
}
instance.reply(await openticket.builders.messages.getSafe("openticket:error-responder-timeout").build(source,{guild:instance.guild,channel:instance.channel,user:instance.user}))
instance.reply(await opendiscord.builders.messages.getSafe("openticket:error-responder-timeout").build(source,{guild:instance.guild,channel:instance.channel,user:instance.user}))
},null)
}))
}
export const loadStartListeningInteractionsCode = async () => {
//START LISTENING TO INTERACTIONS
openticket.code.add(new api.ODCode("openticket:start-listening-interactions",13,() => {
openticket.client.slashCommands.startListeningToInteractions()
openticket.client.textCommands.startListeningToInteractions()
opendiscord.code.add(new api.ODCode("openticket:start-listening-interactions",13,() => {
opendiscord.client.slashCommands.startListeningToInteractions()
opendiscord.client.textCommands.startListeningToInteractions()
}))
}
@@ -69,7 +69,7 @@ export const loadDatabaseCleanersCode = async () => {
if (!mainServer) return
//PANEL DATABASE CLEANER
openticket.code.add(new api.ODCode("openticket:panel-database-cleaner",12,async () => {
opendiscord.code.add(new api.ODCode("openticket:panel-database-cleaner",12,async () => {
const validPanels: string[] = []
//check global database for valid panel embeds
@@ -77,7 +77,7 @@ export const loadDatabaseCleanersCode = async () => {
if (!validPanels.includes(panel.key)){
try{
const splittedId = panel.key.split("_")
const message = await openticket.client.fetchGuildChannelMessage(mainServer,splittedId[0],splittedId[1])
const message = await opendiscord.client.fetchGuildChannelMessage(mainServer,splittedId[0],splittedId[1])
if (message) validPanels.push(panel.key)
}catch{}
}
@@ -91,7 +91,7 @@ export const loadDatabaseCleanersCode = async () => {
}
//delete panel from database on delete
openticket.client.client.on("messageDelete",async (msg) => {
opendiscord.client.client.on("messageDelete",async (msg) => {
if (await globalDatabase.exists("openticket:panel-update",msg.channel.id+"_"+msg.id)){
await globalDatabase.delete("openticket:panel-update",msg.channel.id+"_"+msg.id)
}
@@ -99,21 +99,21 @@ export const loadDatabaseCleanersCode = async () => {
}))
//SUFFIX DATABASE CLEANER
openticket.code.add(new api.ODCode("openticket:suffix-database-cleaner",11,async () => {
opendiscord.code.add(new api.ODCode("openticket:suffix-database-cleaner",11,async () => {
const validSuffixCounters: string[] = []
const validSuffixHistories: string[] = []
//check global database for valid option suffix counters
for (const counter of (await globalDatabase.getCategory("openticket:option-suffix-counter") ?? [])){
if (!validSuffixCounters.includes(counter.key)){
if (openticket.options.exists(counter.key)) validSuffixCounters.push(counter.key)
if (opendiscord.options.exists(counter.key)) validSuffixCounters.push(counter.key)
}
}
//check global database for valid option suffix histories
for (const history of (await globalDatabase.getCategory("openticket:option-suffix-history") ?? [])){
if (!validSuffixHistories.includes(history.key)){
if (openticket.options.exists(history.key)) validSuffixHistories.push(history.key)
if (opendiscord.options.exists(history.key)) validSuffixHistories.push(history.key)
}
}
@@ -133,13 +133,13 @@ export const loadDatabaseCleanersCode = async () => {
}))
//OPTION DATABASE CLEANER
openticket.code.add(new api.ODCode("openticket:option-database-cleaner",10,async () => {
opendiscord.code.add(new api.ODCode("openticket:option-database-cleaner",10,async () => {
//delete all unused options (async)
for (const option of (await optionDatabase.getCategory("openticket:used-option") ?? [])){
if (!openticket.options.exists(option.key)){
if (!opendiscord.options.exists(option.key)){
//remove because option isn't loaded into memory (0 tickets require it)
await optionDatabase.delete("openticket:used-option",option.key)
}else if (!openticket.tickets.getAll().some((ticket) => ticket.option.id.value == option.key)){
}else if (!opendiscord.tickets.getAll().some((ticket) => ticket.option.id.value == option.key)){
//remove when loaded into memory (0 tickets require it)
await optionDatabase.delete("openticket:used-option",option.key)
}
@@ -147,7 +147,7 @@ export const loadDatabaseCleanersCode = async () => {
}))
//USER DATABASE CLEANER (full async/parallel because it takes a lot of time)
openticket.code.add(new api.ODCode("openticket:user-database-cleaner",9,() => {
opendiscord.code.add(new api.ODCode("openticket:user-database-cleaner",9,() => {
utilities.runAsync(async () => {
const validUsers: string[] = []
@@ -191,7 +191,7 @@ export const loadDatabaseCleanersCode = async () => {
})
//delete user from database on leave
openticket.client.client.on("guildMemberRemove",async (member) => {
opendiscord.client.client.on("guildMemberRemove",async (member) => {
if (member.guild.id != mainServer.id) return
//remove unused user
@@ -213,14 +213,14 @@ export const loadDatabaseCleanersCode = async () => {
}))
//TICKET DATABASE CLEANER
openticket.code.add(new api.ODCode("openticket:ticket-database-cleaner",8,async () => {
opendiscord.code.add(new api.ODCode("openticket:ticket-database-cleaner",8,async () => {
const validTickets: string[] = []
//check ticket database for valid tickets
for (const ticket of (await ticketDatabase.getAll())){
if (!validTickets.includes(ticket.key)){
try{
const channel = await openticket.client.fetchGuildTextChannel(mainServer,ticket.key)
const channel = await opendiscord.client.fetchGuildTextChannel(mainServer,ticket.key)
if (channel) validTickets.push(channel.id)
}catch{}
}
@@ -231,7 +231,7 @@ export const loadDatabaseCleanersCode = async () => {
if (stat.category.startsWith("openticket:ticket_")){
if (!validTickets.includes(stat.key)){
try{
const channel = await openticket.client.fetchGuildTextChannel(mainServer,stat.key)
const channel = await opendiscord.client.fetchGuildTextChannel(mainServer,stat.key)
if (channel) validTickets.push(channel.id)
}catch{}
}
@@ -242,7 +242,7 @@ export const loadDatabaseCleanersCode = async () => {
for (const ticket of (await ticketDatabase.getAll())){
if (!validTickets.includes(ticket.key)){
await ticketDatabase.delete(ticket.category,ticket.key)
openticket.tickets.remove(ticket.key)
opendiscord.tickets.remove(ticket.key)
}
}
@@ -256,14 +256,14 @@ export const loadDatabaseCleanersCode = async () => {
}
//delete ticket from database on delete
openticket.client.client.on("channelDelete",async (channel) => {
opendiscord.client.client.on("channelDelete",async (channel) => {
if (channel.isDMBased() || channel.guild.id != mainServer.id) return
//remove unused ticket
for (const ticket of (await ticketDatabase.getAll())){
if (ticket.key == channel.id){
await ticketDatabase.delete(ticket.category,ticket.key)
openticket.tickets.remove(ticket.key)
opendiscord.tickets.remove(ticket.key)
}
}
@@ -281,13 +281,13 @@ export const loadDatabaseCleanersCode = async () => {
export const loadPanelAutoUpdateCode = async () => {
//PANEL AUTO UPDATE
openticket.code.add(new api.ODCode("openticket:panel-auto-update",7,async () => {
const globalDatabase = openticket.databases.get("openticket:global")
opendiscord.code.add(new api.ODCode("openticket:panel-auto-update",7,async () => {
const globalDatabase = opendiscord.databases.get("openticket:global")
const panelIds = await globalDatabase.getCategory("openticket:panel-update") ?? []
if (!mainServer) return
for (const panelId of panelIds){
const panel = openticket.panels.get(panelId.value)
const panel = opendiscord.panels.get(panelId.value)
//panel doesn't exist anymore in config and needs to be removed
if (!panel){
@@ -297,13 +297,13 @@ export const loadPanelAutoUpdateCode = async () => {
try{
const splittedId = panelId.key.split("_")
const channel = await openticket.client.fetchGuildTextChannel(mainServer,splittedId[0])
const channel = await opendiscord.client.fetchGuildTextChannel(mainServer,splittedId[0])
if (!channel) return
const message = await openticket.client.fetchGuildChannelMessage(mainServer,channel,splittedId[1])
const message = await opendiscord.client.fetchGuildChannelMessage(mainServer,channel,splittedId[1])
if (!message || !message.editable) return
message.edit((await openticket.builders.messages.getSafe("openticket:panel").build("auto-update",{guild:mainServer,channel,user:openticket.client.client.user,panel})).message)
openticket.log("Panel in server got auto-updated!","info",[
message.edit((await opendiscord.builders.messages.getSafe("openticket:panel").build("auto-update",{guild:mainServer,channel,user:opendiscord.client.client.user,panel})).message)
opendiscord.log("Panel in server got auto-updated!","info",[
{key:"channelid",value:splittedId[0]},
{key:"messageid",value:splittedId[1]},
{key:"panel",value:panelId.value}
@@ -315,10 +315,10 @@ export const loadPanelAutoUpdateCode = async () => {
export const loadDatabaseSaversCode = async () => {
//TICKET SAVER
openticket.code.add(new api.ODCode("openticket:ticket-saver",6,() => {
const mainVersion = openticket.versions.get("openticket:version")
opendiscord.code.add(new api.ODCode("openticket:ticket-saver",6,() => {
const mainVersion = opendiscord.versions.get("openticket:version")
openticket.tickets.onAdd(async (ticket) => {
opendiscord.tickets.onAdd(async (ticket) => {
await ticketDatabase.set("openticket:ticket",ticket.id.value,ticket.toJson(mainVersion))
//add option to database if non-existent
@@ -326,7 +326,7 @@ export const loadDatabaseSaversCode = async () => {
await optionDatabase.set("openticket:used-option",ticket.option.id.value,ticket.option.toJson(mainVersion))
}
})
openticket.tickets.onChange(async (ticket) => {
opendiscord.tickets.onChange(async (ticket) => {
await ticketDatabase.set("openticket:ticket",ticket.id.value,ticket.toJson(mainVersion))
//add option to database if non-existent
@@ -335,42 +335,42 @@ export const loadDatabaseSaversCode = async () => {
}
//delete all unused options on ticket move
for (const option of openticket.options.getAll()){
if (await optionDatabase.exists("openticket:used-option",option.id.value) && !openticket.tickets.getAll().some((ticket) => ticket.option.id.value == option.id.value)){
for (const option of opendiscord.options.getAll()){
if (await optionDatabase.exists("openticket:used-option",option.id.value) && !opendiscord.tickets.getAll().some((ticket) => ticket.option.id.value == option.id.value)){
await optionDatabase.delete("openticket:used-option",option.id.value)
}
}
})
openticket.tickets.onRemove(async (ticket) => {
opendiscord.tickets.onRemove(async (ticket) => {
await ticketDatabase.delete("openticket:ticket",ticket.id.value)
//remove option from database if unused
if (!openticket.tickets.getAll().some((ticket) => ticket.option.id.value == ticket.option.id.value)){
if (!opendiscord.tickets.getAll().some((ticket) => ticket.option.id.value == ticket.option.id.value)){
await optionDatabase.delete("openticket:used-option",ticket.option.id.value)
}
})
}))
//BLACKLIST SAVER
openticket.code.add(new api.ODCode("openticket:blacklist-saver",5,() => {
openticket.blacklist.onAdd(async (blacklist) => {
opendiscord.code.add(new api.ODCode("openticket:blacklist-saver",5,() => {
opendiscord.blacklist.onAdd(async (blacklist) => {
await userDatabase.set("openticket:blacklist",blacklist.id.value,blacklist.reason)
})
openticket.blacklist.onChange(async (blacklist) => {
opendiscord.blacklist.onChange(async (blacklist) => {
await userDatabase.set("openticket:blacklist",blacklist.id.value,blacklist.reason)
})
openticket.blacklist.onRemove(async (blacklist) => {
opendiscord.blacklist.onRemove(async (blacklist) => {
await userDatabase.delete("openticket:blacklist",blacklist.id.value)
})
}))
//AUTO ROLE ON JOIN
openticket.code.add(new api.ODCode("openticket:auto-role-on-join",4,() => {
openticket.client.client.on("guildMemberAdd",async (member) => {
for (const option of openticket.options.getAll()){
opendiscord.code.add(new api.ODCode("openticket:auto-role-on-join",4,() => {
opendiscord.client.client.on("guildMemberAdd",async (member) => {
for (const option of opendiscord.options.getAll()){
if (option instanceof api.ODRoleOption && option.get("openticket:add-on-join").value){
//add these roles on user join
await openticket.actions.get("openticket:reaction-role").run("panel-button",{guild:member.guild,user:member.user,option,overwriteMode:"add"})
await opendiscord.actions.get("openticket:reaction-role").run("panel-button",{guild:member.guild,user:member.user,option,overwriteMode:"add"})
}
}
})
@@ -379,11 +379,11 @@ export const loadDatabaseSaversCode = async () => {
const loadAutoCode = () => {
//AUTOCLOSE TIMEOUT
openticket.code.add(new api.ODCode("openticket:autoclose-timeout",3,() => {
opendiscord.code.add(new api.ODCode("openticket:autoclose-timeout",3,() => {
setInterval(async () => {
let count = 0
for (const ticket of openticket.tickets.getAll()){
const channel = await openticket.tickets.getTicketChannel(ticket)
for (const ticket of opendiscord.tickets.getAll()){
const channel = await opendiscord.tickets.getTicketChannel(ticket)
if (!channel) return
const lastMessage = (await channel.messages.fetch({limit:5})).first()
if (lastMessage && !ticket.get("openticket:closed").value){
@@ -395,26 +395,26 @@ const loadAutoCode = () => {
const time = hours*60*60*1000 //hours in milliseconds
if (enabled && (new Date().getTime() - lastMessage.createdTimestamp) >= time){
//autoclose ticket
await openticket.actions.get("openticket:close-ticket").run("autoclose",{guild:channel.guild,channel,user:openticket.client.client.user,ticket,reason:"Autoclose",sendMessage:false})
await channel.send((await openticket.builders.messages.getSafe("openticket:autoclose-message").build("timeout",{guild:channel.guild,channel,user:openticket.client.client.user,ticket})).message)
await opendiscord.actions.get("openticket:close-ticket").run("autoclose",{guild:channel.guild,channel,user:opendiscord.client.client.user,ticket,reason:"Autoclose",sendMessage:false})
await channel.send((await opendiscord.builders.messages.getSafe("openticket:autoclose-message").build("timeout",{guild:channel.guild,channel,user:opendiscord.client.client.user,ticket})).message)
count++
await openticket.stats.get("openticket:global").setStat("openticket:tickets-autoclosed",1,"increase")
await opendiscord.stats.get("openticket:global").setStat("openticket:tickets-autoclosed",1,"increase")
}
}
}
openticket.debug.debug("Finished autoclose timeout cycle!",[
{key:"interval",value:openticket.defaults.getDefault("autocloseCheckInterval").toString()},
opendiscord.debug.debug("Finished autoclose timeout cycle!",[
{key:"interval",value:opendiscord.defaults.getDefault("autocloseCheckInterval").toString()},
{key:"closed",value:count.toString()}
])
},openticket.defaults.getDefault("autocloseCheckInterval"))
},opendiscord.defaults.getDefault("autocloseCheckInterval"))
}))
//AUTOCLOSE LEAVE
openticket.code.add(new api.ODCode("openticket:autoclose-leave",2,() => {
openticket.client.client.on("guildMemberRemove",async (member) => {
for (const ticket of openticket.tickets.getAll()){
opendiscord.code.add(new api.ODCode("openticket:autoclose-leave",2,() => {
opendiscord.client.client.on("guildMemberRemove",async (member) => {
for (const ticket of opendiscord.tickets.getAll()){
if (ticket.get("openticket:opened-by").value == member.id){
const channel = await openticket.tickets.getTicketChannel(ticket)
const channel = await opendiscord.tickets.getTicketChannel(ticket)
if (!channel) return
//ticket has been created by this user
const disableOnClaim = ticket.option.get("openticket:autoclose-disable-claim").value && ticket.get("openticket:claimed").value
@@ -422,9 +422,9 @@ const loadAutoCode = () => {
if (enabled){
//autoclose ticket
await openticket.actions.get("openticket:close-ticket").run("autoclose",{guild:channel.guild,channel,user:openticket.client.client.user,ticket,reason:"Autoclose",sendMessage:false})
await channel.send((await openticket.builders.messages.getSafe("openticket:autoclose-message").build("leave",{guild:channel.guild,channel,user:openticket.client.client.user,ticket})).message)
await openticket.stats.get("openticket:global").setStat("openticket:tickets-autoclosed",1,"increase")
await opendiscord.actions.get("openticket:close-ticket").run("autoclose",{guild:channel.guild,channel,user:opendiscord.client.client.user,ticket,reason:"Autoclose",sendMessage:false})
await channel.send((await opendiscord.builders.messages.getSafe("openticket:autoclose-message").build("leave",{guild:channel.guild,channel,user:opendiscord.client.client.user,ticket})).message)
await opendiscord.stats.get("openticket:global").setStat("openticket:tickets-autoclosed",1,"increase")
}
}
}
@@ -432,11 +432,11 @@ const loadAutoCode = () => {
}))
//AUTODELETE TIMEOUT
openticket.code.add(new api.ODCode("openticket:autodelete-timeout",1,() => {
opendiscord.code.add(new api.ODCode("openticket:autodelete-timeout",1,() => {
setInterval(async () => {
let count = 0
for (const ticket of openticket.tickets.getAll()){
const channel = await openticket.tickets.getTicketChannel(ticket)
for (const ticket of opendiscord.tickets.getAll()){
const channel = await opendiscord.tickets.getTicketChannel(ticket)
if (!channel) return
const lastMessage = (await channel.messages.fetch({limit:5})).first()
if (lastMessage){
@@ -448,26 +448,26 @@ const loadAutoCode = () => {
const time = days*24*60*60*1000 //days in milliseconds
if (enabled && (new Date().getTime() - lastMessage.createdTimestamp) >= time){
//autodelete ticket
await channel.send((await openticket.builders.messages.getSafe("openticket:autodelete-message").build("timeout",{guild:channel.guild,channel,user:openticket.client.client.user,ticket})).message)
await openticket.actions.get("openticket:delete-ticket").run("autodelete",{guild:channel.guild,channel,user:openticket.client.client.user,ticket,reason:"Autodelete",sendMessage:false,withoutTranscript:false})
await channel.send((await opendiscord.builders.messages.getSafe("openticket:autodelete-message").build("timeout",{guild:channel.guild,channel,user:opendiscord.client.client.user,ticket})).message)
await opendiscord.actions.get("openticket:delete-ticket").run("autodelete",{guild:channel.guild,channel,user:opendiscord.client.client.user,ticket,reason:"Autodelete",sendMessage:false,withoutTranscript:false})
count++
await openticket.stats.get("openticket:global").setStat("openticket:tickets-autodeleted",1,"increase")
await opendiscord.stats.get("openticket:global").setStat("openticket:tickets-autodeleted",1,"increase")
}
}
}
openticket.debug.debug("Finished autodelete timeout cycle!",[
{key:"interval",value:openticket.defaults.getDefault("autodeleteCheckInterval").toString()},
opendiscord.debug.debug("Finished autodelete timeout cycle!",[
{key:"interval",value:opendiscord.defaults.getDefault("autodeleteCheckInterval").toString()},
{key:"deleted",value:count.toString()}
])
},openticket.defaults.getDefault("autodeleteCheckInterval"))
},opendiscord.defaults.getDefault("autodeleteCheckInterval"))
}))
//AUTODELETE LEAVE
openticket.code.add(new api.ODCode("openticket:autodelete-leave",0,() => {
openticket.client.client.on("guildMemberRemove",async (member) => {
for (const ticket of openticket.tickets.getAll()){
opendiscord.code.add(new api.ODCode("openticket:autodelete-leave",0,() => {
opendiscord.client.client.on("guildMemberRemove",async (member) => {
for (const ticket of opendiscord.tickets.getAll()){
if (ticket.get("openticket:opened-by").value == member.id){
const channel = await openticket.tickets.getTicketChannel(ticket)
const channel = await opendiscord.tickets.getTicketChannel(ticket)
if (!channel) return
//ticket has been created by this user
const disableOnClaim = ticket.option.get("openticket:autodelete-disable-claim").value && ticket.get("openticket:claimed").value
@@ -475,9 +475,9 @@ const loadAutoCode = () => {
if (enabled){
//autodelete ticket
await channel.send((await openticket.builders.messages.getSafe("openticket:autodelete-message").build("leave",{guild:channel.guild,channel,user:openticket.client.client.user,ticket})).message)
await openticket.actions.get("openticket:delete-ticket").run("autodelete",{guild:channel.guild,channel,user:openticket.client.client.user,ticket,reason:"Autodelete",sendMessage:false,withoutTranscript:false})
await openticket.stats.get("openticket:global").setStat("openticket:tickets-autodeleted",1,"increase")
await channel.send((await opendiscord.builders.messages.getSafe("openticket:autodelete-message").build("leave",{guild:channel.guild,channel,user:opendiscord.client.client.user,ticket})).message)
await opendiscord.actions.get("openticket:delete-ticket").run("autodelete",{guild:channel.guild,channel,user:opendiscord.client.client.user,ticket,reason:"Autodelete",sendMessage:false,withoutTranscript:false})
await opendiscord.stats.get("openticket:global").setStat("openticket:tickets-autodeleted",1,"increase")
}
}
}
@@ -485,8 +485,8 @@ const loadAutoCode = () => {
}))
//TICKET ANTI BUSY
openticket.code.add(new api.ODCode("openticket:ticket-anti-busy",-1,() => {
for (const ticket of openticket.tickets.getAll()){
opendiscord.code.add(new api.ODCode("openticket:ticket-anti-busy",-1,() => {
for (const ticket of opendiscord.tickets.getAll()){
//free tickets from corruption due to openticket:busy variable
ticket.get("openticket:busy").value = false
}
+10 -10
View File
@@ -1,11 +1,11 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
import * as discord from "discord.js"
const lang = openticket.languages
const lang = opendiscord.languages
export const loadAllSlashCommands = async () => {
const commands = openticket.client.slashCommands
const generalConfig = openticket.configs.get("openticket:general")
const commands = opendiscord.client.slashCommands
const generalConfig = opendiscord.configs.get("openticket:general")
if (!generalConfig) return
const act = discord.ApplicationCommandType
@@ -15,13 +15,13 @@ export const loadAllSlashCommands = async () => {
//create panel choices
const panelChoices : {name:string, value:string}[] = []
openticket.configs.get("openticket:panels").data.forEach((panel) => {
opendiscord.configs.get("openticket:panels").data.forEach((panel) => {
panelChoices.push({name:panel.name, value:panel.id})
})
//create ticket choices
const ticketChoices : {name:string, value:string}[] = []
openticket.configs.get("openticket:options").data.forEach((option) => {
opendiscord.configs.get("openticket:options").data.forEach((option) => {
if (option.type != "ticket") return
ticketChoices.push({name:option.name, value:option.id})
})
@@ -585,8 +585,8 @@ export const loadAllSlashCommands = async () => {
}
export const loadAllTextCommands = async () => {
const commands = openticket.client.textCommands
const generalConfig = openticket.configs.get("openticket:general")
const commands = opendiscord.client.textCommands
const generalConfig = opendiscord.configs.get("openticket:general")
if (!generalConfig) return
if (!generalConfig.data.textCommands) return
@@ -594,13 +594,13 @@ export const loadAllTextCommands = async () => {
//create panel choices
const panelChoices : string[] = []
openticket.configs.get("openticket:panels").data.forEach((panel) => {
opendiscord.configs.get("openticket:panels").data.forEach((panel) => {
panelChoices.push(panel.id)
})
//create ticket choices
const ticketChoices : string[] = []
openticket.configs.get("openticket:options").data.forEach((option) => {
opendiscord.configs.get("openticket:options").data.forEach((option) => {
if (option.type != "ticket") return
ticketChoices.push(option.id)
})
+7 -7
View File
@@ -1,12 +1,12 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
export const loadAllConfigs = async () => {
const devconfigFlag = openticket.flags.get("openticket:dev-config")
const devconfigFlag = opendiscord.flags.get("openticket:dev-config")
const isDevconfig = devconfigFlag ? devconfigFlag.value : false
openticket.configs.add(new api.ODJsonConfig("openticket:general","general.json",(isDevconfig) ? "./devconfig/" : "./config/"))
openticket.configs.add(new api.ODJsonConfig("openticket:options","options.json",(isDevconfig) ? "./devconfig/" : "./config/"))
openticket.configs.add(new api.ODJsonConfig("openticket:panels","panels.json",(isDevconfig) ? "./devconfig/" : "./config/"))
openticket.configs.add(new api.ODJsonConfig("openticket:questions","questions.json",(isDevconfig) ? "./devconfig/" : "./config/"))
openticket.configs.add(new api.ODJsonConfig("openticket:transcripts","transcripts.json",(isDevconfig) ? "./devconfig/" : "./config/"))
opendiscord.configs.add(new api.ODJsonConfig("openticket:general","general.json",(isDevconfig) ? "./devconfig/" : "./config/"))
opendiscord.configs.add(new api.ODJsonConfig("openticket:options","options.json",(isDevconfig) ? "./devconfig/" : "./config/"))
opendiscord.configs.add(new api.ODJsonConfig("openticket:panels","panels.json",(isDevconfig) ? "./devconfig/" : "./config/"))
opendiscord.configs.add(new api.ODJsonConfig("openticket:questions","questions.json",(isDevconfig) ? "./devconfig/" : "./config/"))
opendiscord.configs.add(new api.ODJsonConfig("openticket:transcripts","transcripts.json",(isDevconfig) ? "./devconfig/" : "./config/"))
}
+3 -3
View File
@@ -1,7 +1,7 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
export const loadAllCooldowns = async () => {
await openticket.options.loopAll((option) => {
await opendiscord.options.loopAll((option) => {
if (!(option instanceof api.ODTicketOption)) return
loadTicketOptionCooldown(option)
})
@@ -12,6 +12,6 @@ export const loadTicketOptionCooldown = (option:api.ODTicketOption) => {
//option has cooldown
const minutes = option.get("openticket:cooldown-minutes").value
const milliseconds = minutes*60000
openticket.cooldowns.add(new api.ODTimeoutCooldown("openticket:option-cooldown_"+option.id.value,milliseconds))
opendiscord.cooldowns.add(new api.ODTimeoutCooldown("openticket:option-cooldown_"+option.id.value,milliseconds))
}
}
+7 -7
View File
@@ -1,15 +1,15 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
import * as fjs from "formatted-json-stringify"
const devdatabaseFlag = openticket.flags.get("openticket:dev-database")
const devdatabaseFlag = opendiscord.flags.get("openticket:dev-database")
const isDevdatabase = devdatabaseFlag ? devdatabaseFlag.value : false
export const loadAllDatabases = async () => {
openticket.databases.add(defaultGlobalDatabase)
openticket.databases.add(defaultStatsDatabase)
openticket.databases.add(defaultTicketsDatabase)
openticket.databases.add(defaultUsersDatabase)
openticket.databases.add(defaultOptionsDatabase)
opendiscord.databases.add(defaultGlobalDatabase)
opendiscord.databases.add(defaultStatsDatabase)
opendiscord.databases.add(defaultTicketsDatabase)
opendiscord.databases.add(defaultUsersDatabase)
opendiscord.databases.add(defaultOptionsDatabase)
}
const defaultInlineFormatter = new fjs.ArrayFormatter(null,true,new fjs.ObjectFormatter(null,false,[
+2 -2
View File
@@ -1,4 +1,4 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
export const loadAllEvents = () => {
const eventList: (keyof api.ODEventIds_Default)[] = [
@@ -245,5 +245,5 @@ export const loadAllEvents = () => {
//ready
"onReadyForUsage"
]
eventList.forEach((event) => openticket.events.add(new api.ODEvent(event)))
eventList.forEach((event) => opendiscord.events.add(new api.ODEvent(event)))
}
+15 -15
View File
@@ -1,18 +1,18 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
export const loadAllFlags = async () => {
openticket.flags.add(new api.ODFlag("openticket:no-migration","No Migration","Disable Open Ticket data migration on update!","--no-migration",["-nm"]))
openticket.flags.add(new api.ODFlag("openticket:dev-config","Developer Config","Use the configs in /devconfig/ instead of /config/!","--dev-config",["-dc"]))
openticket.flags.add(new api.ODFlag("openticket:dev-database","Developer Database","Use the databases in /devdatabase/ instead of /database/!","--dev-database",["-nd"]))
openticket.flags.add(new api.ODFlag("openticket:debug","Debug Mode","Couldn't you find the error? Try to check this out!","--debug",["-d"]))
openticket.flags.add(new api.ODFlag("openticket:crash","Crash On Error","Crash the bot on an unknown error!","--crash",["-cr"]))
openticket.flags.add(new api.ODFlag("openticket:no-transcripts","No HTML Transcripts","Disable uploading HTML transcripts (for debugging)","--no-transcripts",["-nt"]))
openticket.flags.add(new api.ODFlag("openticket:no-checker","No Config Checker","Disable the Config Checker (for debugging)","--no-checker",["-nc"]))
openticket.flags.add(new api.ODFlag("openticket:checker","Full Config Checker","Render the Config Checker with extra details!","--checker",["-c"]))
openticket.flags.add(new api.ODFlag("openticket:no-easter","No Easter Eggs","Disable little Open Ticket easter eggs hidden in the bot!","--no-easter",["-ne"]))
openticket.flags.add(new api.ODFlag("openticket:no-plugins","No Plugins","Disable all Open Ticket plugins!","--no-plugins",["-np"]))
openticket.flags.add(new api.ODFlag("openticket:soft-plugins","Soft Plugins","Don't crash the bot when a plugin crashes!","--soft-plugins",["-sp"]))
openticket.flags.add(new api.ODFlag("openticket:force-slash-update","Force Slash Update","Force update all slash commands.","--force-slash",["-fs"]))
openticket.flags.add(new api.ODFlag("openticket:no-compile","No Compile","Disable compilation of plugins & bot before starting.","--no-compile",[]))
openticket.flags.add(new api.ODFlag("openticket:compile-only","Compile Only","This description will never be shown because the bot wouldn't run when this flag is enabled :)","--compile-only",[]))
opendiscord.flags.add(new api.ODFlag("openticket:no-migration","No Migration","Disable Open Ticket data migration on update!","--no-migration",["-nm"]))
opendiscord.flags.add(new api.ODFlag("openticket:dev-config","Developer Config","Use the configs in /devconfig/ instead of /config/!","--dev-config",["-dc"]))
opendiscord.flags.add(new api.ODFlag("openticket:dev-database","Developer Database","Use the databases in /devdatabase/ instead of /database/!","--dev-database",["-nd"]))
opendiscord.flags.add(new api.ODFlag("openticket:debug","Debug Mode","Couldn't you find the error? Try to check this out!","--debug",["-d"]))
opendiscord.flags.add(new api.ODFlag("openticket:crash","Crash On Error","Crash the bot on an unknown error!","--crash",["-cr"]))
opendiscord.flags.add(new api.ODFlag("openticket:no-transcripts","No HTML Transcripts","Disable uploading HTML transcripts (for debugging)","--no-transcripts",["-nt"]))
opendiscord.flags.add(new api.ODFlag("openticket:no-checker","No Config Checker","Disable the Config Checker (for debugging)","--no-checker",["-nc"]))
opendiscord.flags.add(new api.ODFlag("openticket:checker","Full Config Checker","Render the Config Checker with extra details!","--checker",["-c"]))
opendiscord.flags.add(new api.ODFlag("openticket:no-easter","No Easter Eggs","Disable little Open Ticket easter eggs hidden in the bot!","--no-easter",["-ne"]))
opendiscord.flags.add(new api.ODFlag("openticket:no-plugins","No Plugins","Disable all Open Ticket plugins!","--no-plugins",["-np"]))
opendiscord.flags.add(new api.ODFlag("openticket:soft-plugins","Soft Plugins","Don't crash the bot when a plugin crashes!","--soft-plugins",["-sp"]))
opendiscord.flags.add(new api.ODFlag("openticket:force-slash-update","Force Slash Update","Force update all slash commands.","--force-slash",["-fs"]))
opendiscord.flags.add(new api.ODFlag("openticket:no-compile","No Compile","Disable compilation of plugins & bot before starting.","--no-compile",[]))
opendiscord.flags.add(new api.ODFlag("openticket:compile-only","Compile Only","This description will never be shown because the bot wouldn't run when this flag is enabled :)","--compile-only",[]))
}
+5 -5
View File
@@ -1,9 +1,9 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
const lang = openticket.languages
const lang = opendiscord.languages
export const loadAllHelpMenuCategories = async () => {
const helpmenu = openticket.helpmenu
const helpmenu = opendiscord.helpmenu
helpmenu.add(new api.ODHelpMenuCategory("openticket:general",5,utilities.emojiTitle("📎","General Commands"))) //TODO TRANSLATION!!!
helpmenu.add(new api.ODHelpMenuCategory("openticket:ticket-basic",4,utilities.emojiTitle("🎫","Basic Ticket Commands"))) //TODO TRANSLATION!!!
@@ -15,8 +15,8 @@ export const loadAllHelpMenuCategories = async () => {
}
export const loadAllHelpMenuComponents = async () => {
const helpmenu = openticket.helpmenu
const generalConfig = openticket.configs.get("openticket:general")
const helpmenu = opendiscord.helpmenu
const generalConfig = opendiscord.configs.get("openticket:general")
if (!generalConfig) return
const prefix = generalConfig.data.prefix
+24 -24
View File
@@ -1,30 +1,30 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
export const loadAllLanguages = async () => {
//register languages
openticket.languages.add(new api.ODJsonLanguage("openticket:custom","custom.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:english","english.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:dutch","dutch.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:portuguese","portuguese.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:czech","czech.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:german","german.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:catalan","catalan.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:hungarian","hungarian.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:spanish","spanish.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:romanian","romanian.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:ukrainian","ukrainian.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:indonesian","indonesian.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:italian","italian.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:estonian","estonian.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:finnish","finnish.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:danish","danish.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:thai","thai.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:turkish","turkish.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:french","french.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:arabic","arabic.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:hindi","hindi.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:lithuanian","lithuanian.json"))
openticket.languages.add(new api.ODJsonLanguage("openticket:polish","polish.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:custom","custom.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:english","english.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:dutch","dutch.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:portuguese","portuguese.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:czech","czech.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:german","german.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:catalan","catalan.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:hungarian","hungarian.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:spanish","spanish.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:romanian","romanian.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:ukrainian","ukrainian.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:indonesian","indonesian.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:italian","italian.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:estonian","estonian.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:finnish","finnish.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:danish","danish.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:thai","thai.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:turkish","turkish.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:french","french.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:arabic","arabic.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:hindi","hindi.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:lithuanian","lithuanian.json"))
opendiscord.languages.add(new api.ODJsonLanguage("openticket:polish","polish.json"))
/** How to add more languages?
* - Register the language to the manager (see above)
+2 -2
View File
@@ -1,6 +1,6 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
export const loadAllLiveStatusSources = async () => {
//DEFAULT DJDJ DEV
openticket.livestatus.add(new api.ODLiveStatusUrlSource("openticket:default-djdj-dev","https://raw.githubusercontent.com/DJj123dj/open-ticket/refs/heads/dev/src/livestatus.json"))
opendiscord.livestatus.add(new api.ODLiveStatusUrlSource("openticket:default-djdj-dev","https://raw.githubusercontent.com/DJj123dj/open-ticket/refs/heads/dev/src/livestatus.json"))
}
+22 -22
View File
@@ -1,76 +1,76 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
import * as discord from "discord.js"
export const loadAllPermissions = async () => {
const generalConfig = openticket.configs.get("openticket:general")
const generalConfig = opendiscord.configs.get("openticket:general")
if (!generalConfig) return
const mainServer = openticket.client.mainServer
const mainServer = opendiscord.client.mainServer
if (!mainServer) return
//DEVELOPER & OWNER
const developer = (await openticket.client.client.application.fetch()).owner
const developer = (await opendiscord.client.client.application.fetch()).owner
if (developer instanceof discord.User){
openticket.permissions.add(new api.ODPermission("openticket:developer-"+developer.id,"global-user","developer",developer))
opendiscord.permissions.add(new api.ODPermission("openticket:developer-"+developer.id,"global-user","developer",developer))
}else if (developer instanceof discord.Team){
developer.members.forEach((member) => {
openticket.permissions.add(new api.ODPermission("openticket:developer-"+member.user.id,"global-user","developer",member.user))
opendiscord.permissions.add(new api.ODPermission("openticket:developer-"+member.user.id,"global-user","developer",member.user))
})
}
const owner = (await mainServer.members.fetch(mainServer.ownerId)).user
openticket.permissions.add(new api.ODPermission("openticket:owner-"+owner.id,"global-user","owner",owner))
opendiscord.permissions.add(new api.ODPermission("openticket:owner-"+owner.id,"global-user","owner",owner))
//GLOBAL ADMINS
generalConfig.data.globalAdmins.forEach(async (admin) => {
const role = await mainServer.roles.fetch(admin)
if (!role) return openticket.log("Unable to register permission for global admin!","error",[
if (!role) return opendiscord.log("Unable to register permission for global admin!","error",[
{key:"roleid",value:admin}
])
openticket.permissions.add(new api.ODPermission("openticket:global-admin-"+admin,"global-role","admin",role))
opendiscord.permissions.add(new api.ODPermission("openticket:global-admin-"+admin,"global-role","admin",role))
})
//TICKET ADMINS
await openticket.tickets.loopAll(async (ticket) => {
await opendiscord.tickets.loopAll(async (ticket) => {
try {
const channel = await openticket.client.fetchGuildTextChannel(mainServer,ticket.id.value)
const channel = await opendiscord.client.fetchGuildTextChannel(mainServer,ticket.id.value)
if (!channel) return
const admins = ticket.option.exists("openticket:admins") ? ticket.option.get("openticket:admins").value : []
const readAdmins = ticket.option.exists("openticket:admins-readonly") ? ticket.option.get("openticket:admins-readonly").value : []
for (const admin of admins.concat(readAdmins)){
if (openticket.permissions.exists("openticket:ticket-admin_"+ticket.id.value+"_"+admin)) return
if (opendiscord.permissions.exists("openticket:ticket-admin_"+ticket.id.value+"_"+admin)) return
const role = await mainServer.roles.fetch(admin)
if (!role) return openticket.log("Unable to register permission for ticket admin!","error",[
if (!role) return opendiscord.log("Unable to register permission for ticket admin!","error",[
{key:"roleid",value:admin}
])
openticket.permissions.add(new api.ODPermission("openticket:ticket-admin_"+ticket.id.value+"_"+admin,"channel-role","support",role,channel))
opendiscord.permissions.add(new api.ODPermission("openticket:ticket-admin_"+ticket.id.value+"_"+admin,"channel-role","support",role,channel))
}
}catch(err){
process.emit("uncaughtException",err)
openticket.log("Ticket Admin Loading Permissions Error (see above)","error")
opendiscord.log("Ticket Admin Loading Permissions Error (see above)","error")
}
})
}
export const addTicketPermissions = async (ticket:api.ODTicket) => {
const mainServer = openticket.client.mainServer
const mainServer = opendiscord.client.mainServer
if (!mainServer) return
const channel = await openticket.client.fetchGuildTextChannel(mainServer,ticket.id.value)
const channel = await opendiscord.client.fetchGuildTextChannel(mainServer,ticket.id.value)
if (!channel) return
const admins = ticket.option.exists("openticket:admins") ? ticket.option.get("openticket:admins").value : []
const readAdmins = ticket.option.exists("openticket:admins-readonly") ? ticket.option.get("openticket:admins-readonly").value : []
for (const admin of admins.concat(readAdmins)){
if (openticket.permissions.exists("openticket:ticket-admin_"+ticket.id.value+"_"+admin)) return
if (opendiscord.permissions.exists("openticket:ticket-admin_"+ticket.id.value+"_"+admin)) return
const role = await mainServer.roles.fetch(admin)
if (!role) return openticket.log("Unable to register permission for ticket admin!","error",[
if (!role) return opendiscord.log("Unable to register permission for ticket admin!","error",[
{key:"roleid",value:admin}
])
openticket.permissions.add(new api.ODPermission("openticket:ticket-admin_"+ticket.id.value+"_"+admin,"channel-role","support",role,channel))
opendiscord.permissions.add(new api.ODPermission("openticket:ticket-admin_"+ticket.id.value+"_"+admin,"channel-role","support",role,channel))
}
}
@@ -79,7 +79,7 @@ export const removeTicketPermissions = async (ticket:api.ODTicket) => {
const readAdmins = ticket.option.exists("openticket:admins-readonly") ? ticket.option.get("openticket:admins-readonly").value : []
admins.concat(readAdmins).forEach(async (admin) => {
if (!openticket.permissions.exists("openticket:ticket-admin_"+ticket.id.value+"_"+admin)) return
openticket.permissions.remove("openticket:ticket-admin_"+ticket.id.value+"_"+admin)
if (!opendiscord.permissions.exists("openticket:ticket-admin_"+ticket.id.value+"_"+admin)) return
opendiscord.permissions.remove("openticket:ticket-admin_"+ticket.id.value+"_"+admin)
})
}
+5 -5
View File
@@ -1,14 +1,14 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
export const loadAllPosts = async () => {
const generalConfig = openticket.configs.get("openticket:general")
const generalConfig = opendiscord.configs.get("openticket:general")
if (!generalConfig) return
const transcriptConfig = openticket.configs.get("openticket:transcripts")
const transcriptConfig = opendiscord.configs.get("openticket:transcripts")
if (!transcriptConfig) return
//LOGS CHANNEL
if (generalConfig.data.system.logs.enabled) openticket.posts.add(new api.ODPost("openticket:logs",generalConfig.data.system.logs.channel))
if (generalConfig.data.system.logs.enabled) opendiscord.posts.add(new api.ODPost("openticket:logs",generalConfig.data.system.logs.channel))
//TRANSCRIPTS CHANNEL
if (transcriptConfig.data.general.enabled && transcriptConfig.data.general.enableChannel) openticket.posts.add(new api.ODPost("openticket:transcripts",transcriptConfig.data.general.channel))
if (transcriptConfig.data.general.enabled && transcriptConfig.data.general.enableChannel) opendiscord.posts.add(new api.ODPost("openticket:transcripts",transcriptConfig.data.general.channel))
}
+11 -11
View File
@@ -1,4 +1,4 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
export const loadAllProgressBarRenderers = async () => {
const defaultSettings: api.ODProgressBarRenderer_DefaultSettings = {
@@ -25,43 +25,43 @@ export const loadAllProgressBarRenderers = async () => {
//VALUE RENDERER
const valueRendererSettings: api.ODProgressBarRenderer_DefaultSettings = {...defaultSettings}
valueRendererSettings.labelType = "value"
openticket.progressbars.renderers.add(new api.ODProgressBarRenderer_Default("openticket:value-renderer",valueRendererSettings))
opendiscord.progressbars.renderers.add(new api.ODProgressBarRenderer_Default("openticket:value-renderer",valueRendererSettings))
//FRACTION RENDERER
const fractionRendererSettings: api.ODProgressBarRenderer_DefaultSettings = {...defaultSettings}
fractionRendererSettings.labelType = "fraction"
openticket.progressbars.renderers.add(new api.ODProgressBarRenderer_Default("openticket:fraction-renderer",fractionRendererSettings))
opendiscord.progressbars.renderers.add(new api.ODProgressBarRenderer_Default("openticket:fraction-renderer",fractionRendererSettings))
//PERCENTAGE RENDERER
const percentageRendererSettings: api.ODProgressBarRenderer_DefaultSettings = {...defaultSettings}
percentageRendererSettings.labelType = "percentage"
openticket.progressbars.renderers.add(new api.ODProgressBarRenderer_Default("openticket:percentage-renderer",percentageRendererSettings))
opendiscord.progressbars.renderers.add(new api.ODProgressBarRenderer_Default("openticket:percentage-renderer",percentageRendererSettings))
//TIME MS RENDERER
const timeMsRendererSettings: api.ODProgressBarRenderer_DefaultSettings = {...defaultSettings}
timeMsRendererSettings.labelType = "time-ms"
openticket.progressbars.renderers.add(new api.ODProgressBarRenderer_Default("openticket:time-ms-renderer",timeMsRendererSettings))
opendiscord.progressbars.renderers.add(new api.ODProgressBarRenderer_Default("openticket:time-ms-renderer",timeMsRendererSettings))
//TIME SEC RENDERER
const timeSecRendererSettings: api.ODProgressBarRenderer_DefaultSettings = {...defaultSettings}
timeSecRendererSettings.labelType = "time-sec"
openticket.progressbars.renderers.add(new api.ODProgressBarRenderer_Default("openticket:time-sec-renderer",timeSecRendererSettings))
opendiscord.progressbars.renderers.add(new api.ODProgressBarRenderer_Default("openticket:time-sec-renderer",timeSecRendererSettings))
//TIME MIN RENDERER
const timeMinRendererSettings: api.ODProgressBarRenderer_DefaultSettings = {...defaultSettings}
timeMinRendererSettings.labelType = "time-min"
openticket.progressbars.renderers.add(new api.ODProgressBarRenderer_Default("openticket:time-min-renderer",timeMinRendererSettings))
opendiscord.progressbars.renderers.add(new api.ODProgressBarRenderer_Default("openticket:time-min-renderer",timeMinRendererSettings))
}
export const loadAllProgressBars = async () => {
const fractRenderer = openticket.progressbars.renderers.get("openticket:fraction-renderer")
const fractRenderer = opendiscord.progressbars.renderers.get("openticket:fraction-renderer")
//SLASH COMMAND REMOVE (doesn't have correct amount yet)
openticket.progressbars.add(new api.ODManualProgressBar("openticket:slash-command-remove",fractRenderer.withAdditionalSettings({filledBarColor:"red"}),0,"max",null,"Commands Removed"))
opendiscord.progressbars.add(new api.ODManualProgressBar("openticket:slash-command-remove",fractRenderer.withAdditionalSettings({filledBarColor:"red"}),0,"max",null,"Commands Removed"))
//SLASH COMMAND CREATE (doesn't have correct amount yet)
openticket.progressbars.add(new api.ODManualProgressBar("openticket:slash-command-create",fractRenderer.withAdditionalSettings({filledBarColor:"green"}),0,"max",null,"Commands Created"))
opendiscord.progressbars.add(new api.ODManualProgressBar("openticket:slash-command-create",fractRenderer.withAdditionalSettings({filledBarColor:"green"}),0,"max",null,"Commands Created"))
//SLASH COMMAND UPDATE (doesn't have correct amount yet)
openticket.progressbars.add(new api.ODManualProgressBar("openticket:slash-command-update",fractRenderer.withAdditionalSettings({filledBarColor:"openticket"}),0,"max",null,"Commands Updated"))
opendiscord.progressbars.add(new api.ODManualProgressBar("openticket:slash-command-update",fractRenderer.withAdditionalSettings({filledBarColor:"openticket"}),0,"max",null,"Commands Updated"))
}
+17 -17
View File
@@ -1,9 +1,9 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
import ansis from "ansis"
export const loadAllStartScreenComponents = async () => {
//LOGO
openticket.startscreen.add(new api.ODStartScreenLogoComponent("openticket:logo",1000,[
opendiscord.startscreen.add(new api.ODStartScreenLogoComponent("openticket:logo",1000,[
" ██████╗ ██████╗ ███████╗███╗ ██╗ ████████╗██╗ ██████╗██╗ ██╗███████╗████████╗ ",
" ██╔═══██╗██╔══██╗██╔════╝████╗ ██║ ╚══██╔══╝██║██╔════╝██║ ██╔╝██╔════╝╚══██╔══╝ ",
" ██║ ██║██████╔╝█████╗ ██╔██╗ ██║ ██║ ██║██║ █████╔╝ █████╗ ██║ ",
@@ -13,35 +13,35 @@ export const loadAllStartScreenComponents = async () => {
],true,false))
//HEADER
const currentLanguageMetadata = openticket.languages.getLanguageMetadata()
openticket.startscreen.add(new api.ODStartScreenHeaderComponent("openticket:header",999,[
{key:"Version",value:openticket.versions.get("openticket:version").toString()},
const currentLanguageMetadata = opendiscord.languages.getLanguageMetadata()
opendiscord.startscreen.add(new api.ODStartScreenHeaderComponent("openticket:header",999,[
{key:"Version",value:opendiscord.versions.get("openticket:version").toString()},
{key:"Support",value:"https://discord.dj-dj.be"},
{key:"Language",value:(currentLanguageMetadata ? currentLanguageMetadata.language : "Unknown")}
]," - ",{
align:"center",
width:openticket.startscreen.get("openticket:logo")
width:opendiscord.startscreen.get("openticket:logo")
}))
//FLAGS
openticket.startscreen.add(new api.ODStartScreenFlagsCategoryComponent("openticket:flags",4,openticket.flags.getAll()))
opendiscord.startscreen.add(new api.ODStartScreenFlagsCategoryComponent("openticket:flags",4,opendiscord.flags.getAll()))
//PLUGINS
openticket.startscreen.add(new api.ODStartScreenPluginsCategoryComponent("openticket:plugins",3,openticket.plugins.getAll(),openticket.plugins.unknownCrashedPlugins))
opendiscord.startscreen.add(new api.ODStartScreenPluginsCategoryComponent("openticket:plugins",3,opendiscord.plugins.getAll(),opendiscord.plugins.unknownCrashedPlugins))
//STATS
openticket.startscreen.add(new api.ODStartScreenPropertiesCategoryComponent("openticket:stats",2,"startup info",[
{key:"status",value:ansis.bold(openticket.client.activity.getStatusType())+openticket.client.activity.text+" ("+openticket.client.activity.status+")"},
{key:"options",value:"loaded "+ansis.bold(openticket.options.getLength().toString())+" options!"},
{key:"panels",value:"loaded "+ansis.bold(openticket.panels.getLength().toString())+" panels!"},
{key:"tickets",value:"loaded "+ansis.bold(openticket.tickets.getLength().toString())+" tickets!"},
{key:"roles",value:"loaded "+ansis.bold(openticket.roles.getLength().toString())+" roles!"},
{key:"help",value:ansis.bold(openticket.configs.get("openticket:general").data.prefix+"help")+" or "+ansis.bold("/help")}
opendiscord.startscreen.add(new api.ODStartScreenPropertiesCategoryComponent("openticket:stats",2,"startup info",[
{key:"status",value:ansis.bold(opendiscord.client.activity.getStatusType())+opendiscord.client.activity.text+" ("+opendiscord.client.activity.status+")"},
{key:"options",value:"loaded "+ansis.bold(opendiscord.options.getLength().toString())+" options!"},
{key:"panels",value:"loaded "+ansis.bold(opendiscord.panels.getLength().toString())+" panels!"},
{key:"tickets",value:"loaded "+ansis.bold(opendiscord.tickets.getLength().toString())+" tickets!"},
{key:"roles",value:"loaded "+ansis.bold(opendiscord.roles.getLength().toString())+" roles!"},
{key:"help",value:ansis.bold(opendiscord.configs.get("openticket:general").data.prefix+"help")+" or "+ansis.bold("/help")}
]))
//LIVESTATUS
openticket.startscreen.add(new api.ODStartScreenLiveStatusCategoryComponent("openticket:livestatus",1,openticket.livestatus))
opendiscord.startscreen.add(new api.ODStartScreenLiveStatusCategoryComponent("openticket:livestatus",1,opendiscord.livestatus))
//LOGS
openticket.startscreen.add(new api.ODStartScreenLogCategoryComponent("openticket:logs",0))
opendiscord.startscreen.add(new api.ODStartScreenLogCategoryComponent("openticket:logs",0))
}
+13 -13
View File
@@ -1,8 +1,8 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
import * as discord from "discord.js"
const stats = openticket.stats
const lang = openticket.languages
const stats = opendiscord.stats
const lang = opendiscord.languages
export const loadAllStatScopes = async () => {
stats.add(new api.ODStatGlobalScope("openticket:global",utilities.emojiTitle("📊",lang.getTranslation("stats.scopes.global"))))
@@ -13,7 +13,7 @@ export const loadAllStatScopes = async () => {
}
export const loadAllStats = async () => {
const generalConfig = openticket.configs.get("openticket:general")
const generalConfig = opendiscord.configs.get("openticket:general")
if (!generalConfig) return
const global = stats.get("openticket:global")
@@ -34,10 +34,10 @@ export const loadAllStats = async () => {
const system = stats.get("openticket:system")
if (system){
system.add(new api.ODDynamicStat("openticket:startup-date",1,() => {
return lang.getTranslation("params.uppercase.startupDate")+": "+discord.time(openticket.processStartupDate,"f")
return lang.getTranslation("params.uppercase.startupDate")+": "+discord.time(opendiscord.processStartupDate,"f")
}))
system.add(new api.ODDynamicStat("openticket:version",0,() => {
return lang.getTranslation("params.uppercase.version")+": `"+openticket.versions.get("openticket:version").toString()+"`"
return lang.getTranslation("params.uppercase.version")+": `"+opendiscord.versions.get("openticket:version").toString()+"`"
}))
}
@@ -51,7 +51,7 @@ export const loadAllStats = async () => {
const scopeMember = await guild.members.fetch(scopeId)
if (!scopeMember) return ""
const permissions = await openticket.permissions.getPermissions(scopeMember.user,channel,guild)
const permissions = await opendiscord.permissions.getPermissions(scopeMember.user,channel,guild)
if (permissions.type == "developer") return lang.getTranslation("params.uppercase.role")+": 💻 `Developer`" //TODO TRANSLATION!!!
if (permissions.type == "owner") return lang.getTranslation("params.uppercase.role")+": 👑 `Server Owner`" //TODO TRANSLATION!!!
if (permissions.type == "admin") return lang.getTranslation("params.uppercase.role")+": 💼 `Server Admin`" //TODO TRANSLATION!!!
@@ -79,7 +79,7 @@ export const loadAllStats = async () => {
return lang.getTranslation("params.uppercase.ticket")+": "+discord.channelMention(scopeId)
}))
ticket.add(new api.ODDynamicStat("openticket:status",4,async (scopeId,guild,channel,user) => {
const ticket = openticket.tickets.get(scopeId)
const ticket = opendiscord.tickets.get(scopeId)
if (!ticket) return ""
const closed = ticket.exists("openticket:closed") ? ticket.get("openticket:closed").value : false
@@ -87,28 +87,28 @@ export const loadAllStats = async () => {
return closed ? lang.getTranslation("params.uppercase.status")+": 🔒 `Closed`" : lang.getTranslation("params.uppercase.status")+": 🔓 `Open`" //TODO TRANSLATION!!!
}))
ticket.add(new api.ODDynamicStat("openticket:claimed",3,async (scopeId,guild,channel,user) => {
const ticket = openticket.tickets.get(scopeId)
const ticket = opendiscord.tickets.get(scopeId)
if (!ticket) return ""
const claimed = ticket.exists("openticket:claimed") ? ticket.get("openticket:claimed").value : false
return claimed ? lang.getTranslation("params.uppercase.claimed")+": 🟢 `Yes`" : lang.getTranslation("params.uppercase.claimed")+": 🔴 `No`" //TODO TRANSLATION!!!
}))
ticket.add(new api.ODDynamicStat("openticket:pinned",2,async (scopeId,guild,channel,user) => {
const ticket = openticket.tickets.get(scopeId)
const ticket = opendiscord.tickets.get(scopeId)
if (!ticket) return ""
const pinned = ticket.exists("openticket:pinned") ? ticket.get("openticket:pinned").value : false
return pinned ? lang.getTranslation("params.uppercase.pinned")+": 🟢 `Yes`" : lang.getTranslation("params.uppercase.pinned")+": 🔴 `No`" //TODO TRANSLATION!!!
}))
ticket.add(new api.ODDynamicStat("openticket:creation-date",1,async (scopeId,guild,channel,user) => {
const ticket = openticket.tickets.get(scopeId)
const ticket = opendiscord.tickets.get(scopeId)
if (!ticket) return ""
const rawDate = ticket.get("openticket:opened-on").value ?? new Date().getTime()
return lang.getTranslation("params.uppercase.creationDate")+": "+discord.time(new Date(rawDate),"f")
}))
ticket.add(new api.ODDynamicStat("openticket:creator",0,async (scopeId,guild,channel,user) => {
const ticket = openticket.tickets.get(scopeId)
const ticket = opendiscord.tickets.get(scopeId)
if (!ticket) return ""
const creator = ticket.get("openticket:opened-by").value
@@ -119,7 +119,7 @@ export const loadAllStats = async () => {
const participants = stats.get("openticket:participants")
if (participants){
participants.add(new api.ODDynamicStat("openticket:participants",0,async (scopeId,guild,channel,user) => {
const ticket = openticket.tickets.get(scopeId)
const ticket = opendiscord.tickets.get(scopeId)
if (!ticket) return ""
const participants = ticket.exists("openticket:participants") ? ticket.get("openticket:participants").value : []
+3 -3
View File
@@ -1,11 +1,11 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
export const loadAllBlacklistedUsers = async () => {
const userDatabase = openticket.databases.get("openticket:users")
const userDatabase = opendiscord.databases.get("openticket:users")
if (!userDatabase) return
const users = await userDatabase.getCategory("openticket:blacklist") ?? []
users.forEach((user) => {
if (typeof user.value == "string" || user.value === null) openticket.blacklist.add(new api.ODBlacklist(user.key,user.value))
if (typeof user.value == "string" || user.value === null) opendiscord.blacklist.add(new api.ODBlacklist(user.key,user.value))
})
}
+17 -17
View File
@@ -1,47 +1,47 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
export const loadAllOptions = async () => {
const optionConfig = openticket.configs.get("openticket:options")
const optionConfig = opendiscord.configs.get("openticket:options")
if (!optionConfig) return
optionConfig.data.forEach((option) => {
if (option.type == "ticket"){
const loadedOption = loadTicketOption(option)
openticket.options.add(loadedOption)
openticket.options.suffix.add(loadTicketOptionSuffix(loadedOption))
opendiscord.options.add(loadedOption)
opendiscord.options.suffix.add(loadTicketOptionSuffix(loadedOption))
}else if (option.type == "website"){
openticket.options.add(loadWebsiteOption(option))
opendiscord.options.add(loadWebsiteOption(option))
}else if (option.type == "role"){
openticket.options.add(loadRoleOption(option))
opendiscord.options.add(loadRoleOption(option))
}
})
//update options on config reload
optionConfig.onReload(async () => {
//clear previous options & suffixes
await openticket.options.loopAll((data,id) => {openticket.options.remove(id)})
await openticket.options.suffix.loopAll((data,id) => {openticket.options.suffix.remove(id)})
await opendiscord.options.loopAll((data,id) => {opendiscord.options.remove(id)})
await opendiscord.options.suffix.loopAll((data,id) => {opendiscord.options.suffix.remove(id)})
//add new options
optionConfig.data.forEach((option) => {
if (option.type == "ticket"){
const loadedOption = loadTicketOption(option)
openticket.options.add(loadedOption)
openticket.options.suffix.add(loadTicketOptionSuffix(loadedOption))
opendiscord.options.add(loadedOption)
opendiscord.options.suffix.add(loadTicketOptionSuffix(loadedOption))
}else if (option.type == "website"){
openticket.options.add(loadWebsiteOption(option))
opendiscord.options.add(loadWebsiteOption(option))
}else if (option.type == "role"){
openticket.options.add(loadRoleOption(option))
opendiscord.options.add(loadRoleOption(option))
}
})
//update options in tickets
await openticket.tickets.loopAll((ticket) => {
await opendiscord.tickets.loopAll((ticket) => {
const optionId = ticket.option.id
const option = openticket.options.get(optionId)
const option = opendiscord.options.get(optionId)
if (option && option instanceof api.ODTicketOption) ticket.option = option
else{
openticket.log("Unable to move ticket to unexisting option due to config reload!","warning",[
opendiscord.log("Unable to move ticket to unexisting option due to config reload!","warning",[
{key:"channelid",value:ticket.id.value},
{key:"option",value:optionId.value}
])
@@ -49,7 +49,7 @@ export const loadAllOptions = async () => {
})
//update roles on config reload
await openticket.roles.loopAll((data,id) => {openticket.roles.remove(id)})
await opendiscord.roles.loopAll((data,id) => {opendiscord.roles.remove(id)})
await (await import("./roleLoader.js")).loadAllRoles()
})
}
@@ -134,7 +134,7 @@ export const loadRoleOption = (opt:api.ODJsonConfig_DefaultOptionRoleType): api.
export const loadTicketOptionSuffix = (option:api.ODTicketOption): api.ODOptionSuffix => {
const mode = option.get("openticket:channel-suffix").value
const globalDatabase = openticket.databases.get("openticket:global")
const globalDatabase = opendiscord.databases.get("openticket:global")
if (mode == "user-name") return new api.ODOptionUserNameSuffix(option.id.value,option)
else if (mode == "random-number") return new api.ODOptionRandomNumberSuffix(option.id.value,option,globalDatabase)
else if (mode == "random-hex") return new api.ODOptionRandomHexSuffix(option.id.value,option,globalDatabase)
+6 -6
View File
@@ -1,22 +1,22 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
import * as discord from "discord.js"
export const loadAllPanels = async () => {
const panelConfig = openticket.configs.get("openticket:panels")
const panelConfig = opendiscord.configs.get("openticket:panels")
if (!panelConfig) return
panelConfig.data.forEach((panel) => {
openticket.panels.add(loadPanel(panel))
opendiscord.panels.add(loadPanel(panel))
})
//update panels on config reload
panelConfig.onReload(async () => {
//clear previous panels
await openticket.panels.loopAll((data,id) => {openticket.panels.remove(id)})
await opendiscord.panels.loopAll((data,id) => {opendiscord.panels.remove(id)})
//add new panels
panelConfig.data.forEach((panel) => {
openticket.panels.add(loadPanel(panel))
opendiscord.panels.add(loadPanel(panel))
})
})
}
@@ -53,7 +53,7 @@ export function describePanelOptions(mode:"fields"|"text", panel:api.ODPanel): {
let websiteOnly = true
let roleOnly = true
panel.get("openticket:options").value.forEach((id) => {
const opt = openticket.options.get(id)
const opt = opendiscord.options.get(id)
if (opt){
if (opt instanceof api.ODTicketOption){
options.push(opt)
+7 -7
View File
@@ -1,28 +1,28 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
export const loadAllQuestions = async () => {
const questionConfig = openticket.configs.get("openticket:questions")
const questionConfig = opendiscord.configs.get("openticket:questions")
if (!questionConfig) return
questionConfig.data.forEach((question) => {
if (question.type == "short"){
openticket.questions.add(loadShortQuestion(question))
opendiscord.questions.add(loadShortQuestion(question))
}else if (question.type == "paragraph"){
openticket.questions.add(loadParagraphQuestion(question))
opendiscord.questions.add(loadParagraphQuestion(question))
}
})
//update questions on config reload
questionConfig.onReload(async () => {
//clear previous questions
await openticket.questions.loopAll((data,id) => {openticket.questions.remove(id)})
await opendiscord.questions.loopAll((data,id) => {opendiscord.questions.remove(id)})
//add new questions
questionConfig.data.forEach((question) => {
if (question.type == "short"){
openticket.questions.add(loadShortQuestion(question))
opendiscord.questions.add(loadShortQuestion(question))
}else if (question.type == "paragraph"){
openticket.questions.add(loadParagraphQuestion(question))
opendiscord.questions.add(loadParagraphQuestion(question))
}
})
})
+3 -3
View File
@@ -1,9 +1,9 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
export const loadAllRoles = async () => {
await openticket.options.loopAll((opt) => {
await opendiscord.options.loopAll((opt) => {
if (opt instanceof api.ODRoleOption){
openticket.roles.add(loadRole(opt))
opendiscord.roles.add(loadRole(opt))
}
})
}
+7 -7
View File
@@ -1,16 +1,16 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
const optionDatabase = openticket.databases.get("openticket:options")
const optionDatabase = opendiscord.databases.get("openticket:options")
export const loadAllTickets = async () => {
const ticketDatabase = openticket.databases.get("openticket:tickets")
const ticketDatabase = opendiscord.databases.get("openticket:tickets")
if (!ticketDatabase) return
const tickets = await ticketDatabase.getCategory("openticket:ticket")
if (!tickets) return
for (const ticket of tickets){
try {
openticket.tickets.add(await loadTicket(ticket.value))
opendiscord.tickets.add(await loadTicket(ticket.value))
}catch (err){
process.emit("uncaughtException",err)
process.emit("uncaughtException",new api.ODSystemError("Failed to load ticket from database! => id: "+ticket.key+"\n ===> "+err))
@@ -20,14 +20,14 @@ export const loadAllTickets = async () => {
export const loadTicket = async (ticket:api.ODTicketJson) => {
const backupOption = (await optionDatabase.exists("openticket:used-option",ticket.option)) ? api.ODTicketOption.fromJson(await optionDatabase.get("openticket:used-option",ticket.option) as api.ODOptionJson) : null
const configOption = openticket.options.get(ticket.option)
const configOption = opendiscord.options.get(ticket.option)
//check if option is of type "ticket"
if (configOption && !(configOption instanceof api.ODTicketOption)) throw new api.ODSystemError("Unable to load ticket because option is not of 'ticket' type!")
//manage backup option
if (configOption) await optionDatabase.set("openticket:used-option",configOption.id.value,configOption.toJson(openticket.versions.get("openticket:version")))
else if (backupOption) openticket.options.add(backupOption)
if (configOption) await optionDatabase.set("openticket:used-option",configOption.id.value,configOption.toJson(opendiscord.versions.get("openticket:version")))
else if (backupOption) opendiscord.options.add(backupOption)
else throw new api.ODSystemError("Unable to use backup option! Normal option not found in config!")
//load ticket & option
+40 -40
View File
@@ -1,28 +1,28 @@
import {openticket, api, utilities} from "../../index"
import {opendiscord, api, utilities} from "../../index"
import * as discord from "discord.js"
const collector = openticket.transcripts.collector
const messages = openticket.builders.messages
const transcriptConfig = openticket.configs.get("openticket:transcripts")
const collector = opendiscord.transcripts.collector
const messages = opendiscord.builders.messages
const transcriptConfig = opendiscord.configs.get("openticket:transcripts")
const textConfig = transcriptConfig.data.textTranscriptStyle
const htmlVersion = Buffer.from("b3BlbnRpY2tldFRSQU5TQ1JJUFQxMjM0","base64").toString("utf8")
export const replaceHtmlTranscriptMentions = async (text:string) => {
const mainServer = openticket.client.mainServer
const mainServer = opendiscord.client.mainServer
if (!mainServer) throw new api.ODSystemError("Unknown mainServer! => Required for mention replacement in Html Transcripts!")
const usertext = await utilities.asyncReplace(text,/<@([0-9]+)>/g,async (match,id) => {
const member = await openticket.client.fetchGuildMember(mainServer,id)
const member = await opendiscord.client.fetchGuildMember(mainServer,id)
return (member ? "<@"+(member.user.displayName).replace(/\s/g,"&nbsp;")+"> " : id) //replace with html spaces => BUG: whitespace CSS isn't "pre-wrap"
})
const channeltext = await utilities.asyncReplace(usertext,/<#([0-9]+)>/g,async (match,id) => {
const channel = await openticket.client.fetchGuildChannel(mainServer,id)
const channel = await opendiscord.client.fetchGuildChannel(mainServer,id)
return (channel ? "<#"+channel.name.replace(/\s/g,"&nbsp;")+"> " : id) //replace with html spaces => BUG: whitespace CSS isn't "pre-wrap"
})
const roletext = await utilities.asyncReplace(channeltext,/<@&([0-9]+)>/g,async (match,id) => {
const role = await openticket.client.fetchGuildRole(mainServer,id)
const role = await opendiscord.client.fetchGuildRole(mainServer,id)
let text = role ? role.name.replace(/\s/g,"&nbsp;") : id
let color = role ? ((role.hexColor == "#000000") ? "regular" : role.hexColor) : "regular" //when hex color is #000000 => render as default
return "<@&"+text+"::"+color+"> "
@@ -44,7 +44,7 @@ export const loadAllTranscriptCompilers = async () => {
}
//TEXT COMPILER
openticket.transcripts.add(new api.ODTranscriptCompiler<{contents:string}>("openticket:text-compiler",undefined,async (ticket,channel,user) => {
opendiscord.transcripts.add(new api.ODTranscriptCompiler<{contents:string}>("openticket:text-compiler",undefined,async (ticket,channel,user) => {
//COMPILE
const rawMessages = await collector.collectAllMessages(ticket)
if (!rawMessages) return {ticket,channel,user,success:false,errorReason:"Unable to collect messages! Channel not found!",messages:null,data:null}
@@ -108,10 +108,10 @@ export const loadAllTranscriptCompilers = async () => {
const closeDate = ticket.get("openticket:closed-on").value
const claimDate = ticket.get("openticket:claimed-on").value
const pinDate = ticket.get("openticket:pinned-on").value
const creator = await openticket.tickets.getTicketUser(ticket,"creator")
const closer = await openticket.tickets.getTicketUser(ticket,"closer")
const claimer = await openticket.tickets.getTicketUser(ticket,"claimer")
const pinner = await openticket.tickets.getTicketUser(ticket,"pinner")
const creator = await opendiscord.tickets.getTicketUser(ticket,"creator")
const closer = await opendiscord.tickets.getTicketUser(ticket,"closer")
const claimer = await opendiscord.tickets.getTicketUser(ticket,"claimer")
const pinner = await opendiscord.tickets.getTicketUser(ticket,"pinner")
if (textConfig.includeStats){
//TODO TRANSLATION!!!
@@ -164,21 +164,21 @@ export const loadAllTranscriptCompilers = async () => {
},async (result) => {
//READY
return {
channelMessage:await messages.getSafe("openticket:transcript-text-ready").build("channel",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:text-compiler")}),
creatorDmMessage:await messages.getSafe("openticket:transcript-text-ready").build("creator-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:text-compiler")}),
participantDmMessage:await messages.getSafe("openticket:transcript-text-ready").build("participant-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:text-compiler")}),
activeAdminDmMessage:await messages.getSafe("openticket:transcript-text-ready").build("active-admin-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:text-compiler")}),
everyAdminDmMessage:await messages.getSafe("openticket:transcript-text-ready").build("every-admin-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:text-compiler")})
channelMessage:await messages.getSafe("openticket:transcript-text-ready").build("channel",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:opendiscord.transcripts.get("openticket:text-compiler")}),
creatorDmMessage:await messages.getSafe("openticket:transcript-text-ready").build("creator-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:opendiscord.transcripts.get("openticket:text-compiler")}),
participantDmMessage:await messages.getSafe("openticket:transcript-text-ready").build("participant-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:opendiscord.transcripts.get("openticket:text-compiler")}),
activeAdminDmMessage:await messages.getSafe("openticket:transcript-text-ready").build("active-admin-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:opendiscord.transcripts.get("openticket:text-compiler")}),
everyAdminDmMessage:await messages.getSafe("openticket:transcript-text-ready").build("every-admin-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:opendiscord.transcripts.get("openticket:text-compiler")})
}
}))
//HTML COMPILER
openticket.transcripts.add(new api.ODTranscriptCompiler<{url:string}>("openticket:html-compiler",async (ticket,channel,user) => {
opendiscord.transcripts.add(new api.ODTranscriptCompiler<{url:string}>("openticket:html-compiler",async (ticket,channel,user) => {
//INIT
const req = new api.ODHTTPGetRequest("https://apis.dj-dj.be/transcripts/status.json",false)
const res = await req.run()
if (!res || res.status != 200 || !res.body){
openticket.debugfile.writeNote("HTML Transcripts Error => status: "+res.status+", body:\n"+res.body)
opendiscord.debugfile.writeNote("HTML Transcripts Error => status: "+res.status+", body:\n"+res.body)
process.emit("uncaughtException",new api.ODSystemError("HTML Transcripts INIT_COMMUNICATON error! (check otdebug.txt for details)"))
return {success:false,errorReason:"HTML Transcripts are currently unavailable!",pendingMessage:null}
}
@@ -186,12 +186,12 @@ export const loadAllTranscriptCompilers = async () => {
const data = JSON.parse(res.body)
if (!data || data["v2"] != "online") return {success:false,errorReason:"HTML Transcripts are currently unavailable due to maintenance!",pendingMessage:null}
}catch{
openticket.debugfile.writeNote("HTML Transcripts Error => unable to parse status! body:\n"+res.body)
opendiscord.debugfile.writeNote("HTML Transcripts Error => unable to parse status! body:\n"+res.body)
process.emit("uncaughtException",new api.ODSystemError("HTML Transcripts INIT_STATUS_PARSE error! (check otdebug.txt for details)"))
return {success:false,errorReason:"HTML Transcripts are currently unavailable due to JSON parse error!",pendingMessage:null}
}
return {success:true,errorReason:null,pendingMessage:await messages.getSafe("openticket:transcript-html-progress").build("channel",{guild:channel.guild,channel,user,ticket,compiler:openticket.transcripts.get("openticket:html-compiler"),remaining:16000})}
return {success:true,errorReason:null,pendingMessage:await messages.getSafe("openticket:transcript-html-progress").build("channel",{guild:channel.guild,channel,user,ticket,compiler:opendiscord.transcripts.get("openticket:html-compiler"),remaining:16000})}
},async (ticket,channel,user) => {
//COMPILE
const rawMessages = await collector.collectAllMessages(ticket)
@@ -349,19 +349,19 @@ export const loadAllTranscriptCompilers = async () => {
const dss = transcriptConfig.data.htmlTranscriptStyle.stats
const dsf = transcriptConfig.data.htmlTranscriptStyle.favicon
const creator = await openticket.tickets.getTicketUser(ticket,"creator")
const claimer = await openticket.tickets.getTicketUser(ticket,"claimer")
const closer = await openticket.tickets.getTicketUser(ticket,"closer")
const creator = await opendiscord.tickets.getTicketUser(ticket,"creator")
const claimer = await opendiscord.tickets.getTicketUser(ticket,"claimer")
const closer = await opendiscord.tickets.getTicketUser(ticket,"closer")
const htmlFinal: api.ODTranscriptHtmlV2Data = {
version:"2",
otversion:openticket.versions.get("openticket:version").toString(true),
otversion:opendiscord.versions.get("openticket:version").toString(true),
bot:{
name:openticket.client.client.user.displayName,
id:openticket.client.client.user.id,
pfp:openticket.client.client.user.displayAvatarURL({extension:"png"}),
name:opendiscord.client.client.user.displayName,
id:opendiscord.client.client.user.id,
pfp:opendiscord.client.client.user.displayAvatarURL({extension:"png"}),
},
language:openticket.languages.getLanguageMetadata()?.language ?? "english",
language:opendiscord.languages.getLanguageMetadata()?.language ?? "english",
style:{
background:{
backgroundData:(dsb.backgroundImage == "") ? dsb.backgroundColor : dsb.backgroundImage,
@@ -426,12 +426,12 @@ export const loadAllTranscriptCompilers = async () => {
customCredits:{
enable:false,
replaceText:"Powered By Open Ticket!",
replaceURL:"https://openticket.dj-dj.be",
replaceURL:"https://opendiscord.dj-dj.be",
enableReportBug:true
},
customHeaderUrl:{
enabled:false,
url:"https://openticket.dj-dj.be",
url:"https://opendiscord.dj-dj.be",
text:"Hello!"
},
customTranscriptUrl:{
@@ -454,17 +454,17 @@ export const loadAllTranscriptCompilers = async () => {
if (res.status == 429) return {ticket,channel,user,success:false,errorReason:"Failed to upload HTML Transcripts! (Ratelimit)\nTry again in a few minutes!",messages,data:null}
//unknown status error
openticket.debugfile.writeNote("HTML Transcripts Error => status: "+res.status+", body:\n"+res.body)
opendiscord.debugfile.writeNote("HTML Transcripts Error => status: "+res.status+", body:\n"+res.body)
return {ticket,channel,user,success:false,errorReason:"Failed to upload HTML Transcripts! (Unknown Error)",messages,data:null}
}
//check body
try{
var data: api.ODTranscriptHtmlV2Response = JSON.parse(res.body)
if (!data || data["status"] != "success"){
openticket.debugfile.writeNote("HTML Transcripts Error => status: "+res.status+", body:\n"+res.body)
opendiscord.debugfile.writeNote("HTML Transcripts Error => status: "+res.status+", body:\n"+res.body)
return {ticket,channel,user,success:false,errorReason:"Failed to upload HTML Transcripts! (Server 500 Error)",messages,data:null}}
}catch{
openticket.debugfile.writeNote("HTML Transcripts Error => status: "+res.status+", body:\n"+res.body)
opendiscord.debugfile.writeNote("HTML Transcripts Error => status: "+res.status+", body:\n"+res.body)
return {ticket,channel,user,success:false,errorReason:"Failed to upload HTML Transcripts! (JSON parse error)",messages,data:null}
}
@@ -474,11 +474,11 @@ export const loadAllTranscriptCompilers = async () => {
//READY
await utilities.timer(16000) //wait until transcript is ready
return {
channelMessage:await messages.getSafe("openticket:transcript-html-ready").build("channel",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:html-compiler")}),
creatorDmMessage:await messages.getSafe("openticket:transcript-html-ready").build("creator-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:html-compiler")}),
participantDmMessage:await messages.getSafe("openticket:transcript-html-ready").build("participant-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:html-compiler")}),
activeAdminDmMessage:await messages.getSafe("openticket:transcript-html-ready").build("active-admin-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:html-compiler")}),
everyAdminDmMessage:await messages.getSafe("openticket:transcript-html-ready").build("every-admin-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:openticket.transcripts.get("openticket:html-compiler")})
channelMessage:await messages.getSafe("openticket:transcript-html-ready").build("channel",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:opendiscord.transcripts.get("openticket:html-compiler")}),
creatorDmMessage:await messages.getSafe("openticket:transcript-html-ready").build("creator-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:opendiscord.transcripts.get("openticket:html-compiler")}),
participantDmMessage:await messages.getSafe("openticket:transcript-html-ready").build("participant-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:opendiscord.transcripts.get("openticket:html-compiler")}),
activeAdminDmMessage:await messages.getSafe("openticket:transcript-html-ready").build("active-admin-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:opendiscord.transcripts.get("openticket:html-compiler")}),
everyAdminDmMessage:await messages.getSafe("openticket:transcript-html-ready").build("every-admin-dm",{guild:result.channel.guild,channel:result.channel,user:result.user,ticket:result.ticket,result,compiler:opendiscord.transcripts.get("openticket:html-compiler")})
}
}))
}