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

0% Statements 0/14
0% Branches 0/2
0% Functions 0/3
0% Lines 0/13

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                                                                 
import type { IDatabaseService } from "@/modules/shared/database/interfaces/IDatabaseService";
import { Services } from "@/types/Constants";
import { Inject, Injectable } from "@nestjs/common";
import { Client } from "discord.js";
import { Context, ContextOf, On } from "necord";
import type { IMusicService } from "../interfaces";
import { Music } from "../types/constants";
 
@Injectable()
export class GuildEvents {
	public constructor(
		@Inject(Services.Database) private readonly database: IDatabaseService,
		@Inject(Music.Service) private readonly MusicService: IMusicService,
		private readonly client: Client,
	) {}
 
	@On("guildDelete")
	public async onGuildDelete(@Context() [guild]: ContextOf<"guildDelete">) {
		const guildRepo = this.database.GuildRepo();
		const { Premium } = (await guildRepo.get(guild.id)).Settings;
		(await this.MusicService.getPlayerEvent(guild.id, Premium)).destroy("Guild has deleted");
	}
 
	@On("guildMemberRemove")
	public async onGuildMemberRemove(@Context() [member]: ContextOf<"guildMemberRemove">) {
		if (member.id === this.client.user.id) {
			const guildRepo = this.database.GuildRepo();
			const { Premium } = (await guildRepo.get(member.guild.id)).Settings;
			await (await this.MusicService.getPlayerEvent(member.guild.id, Premium)).destroy("Removed from guild");
		}
	}
}