24 lines
1.2 KiB
TypeScript
24 lines
1.2 KiB
TypeScript
import { EmbedBuilder, MessageReaction, PartialMessageReaction } from 'discord.js';
|
|
|
|
export default function awardEmbed(reaction: MessageReaction | PartialMessageReaction, score: number) {
|
|
function formatTime(time: Date) {
|
|
const yyyy = time.getFullYear();
|
|
const mm = time.getMonth().toString().padStart(2, '0');
|
|
const dd = time.getDate().toString().padStart(2, '0');
|
|
const hh = time.getHours().toString().padStart(2, '0');
|
|
const MM = time.getMinutes().toString().padStart(2, '0');
|
|
return `${yyyy}-${mm}-${dd} ${hh}:${MM}`;
|
|
}
|
|
return new EmbedBuilder()
|
|
.setColor(0x777777)
|
|
.setAuthor({
|
|
name: reaction.message.author?.displayName || "unknown",
|
|
iconURL: reaction.message.author?.avatarURL() || undefined,
|
|
})
|
|
.setDescription(reaction.message.content || null)
|
|
.setThumbnail(reaction.message.attachments.filter((attachment) => !(!attachment.height && !attachment.width)).first()?.url || null)
|
|
.addFields({
|
|
name: `${reaction.message.reactions.cache.map((reaction) => `${reaction.emoji} x${reaction.count},`).join(' ')} / ${score.toFixed(1)}`,
|
|
value: `${reaction.message.url} • ${formatTime(reaction.message.createdAt)}\n-# ${reaction.message.id}`,
|
|
})
|
|
} |