mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 12:09:51 +02:00
the worst code i have ever written in my life
This commit is contained in:
1 parent
19531aa9ae
commit
f726793819
2 files changed
+67
-59
No files matched your search
@@ -1,6 +0,0 @@
|
|||||||
import { assertSecret } from '@blitzkit/core';
|
|
||||||
import { ShardingManager } from 'discord.js';
|
|
||||||
|
|
||||||
export const manager = new ShardingManager('dist/bot/workers/bot.js', {
|
|
||||||
token: assertSecret(import.meta.env.DISCORD_TOKEN),
|
|
||||||
});
|
|
||||||
+67
-53
@@ -1,67 +1,81 @@
|
|||||||
import { ActivityType } from 'discord.js';
|
import { assertSecret, EventManager } from '@blitzkit/core';
|
||||||
|
import { ActivityType, ShardingManager } from 'discord.js';
|
||||||
import {
|
import {
|
||||||
discoveredIdsDefinitions,
|
discoveredIdsDefinitions,
|
||||||
tankDefinitions,
|
tankDefinitions,
|
||||||
} from './core/blitzkit/nonBlockingPromises';
|
} from './core/blitzkit/nonBlockingPromises';
|
||||||
import { manager } from './core/discord/manager';
|
|
||||||
|
|
||||||
console.log('pre manager event listeners and spawn');
|
const somethingEvent = new EventManager();
|
||||||
|
|
||||||
const shards = await manager
|
somethingEvent.on(async () => {
|
||||||
.on('shardCreate', (shard) => {
|
const manager = new ShardingManager('dist/bot/workers/bot.js', {
|
||||||
console.log(`🟡 Launching shard ${shard.id}`);
|
token: assertSecret(import.meta.env.DISCORD_TOKEN),
|
||||||
shard.on('ready', () => console.log(`🟢 Launched shard ${shard.id}`));
|
});
|
||||||
})
|
|
||||||
.spawn();
|
|
||||||
|
|
||||||
console.log('post manager event listeners and spawn');
|
const timeout = setTimeout(() => {
|
||||||
|
console.warn(`Shards didn't launch in 5 seconds; trying again...`);
|
||||||
|
somethingEvent.emit(undefined);
|
||||||
|
|
||||||
try {
|
shards.forEach((shard) => shard.kill());
|
||||||
let servers = 0;
|
}, 5000);
|
||||||
let channels = 0;
|
|
||||||
let users = 0;
|
|
||||||
|
|
||||||
for (const [, shard] of shards) {
|
const shards = await manager
|
||||||
// wtf is this typing bro???
|
.on('shardCreate', (shard) => {
|
||||||
const guilds = (await shard.fetchClientValue('guilds.cache')) as any;
|
clearTimeout(timeout);
|
||||||
|
console.log(`🟡 Launching shard ${shard.id}`);
|
||||||
|
shard.on('ready', () => console.log(`🟢 Launched shard ${shard.id}`));
|
||||||
|
})
|
||||||
|
.spawn();
|
||||||
|
|
||||||
servers += guilds.length;
|
try {
|
||||||
|
let servers = 0;
|
||||||
|
let channels = 0;
|
||||||
|
let users = 0;
|
||||||
|
|
||||||
for (const guild of guilds) {
|
for (const [, shard] of shards) {
|
||||||
channels += guild.channels.length;
|
// wtf is this typing bro???
|
||||||
users += guild.memberCount;
|
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,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const awaitedTankDefinitions = await tankDefinitions;
|
somethingEvent.emit(undefined);
|
||||||
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