mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
fix: cumulative rich presense
This commit is contained in:
1 parent
2237d460bb
commit
33eea3f261
3 files changed
+59
-26
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import {
|
||||
fetchDiscoveredIdsDefinitions,
|
||||
fetchGameDefinitions,
|
||||
fetchMapDefinitions,
|
||||
fetchTankDefinitions,
|
||||
@@ -9,3 +10,4 @@ export const tankDefinitions = fetchTankDefinitions();
|
||||
export const gameDefinitions = fetchGameDefinitions();
|
||||
export const tankNames = fetchTankNames();
|
||||
export const mapDefinitions = fetchMapDefinitions();
|
||||
export const discoveredIdsDefinitions = fetchDiscoveredIdsDefinitions();
|
||||
@@ -1,29 +1,5 @@
|
||||
import { ActivityType, Client } from 'discord.js';
|
||||
import { Client } from 'discord.js';
|
||||
|
||||
export function ready(client: Client<true>) {
|
||||
console.log(`🟢 Launched bot ${client.shard?.ids[0] ?? 'default'}`);
|
||||
|
||||
const activities: (() => string)[] = [
|
||||
() => `Living in ${client.guilds.cache.size.toLocaleString()} servers`,
|
||||
() =>
|
||||
`Serving ${client.guilds.cache
|
||||
.reduce((accumulator, guild) => accumulator + guild.memberCount, 0)
|
||||
.toLocaleString()} users`,
|
||||
() =>
|
||||
`Observing ${client.guilds.cache
|
||||
.reduce(
|
||||
(accumulator, guild) => accumulator + guild.channels.cache.size,
|
||||
0,
|
||||
)
|
||||
.toLocaleString()} channels`,
|
||||
];
|
||||
|
||||
client.user.setPresence({
|
||||
activities: [
|
||||
{
|
||||
type: ActivityType.Custom,
|
||||
name: activities[Math.floor(Math.random() * activities.length)](),
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
@@ -1,8 +1,13 @@
|
||||
import { ActivityType } from 'discord.js';
|
||||
import {
|
||||
discoveredIdsDefinitions,
|
||||
tankDefinitions,
|
||||
} from './core/blitzkit/nonBlockingPromises';
|
||||
import { manager } from './core/discord/manager';
|
||||
|
||||
console.log('pre manager event listeners and spawn');
|
||||
|
||||
manager
|
||||
const shards = await manager
|
||||
.on('shardCreate', (shard) => {
|
||||
console.log(`🟡 Launching shard ${shard.id}`);
|
||||
shard.on('ready', () => console.log(`🟢 Launched shard ${shard.id}`));
|
||||
@@ -10,3 +15,53 @@ manager
|
||||
.spawn();
|
||||
|
||||
console.log('post manager event listeners and spawn');
|
||||
|
||||
try {
|
||||
let servers = 0;
|
||||
let channels = 0;
|
||||
let users = 0;
|
||||
|
||||
for (const [, shard] of shards) {
|
||||
// wtf is this typing bro???
|
||||
const guilds = (await shard.fetchClientValue('guilds.cache')) as any;
|
||||
|
||||
servers += guilds.length;
|
||||
|
||||
for (const guild of guilds) {
|
||||
channels += guild.channels.length;
|
||||
users += guild.memberCount;
|
||||
}
|
||||
}
|
||||
|
||||
const awaitedTankDefinitions = await tankDefinitions;
|
||||
const tanks = Object.values(awaitedTankDefinitions.tanks).length;
|
||||
const awaitedDiscoveredIdsDefinitions = await discoveredIdsDefinitions;
|
||||
const usernames = awaitedDiscoveredIdsDefinitions.count;
|
||||
|
||||
manager.broadcastEval(
|
||||
(client, { servers, users, channels, tanks, usernames }) => {
|
||||
const bios = [
|
||||
`Living in ${servers.toLocaleString()} servers`,
|
||||
`Serving ${users.toLocaleString()} users`,
|
||||
`Observing ${channels.toLocaleString()} channels`,
|
||||
`Tinkering with ${tanks.toLocaleString()} tanks`,
|
||||
`Memorizing ${usernames.toLocaleString()} usernames`,
|
||||
];
|
||||
|
||||
client.user?.setPresence({
|
||||
activities: [
|
||||
{
|
||||
type: ActivityType.Custom,
|
||||
name: bios[Math.floor(Math.random() * bios.length)],
|
||||
},
|
||||
],
|
||||
});
|
||||
},
|
||||
{ context: { servers, channels, users, tanks, usernames } },
|
||||
);
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
'An error occurred when setting up presence, ignoring to keep the process alive',
|
||||
error,
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user