From d5d55715d857536db7618262aedc23d19f6bd42d Mon Sep 17 00:00:00 2001 From: GhomKrosmonaute Date: Fri, 27 Oct 2023 19:48:09 +0200 Subject: [PATCH] implemented message tracker --- src/listeners/tracker.ready.ts | 1 + src/namespaces/tracker.ts | 31 ++++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/listeners/tracker.ready.ts b/src/listeners/tracker.ready.ts index 79f275f9..bac7e3bc 100644 --- a/src/listeners/tracker.ready.ts +++ b/src/listeners/tracker.ready.ts @@ -9,6 +9,7 @@ const listener: app.Listener<"ready"> = { async () => { for (const guild of client.guilds.cache.values()) { await app.updateGuildOnlineCountTracker(guild) + await app.updateGuildMessageCountTracker(guild) } }, 1000 * 60 * 5, diff --git a/src/namespaces/tracker.ts b/src/namespaces/tracker.ts index 7876b97d..2fc8258f 100644 --- a/src/namespaces/tracker.ts +++ b/src/namespaces/tracker.ts @@ -1,5 +1,7 @@ import * as app from "../app.js" +import message from "../tables/message.js" + export async function updateGuildMemberCountTracker(guild: app.Guild) { const config = await app.getGuild(guild) @@ -21,7 +23,23 @@ export async function updateGuildMemberCountTracker(guild: app.Guild) { } } -export async function updateGuildMessageCountTracker(guild: app.Guild) {} +export async function updateGuildMessageCountTracker(guild: app.Guild) { + const config = await app.getGuild(guild) + + if (config?.message_tracker_channel_id) { + const channel = await guild.channels.fetch( + config.message_tracker_channel_id, + ) + + if (channel) { + const messages = await message.count(`guild_id = ${config._id}`) + + await channel.setName( + config.message_tracker_pattern.replace("$n", app.shortNumber(messages)), + ) + } + } +} export async function updateGuildOnlineCountTracker(guild: app.Guild) { const config = await app.getGuild(guild) @@ -36,15 +54,14 @@ export async function updateGuildOnlineCountTracker(guild: app.Guild) { guild.members.cache.clear() + const onlineMembers = members.filter( + (member) => !!member.presence && member.presence.status !== "offline", + ) + await channel.setName( config.online_tracker_pattern.replace( "$n", - app.shortNumber( - members.filter( - (member) => - !!member.presence && member.presence.status !== "offline", - ).size, - ), + app.shortNumber(onlineMembers.size), ), ) }