-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test command for create embeds functions
- Loading branch information
Showing
2 changed files
with
107 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] }) | ||
|
||
} | ||
|
||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |