update auditGuilds to sort guilds by largest to smallest

This commit is contained in:
Ean Milligan 2025-04-28 23:26:14 -04:00
parent 8cf55aacf5
commit ba51bd471c
1 changed files with 28 additions and 15 deletions

View File

@ -3,6 +3,7 @@ import {
// Discordeno deps
cache,
cacheHandlers,
DiscordenoGuild,
DiscordenoMessage,
} from '../../../deps.ts';
import { infoColor2 } from '../../commandUtils.ts';
@ -16,26 +17,38 @@ export const auditGuilds = async (message: DiscordenoMessage) => {
let auditText = '';
cache.guilds.forEach((guild) => {
totalCount += guild.memberCount;
let localBotCount = 0;
let localRealCount = 0;
guild.members.forEach((member) => {
if (member.bot) {
botsCount++;
localBotCount++;
} else {
realCount++;
localRealCount++;
}
});
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)
.forEach((guild) => {
totalCount += guild.memberCount;
let localBotCount = 0;
let localRealCount = 0;
guild.members.forEach((member) => {
if (member.bot) {
botsCount++;
localBotCount++;
} else {
realCount++;
localRealCount++;
}
});
auditText += `Guild: ${guild.name} (${guild.id})
auditText += `Guild: ${guild.name} (${guild.id})
Owner: ${guild.owner?.username}#${guild.owner?.discriminator} (${guild.ownerId})
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' });