Skip to content

Commit

Permalink
added player events: #732
Browse files Browse the repository at this point in the history
  • Loading branch information
appujet committed Oct 6, 2024
1 parent cf54ba6 commit ed3022e
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/events/player/PlayerDestroy.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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<string | undefined>('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
*/
47 changes: 47 additions & 0 deletions src/events/player/PlayerDisconnect.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
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<string | undefined>('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
*/

0 comments on commit ed3022e

Please sign in to comment.