refactor(tags): pull embed options to top level and adopt embed images
This commit is contained in:
parent
845f79fe9b
commit
8e279ae5cf
18 changed files with 78 additions and 102 deletions
|
@ -24,17 +24,15 @@ export const tagsCommand = async (
|
|||
return;
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder();
|
||||
embed.setTitle(tag.title ?? tag.name);
|
||||
embed.setDescription(tag.content);
|
||||
if (tag.color) embed.setColor(tag.color);
|
||||
if (tag.image) embed.setImage(tag.image);
|
||||
if (tag.fields) embed.setFields(tag.fields);
|
||||
|
||||
await i.reply({
|
||||
content:
|
||||
(mention ? `<@${mention.id}> ` : '') +
|
||||
(tag.text ? `**${tag.name}**\n\n` + tag.text : ''),
|
||||
embeds: tag.embed
|
||||
? [
|
||||
new EmbedBuilder(tag.embed).setFooter({
|
||||
text: `Requested by ${i.user.tag}`,
|
||||
iconURL: i.user.avatarURL() ?? undefined,
|
||||
}),
|
||||
]
|
||||
: [],
|
||||
content: mention ? `<@${mention.id}> ` : undefined,
|
||||
embeds: [embed],
|
||||
});
|
||||
};
|
||||
|
|
34
src/tags.ts
34
src/tags.ts
|
@ -1,15 +1,18 @@
|
|||
import type { EmbedData } from 'discord.js';
|
||||
|
||||
import matter from 'gray-matter';
|
||||
import { readdir, readFile } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import { COLORS } from './constants';
|
||||
|
||||
import { type EmbedField } from 'discord.js';
|
||||
|
||||
interface Tag {
|
||||
name: string;
|
||||
aliases?: string[];
|
||||
text?: string;
|
||||
embed?: EmbedData;
|
||||
title?: string;
|
||||
color?: number;
|
||||
content: string;
|
||||
image?: string;
|
||||
fields?: EmbedField[];
|
||||
}
|
||||
|
||||
const TAG_DIR = join(process.cwd(), 'tags');
|
||||
|
@ -22,23 +25,12 @@ export const getTags = async (): Promise<Tag[]> => {
|
|||
const file = join(TAG_DIR, _file);
|
||||
const { data, content } = matter(await readFile(file));
|
||||
|
||||
if (data.embed) {
|
||||
tags.push({
|
||||
...data,
|
||||
name: _file.replace('.md', ''),
|
||||
embed: {
|
||||
...data.embed,
|
||||
description: content.trim(),
|
||||
color: COLORS[data.embed.color],
|
||||
},
|
||||
});
|
||||
} else {
|
||||
tags.push({
|
||||
...data,
|
||||
name: _file.replace('.md', ''),
|
||||
text: content.trim(),
|
||||
});
|
||||
}
|
||||
tags.push({
|
||||
...data,
|
||||
name: _file.replace('.md', ''),
|
||||
content: content.trim(),
|
||||
color: data.color ? COLORS[data.color] : undefined,
|
||||
});
|
||||
}
|
||||
|
||||
return tags;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue