From 0250135c5fa39de9c889f088a2f14162fedae689 Mon Sep 17 00:00:00 2001 From: Ean Milligan Date: Tue, 29 Apr 2025 03:16:41 -0400 Subject: [PATCH] improve audit guilds, show counts of duplicate guild owners --- src/commands/auditCmd/auditGuilds.ts | 37 +++++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/commands/auditCmd/auditGuilds.ts b/src/commands/auditCmd/auditGuilds.ts index 12675ce..5bda149 100644 --- a/src/commands/auditCmd/auditGuilds.ts +++ b/src/commands/auditCmd/auditGuilds.ts @@ -9,23 +9,26 @@ import { import { infoColor2 } from '../../commandUtils.ts'; import utils from '../../utils.ts'; +const sortGuildByMemberCount = (a: DiscordenoGuild, b: DiscordenoGuild) => { + if (a.memberCount < b.memberCount) { + return 1; + } + if (a.memberCount > b.memberCount) { + return -1; + } + return 0; +}; + export const auditGuilds = async (message: DiscordenoMessage) => { const cachedGuilds = await cacheHandlers.size('guilds'); + const guildOwnerCounts = new Map(); + let totalCount = 0; let realCount = 0; let botsCount = 0; let auditText = ''; - const sortGuildByMemberCount = (a: DiscordenoGuild, b: DiscordenoGuild) => { - if (a.memberCount < b.memberCount) { - return 1; - } - if (a.memberCount > b.memberCount) { - return -1; - } - return 0; - }; cache.guilds .array() .sort(sortGuildByMemberCount) @@ -43,6 +46,9 @@ export const auditGuilds = async (message: DiscordenoMessage) => { } }); + // Track repeat guild owners + guildOwnerCounts.set(guild.ownerId, (guildOwnerCounts.get(guild.ownerId) ?? 0) + 1); + auditText += `Guild: ${guild.name} (${guild.id}) Owner: ${guild.owner?.username}#${guild.owner?.discriminator} (${guild.ownerId}) Tot mem: ${guild.memberCount} | Real: ${localRealCount} | Bot: ${localBotCount} @@ -53,6 +59,12 @@ Tot mem: ${guild.memberCount} | Real: ${localRealCount} | Bot: ${localBotCount} const b = await new Blob([auditText as BlobPart], { type: 'text' }); const tooBig = await new Blob(['tooBig' as BlobPart], { type: 'text' }); + // Condense repeat guild owners + const repeatCounts: number[] = []; + Array.from(guildOwnerCounts).map(([_owenId, cnt]) => { + repeatCounts[cnt - 1] = (repeatCounts[cnt - 1] ?? 0) + 1; + }); + message .send({ embeds: [ @@ -99,6 +111,13 @@ Please see attached file for audit details on cached guilds and members.`, value: `${(totalCount / cache.guilds.size).toFixed(2)}`, inline: true, }, + { + name: 'Repeat Guild Owners:', + value: repeatCounts + .map((ownerCnt, serverIdx) => `${ownerCnt} ${ownerCnt === 1 ? 'person has' : 'people have'} me in ${serverIdx + 1} of their guilds`) + .filter((str) => str) + .join('\n') || 'No Repeat Guild Owners', + }, ], }, ],