From fc50a8e83f9226b36fa5c6ada67fb2ff93d255fd Mon Sep 17 00:00:00 2001 From: DJj123dj <80536295+DJj123dj@users.noreply.github.com> Date: Sat, 31 Dec 2022 11:42:33 +0100 Subject: [PATCH] v3.1 last push --- config.json | 1 + core/checker.js | 40 +++++++- core/dynamicdatabase/dynamicfiles/database.js | 7 +- core/ticketActions/ticketCloser.js | 96 ++++++++++--------- 4 files changed, 95 insertions(+), 49 deletions(-) diff --git a/config.json b/config.json index c9e1e82..cab7717 100644 --- a/config.json +++ b/config.json @@ -105,6 +105,7 @@ "other":{ "enableTicketExplaination":true, "enableMaxTicketsWarning":true, + "customDropdownPlaceholder":{ "enable":false, "text":"Choose a ticket" diff --git a/core/checker.js b/core/checker.js index 9da940e..edc73db 100644 --- a/core/checker.js +++ b/core/checker.js @@ -311,10 +311,6 @@ exports.checker = async () => { checkHexColor(input.color,path+"/color") } - //ticket explaination & max tickets warning - checkType(input.other.enableTicketExplaination,"boolean",path+"/other/enableTicketExplaination") - checkType(input.other.enableMaxTicketsWarning,"boolean",path+"/other/enableMaxTicketsWarning") - //OPTIONS!!! var counter = 0 input.options.forEach((option) => {if (!configParser.optionExists(option)){counter++}}) @@ -328,6 +324,42 @@ exports.checker = async () => { } }) } + + //other + //ticket explaination & max tickets warning + if (typeof input.other != "object"){ + createError("'"+path+"/other' | this object doesn't exist!") + }else{ + checkType(input.other.enableTicketExplaination,"boolean",path+"/other/enableTicketExplaination") + checkType(input.other.enableMaxTicketsWarning,"boolean",path+"/other/enableMaxTicketsWarning") + + //customDropdownPlaceholder + if (typeof input.other.customDropdownPlaceholder != "object"){ + createError("'"+path+"/other/customDropdownPlaceholder' | this object doesn't exist!") + }else{ + checkType(input.other.customDropdownPlaceholder.enable,"boolean",path+"/other/customDropdownPlaceholder/enable") + checkType(input.other.customDropdownPlaceholder.text,"string",path+"/other/customDropdownPlaceholder/text") + if (input.other.customDropdownPlaceholder.enable && input.other.customDropdownPlaceholder.text.length < 1){createError("'"+path+"/other/customDropdownPlaceholder/text' | there is no placeholder text!")} + } + + //customCategoryText + if (typeof input.other.customCategoryText != "object"){ + createError("'"+path+"/other/customCategoryText' | this object doesn't exist!") + }else{ + checkType(input.other.customCategoryText.enable,"boolean",path+"/other/customCategoryText/enable") + checkType(input.other.customCategoryText.text,"string",path+"/other/customCategoryText/text") + if (input.other.customCategoryText.enable && input.other.customCategoryText.text.length < 1){createError("'"+path+"/other/customCategoryText/text' | there is no category text!")} + } + + //embedTitleURL + if (typeof input.other.embedTitleURL != "object"){ + createError("'"+path+"/other/embedTitleURL' | this object doesn't exist!") + }else{ + checkType(input.other.embedTitleURL.enable,"boolean",path+"/other/embedTitleURL/enable") + checkType(input.other.embedTitleURL.url,"string",path+"/other/embedTitleURL/text") + if (input.other.embedTitleURL.enable && input.other.embedTitleURL.url.length < 1){createError("'"+path+"/other/embedTitleURL/url' | there is no url!")} + } + } } //--------------------------| diff --git a/core/dynamicdatabase/dynamicfiles/database.js b/core/dynamicdatabase/dynamicfiles/database.js index f89955e..d0b167a 100644 --- a/core/dynamicdatabase/dynamicfiles/database.js +++ b/core/dynamicdatabase/dynamicfiles/database.js @@ -4,7 +4,12 @@ const location = "./storage/database.json" /**@returns {[{category:String, key:String, value:String}]}*/ function getData(){ - return JSON.parse(fs.readFileSync(location).toString()) + if (fs.existsSync(location)){ + return JSON.parse(fs.readFileSync(location).toString()) + }else{ + fs.writeFileSync(location,"[]") + return [] + } } /**@param {[{category:String, key:String, value:String}]} data*/ function setData(data){ diff --git a/core/ticketActions/ticketCloser.js b/core/ticketActions/ticketCloser.js index 8963ec6..ad1ff99 100755 --- a/core/ticketActions/ticketCloser.js +++ b/core/ticketActions/ticketCloser.js @@ -22,7 +22,6 @@ exports.NEWcloseTicket = async (member,channel,prefix,mode,reason,nomessage) => const guild = channel.guild const user = member.user const chalk = await (await import("chalk")).default - const channelmessages = await channel.messages.fetch() const newReason = reason ? reason : l.messages.none @@ -31,9 +30,6 @@ exports.NEWcloseTicket = async (member,channel,prefix,mode,reason,nomessage) => //FIX CHANNEL COULD BE CLOSED AFTER DELETE: if (pendingDelete.includes(channel.id)) return false - //remove ot bot from transcript - channelmessages.sweep((msgSweep) => {return msgSweep.author.id == client.user.id}) - /**@type {String}*/ const channelname = channel.name const ticketOpenerChannelName = channelname.split(prefix)[1] @@ -293,53 +289,65 @@ exports.NEWcloseTicket = async (member,channel,prefix,mode,reason,nomessage) => } - if (enableTranscript == true && mode != "deletenotranscript"){ + const transcriptHandler = async () => { + if (enableTranscript == true && mode != "deletenotranscript"){ + //transcript messages + const transcriptReason = (mode == "close") ? "**"+l.messages.reason+":** "+newReason : "**"+l.messages.reason+":** "+l.messages.none + const closedByPrefix = (mode.startsWith("delete")) ? l.messages.deletedby : l.messages.closedby - const transcriptReason = (mode == "close") ? "**"+l.messages.reason+":** "+newReason : "**"+l.messages.reason+":** "+l.messages.none - const closedByPrefix = (mode.startsWith("delete")) ? l.messages.deletedby : l.messages.closedby + if (config.system.enable_transcript || config.system.enable_DM_transcript){ + const channelmessages = await channel.messages.fetch({cache:true}) + //remove ot bot from transcript + channelmessages.sweep((msgSweep) => {return msgSweep.author.id == client.user.id}) - if (config.system.enable_transcript || config.system.enable_DM_transcript){ - var fileattachment = await require("../transcript").createTranscript(channelmessages,channel) + var fileattachment = await require("../transcript").createTranscript(channelmessages,channel) - if (fileattachment == false){log("system","internal error: transcript is not created!");return} - } - - if (config.system.enable_transcript && !require("../api/api.json").disable.transcripts.server){ - const transcriptEmbed = new discord.EmbedBuilder() - .setColor(config.main_color) - .setTitle("📄 "+l.messages.newTranscriptTitle) - .setDescription(transcriptReason) - .setFooter({text:closedByPrefix+": "+user.tag+" | ticket: "+channelname,iconURL:user.displayAvatarURL()}) - - guild.channels.cache.find(c => c.id == config.system.transcript_channel).send({ - embeds:[transcriptEmbed], - files:[fileattachment] - }) - } + if (fileattachment == false){log("system","internal error: transcript is not created!");return} + } + + if (config.system.enable_transcript && !require("../api/api.json").disable.transcripts.server){ + const transcriptEmbed = new discord.EmbedBuilder() + .setColor(config.main_color) + .setTitle("📄 "+l.messages.newTranscriptTitle) + .setDescription(transcriptReason) + .setFooter({text:closedByPrefix+": "+user.tag+" | ticket: "+channelname,iconURL:user.displayAvatarURL()}) + + guild.channels.cache.find(c => c.id == config.system.transcript_channel).send({ + embeds:[transcriptEmbed], + files:[fileattachment] + }) + } - if (config.system.enable_DM_transcript && !require("../api/api.json").disable.transcripts.dm){ - const transcriptEmbed = new discord.EmbedBuilder() - .setColor(config.main_color) - .setTitle("📄 "+l.messages.newTranscriptTitle) - .setDescription(transcriptReason) - .setFooter({text:closedByPrefix+": "+user.tag+" | ticket: "+channelname,iconURL:user.displayAvatarURL()}) - - if (!isDatabaseError) ticketOpener.send({ - embeds:[transcriptEmbed], - files:[fileattachment] - }) + if (config.system.enable_DM_transcript && !require("../api/api.json").disable.transcripts.dm){ + const transcriptEmbed = new discord.EmbedBuilder() + .setColor(config.main_color) + .setTitle("📄 "+l.messages.newTranscriptTitle) + .setDescription(transcriptReason) + .setFooter({text:closedByPrefix+": "+user.tag+" | ticket: "+channelname,iconURL:user.displayAvatarURL()}) + + if (!isDatabaseError) ticketOpener.send({ + embeds:[transcriptEmbed], + files:[fileattachment] + }) + } } } + const deleteHandler = async () => { + if (deleteRequired){ + //const timer = () => {return new Promise((resolve,reject) => { + // setTimeout(() => {resolve(true)},7000) + //})} + //await timer() - if (deleteRequired){ - //const timer = () => {return new Promise((resolve,reject) => { - // setTimeout(() => {resolve(true)},7000) - //})} - //await timer() - - setTimeout(async () => { pendingDelete.shift() - await channel.delete() - },6000) + await channel.delete() + + //setTimeout(async () => { + // pendingDelete.shift() + // await channel.delete() + //},6000) + } } + await transcriptHandler() + deleteHandler() } \ No newline at end of file