diff --git a/src/award_message.ts b/src/award_message.ts index c094a4c..3385063 100644 --- a/src/award_message.ts +++ b/src/award_message.ts @@ -16,7 +16,7 @@ export default function awardEmbed(reaction: MessageReaction | PartialMessageRea iconURL: reaction.message.author?.avatarURL() || undefined, }) .setDescription(reaction.message.content || null) - .setThumbnail(reaction.message.attachments.first()?.url || null) + .setThumbnail(reaction.message.attachments.filter((attachment) => !(!attachment.height && !attachment.width)).first()?.url || null) .addFields({ name: `${reaction.emoji.name} x${reaction.count} `, value: `in <#${reaction.message.channelId}> • ${formatTime(reaction.message.createdAt)}\n-# ${reaction.message.id}`, diff --git a/src/index.ts b/src/index.ts index d09b293..a1c6f20 100644 --- a/src/index.ts +++ b/src/index.ts @@ -27,9 +27,6 @@ import { GatewayIntentBits, Events, TextChannel, - Webhook, - WebhookMessageCreateOptions, - WebhookClient, } from "discord.js"; import { writeConfig, readConfig } from "./config.ts"; const client = new Client({ @@ -49,7 +46,7 @@ client.on("ready", () => { } console.log(`Logged in as ${client.user.tag}!`); - client.user.setActivity("for reactions"); + client.user.setActivity("👑let's award funny messages!"); }); import { Entry, Type } from "./entry.ts"; @@ -205,21 +202,21 @@ client.on(Events.MessageReactionAdd, async (reaction, user) => { if ((entry.channel_type === Type.EXCLUDE) === entry.channels.includes(reaction.message.channelId)) return; if ((entry.emoji_type === Type.EXCLUDE) === entry.emojis.includes(`${reaction.emoji.name}`)) return; - console.log(`Reaction added: ${reaction.emoji.name} in ${reaction.message.guild.channels.cache.get(reaction.message.channelId)?.name}`); - if (reaction.count === null || reaction.count < entry.count) return; - if (reaction.count === entry.count) { - const attachments = reaction.message.attachments.filter((attachment) => !(!attachment.height && !attachment.width)) - - const channel = reaction.message.guild.channels.cache.get(entry.output_channel) as TextChannel; - if (!channel) return; + const channel = reaction.message.guild.channels.cache.get(entry.output_channel) as TextChannel; + channel.messages.fetch({ limit: 5 }).then((messages) => { + messages.find((message) => { + if (message.embeds[0]?.fields[0].value.includes(reaction.message.id)) { + message.delete(); + return true; + } + return false; + }); channel.send({ embeds: [awardEmbed(reaction)] }); - } else if (reaction.count > entry.count) { - - } + }); }); client.login(TOKEN); \ No newline at end of file