From 5b7cb603828fdd3108c7e48f3869f9546c4aaa84 Mon Sep 17 00:00:00 2001 From: "Ean Milligan (Bastion)" Date: Tue, 5 Jul 2022 23:49:10 -0400 Subject: [PATCH] Guild Audit command flushed out --- src/commands/auditCmd/auditGuilds.ts | 76 +++++++++++++++++++++++++++- src/solver/roller.ts | 4 +- 2 files changed, 76 insertions(+), 4 deletions(-) diff --git a/src/commands/auditCmd/auditGuilds.ts b/src/commands/auditCmd/auditGuilds.ts index 11fd6de..bc55f3b 100644 --- a/src/commands/auditCmd/auditGuilds.ts +++ b/src/commands/auditCmd/auditGuilds.ts @@ -1,17 +1,89 @@ +import config from '../../../config.ts'; import { // Discordeno deps + cache, + cacheHandlers, DiscordenoMessage, } from '../../../deps.ts'; import { infoColor2 } from '../../commandUtils.ts'; import utils from '../../utils.ts'; -export const auditGuilds = (message: DiscordenoMessage) => { +export const auditGuilds = async (message: DiscordenoMessage) => { + const cachedGuilds = await cacheHandlers.size('guilds'); + let totalCount = 0; + let realCount = 0; + let botsCount = 0; + + 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++; + } + }); + + 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' }); + message.send({ embeds: [{ color: infoColor2, title: 'Guilds Audit', - description: 'WIP', + description: `Shows details of the guilds that ${config.name} serves. + +Please see attached file for audit details on cached guilds and members.`, timestamp: new Date().toISOString(), + fields: [ + { + name: 'Total Guilds:', + value: `${cache.guilds.size}`, + inline: true, + }, + { + name: 'Cached Guilds:', + value: `${cachedGuilds}`, + inline: true, + }, + { + name: 'Uncached Guilds:', + value: `${cache.dispatchedGuildIds.size}`, + inline: true, + }, + { + name: 'Total Members\n(may be artificially higher if 1 user is in multiple guilds the bot is in):', + value: `${totalCount}`, + inline: true, + }, + { + name: 'Cached Real People:', + value: `${realCount}`, + inline: true, + }, + { + name: 'Cached Bots:', + value: `${botsCount}`, + inline: true, + }, + ], }], + file: { + 'blob': b.size > 8388290 ? tooBig : b, + 'name': 'auditDetails.txt', + }, }).catch((e: Error) => utils.commonLoggers.messageSendError('auditGuild.ts:19', message, e)); }; diff --git a/src/solver/roller.ts b/src/solver/roller.ts index 5589406..e3e1c28 100644 --- a/src/solver/roller.ts +++ b/src/solver/roller.ts @@ -545,8 +545,8 @@ export const roll = (rollStr: string, maximiseRoll: boolean, nominalRoll: boolea if (loopCount > config.limits.maxLoops) { throw new Error('MaxLoopsExceeded'); } - - // Compound the exploding rolls, including the exploding flag and + + // Compound the exploding rolls, including the exploding flag and if (rollSet[i].exploding) { rollSet[i - 1].roll = rollSet[i - 1].roll + rollSet[i].roll; rollSet[i - 1].exploding = true;