diff --git a/config.json b/config.json index 82b13fb..705dfc9 100644 --- a/config.json +++ b/config.json @@ -46,18 +46,27 @@ }, { - "id":"apply", - "name":"Apply", - "description":"Create this ticket if you want to apply.", - "icon":"💼", - "label":"apply", - "type":"ticket", + "id":"website", + "name":"Website", + "description":"Go to our website.", + "icon":"✅", + "label":"click here", + "type":"website", - "color":"green", - "adminroles":["role id"], - "channelprefix":"apply-", - "category":"category id", - "message":"You created a ticket!", + "url":"https://www.dj-dj.be" + + }, + { + "id":"role", + "name":"Verify", + "description":"Click here to get the verify role.", + "icon":"👮🏼", + "label":"get a role", + "type":"role", + + "color":"red", + "roles":["discord role id"], + "mode":"add&remove|remove|add", "enableDMMessage":true } diff --git a/core/ticketMessageEmbed.js b/core/ticketMessageEmbed.js index f681180..573f13c 100644 --- a/core/ticketMessageEmbed.js +++ b/core/ticketMessageEmbed.js @@ -2,8 +2,7 @@ const discord = require('discord.js') const bot = require('../index') const client = bot.client const config = bot.config -const getOptions = require("./getoptions") -const getbyId = getOptions.getOptionsById +const getButton = require("./utils/getButton") /** * @@ -14,35 +13,23 @@ const getbyId = getOptions.getOptionsById exports.createEmbed = (id) => { + //----------------------------------- //general importing const data = require("./utils/getTicketMessages").getTicketMessage(id) - /**@type {getOptions.exportedOptionClass[]}*/ + /**@type {discord.MessageButton[]}*/ var buttons = [] + /**@type {getButton.rawButtonData[]} */ + var buttonData = [] data.options.forEach((option) => { - var optionIdStats = getbyId("newT"+option) - - if (!optionIdStats){ - var optionIdStats = { - id:"NOTICKET", - name:"ERROR", - description:"There is a ticket in your config.json/messages that doesn't exist.", - icon:"", - label:"ERROR", - type:"ticket", - color:"red", - adminroles:["0"], - channelprefix:"error-", - category:"", - message:"ERROR!", - enableDMMessage:false - - } - return - } - buttons.push(optionIdStats) + var button = getButton.getButton(option) + var localButtonData = getButton.getOption(option) + if (button) buttons.push(button) + if (localButtonData) buttonData.push(localButtonData) }) + //----------------------------------- + //----------------------------------- //create the embed const embed = new discord.MessageEmbed() .setColor(data.color) @@ -55,7 +42,7 @@ exports.createEmbed = (id) => { description = description+"\n\n__choose a category:__\n" var ticketExplainations = [] - buttons.forEach((button) => { + buttonData.forEach((button) => { var explaination = button.icon+" **"+button.name+":**\n"+button.description ticketExplainations.push(explaination) }) @@ -68,7 +55,9 @@ exports.createEmbed = (id) => { } embed.setDescription(description) + //----------------------------------- + //----------------------------------- //create the components var AmountOfRows = Math.ceil(buttons.length / 4) var currentRow = 0 @@ -83,41 +72,14 @@ exports.createEmbed = (id) => { componentRows.push(new discord.MessageActionRow()) } - const getColor = (color) => { - if (color.toLowerCase() == "red"){ - return "DANGER" - }else if (color.toLowerCase() == "green"){ - return "SUCCESS" - }else if (color.toLowerCase() == "blue" || color.toLowerCase() == "blurple"){ - return "PRIMARY" - }else if (color.toLowerCase() == "black" || color.toLowerCase() == "gray" || color.toLowerCase() == "grey"){ - return "SECONDARY" - }else if (color == "DANGER" || color == "SECONDARY" || color == "SUCCESS" || color == "PRIMARY"){ - return color - }else if (color.toLowerCase() == "none" || color.toLowerCase() == "false" || color.toLowerCase() == ""){ - return "SECONDARY" - }else return "SECONDARY" - } - buttons.forEach((button,index) => { - if (button.label){var label = button.label}else{var label = null} - if (button.icon){var icon = button.icon}else{var icon = null} - - var color = getColor(button.color) - - componentRows[currentRow].addComponents([ - new discord.MessageButton() - .setCustomId("newT"+button.id) - .setLabel(label) - .setEmoji(icon) - .setStyle(color) - .setDisabled(false) - ]) + componentRows[currentRow].addComponents([button]) if (index == 3 || index == 7 || index == 11 || index == 15 || index == 19 || index == 23 || index == 27 || index == 31 || index == 35 || index == 39){ currentRow = currentRow + 1 } }) + //----------------------------------- diff --git a/core/utils/getButton.js b/core/utils/getButton.js new file mode 100644 index 0000000..e49a9da --- /dev/null +++ b/core/utils/getButton.js @@ -0,0 +1,92 @@ +const discord = require("discord.js") +const bot = require("../../index") +const config = bot.config +const getoptions = require("../getoptions") + +/**@returns {"DANGER"|"SUCCESS"|"PRIMARY"|"SECONDARY"} */ +const getColor = (color) => { + if (color.toLowerCase() == "red"){ + return "DANGER" + }else if (color.toLowerCase() == "green"){ + return "SUCCESS" + }else if (color.toLowerCase() == "blue" || color.toLowerCase() == "blurple"){ + return "PRIMARY" + }else if (color.toLowerCase() == "black" || color.toLowerCase() == "gray" || color.toLowerCase() == "grey"){ + return "SECONDARY" + }else if (color == "DANGER" || color == "SECONDARY" || color == "SUCCESS" || color == "PRIMARY"){ + return color + }else if (color.toLowerCase() == "none" || color.toLowerCase() == "false" || color.toLowerCase() == ""){ + return "SECONDARY" + }else return "SECONDARY" +} + +const getOption = (id) => { + const result = config.options.find((option) => option.id == id) + if (!result){return false}else return result +} +exports.getOption = getOption +/** + * + * @param {String} id + * @returns {discord.MessageButton|false} + */ +exports.getButton = (id) => { + const option = getOption(id) + if (!option) return false + if (option.type == "ticket"){ + var button = new discord.MessageButton() + .setCustomId("newT"+option.id) + .setDisabled(false) + .setStyle(getColor(option.color)) + + if (option.label){button.setLabel(option.label)} + if (option.icon){button.setEmoji(option.icon)} + if (!option.label && !option.icon){button.setLabel("no label or emoji")} + + }else if (option.type == "website"){ + var button = new discord.MessageButton() + .setDisabled(false) + .setStyle("LINK") + .setURL(option.url) + + if (option.label){button.setLabel(option.label)} + if (option.icon){button.setEmoji(option.icon)} + if (!option.label && !option.icon){button.setLabel("no label or emoji")} + + }else if (option.type == "role"){ + var button = new discord.MessageButton() + .setCustomId("newR"+option.id) + .setDisabled(false) + .setStyle(getColor(option.color)) + + if (option.label){button.setLabel(option.label)} + if (option.icon){button.setEmoji(option.icon)} + if (!option.label && !option.icon){button.setLabel("no label or emoji")} + + } + + return button +} + + +exports.rawButtonData = class { + constructor() { + this.id = "" + this.name = "" + this.description = "" + this.icon = "" + this.label = "" + this.type = "" + + this.color = "" + this.enableDMMessage = true + this.url = "" + this.roles = ["",""] + this.mode = "" + this.adminroles = ["",""] + this.channelprefix = "" + this.category = "" + this.message = "" + + } +} \ No newline at end of file diff --git a/storage/userTickets/971471181670662204 b/storage/userTickets/971471181670662204 new file mode 100644 index 0000000..71d7104 --- /dev/null +++ b/storage/userTickets/971471181670662204 @@ -0,0 +1 @@ +779742674932072469 \ No newline at end of file