updated the button system for new types of buttons

You can now also create "website" & "role" tickets. more on these types in the following updates
This commit is contained in:
DJj123dj
2022-05-04 20:02:51 +02:00
parent 0f143c7ebb
commit 046cef0088
4 changed files with 129 additions and 65 deletions
+16 -54
View File
@@ -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
}
})
//-----------------------------------