From efcfad7b2f46e0f9f0d71a8a3e4ab3adca751560 Mon Sep 17 00:00:00 2001 From: brblacky <77108939+brblacky@users.noreply.github.com> Date: Wed, 13 Mar 2024 11:44:09 +0530 Subject: [PATCH] Update .env.example, .gitignore, NodeConnect.ts, and Lavamusic.ts --- .env.example | 2 -- .gitignore | 4 ++++ src/events/player/NodeConnect.ts | 2 ++ src/events/player/NodeDestroy.ts | 14 +++++++++++ src/events/player/NodeDisconnect.ts | 14 +++++++++++ src/events/player/NodeError.ts | 14 +++++++++++ src/events/player/NodeRaw.ts | 13 ++++++++++ src/events/player/NodeReconnect.ts | 14 +++++++++++ src/structures/Lavamusic.ts | 6 ++--- src/utils/BotLog.ts | 37 +++++++++++++++++++++++++++++ 10 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 src/events/player/NodeDestroy.ts create mode 100644 src/events/player/NodeDisconnect.ts create mode 100644 src/events/player/NodeError.ts create mode 100644 src/events/player/NodeRaw.ts create mode 100644 src/events/player/NodeReconnect.ts create mode 100644 src/utils/BotLog.ts diff --git a/.env.example b/.env.example index 1e7648935..bbd14ef93 100644 --- a/.env.example +++ b/.env.example @@ -6,8 +6,6 @@ OWNER_IDS=["959276033683628122","859640640640640640"] # Your discord id, you can GUILD_ID= "859640640640640640" # Your server Id if you want to use the for single server -CLIENT_SECRET= "" - PRODUCTION="true" # true for production SEARCH_ENGINE= "ytsearch" # ytsearch, scsearch or ytmsearch diff --git a/.gitignore b/.gitignore index 14346e5c7..dc4c44a13 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,7 @@ /Lavalink/application.yml /Lavalink/plugins + +lavamusic.db +lavamusic.db-shm +lavamusic.db-wal \ No newline at end of file diff --git a/src/events/player/NodeConnect.ts b/src/events/player/NodeConnect.ts index b9e7957de..0378adb49 100644 --- a/src/events/player/NodeConnect.ts +++ b/src/events/player/NodeConnect.ts @@ -1,4 +1,5 @@ import { Event, Lavamusic } from '../../structures/index.js'; +import BotLog from '../../utils/BotLog.js'; export default class NodeConnect extends Event { constructor(client: Lavamusic, file: string) { @@ -22,5 +23,6 @@ export default class NodeConnect extends Event { await this.client.queue.create(guild, vc, channel); }, index * 1000); } + BotLog.send(this.client, `Node ${node} is ready!`, 'success'); } } diff --git a/src/events/player/NodeDestroy.ts b/src/events/player/NodeDestroy.ts new file mode 100644 index 000000000..81bb3e071 --- /dev/null +++ b/src/events/player/NodeDestroy.ts @@ -0,0 +1,14 @@ +import { Event, Lavamusic } from '../../structures/index.js'; +import BotLog from '../../utils/BotLog.js'; + +export default class NodeDestroy extends Event { + constructor(client: Lavamusic, file: string) { + super(client, file, { + name: 'nodeDestroy', + }); + } + public async run(node: string, code: number, reason: string): Promise { + this.client.logger.error(`Node ${node} destroyed with code ${code} and reason ${reason}`); + BotLog.send(this.client, `Node ${node} destroyed with code ${code} and reason ${reason}`, 'error') + } +} \ No newline at end of file diff --git a/src/events/player/NodeDisconnect.ts b/src/events/player/NodeDisconnect.ts new file mode 100644 index 000000000..58cdf7ca2 --- /dev/null +++ b/src/events/player/NodeDisconnect.ts @@ -0,0 +1,14 @@ +import { Event, Lavamusic } from '../../structures/index.js'; +import BotLog from '../../utils/BotLog.js'; + +export default class NodeDisconnect extends Event { + constructor(client: Lavamusic, file: string) { + super(client, file, { + name: 'nodeDisconnect', + }); + } + public async run(node: string, count: number): Promise { + this.client.logger.warn(`Node ${node} disconnected ${count} times`); + BotLog.send(this.client, `Node ${node} disconnected ${count} times`, 'warn') + } +} \ No newline at end of file diff --git a/src/events/player/NodeError.ts b/src/events/player/NodeError.ts new file mode 100644 index 000000000..1ae5e8e1a --- /dev/null +++ b/src/events/player/NodeError.ts @@ -0,0 +1,14 @@ +import { Event, Lavamusic } from '../../structures/index.js'; +import BotLog from '../../utils/BotLog.js'; + +export default class NodeError extends Event { + constructor(client: Lavamusic, file: string) { + super(client, file, { + name: 'nodeError', + }); + } + public async run(node: string, error: any): Promise { + this.client.logger.error(`Node ${node} Error: ${JSON.stringify(error)}`); + BotLog.send(this.client, `Node ${node} Error: ${JSON.stringify(error)}`, 'error') + } +} \ No newline at end of file diff --git a/src/events/player/NodeRaw.ts b/src/events/player/NodeRaw.ts new file mode 100644 index 000000000..cd3d8b23a --- /dev/null +++ b/src/events/player/NodeRaw.ts @@ -0,0 +1,13 @@ +import { Event, Lavamusic } from '../../structures/index.js'; + + +export default class NodeRaw extends Event { + constructor(client: Lavamusic, file: string) { + super(client, file, { + name: 'nodeRaw', + }); + } + public async run(payload: any): Promise { + //this.client.logger.debug(`Node raw event: ${JSON.stringify(payload)}`); + } +} \ No newline at end of file diff --git a/src/events/player/NodeReconnect.ts b/src/events/player/NodeReconnect.ts new file mode 100644 index 000000000..e98e66779 --- /dev/null +++ b/src/events/player/NodeReconnect.ts @@ -0,0 +1,14 @@ +import { Event, Lavamusic } from '../../structures/index.js'; +import BotLog from '../../utils/BotLog.js'; + +export default class NodeReconnect extends Event { + constructor(client: Lavamusic, file: string) { + super(client, file, { + name: 'nodeReconnect', + }); + } + public async run(node: string): Promise { + this.client.logger.warn(`Node ${node} reconnected`); + BotLog.send(this.client, `Node ${node} reconnected`, 'warn') + } +} \ No newline at end of file diff --git a/src/structures/Lavamusic.ts b/src/structures/Lavamusic.ts index 26eb2b336..97413f776 100644 --- a/src/structures/Lavamusic.ts +++ b/src/structures/Lavamusic.ts @@ -117,9 +117,9 @@ export default class Lavamusic extends Client { this.config.production === true ? Routes.applicationCommands(this.user.id ?? '') : Routes.applicationGuildCommands( - this.user.id ?? '', - this.config.guildId ?? '' - ); + this.user.id ?? '', + this.config.guildId ?? '' + ); try { const rest = new REST({ version: '9' }).setToken(this.config.token ?? ''); await rest.put(applicationCommands, { body: this.body }); diff --git a/src/utils/BotLog.ts b/src/utils/BotLog.ts new file mode 100644 index 000000000..4aacc27b4 --- /dev/null +++ b/src/utils/BotLog.ts @@ -0,0 +1,37 @@ +import { TextChannel } from 'discord.js'; +import { Lavamusic } from '../structures/index.js'; + + +export default class BotLog { + public static send(client: Lavamusic, message: string, type: string): void { + if (!client) return; + if (!client.channels.cache) return; + if (!client.config.logChannelId) return; + const channel = client.channels.cache.get(client.config.logChannelId) as TextChannel; + if (!channel) return; + let color: string | number | readonly [red: number, green: number, blue: number]; + switch (type) { + case 'error': + color = 0xff0000; + break; + case 'warn': + color = 0xffff00; + break; + case 'info': + color = 0x00ff00; + break; + case 'success': + color = 0x00ff00; + break; + default: + color = 0x000000; + break; + } + const embed = client.embed() + .setColor(color) + .setDescription(message) + .setTimestamp(); + + channel.send({ embeds: [embed] }).catch(() => {null}); + } +} \ No newline at end of file