mirror of
https://github.com/darksaid98/cadence-discord-bot.git
synced 2026-12-04 22:15:29 +00:00
fix: Fixed mapped guild list not being parsed by Bun
This commit is contained in:
1 parent
6fb370147e
commit
d953fc97af
1 file changed
+7
-5
@@ -2,26 +2,28 @@ import { GuildQueueStatisticsMetadata } from 'discord-player';
|
|||||||
import { Client, Guild } from 'discord.js';
|
import { Client, Guild } from 'discord.js';
|
||||||
import { PlayerStatistics, ShardPlayerStatistics } from '../types/utilTypes';
|
import { PlayerStatistics, ShardPlayerStatistics } from '../types/utilTypes';
|
||||||
|
|
||||||
async function fetchGuildsPerShard(client?: Client): Promise<Guild[][]> {
|
async function fetchGuildsPerShard(client?: Client): Promise<Map<string, Guild>[]> {
|
||||||
if (!client || !client.shard) {
|
if (!client || !client.shard) {
|
||||||
throw new Error('Client is undefined or not sharded.');
|
throw new Error('Client is undefined or not sharded.');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return (await client.shard.fetchClientValues('guilds.cache')) as Guild[][];
|
return (await client.shard.fetchClientValues('guilds.cache')) as Map<string, Guild>[];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error('Failed to fetch client values from shards.');
|
throw new Error('Failed to fetch client values from shards.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateTotalCountForShard(guildList: Guild[]) {
|
function calculateTotalCountForShard(guildListMap: Map<string, Guild>) {
|
||||||
|
const guildList: Guild[] = [...guildListMap.values()];
|
||||||
|
|
||||||
const totalGuildCount: number = guildList.length;
|
const totalGuildCount: number = guildList.length;
|
||||||
const totalMemberCount: number = guildList.reduce((acc: number, guild: Guild) => acc + guild.memberCount, 0);
|
const totalMemberCount: number = guildList.reduce((acc: number, guild: Guild) => acc + guild.memberCount, 0);
|
||||||
|
|
||||||
return { totalGuildCount, totalMemberCount };
|
return { totalGuildCount, totalMemberCount };
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateTotalCountForAllShards(guildListPerShard: Guild[][]) {
|
function calculateTotalCountForAllShards(guildListPerShard: Map<string, Guild>[]) {
|
||||||
return guildListPerShard.reduce(
|
return guildListPerShard.reduce(
|
||||||
(totals, guildList) => {
|
(totals, guildList) => {
|
||||||
const { totalGuildCount, totalMemberCount } = calculateTotalCountForShard(guildList);
|
const { totalGuildCount, totalMemberCount } = calculateTotalCountForShard(guildList);
|
||||||
@@ -35,7 +37,7 @@ function calculateTotalCountForAllShards(guildListPerShard: Guild[][]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchTotalGuildStatistics(client?: Client) {
|
export async function fetchTotalGuildStatistics(client?: Client) {
|
||||||
const guildsPerShard: Guild[][] = await fetchGuildsPerShard(client);
|
const guildsPerShard: Map<string, Guild>[] = await fetchGuildsPerShard(client);
|
||||||
const { totalGuildCount, totalMemberCount } = calculateTotalCountForAllShards(guildsPerShard);
|
const { totalGuildCount, totalMemberCount } = calculateTotalCountForAllShards(guildsPerShard);
|
||||||
|
|
||||||
return { totalGuildCount, totalMemberCount };
|
return { totalGuildCount, totalMemberCount };
|
||||||
|
|||||||
Reference in new issue
Block a user