Improv: Decreased QuickBuilder boilerplate params
This commit is contained in:
@@ -257,7 +257,7 @@ export class ODQuickButton {
|
|||||||
/**The id of this button. */
|
/**The id of this button. */
|
||||||
id: ODId
|
id: ODId
|
||||||
/**The current data of this button */
|
/**The current data of this button */
|
||||||
data: ODButtonData = {
|
data: Partial<ODButtonData> = {
|
||||||
customId:"",
|
customId:"",
|
||||||
mode:"button",
|
mode:"button",
|
||||||
url:null,
|
url:null,
|
||||||
@@ -267,7 +267,7 @@ export class ODQuickButton {
|
|||||||
disabled:false
|
disabled:false
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(id:ODValidId,data:ODButtonData){
|
constructor(id:ODValidId,data:Partial<ODButtonData>){
|
||||||
this.id = new ODId(id)
|
this.id = new ODId(id)
|
||||||
this.data = data
|
this.data = data
|
||||||
}
|
}
|
||||||
@@ -277,7 +277,7 @@ export class ODQuickButton {
|
|||||||
try {
|
try {
|
||||||
//create the discord.js button
|
//create the discord.js button
|
||||||
const button = new discord.ButtonBuilder()
|
const button = new discord.ButtonBuilder()
|
||||||
if (this.data.mode == "button") button.setCustomId(this.data.customId)
|
if (this.data.mode == "button") button.setCustomId(this.data.customId ?? "od:unknown-button")
|
||||||
if (this.data.mode == "url") button.setStyle(discord.ButtonStyle.Link)
|
if (this.data.mode == "url") button.setStyle(discord.ButtonStyle.Link)
|
||||||
else if (this.data.color == "gray") button.setStyle(discord.ButtonStyle.Secondary)
|
else if (this.data.color == "gray") button.setStyle(discord.ButtonStyle.Secondary)
|
||||||
else if (this.data.color == "blue") button.setStyle(discord.ButtonStyle.Primary)
|
else if (this.data.color == "blue") button.setStyle(discord.ButtonStyle.Primary)
|
||||||
@@ -287,7 +287,7 @@ export class ODQuickButton {
|
|||||||
if (this.data.label) button.setLabel(this.data.label)
|
if (this.data.label) button.setLabel(this.data.label)
|
||||||
if (this.data.emoji) button.setEmoji(this.data.emoji)
|
if (this.data.emoji) button.setEmoji(this.data.emoji)
|
||||||
if (this.data.disabled) button.setDisabled(this.data.disabled)
|
if (this.data.disabled) button.setDisabled(this.data.disabled)
|
||||||
if (!this.data.emoji && !this.data.label) button.setLabel(this.data.customId)
|
if (!this.data.emoji && !this.data.label) button.setLabel(this.data.customId ?? "od:unknown-button")
|
||||||
|
|
||||||
return {id:this.id,component:button}
|
return {id:this.id,component:button}
|
||||||
}catch(err){
|
}catch(err){
|
||||||
@@ -564,7 +564,7 @@ export class ODQuickDropdown {
|
|||||||
/**The id of this dropdown. */
|
/**The id of this dropdown. */
|
||||||
id: ODId
|
id: ODId
|
||||||
/**The current data of this dropdown */
|
/**The current data of this dropdown */
|
||||||
data: ODDropdownData = {
|
data: Partial<ODDropdownData> = {
|
||||||
customId:"",
|
customId:"",
|
||||||
type:"string",
|
type:"string",
|
||||||
placeholder:null,
|
placeholder:null,
|
||||||
@@ -580,7 +580,7 @@ export class ODQuickDropdown {
|
|||||||
mentionables:[]
|
mentionables:[]
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(id:ODValidId,data:ODDropdownData){
|
constructor(id:ODValidId,data:Partial<ODDropdownData>){
|
||||||
this.id = new ODId(id)
|
this.id = new ODId(id)
|
||||||
this.data = data
|
this.data = data
|
||||||
}
|
}
|
||||||
@@ -590,8 +590,9 @@ export class ODQuickDropdown {
|
|||||||
try{
|
try{
|
||||||
//create the discord.js dropdown
|
//create the discord.js dropdown
|
||||||
if (this.data.type == "string"){
|
if (this.data.type == "string"){
|
||||||
|
if (!this.data.options) throw new ODSystemError("ODQuickDropdown:build(): "+this.id.value+" => Dropdown requires at least 1 option to be present.")
|
||||||
const dropdown = new discord.StringSelectMenuBuilder()
|
const dropdown = new discord.StringSelectMenuBuilder()
|
||||||
dropdown.setCustomId(this.data.customId)
|
dropdown.setCustomId(this.data.customId ?? "od:unknown-dropdown")
|
||||||
dropdown.setOptions(...this.data.options)
|
dropdown.setOptions(...this.data.options)
|
||||||
if (this.data.placeholder) dropdown.setPlaceholder(this.data.placeholder)
|
if (this.data.placeholder) dropdown.setPlaceholder(this.data.placeholder)
|
||||||
if (this.data.minValues) dropdown.setMinValues(this.data.minValues)
|
if (this.data.minValues) dropdown.setMinValues(this.data.minValues)
|
||||||
@@ -601,8 +602,9 @@ export class ODQuickDropdown {
|
|||||||
return {id:this.id,component:dropdown}
|
return {id:this.id,component:dropdown}
|
||||||
|
|
||||||
}else if (this.data.type == "user"){
|
}else if (this.data.type == "user"){
|
||||||
|
if (!this.data.users) throw new ODSystemError("ODQuickDropdown:build(): "+this.id.value+" => Dropdown requires at least 1 user option to be present.")
|
||||||
const dropdown = new discord.UserSelectMenuBuilder()
|
const dropdown = new discord.UserSelectMenuBuilder()
|
||||||
dropdown.setCustomId(this.data.customId)
|
dropdown.setCustomId(this.data.customId ?? "od:unknown-dropdown")
|
||||||
if (this.data.users.length > 0) dropdown.setDefaultUsers(...this.data.users.map((u) => u.id))
|
if (this.data.users.length > 0) dropdown.setDefaultUsers(...this.data.users.map((u) => u.id))
|
||||||
if (this.data.placeholder) dropdown.setPlaceholder(this.data.placeholder)
|
if (this.data.placeholder) dropdown.setPlaceholder(this.data.placeholder)
|
||||||
if (this.data.minValues) dropdown.setMinValues(this.data.minValues)
|
if (this.data.minValues) dropdown.setMinValues(this.data.minValues)
|
||||||
@@ -612,8 +614,9 @@ export class ODQuickDropdown {
|
|||||||
return {id:this.id,component:dropdown}
|
return {id:this.id,component:dropdown}
|
||||||
|
|
||||||
}else if (this.data.type == "role"){
|
}else if (this.data.type == "role"){
|
||||||
|
if (!this.data.roles) throw new ODSystemError("ODQuickDropdown:build(): "+this.id.value+" => Dropdown requires at least 1 role option to be present.")
|
||||||
const dropdown = new discord.RoleSelectMenuBuilder()
|
const dropdown = new discord.RoleSelectMenuBuilder()
|
||||||
dropdown.setCustomId(this.data.customId)
|
dropdown.setCustomId(this.data.customId ?? "od:unknown-dropdown")
|
||||||
if (this.data.roles.length > 0) dropdown.setDefaultRoles(...this.data.roles.map((r) => r.id))
|
if (this.data.roles.length > 0) dropdown.setDefaultRoles(...this.data.roles.map((r) => r.id))
|
||||||
if (this.data.placeholder) dropdown.setPlaceholder(this.data.placeholder)
|
if (this.data.placeholder) dropdown.setPlaceholder(this.data.placeholder)
|
||||||
if (this.data.minValues) dropdown.setMinValues(this.data.minValues)
|
if (this.data.minValues) dropdown.setMinValues(this.data.minValues)
|
||||||
@@ -623,8 +626,9 @@ export class ODQuickDropdown {
|
|||||||
return {id:this.id,component:dropdown}
|
return {id:this.id,component:dropdown}
|
||||||
|
|
||||||
}else if (this.data.type == "channel"){
|
}else if (this.data.type == "channel"){
|
||||||
|
if (!this.data.channels) throw new ODSystemError("ODQuickDropdown:build(): "+this.id.value+" => Dropdown requires at least 1 channel option to be present.")
|
||||||
const dropdown = new discord.ChannelSelectMenuBuilder()
|
const dropdown = new discord.ChannelSelectMenuBuilder()
|
||||||
dropdown.setCustomId(this.data.customId)
|
dropdown.setCustomId(this.data.customId ?? "od:unknown-dropdown")
|
||||||
if (this.data.channels.length > 0) dropdown.setDefaultChannels(...this.data.channels.map((c) => c.id))
|
if (this.data.channels.length > 0) dropdown.setDefaultChannels(...this.data.channels.map((c) => c.id))
|
||||||
if (this.data.placeholder) dropdown.setPlaceholder(this.data.placeholder)
|
if (this.data.placeholder) dropdown.setPlaceholder(this.data.placeholder)
|
||||||
if (this.data.minValues) dropdown.setMinValues(this.data.minValues)
|
if (this.data.minValues) dropdown.setMinValues(this.data.minValues)
|
||||||
@@ -634,6 +638,7 @@ export class ODQuickDropdown {
|
|||||||
return {id:this.id,component:dropdown}
|
return {id:this.id,component:dropdown}
|
||||||
|
|
||||||
}else if (this.data.type == "mentionable"){
|
}else if (this.data.type == "mentionable"){
|
||||||
|
if (!this.data.mentionables) throw new ODSystemError("ODQuickDropdown:build(): "+this.id.value+" => Dropdown requires at least 1 mentionable option to be present.")
|
||||||
const dropdown = new discord.MentionableSelectMenuBuilder()
|
const dropdown = new discord.MentionableSelectMenuBuilder()
|
||||||
|
|
||||||
const values: ({type:discord.SelectMenuDefaultValueType.User,id:string}|{type:discord.SelectMenuDefaultValueType.Role,id:string})[] = []
|
const values: ({type:discord.SelectMenuDefaultValueType.User,id:string}|{type:discord.SelectMenuDefaultValueType.Role,id:string})[] = []
|
||||||
@@ -645,7 +650,7 @@ export class ODQuickDropdown {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
dropdown.setCustomId(this.data.customId)
|
dropdown.setCustomId(this.data.customId ?? "od:unknown-dropdown")
|
||||||
if (this.data.mentionables.length > 0) dropdown.setDefaultValues(...values)
|
if (this.data.mentionables.length > 0) dropdown.setDefaultValues(...values)
|
||||||
if (this.data.placeholder) dropdown.setPlaceholder(this.data.placeholder)
|
if (this.data.placeholder) dropdown.setPlaceholder(this.data.placeholder)
|
||||||
if (this.data.minValues) dropdown.setMinValues(this.data.minValues)
|
if (this.data.minValues) dropdown.setMinValues(this.data.minValues)
|
||||||
@@ -799,14 +804,14 @@ export class ODQuickFile {
|
|||||||
/**The id of this file. */
|
/**The id of this file. */
|
||||||
id: ODId
|
id: ODId
|
||||||
/**The current data of this file */
|
/**The current data of this file */
|
||||||
data: ODFileData = {
|
data: Partial<ODFileData> = {
|
||||||
file:"",
|
file:"",
|
||||||
name:"file.txt",
|
name:"file.txt",
|
||||||
description:null,
|
description:null,
|
||||||
spoiler:false
|
spoiler:false
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(id:ODValidId,data:ODFileData){
|
constructor(id:ODValidId,data:Partial<ODFileData>){
|
||||||
this.id = new ODId(id)
|
this.id = new ODId(id)
|
||||||
this.data = data
|
this.data = data
|
||||||
}
|
}
|
||||||
@@ -815,7 +820,7 @@ export class ODQuickFile {
|
|||||||
async build(): Promise<ODFileBuildResult> {
|
async build(): Promise<ODFileBuildResult> {
|
||||||
try{
|
try{
|
||||||
//create the discord.js attachment
|
//create the discord.js attachment
|
||||||
const file = new discord.AttachmentBuilder(this.data.file)
|
const file = new discord.AttachmentBuilder(this.data.file ?? "<empty-file>")
|
||||||
file.setName(this.data.name ? this.data.name : "file.txt")
|
file.setName(this.data.name ? this.data.name : "file.txt")
|
||||||
if (this.data.description) file.setDescription(this.data.description)
|
if (this.data.description) file.setDescription(this.data.description)
|
||||||
if (this.data.spoiler) file.setSpoiler(this.data.spoiler)
|
if (this.data.spoiler) file.setSpoiler(this.data.spoiler)
|
||||||
@@ -1055,7 +1060,7 @@ export class ODQuickEmbed {
|
|||||||
/**The id of this embed. */
|
/**The id of this embed. */
|
||||||
id: ODId
|
id: ODId
|
||||||
/**The current data of this embed */
|
/**The current data of this embed */
|
||||||
data: ODEmbedData = {
|
data: Partial<ODEmbedData> = {
|
||||||
title:null,
|
title:null,
|
||||||
color:null,
|
color:null,
|
||||||
url:null,
|
url:null,
|
||||||
@@ -1071,7 +1076,7 @@ export class ODQuickEmbed {
|
|||||||
timestamp:null
|
timestamp:null
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(id:ODValidId,data:ODEmbedData){
|
constructor(id:ODValidId,data:Partial<ODEmbedData>){
|
||||||
this.id = new ODId(id)
|
this.id = new ODId(id)
|
||||||
this.data = data
|
this.data = data
|
||||||
}
|
}
|
||||||
@@ -1097,7 +1102,7 @@ export class ODQuickEmbed {
|
|||||||
if (this.data.image) embed.setImage(this.data.image)
|
if (this.data.image) embed.setImage(this.data.image)
|
||||||
if (this.data.thumbnail) embed.setThumbnail(this.data.thumbnail)
|
if (this.data.thumbnail) embed.setThumbnail(this.data.thumbnail)
|
||||||
if (this.data.timestamp) embed.setTimestamp(this.data.timestamp)
|
if (this.data.timestamp) embed.setTimestamp(this.data.timestamp)
|
||||||
if (this.data.fields.length > 0) embed.setFields(this.data.fields)
|
if (this.data.fields && this.data.fields.length > 0) embed.setFields(this.data.fields)
|
||||||
|
|
||||||
return {id:this.id,embed}
|
return {id:this.id,embed}
|
||||||
}catch(err){
|
}catch(err){
|
||||||
|
|||||||
Reference in New Issue
Block a user