All files / src/modules/bot/music/events Node.ts

0% Statements 0/19
0% Branches 0/2
0% Functions 0/8
0% Lines 0/18

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 47 48 49 50 51 52 53 54 55 56                                                                                                               
import { Config } from "@/modules/shared/config/types";
import { Injectable, Logger } from "@nestjs/common";
import { ConfigService } from "@nestjs/config";
import { OnEvent } from "@nestjs/event-emitter";
import { LavalinkNode } from "lavalink-client";
 
@Injectable()
export class NodeEvents {
	public constructor(private readonly config: ConfigService) {}
 
	private readonly logger = new Logger(NodeEvents.name);
 
	@OnEvent("node.create")
	public async onNodeCreate(node: LavalinkNode, username: string): Promise<void> {
		this.logger.log(`${username} | Lavalink Node: ${node.options.id} criado!`);
	}
 
	@OnEvent("node.destroy")
	public async onNodeDestroy(node: LavalinkNode, destroyReason: string, username: string): Promise<void> {
		this.logger.fatal(`${username} | Lavalink Node: ${node.options.id} destruído pelo motivo: ${destroyReason}`);
	}
 
	@OnEvent("node.connect")
	public async onNodeConnect(node: LavalinkNode, username: string): Promise<void> {
		this.logger.log(`${username} | Lavalink Node: ${node.options.id} Conectado!`);
	}
 
	@OnEvent("node.reconnecting")
	public async onNodeReconnecting(node: LavalinkNode, username: string): Promise<void> {
		this.logger.warn(`${username} | Lavalink Node: ${node.options.id} Reconectando...`);
	}
 
	@OnEvent("node.disconnect")
	public async onNodeDisconnect(
		node: LavalinkNode,
		reason: { code: number; reason: string },
		username: string,
	): Promise<void> {
		this.logger.error(
			`${username} | Lavalink Node: ${node.options.id} Desconectado. Código: ${reason.code}, Motivo: ${reason.reason}`,
		);
	}
 
	@OnEvent("node.error")
	public async onNodeError(node: LavalinkNode, error: Error, payload: unknown, username: string): Promise<void> {
		this.logger.error(`${username} | Lavalink Node: ${node.options.id} Error: ${error.message}`);
	}
 
	@OnEvent("node.raw")
	public async onNodeRaw(node: LavalinkNode, payload: unknown, username: string): Promise<void> {
		if (this.config.getOrThrow<Config["Debug"]>("Debug").Lavalink) {
			this.logger.debug(`${username} | Lavalink Node: ${node.options.id} Raw: \n${JSON.stringify(payload, null, 2)}`);
		}
	}
}