Major bug fixes + updated contributing guidelines

This commit is contained in:
DJj123dj
2024-11-06 20:59:00 +01:00
parent 319bbe318d
commit 4022ae49c2
7 changed files with 123 additions and 23 deletions
+16
View File
@@ -82,6 +82,22 @@ export const registerCommandResponders = async () => {
ticket.get("openticket:autoclose-hours").value = time
await instance.reply(await openticket.builders.messages.getSafe("openticket:autoclose-enable").build(source,{guild,channel,user,ticket,reason,time}))
}
//update ticket message
const ticketMessage = await openticket.tickets.getTicketMessage(ticket)
if (ticketMessage){
try{
ticketMessage.edit((await openticket.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket})).message)
}catch(e){
openticket.log("Unable to edit ticket message on autoclose "+scope+"!","error",[
{key:"channel",value:"#"+channel.name},
{key:"channelid",value:channel.id,hidden:true},
{key:"messageid",value:ticketMessage.id},
{key:"option",value:ticket.option.id.value}
])
openticket.debugfile.writeErrorMessage(new api.ODError(e,"uncaughtException"))
}
}
}),
new api.ODWorker("openticket:logs",-1,(instance,params,source,cancel) => {
const scope = instance.options.getSubCommand()
+16
View File
@@ -77,6 +77,22 @@ export const registerCommandResponders = async () => {
ticket.get("openticket:autodelete-days").value = time
await instance.reply(await openticket.builders.messages.getSafe("openticket:autodelete-enable").build(source,{guild,channel,user,ticket,reason,time}))
}
//update ticket message
const ticketMessage = await openticket.tickets.getTicketMessage(ticket)
if (ticketMessage){
try{
ticketMessage.edit((await openticket.builders.messages.getSafe("openticket:ticket-message").build("other",{guild,channel,user,ticket})).message)
}catch(e){
openticket.log("Unable to edit ticket message on autodelete "+scope+"!","error",[
{key:"channel",value:"#"+channel.name},
{key:"channelid",value:channel.id,hidden:true},
{key:"messageid",value:ticketMessage.id},
{key:"option",value:ticket.option.id.value}
])
openticket.debugfile.writeErrorMessage(new api.ODError(e,"uncaughtException"))
}
}
}),
new api.ODWorker("openticket:logs",-1,(instance,params,source,cancel) => {
const scope = instance.options.getSubCommand()
+7 -2
View File
@@ -1,7 +1,7 @@
///////////////////////////////////////
//DATABASE MODULE
///////////////////////////////////////
import { ODId, ODManager, ODManagerData, ODValidId, ODValidJsonType } from "./base"
import { ODId, ODManager, ODManagerData, ODSystemError, ODValidId, ODValidJsonType } from "./base"
import fs from "fs"
import nodepath from "path"
import { ODDebugger } from "./console"
@@ -203,7 +203,12 @@ export class ODJsonDatabase extends ODDatabase {
/**Read parsed data from the json file */
getData: (): ODJsonDatabaseStructure => {
if (fs.existsSync(this.file)){
return JSON.parse(fs.readFileSync(this.file).toString())
try{
return JSON.parse(fs.readFileSync(this.file).toString())
}catch(err){
process.emit("uncaughtException",err)
throw new ODSystemError("Unable to read database "+this.file+"! getData() read error. (see error above)")
}
}else{
fs.writeFileSync(this.file,"[]")
return []
+19 -1
View File
@@ -114,6 +114,9 @@ export const registerDefaultCheckerCustomTranslations = (tm:api.ODCheckerTransla
tm.quickTranslate(lm,"checker.messages.unusedOption","message","openticket:unused-option") // The option {0} isn't used anywhere!
tm.quickTranslate(lm,"checker.messages.unusedQuestion","message","openticket:unused-question") // The question {0} isn't used anywhere!
tm.quickTranslate(lm,"checker.messages.dropdownOption","message","openticket:dropdown-option") // A panel with dropdown enabled can only contain options of the 'ticket' type!
//TODO TRANSLATION!!!
//tm.quickTranslate(lm,"checker.messages.TODO","message","openticket:invalid-version") // The version specified in your config is invalid! Make sure you have updated it to the latest version!
}
//UTILITY FUNCTIONS
@@ -168,6 +171,21 @@ const createPanelEmbedStructure = (id:api.ODValidId) => {
//STRUCTURES
export const defaultGeneralStructure = new api.ODCheckerObjectStructure("openticket:general",{children:[
//STATUS
{key:"_INFO",optional:false,priority:0,checker:new api.ODCheckerObjectStructure("openticket:info",{children:[
{key:"support",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:info-support",{choices:["https://otdocs.dj-dj.be"]})},
{key:"discord",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:info-discord",{choices:["https://discord.dj-dj.be"]})},
{key:"version",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:info-version",{custom(checker,value,locationTrace,locationId,locationDocs) {
const lt = checker.locationTraceDeref(locationTrace)
if (typeof value != "string") return false
else if (value != "open-ticket-"+openticket.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
},})},
]})},
//BASIC
{key:"token",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_DiscordToken("openticket:token")},
{key:"tokenFromENV",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:token-env",{})},
@@ -439,7 +457,7 @@ export const defaultPanelsStructure = new api.ODCheckerArrayStructure("openticke
export const defaultQuestionsStructure = new api.ODCheckerArrayStructure("openticket:questions",{allowedTypes:["object"],propertyChecker:new api.ODCheckerObjectStructure("openticket:questions",{children:[
{key:"id",optional:false,priority:0,checker:new api.ODCheckerCustomStructure_UniqueId("openticket:question-id","openticket","question-ids",{regex:/^[A-Za-z0-9-éèçàêâôûî]+$/,minLength:3,maxLength:40})},
{key:"name",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:question-name",{minLength:3,maxLength:50})},
{key:"name",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:question-name",{minLength:3,maxLength:45})},
{key:"type",optional:false,priority:0,checker:new api.ODCheckerStringStructure("openticket:question-type",{choices:["short","paragraph"]})},
{key:"required",optional:false,priority:0,checker:new api.ODCheckerBooleanStructure("openticket:question-required",{})},
+22 -3
View File
@@ -5,6 +5,7 @@ const collector = openticket.transcripts.collector
const messages = openticket.builders.messages
const transcriptConfig = openticket.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
@@ -34,6 +35,14 @@ export const replaceHtmlTranscriptMentions = async (text:string) => {
}
export const loadAllTranscriptCompilers = async () => {
class ODHTTPHtmlPostRequest extends api.ODHTTPPostRequest {
constructor(domain:string, htmlFinal:api.ODTranscriptHtmlV2Data){
super("https://"+domain+"/transcripts/upload?auth="+htmlVersion+"&version=2",true,{
body:JSON.stringify(htmlFinal)
})
}
}
//TEXT COMPILER
openticket.transcripts.add(new api.ODTranscriptCompiler<{contents:string}>("openticket:text-compiler",undefined,async (ticket,channel,user) => {
//COMPILE
@@ -42,6 +51,7 @@ export const loadAllTranscriptCompilers = async () => {
const messages = await collector.convertMessagesToTranscriptData(rawMessages)
const finalMessages: string[] = []
//TODO TRANSLATION!!!
finalMessages.push("=============== MESSAGES ===============")
messages.filter((msg) => textConfig.includeBotMessages || !msg.author.tag).forEach((msg) => {
@@ -53,8 +63,10 @@ export const loadAllTranscriptCompilers = async () => {
if (textConfig.layout == "simple"){
//SIMPLE LAYOUT
const header = "["+timestamp+" | "+msg.author.displayname+authorId+"]"+edited+msgId
//TODO TRANSLATION!!!
const embeds = (textConfig.includeEmbeds) ? "\nEmbeds: "+msg.embeds.length : ""
const files = (textConfig.includeFiles) ? "\nFiles: "+msg.files.length : ""
//TODO TRANSLATION!!!
const content = (msg.content) ? msg.content : ("<content is empty>"+embeds+files)
finalMessages.push(header+"\n "+content.split("\n").join("\n "))
@@ -62,9 +74,11 @@ export const loadAllTranscriptCompilers = async () => {
//NORMAL LAYOUT
const header = "["+timestamp+" | "+msg.author.displayname+authorId+"]"+edited+msgId
const embeds = (textConfig.includeEmbeds && msg.embeds.length > 0) ? "\n"+msg.embeds.map((embed) => {
//TODO TRANSLATION!!!
return "==== (EMBED) "+(embed.title ?? "<no-title>")+" ====\n"+(embed.description ?? "<no-description>")
}) : ""
const files = (textConfig.includeFiles && msg.files.length > 0) ? "\n"+msg.files.map((file) => {
//TODO TRANSLATION!!!
return "==== (FILE) "+(file.name)+" ====\nSize: "+(file.size+" "+file.unit)+"\nUrl: "+file.url
}) : ""
const content = (msg.content) ? msg.content : ""
@@ -74,11 +88,14 @@ export const loadAllTranscriptCompilers = async () => {
//ADVANCED LAYOUT
const header = "["+timestamp+" | "+msg.author.displayname+authorId+"]"+edited+msgId
const embeds = (textConfig.includeEmbeds && msg.embeds.length > 0) ? "\n"+msg.embeds.map((embed) => {
//TODO TRANSLATION!!!
return "\n==== (EMBED) "+(embed.title ?? "<no-title>")+" ====\n"+(embed.description ?? "<no-description>")+(embed.fields.length > 0 ? "\n\n== (FIELDS) ==\n"+embed.fields.map((field) => field.name+": "+field.value).join("\n") : "")
}) : ""
const files = (textConfig.includeFiles && msg.files.length > 0) ? "\n"+msg.files.map((file) => {
//TODO TRANSLATION!!!
return "\n==== (FILE) "+(file.name)+" ====\nSize: "+(file.size+" "+file.unit)+"\nUrl: "+file.url+"\nAlt: "+(file.alt ?? "/")
}) : ""
//TODO TRANSLATION!!!
const reactions = (msg.reactions.filter((r) => !r.custom).length > 0) ? "\n==== (REACTIONS) ====\n"+msg.reactions.filter((r) => !r.custom).map((r) => r.amount+" "+r.emoji).join(" - ") : ""
const content = (msg.content) ? msg.content : ""
finalMessages.push(header+"\n "+(content+embeds+files+reactions).split("\n").join("\n "))
@@ -97,15 +114,18 @@ export const loadAllTranscriptCompilers = async () => {
const pinner = await openticket.tickets.getTicketUser(ticket,"pinner")
if (textConfig.includeStats){
//TODO TRANSLATION!!!
finalStats.push("=============== STATS ===============")
if (textConfig.layout == "simple"){
//SIMPLE LAYOUT
//TODO TRANSLATION!!!
if (creationDate) finalStats.push("Created On: "+utilities.dateString(new Date(creationDate)))
if (creator) finalStats.push("Created By: "+creator.displayName)
finalStats.push("\n")
}else if (textConfig.layout == "normal"){
//NORMAL LAYOUT
//TODO TRANSLATION!!!
if (creationDate) finalStats.push("Created On: "+utilities.dateString(new Date(creationDate)))
if (creator) finalStats.push("Created By: "+creator.displayName)
finalStats.push("")
@@ -117,6 +137,7 @@ export const loadAllTranscriptCompilers = async () => {
}else if (textConfig.layout == "detailed"){
//ADVANCED LAYOUT
//TODO TRANSLATION!!!
if (creationDate) finalStats.push("Created On: "+utilities.dateString(new Date(creationDate)))
if (creator) finalStats.push("Created By: "+creator.displayName)
finalStats.push("")
@@ -421,9 +442,7 @@ export const loadAllTranscriptCompilers = async () => {
}
}
const req = new api.ODHTTPPostRequest("https://apis.dj-dj.be/transcripts/upload?auth=openticketTRANSCRIPT1234&version=2",true,{
body:JSON.stringify(htmlFinal)
})
const req = new ODHTTPHtmlPostRequest("apis.dj-dj.be",htmlFinal)
const res = await req.run()
if (!res || res.status != 200 || !res.body){
if (res.status == 429) return {ticket,channel,user,success:false,errorReason:"Failed to upload HTML Transcripts due to Ratelimt! Try again in a few minutes!",messages,data:null}
+4
View File
@@ -220,6 +220,10 @@ const main = async () => {
//render
openticket.debugfile.writeText("\n[CONFIG CHECKER RESULT]:\n"+ansis.strip(components.join("\n"))+"\n")
openticket.checkers.renderer.render(components)
//wait 5 seconds when there are warnings (not for errors & info)
if (result.messages.length > 0 && result.messages.every((message) => message.type != "error")) await utilities.timer(5000)
await openticket.events.get("afterCheckersRendered").emit([openticket.checkers.renderer,openticket.checkers])
}