From dcf01ff320a106ba0e9fa463925a4bd6db3cfb6f Mon Sep 17 00:00:00 2001 From: Rian8337 <52914632+Rian8337@users.noreply.github.com> Date: Sat, 17 Aug 2024 21:07:19 +0700 Subject: [PATCH] Cleanup `emojiStatistician` --- .../messageCreate/utils/emojiStatistician.ts | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/src/events/messageCreate/utils/emojiStatistician.ts b/src/events/messageCreate/utils/emojiStatistician.ts index cc14cbb4b..608d6eafd 100644 --- a/src/events/messageCreate/utils/emojiStatistician.ts +++ b/src/events/messageCreate/utils/emojiStatistician.ts @@ -1,37 +1,33 @@ -import { Collection, GuildEmoji, Message, Snowflake } from "discord.js"; +import { Collection, Message, Snowflake } from "discord.js"; import { DatabaseManager } from "@alice-database/DatabaseManager"; import { EventUtil } from "structures/core/EventUtil"; -import { EmojiStat } from "structures/moderation/EmojiStat"; -import { EmojiStatistics } from "@alice-database/utils/aliceDb/EmojiStatistics"; export const run: EventUtil["run"] = async (_, message: Message) => { if (message.channel.isDMBased() || message.author.bot) { return; } - const emojiMessages: RegExpMatchArray | null = message.content.match( - /|<:.+?:\d+>/g - ); + const emojiMessages = message.content.match(/|<:.+?:\d+>/g); if (!emojiMessages) { return; } - const guildEmojiData: EmojiStatistics | null = + const guildEmojiData = await DatabaseManager.aliceDb.collections.emojiStatistics.getGuildStatistics( - message.guild!.id + message.guild!.id, ); - const guildEmojiStats: Collection = - guildEmojiData?.emojiStats ?? new Collection(); + const guildEmojiStats = guildEmojiData?.emojiStats ?? new Collection(); for (const emojiMessage of emojiMessages) { - const emojiID: Snowflake = ( + const emojiID = ( (emojiMessage.split(":").pop()).replace(">", "") ); - const actualEmoji: GuildEmoji | undefined = - message.guild!.emojis.cache.find((e) => e.id === emojiID); + const actualEmoji = message.guild!.emojis.cache.find( + (e) => e.id === emojiID, + ); if (!actualEmoji) { return; @@ -46,7 +42,7 @@ export const run: EventUtil["run"] = async (_, message: Message) => { await DatabaseManager.aliceDb.collections.emojiStatistics.updateOne( { guildID: message.guild?.id }, { $set: { emojiStats: [...guildEmojiStats.values()] } }, - { upsert: true } + { upsert: true }, ); };