improve audit guilds, show counts of duplicate guild owners

This commit is contained in:
Ean Milligan 2025-04-29 03:16:41 -04:00
parent 15ecb45e65
commit 0250135c5f
1 changed files with 28 additions and 9 deletions

View File

@ -9,15 +9,7 @@ import {
import { infoColor2 } from '../../commandUtils.ts'; import { infoColor2 } from '../../commandUtils.ts';
import utils from '../../utils.ts'; import utils from '../../utils.ts';
export const auditGuilds = async (message: DiscordenoMessage) => { const sortGuildByMemberCount = (a: DiscordenoGuild, b: DiscordenoGuild) => {
const cachedGuilds = await cacheHandlers.size('guilds');
let totalCount = 0;
let realCount = 0;
let botsCount = 0;
let auditText = '';
const sortGuildByMemberCount = (a: DiscordenoGuild, b: DiscordenoGuild) => {
if (a.memberCount < b.memberCount) { if (a.memberCount < b.memberCount) {
return 1; return 1;
} }
@ -25,7 +17,18 @@ export const auditGuilds = async (message: DiscordenoMessage) => {
return -1; return -1;
} }
return 0; return 0;
}; };
export const auditGuilds = async (message: DiscordenoMessage) => {
const cachedGuilds = await cacheHandlers.size('guilds');
const guildOwnerCounts = new Map<bigint, number>();
let totalCount = 0;
let realCount = 0;
let botsCount = 0;
let auditText = '';
cache.guilds cache.guilds
.array() .array()
.sort(sortGuildByMemberCount) .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}) auditText += `Guild: ${guild.name} (${guild.id})
Owner: ${guild.owner?.username}#${guild.owner?.discriminator} (${guild.ownerId}) Owner: ${guild.owner?.username}#${guild.owner?.discriminator} (${guild.ownerId})
Tot mem: ${guild.memberCount} | Real: ${localRealCount} | Bot: ${localBotCount} 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 b = await new Blob([auditText as BlobPart], { type: 'text' });
const tooBig = await new Blob(['tooBig' 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 message
.send({ .send({
embeds: [ embeds: [
@ -99,6 +111,13 @@ Please see attached file for audit details on cached guilds and members.`,
value: `${(totalCount / cache.guilds.size).toFixed(2)}`, value: `${(totalCount / cache.guilds.size).toFixed(2)}`,
inline: true, 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',
},
], ],
}, },
], ],