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:
+16
-54
@@ -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
|
||||
}
|
||||
})
|
||||
//-----------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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 = ""
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user