From ed3022e414923889f71aa53097de313a54951da4 Mon Sep 17 00:00:00 2001 From: appujet Date: Sun, 6 Oct 2024 23:30:40 +0530 Subject: [PATCH] added player events: #732 --- src/events/player/PlayerDestroy.ts | 47 +++++++++++++++++++++++++++ src/events/player/PlayerDisconnect.ts | 47 +++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 src/events/player/PlayerDestroy.ts create mode 100644 src/events/player/PlayerDisconnect.ts diff --git a/src/events/player/PlayerDestroy.ts b/src/events/player/PlayerDestroy.ts new file mode 100644 index 000000000..f5ead1230 --- /dev/null +++ b/src/events/player/PlayerDestroy.ts @@ -0,0 +1,47 @@ +import type { TextChannel } from 'discord.js'; +import type { Player } from 'lavalink-client'; +import { Event, type Lavamusic } from '../../structures/index'; +import { updateSetup } from '../../utils/SetupSystem'; + +export default class PlayerDestroy extends Event { + constructor(client: Lavamusic, file: string) { + super(client, file, { + name: 'playerDestroy', + }); + } + + public async run(player: Player, _reason: string): Promise { + const guild = this.client.guilds.cache.get(player.guildId); + if (!guild) return; + const locale = await this.client.db.getLanguage(player.guildId); + await updateSetup(this.client, guild, locale); + + const messageId = player.get('messageId'); + if (!messageId) return; + + const channel = guild.channels.cache.get(player.textChannelId!) as TextChannel; + if (!channel) return; + + const message = await channel.messages.fetch(messageId).catch(() => { + null; + }); + if (!message) return; + + if (message.editable) { + await message.edit({ components: [] }).catch(() => { + null; + }); + } + } +} + +/** + * Project: lavamusic + * Author: Appu + * Main Contributor: LucasB25 + * Company: Coders + * Copyright (c) 2024. All rights reserved. + * This code is the property of Coder and may not be reproduced or + * modified without permission. For more information, contact us at + * https://discord.gg/ns8CTk9J3e + */ diff --git a/src/events/player/PlayerDisconnect.ts b/src/events/player/PlayerDisconnect.ts new file mode 100644 index 000000000..630e5a8f7 --- /dev/null +++ b/src/events/player/PlayerDisconnect.ts @@ -0,0 +1,47 @@ +import type { TextChannel } from 'discord.js'; +import type { Player } from 'lavalink-client'; +import { Event, type Lavamusic } from '../../structures/index'; +import { updateSetup } from '../../utils/SetupSystem'; + +export default class PlayerDisconnect extends Event { + constructor(client: Lavamusic, file: string) { + super(client, file, { + name: 'playerDisconnect', + }); + } + + public async run(player: Player, _voiceChannelId: string): Promise { + const guild = this.client.guilds.cache.get(player.guildId); + if (!guild) return; + const locale = await this.client.db.getLanguage(player.guildId); + await updateSetup(this.client, guild, locale); + + const messageId = player.get('messageId'); + if (!messageId) return; + + const channel = guild.channels.cache.get(player.textChannelId!) as TextChannel; + if (!channel) return; + + const message = await channel.messages.fetch(messageId).catch(() => { + null; + }); + if (!message) return; + + if (message.editable) { + await message.edit({ components: [] }).catch(() => { + null; + }); + } + } +} + +/** + * Project: lavamusic + * Author: Appu + * Main Contributor: LucasB25 + * Company: Coders + * Copyright (c) 2024. All rights reserved. + * This code is the property of Coder and may not be reproduced or + * modified without permission. For more information, contact us at + * https://discord.gg/ns8CTk9J3e + */