Skip to content

Commit

Permalink
implemented message tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
GhomKrosmonaute committed Oct 27, 2023
1 parent 9209351 commit d5d5571
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/listeners/tracker.ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 24 additions & 7 deletions src/namespaces/tracker.ts
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -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)
Expand All @@ -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),
),
)
}
Expand Down

0 comments on commit d5d5571

Please sign in to comment.