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:
+20
-11
@@ -46,18 +46,27 @@
|
|||||||
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id":"apply",
|
"id":"website",
|
||||||
"name":"Apply",
|
"name":"Website",
|
||||||
"description":"Create this ticket if you want to apply.",
|
"description":"Go to our website.",
|
||||||
"icon":"💼",
|
"icon":"✅",
|
||||||
"label":"apply",
|
"label":"click here",
|
||||||
"type":"ticket",
|
"type":"website",
|
||||||
|
|
||||||
"color":"green",
|
"url":"https://www.dj-dj.be"
|
||||||
"adminroles":["role id"],
|
|
||||||
"channelprefix":"apply-",
|
},
|
||||||
"category":"category id",
|
{
|
||||||
"message":"You created a ticket!",
|
"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
|
"enableDMMessage":true
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-54
@@ -2,8 +2,7 @@ const discord = require('discord.js')
|
|||||||
const bot = require('../index')
|
const bot = require('../index')
|
||||||
const client = bot.client
|
const client = bot.client
|
||||||
const config = bot.config
|
const config = bot.config
|
||||||
const getOptions = require("./getoptions")
|
const getButton = require("./utils/getButton")
|
||||||
const getbyId = getOptions.getOptionsById
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -14,35 +13,23 @@ const getbyId = getOptions.getOptionsById
|
|||||||
|
|
||||||
|
|
||||||
exports.createEmbed = (id) => {
|
exports.createEmbed = (id) => {
|
||||||
|
//-----------------------------------
|
||||||
//general importing
|
//general importing
|
||||||
const data = require("./utils/getTicketMessages").getTicketMessage(id)
|
const data = require("./utils/getTicketMessages").getTicketMessage(id)
|
||||||
/**@type {getOptions.exportedOptionClass[]}*/
|
/**@type {discord.MessageButton[]}*/
|
||||||
var buttons = []
|
var buttons = []
|
||||||
|
/**@type {getButton.rawButtonData[]} */
|
||||||
|
var buttonData = []
|
||||||
|
|
||||||
data.options.forEach((option) => {
|
data.options.forEach((option) => {
|
||||||
var optionIdStats = getbyId("newT"+option)
|
var button = getButton.getButton(option)
|
||||||
|
var localButtonData = getButton.getOption(option)
|
||||||
if (!optionIdStats){
|
if (button) buttons.push(button)
|
||||||
var optionIdStats = {
|
if (localButtonData) buttonData.push(localButtonData)
|
||||||
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)
|
|
||||||
})
|
})
|
||||||
|
//-----------------------------------
|
||||||
|
|
||||||
|
//-----------------------------------
|
||||||
//create the embed
|
//create the embed
|
||||||
const embed = new discord.MessageEmbed()
|
const embed = new discord.MessageEmbed()
|
||||||
.setColor(data.color)
|
.setColor(data.color)
|
||||||
@@ -55,7 +42,7 @@ exports.createEmbed = (id) => {
|
|||||||
description = description+"\n\n__choose a category:__\n"
|
description = description+"\n\n__choose a category:__\n"
|
||||||
|
|
||||||
var ticketExplainations = []
|
var ticketExplainations = []
|
||||||
buttons.forEach((button) => {
|
buttonData.forEach((button) => {
|
||||||
var explaination = button.icon+" **"+button.name+":**\n"+button.description
|
var explaination = button.icon+" **"+button.name+":**\n"+button.description
|
||||||
ticketExplainations.push(explaination)
|
ticketExplainations.push(explaination)
|
||||||
})
|
})
|
||||||
@@ -68,7 +55,9 @@ exports.createEmbed = (id) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
embed.setDescription(description)
|
embed.setDescription(description)
|
||||||
|
//-----------------------------------
|
||||||
|
|
||||||
|
//-----------------------------------
|
||||||
//create the components
|
//create the components
|
||||||
var AmountOfRows = Math.ceil(buttons.length / 4)
|
var AmountOfRows = Math.ceil(buttons.length / 4)
|
||||||
var currentRow = 0
|
var currentRow = 0
|
||||||
@@ -83,41 +72,14 @@ exports.createEmbed = (id) => {
|
|||||||
componentRows.push(new discord.MessageActionRow())
|
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) => {
|
buttons.forEach((button,index) => {
|
||||||
if (button.label){var label = button.label}else{var label = null}
|
componentRows[currentRow].addComponents([button])
|
||||||
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)
|
|
||||||
])
|
|
||||||
|
|
||||||
if (index == 3 || index == 7 || index == 11 || index == 15 || index == 19 || index == 23 || index == 27 || index == 31 || index == 35 || index == 39){
|
if (index == 3 || index == 7 || index == 11 || index == 15 || index == 19 || index == 23 || index == 27 || index == 31 || index == 35 || index == 39){
|
||||||
currentRow = currentRow + 1
|
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 = ""
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
779742674932072469
|
||||||
Reference in New Issue
Block a user