Skip to content

Commit

Permalink
Added test command for create embeds functions
Browse files Browse the repository at this point in the history
  • Loading branch information
raphdcst committed Jun 25, 2024
1 parent 54b6074 commit 0221b01
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 45 deletions.
48 changes: 48 additions & 0 deletions src/commands/embedTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as app from "#app"

export default new app.Command({
name: "embedTest",
botOwnerOnly: true,
description: "The embedTest command",
aliases: ["et"],
channelType: "all",
positional: [
{
name: "embedFuction",
type: "string",
description: "An embed function",
},
{
name: "color",
type: "string",
description: "A associated color : INFO, SUCCESS, WARN, ERROR",
}
],
async run(message) {

const func = message.args.embedFuction
const color = message.args.color as app.EmbedColor

if (!func) return message.reply({ content: `Please select an option...`})

if (func == 'error') {

const err = new Error("Here's a fake error")

const embed = app.createErrorEmbed({err: err, color: color})

return await message.reply({ embeds: [embed] })
}

if (func == 'small') {

const desc = "Here's a fake description"

const embed = app.createSmallEmbed({description: desc, color: color})

return await message.reply({ embeds: [embed] })

}

}
})
104 changes: 59 additions & 45 deletions src/namespaces/embeds.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,65 @@
import * as app from "#app"

export enum EmbedColors {
SUCCESS = 0x14b714,
INFO = 0x081a49,
WARN = 0xf74100,
ERROR = 0xc60800
}


export type EmbedColor = keyof typeof EmbedColors


export async function sendSmallEmbed(description: string, bot?: app.ClientUser, c?: EmbedColor): Promise<object> {

const smallEmbed = {
color: c || EmbedColors.INFO,
description: description,
footer: {
text: bot?.username || '',
icon_url: bot?.avatarURL() || undefined
}
SUCCESS = 0x14b714,
INFO = 0x081a49,
WARN = 0xf74100,
ERROR = 0xc60800
}

export type smallEmbedOptions = {
description: string
bot?: app.ClientUser
color?: EmbedColor
}

export type errorEmbedOptions = {
err: Error
bot?: app.ClientUser
color?: EmbedColor
}


export type EmbedColor = keyof typeof EmbedColors


export function createSmallEmbed(options: smallEmbedOptions): app.APIEmbed {

const smallEmbed = {
color: EmbedColors[options?.color || 'INFO'],
description: options.description,
timeStamp: new Date().toISOString(),
footer: {
text: options.bot?.username || '',
icon_url: options.bot?.avatarURL() || undefined
}

return smallEmbed
}

export async function sendErrorEmbed(err: Error, bot?: app.ClientUser,): Promise<object> {

const cancelEmbed = {
color: EmbedColors.ERROR,
title: 'Something went wrong, cancelling !',
description: 'Error description below',
fields: [
{
name: 'Name',
value: err.name
},
{
name: 'Message',
value: err.message
},
],
footer: {
text: bot?.username || '',
icon_url: bot?.avatarURL() || undefined

return smallEmbed
}

export function createErrorEmbed(options: errorEmbedOptions): app.APIEmbed {

const cancelEmbed = {
color: EmbedColors[options?.color || 'ERROR'],
title: 'Something went wrong, cancelling !',
description: 'Error description below',
timeStamp: new Date().toISOString(),
fields: [
{
name: 'Name',
value: options.err.name
},
}

return cancelEmbed
}
{
name: 'Message',
value: options.err.message
},
],
footer: {
text: options.bot?.username || '',
icon_url: options.bot?.avatarURL() || undefined
},
}

return cancelEmbed
}

0 comments on commit 0221b01

Please sign in to comment.