All files / src/lib sharding.ts

0% Statements 0/16
100% Branches 0/0
0% Functions 0/8
0% Lines 0/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46                                                                                           
import path from "node:path";
import { Logger } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { ShardingManager as _ShardingManager } from "discord.js";
import { Config } from "../modules/shared/config/types";
 
export class ShardingManager extends _ShardingManager {
	public constructor(private readonly config: ConfigService) {
		super(path.join(__dirname, "bot.js"), {
			token: config.getOrThrow<Config["Discord"]>("Discord").Token,
			shardList: "auto",
			respawn: true,
			mode: "process",
		});
	}
 
	private readonly logger = new Logger(ShardingManager.name);
 
	public async init() {
		this.spawn();
 
		this.on("shardCreate", (shard) => {
			shard.on("reconnecting", () => {
				this.logger.warn(`Reconnecting shard: [${shard.id}]`);
			});
 
			shard.on("spawn", () => {
				this.logger.log(`Spawned shard: [${shard.id}]`);
			});
 
			shard.on("ready", () => {
				this.logger.log(`Shard [${shard.id}] is ready`);
			});
 
			shard.on("death", () => {
				this.logger.fatal(`Died shard: [${shard.id}]`);
			});
 
			shard.on("error", (err) => {
				this.logger.error(`Error in shard [${shard.id}] with : ${err} `);
				shard.respawn();
			});
		});
	}
}