This commit is contained in:
Marius Begby committed 2023-09-05 12:18:32 +02:00
1 parent 26a5022280
commit 5bb25e030d
2 files changed
-96

No files matched your search

-54
View File
@@ -1,54 +0,0 @@
import config from 'config';
import {
ChatInputCommandInteraction,
EmbedAuthorData,
EmbedBuilder,
EmbedFooterData,
InteractionResponse,
Message,
MessageComponentInteraction,
EmbedField
} from 'discord.js';
import { EmbedOptions } from '../types/configTypes';
export type EmbedContext = {
author?: EmbedAuthorData;
title?: string;
description: string;
footer?: EmbedFooterData;
thumbnail?: string;
fields?: EmbedField[];
};
abstract class BaseEmbed {
embedOptions: EmbedOptions;
context: EmbedContext;
interaction: ChatInputCommandInteraction | MessageComponentInteraction;
embed: EmbedBuilder;
constructor(interaction: ChatInputCommandInteraction | MessageComponentInteraction, context: EmbedContext) {
this.embedOptions = config.get('embedOptions');
this.context = context;
this.interaction = interaction;
this.embed = new EmbedBuilder();
this.embed.setDescription(`${context.title ? `**${context.title}**\n` : ''}${context.description}`);
context.author && this.embed.setAuthor(context.author);
context.footer && this.embed.setFooter(context.footer);
context.thumbnail && this.embed.setThumbnail(context.thumbnail);
}
abstract send(): Promise<Message<boolean> | InteractionResponse<boolean>>;
}
export class InfoEmbed extends BaseEmbed {
constructor(interaction: ChatInputCommandInteraction | MessageComponentInteraction, context: EmbedContext) {
super(interaction, context);
this.embed.setColor(this.embedOptions.colors.info);
}
async send(): Promise<Message<boolean>> {
const embeds = { embeds: [this.embed] };
return await this.interaction.editReply(embeds);
}
}
-42
View File
@@ -1,42 +0,0 @@
import { SlashCommandBuilder } from 'discord.js';
import { EmbedContext, InfoEmbed } from '../../../classes/embeds';
import { BaseSlashCommandInteraction } from '../../../classes/interactions';
import { BaseSlashCommandParams, BaseSlashCommandReturnType } from '../../../types/interactionTypes';
class TestCommand extends BaseSlashCommandInteraction {
constructor() {
const data = new SlashCommandBuilder().setName('test').setDescription('Test command.');
super(data);
}
async execute(params: BaseSlashCommandParams): BaseSlashCommandReturnType {
const { executionId, interaction } = params;
const logger = this.getLogger(this.name, executionId, interaction);
const embedContext: EmbedContext = {
title: 'Test title',
description: 'This is a test embed.',
author: {
name: 'Test author',
iconURL: 'https://cdn.discordapp.com/embed/avatars/0.png'
},
footer: {
text: 'Test footer',
iconURL: 'https://cdn.discordapp.com/embed/avatars/0.png'
},
thumbnail: 'https://cdn.discordapp.com/embed/avatars/0.png',
fields: [
{
name: 'Test field',
value: 'Test field value',
inline: false
}
]
};
logger.debug('Responding with info embed.');
return new InfoEmbed(interaction, embedContext).send();
}
}
export default new TestCommand();