From 893a7c5b1f6236accdb7350f727a0a7b9860447d Mon Sep 17 00:00:00 2001 From: DJj123dj <80536295+DJj123dj@users.noreply.github.com> Date: Sat, 1 Oct 2022 11:14:37 +0200 Subject: [PATCH] 3.0 public beta 2 --- README.md | 1 + config.json | 5 +- core/checker.js | 88 +++++++++++++++++++++++++++--- core/ticketActions/ticketOpener.js | 2 + core/utils/configParser.js | 35 +++++++++++- core/utils/getEmbed.js | 3 +- 6 files changed, 122 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 4d53e60..bd5c6fc 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ This is an open-source discord ticket bot, you can configure it and it comes wit - t0miiis - josuens14 - M4 +- David. ## features - discord interaction buttons diff --git a/config.json b/config.json index 2128639..d346174 100644 --- a/config.json +++ b/config.json @@ -42,7 +42,10 @@ "category":"category id", "message":"You created a ticket!", "enableDmOnOpen":true, - "ticketmessage":"The staff will help you soon!\n\n*Click on the button below to close the ticket!*" + "ticketmessage":"The staff will help you soon!\n\n*Click on the button below to close the ticket!*", + + "enableThumbnail":false, + "thumbnailUrl":"https://www.example.com/catmemes/cat.png" }, { diff --git a/core/checker.js b/core/checker.js index 96c17bb..2dccb82 100644 --- a/core/checker.js +++ b/core/checker.js @@ -52,9 +52,10 @@ exports.checker = async () => { } /**@param {String} value */ const checkToken = (value) => { - if (value.includes(" ") || value.length < 40){ + if (value.length < 40){ createError("'auth_token' | your token is invalid") } + if (value.includes(" ")) createError("'auth_token' | your token includes spaces!") } /**@param {String} value @param {String} path */ @@ -133,8 +134,12 @@ exports.checker = async () => { } } - const getButtonClass = require("./utils/getButton").rawButtonData - /**@param {getButtonClass} option */ + const configParser = require("./utils/configParser") + /** + * @param {configParser.OTAllOptions} option + * @param {String} path + */ + const checkOption = (option,path) => { //id @@ -219,13 +224,13 @@ exports.checker = async () => { createWarn("'"+path+"/url' | a url can't contain spaces") } if (option.url.length < 1){ - createError("'"+path+"/url' | you have no url in this button") + createError("'"+path+"/url' | there is no url!") } if (!option.url.startsWith("https://") && !option.url.startsWith("http://") && !option.url.startsWith("discord://")){ createWarn("'"+path+"/url' | your url doesn't start with https or http!") } if (option.url.startsWith("http://")){ - createWarn("'"+path+"/url' | your url is not a HTTPS link! discord maybe blocks this url!") + createWarn("'"+path+"/url' | your url is not a HTTPS link! discord can block this url!") } }else if (type == "role"){ //color @@ -246,8 +251,69 @@ exports.checker = async () => { } } + /** + * + * @param {configParser.OTConfigMessage} input + * @param {String} path + */ const checkMessage = (input,path) => { + //id + if (!input.id) createError("'"+path+"/id' | this embed doesn't have an id!") + if (input.id.length > 50) createError("'"+path+"/id' | the id can't be longer than 50") + if (input.id.includes(" ") || input.id.includes("\n")) createError("'"+path+"/id' | the id can't contain spaces!") + //name + if (input.name.length < 1){ + createWarn("'"+path+"/name' | this embed has no name!") + }else if (input.name.length > 99) { + createError("'"+path+"/name' | the name can't be longer than 100") + } + + //description + if (input.description.length < 0){ + createWarn("'"+path+"/description' | this embed doesn't have a description!") + } + + //dropdown + checkType(input.dropdown,"boolean",path+"/dropdown") + + //footer + checkType(input.enableFooter,"boolean",path+"/enableFooter") + if (input.enableFooter){ + if (input.footer.length < 1) createError("'"+path+"/footer' | no footer!") + if (input.footer.length > 200) createError("'"+path+"/footer' | footer length can't be more than 200!") + } + + //thumbnail + checkType(input.enableThumbnail,"boolean",path+"/enableThumbnail") + if (input.enableThumbnail){ + if (input.thumbnail.length < 1) createError("'"+path+"/thumbnail' | no thumbnail url!") + } + + //customColor + checkType(input.enableCustomColor,"boolean",path+"/enableCustomColor") + if (input.enableCustomColor){ + if (input.color.length < 1) createError("'"+path+"/color' | no color!") + checkHexColor(input.color,path+"/color") + } + + //ticket explaination & max tickets warning + checkType(input.enableTicketExplaination,"boolean",path+"/enableTicketExplaination") + checkType(input.enableMaxTicketsWarning,"boolean",path+"/enableMaxTicketsWarning") + + //OPTIONS!!! + var counter = 0 + input.options.forEach((option) => {if (!configParser.optionExists(option)){counter++}}) + + if (counter == input.options.length){ + createWarn("'"+path+"/options' | insert the option ids here!") + }else{ + input.options.forEach((option,index) => { + if (!configParser.optionExists(option)){ + createWarn("'"+path+"/options:"+index+"' | this option doesnt exist!") + } + }) + } } //--------------------------| @@ -281,11 +347,12 @@ exports.checker = async () => { checkType(config.status.enabled,"boolean","status/enabled") if (config.status.enabled){ if (config.status.type != "PLAYING" && config.status.type != "LISTENING" && config.status.type != "WATCHING"){ - createError("'status/type' | not a valid status type!") + createError("'status/type' | not a valid status type! (LISTENING,WATCHING,PLAYING)") } - if (config.status.text.length < 1 || config.status.text.length > 40){ - createError("'status/text' | text too long or short!") + if (config.status.text.length < 1){ + createError("'status/text' | there is no status text!") } + if (config.status.text.length > 50) createError("'status/text' | text too long!") } @@ -320,6 +387,11 @@ exports.checker = async () => { checkOption(option,"options/"+index) }) + //messages + config.messages.forEach((message,index) => { + checkMessage(message,"messages/"+index) + }) + //discord check /** diff --git a/core/ticketActions/ticketOpener.js b/core/ticketActions/ticketOpener.js index 47eed3d..d79b9cc 100755 --- a/core/ticketActions/ticketOpener.js +++ b/core/ticketActions/ticketOpener.js @@ -184,6 +184,8 @@ module.exports = () => { }else{ ticketEmbed.setDescription(hiddendata) } + + if (currentTicketOptions.enableThumbnail) ticketEmbed.setThumbnail(currentTicketOptions.thumbnailUrl) ticketChannel.send({ content:"<@"+interaction.member.id+"> @here", diff --git a/core/utils/configParser.js b/core/utils/configParser.js index 9dec95f..dc05ac5 100644 --- a/core/utils/configParser.js +++ b/core/utils/configParser.js @@ -6,7 +6,7 @@ const l = bot.language //================== //OTTicketOptions -/**@typedef {{id: String,name: String,description: String,icon: String,label: String,type: "ticket"|"role"|"website",color: String,adminroles: String[],channelprefix: String,category: String,message: String,enableDmOnOpen: Boolean,ticketmessage: String}} OTTicketOptions */ +/**@typedef {{id: String,name: String,description: String,icon: String,label: String,type: "ticket"|"role"|"website",color: "red"|"green"|"blue"|"gray",adminroles: String[],channelprefix: String,category: String,message: String,enableDmOnOpen: Boolean,ticketmessage: String, enableThumbnail:Boolean, thumbnailUrl:String}} OTTicketOptions */ //OTRoleOptions /**@typedef {{id: String,name: String,description: String,icon: String,label: String,type: "ticket"|"role"|"website",color:"red"|"green"|"blue"|"gray"|"none",roles:String[],mode:"add&remove"|"remove"|"add",enableDmOnOpen:Boolean}} OTRoleOptions */ @@ -19,7 +19,7 @@ const l = bot.language /**@typedef {{id: string, name: string, description: string, dropdown: boolean, enableFooter: boolean, footer: string, enableThumbnail: boolean, thumbnail: string, enableCustomColor: boolean, color: string, options: string[], enableTicketExplaination: boolean, enableMaxTicketsWarning: boolean}} OTConfigMessage*/ //StringOptions -/**@typedef {"id"|"name"|"description"|"icon"|"label"|"type"|"color"|"adminroles"|"channelprefix"|"category"|"message"|"enableDmOnOpen"|"ticketmessage"} OTTicketStringOptions */ +/**@typedef {"id"|"name"|"description"|"icon"|"label"|"type"|"color"|"adminroles"|"channelprefix"|"category"|"message"|"enableDmOnOpen"|"ticketmessage"|"enableThumbnail"|"thumbnailUrl"} OTTicketStringOptions */ /**@typedef {"id"|"name"|"description"|"icon"|"label"|"type"|"color"|"roles"|"mode"|"enableDmOnOpen"} OTRoleStringOptions */ /**@typedef {"id"|"name"|"description"|"icon"|"label"|"type"|"url"} OTWebsiteStringOptions */ @@ -153,4 +153,35 @@ exports.getTicketValuesArray = (value,idWithoutOTnewT) => { } }) return result +} + +/**@type {OTTicketOptions} */ +this.ticketType = {} + +/**@type {OTRoleOptions} */ +this.roleType = {} + +/**@type {OTWebsiteOptions} */ +this.websiteType = {} + +/**@type {OTConfigMessage} */ +this.messageType = {} + + +//OTAllOptions +/**@typedef {{id: String,name: String,description: String,icon: String,label: String,type: "ticket"|"role"|"website",color:"red"|"green"|"blue"|"gray"|"none",roles:String[],mode:"add&remove"|"remove"|"add",adminroles: String[],channelprefix: String,category: String,message: String,enableDmOnOpen: Boolean,ticketmessage: String, enableThumbnail:Boolean, thumbnailUrl:String,url:String}} OTAllOptions */ + +/** + * + * @param {String} id + * @returns {Boolean} + */ + exports.optionExists = (id) => { + var result = false + config.options.forEach((option) => { + if (option.id == id){ + result = true + } + }) + return result } \ No newline at end of file diff --git a/core/utils/getEmbed.js b/core/utils/getEmbed.js index c7c8ecb..aa44034 100644 --- a/core/utils/getEmbed.js +++ b/core/utils/getEmbed.js @@ -60,7 +60,8 @@ exports.createEmbed = (id) => { description = description+"\n\n"+l.commands.maxTicketWarning.replace("{0}",config.system.max_allowed_tickets) } - embed.setDescription(description) + if (description) embed.setDescription(description) + //-----------------------------------