From 0f11958f46aed0d22e553f8c6fb57fb919517464 Mon Sep 17 00:00:00 2001 From: brblacky <77108939+brblacky@users.noreply.github.com> Date: Tue, 26 Mar 2024 20:51:57 +0530 Subject: [PATCH] Refactor code and fix minor issues --- Dockerfile | 1 - Lavalink/example.application.yml | 198 ++++++++++++++-------------- README.md | 4 +- docker-compose.yml | 1 - src/commands/info/About.ts | 4 +- src/commands/music/PlayNext.ts | 4 +- src/events/client/GuildDelete.ts | 11 +- src/events/client/SetupButtons.ts | 16 +-- src/events/player/NodeDestroy.ts | 8 +- src/events/player/NodeDisconnect.ts | 4 +- src/events/player/NodeError.ts | 4 +- src/events/player/NodeRaw.ts | 4 +- src/events/player/NodeReconnect.ts | 4 +- src/events/player/TrackStart.ts | 1 - src/plugin/plugins/updateStatus.ts | 1 - src/structures/Lavamusic.ts | 6 +- src/utils/BotLog.ts | 15 +-- src/utils/Utils.ts | 14 +- tsconfig.json | 4 +- 19 files changed, 155 insertions(+), 149 deletions(-) diff --git a/Dockerfile b/Dockerfile index b46a2cb4c..95ae5970b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,7 +28,6 @@ WORKDIR /opt/lavamusic/ # Copy compiled code COPY --from=builder /opt/lavamusic/dist ./dist COPY --from=builder /opt/lavamusic/src/utils/LavaLogo.txt ./src/utils/LavaLogo.txt -COPY --from=builder /opt/lavamusic/database/lavamusic.db ./database/lavamusic.db # Copy package files and install production dependencies COPY package*.json ./ diff --git a/Lavalink/example.application.yml b/Lavalink/example.application.yml index 5923e5ffa..a9ced66d8 100644 --- a/Lavalink/example.application.yml +++ b/Lavalink/example.application.yml @@ -1,113 +1,113 @@ server: # REST and WS server - port: 2333 # The port that the server listens on - address: 0.0.0.0 + port: 2333 # The port that the server listens on + address: 0.0.0.0 plugins: - lavasrc: - sources: - spotify: true # Enable Spotify source - applemusic: true # Enable Apple Music source - deezer: true # Enable Deezer source - yandexmusic: true # Enable Yandex Music source - spotify: - clientId: "" - clientSecret: "" - countryCode: "US" # the country code you want to use for filtering the artists top tracks. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 - playlistLoadLimit: 6 # The number of pages at 100 tracks each - albumLoadLimit: 6 # The number of pages at 50 tracks each - applemusic: - countryCode: "US" # the country code you want to use for filtering the artists top tracks and language. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 - mediaAPIToken: "" # apple music api token - playlistLoadLimit: 6 # The number of pages at 300 tracks each - albumLoadLimit: 6 # The number of pages at 300 tracks each - deezer: - masterDecryptionKey: "" # the master key used for decrypting the deezer tracks. (yes this is not here you need to get it from somewhere else) - yandexmusic: - accessToken: "" # the token used for accessing the yandex music api. See https://github.com/TopiSenpai/LavaSrc#yandex-music + lavasrc: + sources: + spotify: true # Enable Spotify source + applemusic: true # Enable Apple Music source + deezer: true # Enable Deezer source + yandexmusic: true # Enable Yandex Music source + spotify: + clientId: '' + clientSecret: '' + countryCode: 'US' # the country code you want to use for filtering the artists top tracks. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 + playlistLoadLimit: 6 # The number of pages at 100 tracks each + albumLoadLimit: 6 # The number of pages at 50 tracks each + applemusic: + countryCode: 'US' # the country code you want to use for filtering the artists top tracks and language. See https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 + mediaAPIToken: '' # apple music api token + playlistLoadLimit: 6 # The number of pages at 300 tracks each + albumLoadLimit: 6 # The number of pages at 300 tracks each + deezer: + masterDecryptionKey: '' # the master key used for decrypting the deezer tracks. (yes this is not here you need to get it from somewhere else) + yandexmusic: + accessToken: '' # the token used for accessing the yandex music api. See https://github.com/TopiSenpai/LavaSrc#yandex-music lavalink: - plugins: - - dependency: "com.github.topi314.lavasrc:lavasrc-plugin:4.0.1" - repository: "https://maven.lavalink.dev/releases" - snapshot: false - - dependency: "com.github.topi314.sponsorblock:sponsorblock-plugin:3.0.0" - repository: "https://maven.lavalink.dev/releases" # this is optional for lavalink v4.0.0-beta.5 or greater - snapshot: false - - pluginsDir: "./plugins" - server: - password: "youshallnotpass" - sources: - youtube: true - bandcamp: true - soundcloud: true - twitch: true - vimeo: true - http: true - local: false - filters: # All filters are enabled by default - volume: true - equalizer: true - karaoke: true - timescale: true - tremolo: true - vibrato: true - distortion: true - rotation: true - channelMix: true - lowPass: true - bufferDurationMs: 400 # The duration of the NAS buffer. Higher values fare better against longer GC pauses. Duration <= 0 to disable JDA-NAS. Minimum of 40ms, lower values may introduce - frameBufferDurationMs: 1000 # How many milliseconds of audio to keep buffered - opusEncodingQuality: 10 # Opus encoder quality. Valid values range from 0 to 10, where 10 is best quality but is the most expensive on the CPU. - resamplingQuality: MEDIUM # Quality of resampling operations. Valid values are LOW, MEDIUM and HIGH, where HIGH uses the most CPU. - trackStuckThresholdMs: 10000 # The threshold for how long a track can be stuck. A track is stuck if does not return any audio data. - useSeekGhosting: true # Seek ghosting is the effect where whilst a seek is in progress, the audio buffer is read from until empty, or until seek is ready. - youtubePlaylistLoadLimit: 6 # Number of pages at 100 each - playerUpdateInterval: 5 # How frequently to send player updates to clients, in seconds - youtubeSearchEnabled: true - soundcloudSearchEnabled: true - gc-warnings: true - #ratelimit: - #ipBlocks: ["2001:470:28:d66::/64"] # list of ip blocks - #excludedIps: ["...", "..."] # ips which should be explicit excluded from usage by lavalink - #strategy: "RotateOnBan" # RotateOnBan | LoadBalance | NanoSwitch | RotatingNanoSwitch - #searchTriggersFail: true # Whether a search 429 should trigger marking the ip as failing - #retryLimit: -1 # -1 = use default lavaplayer value | 0 = infinity | >0 = retry will happen this numbers times - #youtubeConfig: # Required for avoiding all age restrictions by YouTube, some restricted videos still can be played without. - #email: "" # Email of Google account - #password: "" # Password of Google account - #httpConfig: # Useful for blocking bad-actors from ip-grabbing your music node and attacking it, this way only the http proxy will be attacked - #proxyHost: "localhost" # Hostname of the proxy, (ip or domain) - #proxyPort: 3128 # Proxy port, 3128 is the default for squidProxy - #proxyUser: "" # Optional user for basic authentication fields, leave blank if you don't use basic auth - #proxyPassword: "" # Password for basic authentication + plugins: + - dependency: 'com.github.topi314.lavasrc:lavasrc-plugin:4.0.1' + repository: 'https://maven.lavalink.dev/releases' + snapshot: false + - dependency: 'com.github.topi314.sponsorblock:sponsorblock-plugin:3.0.0' + repository: 'https://maven.lavalink.dev/releases' # this is optional for lavalink v4.0.0-beta.5 or greater + snapshot: false + + pluginsDir: './plugins' + server: + password: 'youshallnotpass' + sources: + youtube: true + bandcamp: true + soundcloud: true + twitch: true + vimeo: true + http: true + local: false + filters: # All filters are enabled by default + volume: true + equalizer: true + karaoke: true + timescale: true + tremolo: true + vibrato: true + distortion: true + rotation: true + channelMix: true + lowPass: true + bufferDurationMs: 400 # The duration of the NAS buffer. Higher values fare better against longer GC pauses. Duration <= 0 to disable JDA-NAS. Minimum of 40ms, lower values may introduce + frameBufferDurationMs: 1000 # How many milliseconds of audio to keep buffered + opusEncodingQuality: 10 # Opus encoder quality. Valid values range from 0 to 10, where 10 is best quality but is the most expensive on the CPU. + resamplingQuality: MEDIUM # Quality of resampling operations. Valid values are LOW, MEDIUM and HIGH, where HIGH uses the most CPU. + trackStuckThresholdMs: 10000 # The threshold for how long a track can be stuck. A track is stuck if does not return any audio data. + useSeekGhosting: true # Seek ghosting is the effect where whilst a seek is in progress, the audio buffer is read from until empty, or until seek is ready. + youtubePlaylistLoadLimit: 6 # Number of pages at 100 each + playerUpdateInterval: 5 # How frequently to send player updates to clients, in seconds + youtubeSearchEnabled: true + soundcloudSearchEnabled: true + gc-warnings: true + #ratelimit: + #ipBlocks: ["2001:470:28:d66::/64"] # list of ip blocks + #excludedIps: ["...", "..."] # ips which should be explicit excluded from usage by lavalink + #strategy: "RotateOnBan" # RotateOnBan | LoadBalance | NanoSwitch | RotatingNanoSwitch + #searchTriggersFail: true # Whether a search 429 should trigger marking the ip as failing + #retryLimit: -1 # -1 = use default lavaplayer value | 0 = infinity | >0 = retry will happen this numbers times + #youtubeConfig: # Required for avoiding all age restrictions by YouTube, some restricted videos still can be played without. + #email: "" # Email of Google account + #password: "" # Password of Google account + #httpConfig: # Useful for blocking bad-actors from ip-grabbing your music node and attacking it, this way only the http proxy will be attacked + #proxyHost: "localhost" # Hostname of the proxy, (ip or domain) + #proxyPort: 3128 # Proxy port, 3128 is the default for squidProxy + #proxyUser: "" # Optional user for basic authentication fields, leave blank if you don't use basic auth + #proxyPassword: "" # Password for basic authentication metrics: - prometheus: - enabled: false - endpoint: /metrics + prometheus: + enabled: false + endpoint: /metrics sentry: - dsn: "" - environment: "" + dsn: '' + environment: '' # tags: # some_key: some_value # another_key: another_value logging: - file: - path: ./logs/ + file: + path: ./logs/ - level: - root: INFO - lavalink: INFO + level: + root: INFO + lavalink: INFO - request: - enabled: true - includeClientInfo: true - includeHeaders: false - includeQueryString: true - includePayload: true - maxPayloadLength: 10000 + request: + enabled: true + includeClientInfo: true + includeHeaders: false + includeQueryString: true + includePayload: true + maxPayloadLength: 10000 - logback: - rollingpolicy: - max-file-size: 1GB - max-history: 30 + logback: + rollingpolicy: + max-file-size: 1GB + max-history: 30 diff --git a/README.md b/README.md index 674c8fec5..6b84b3626 100644 --- a/README.md +++ b/README.md @@ -143,7 +143,7 @@ PREFIX= "!" # Your prefix OWNER_IDS=["959276033683628122","859640640640640640"] # Your discord id, you can add multiple ids GUILD_ID= "859640640640640640" # Your server Id if you want to use the for single server CLIENT_SECRET= "" -PRODUCTION="true" # true for production +PRODUCTION="true" # true for production SEARCH_ENGINE= "ytsearch" # ytsearch, scsearch or ytmsearch MAX_PLAYLIST_SIZE= "100" # Max playlist size MAX_QUEUE_SIZE= "100" # Max queue size @@ -243,7 +243,7 @@ Your contribution will be reviewed by the project maintainers, and any necessary ## 🔐 License -Distributed under the Apache-2.0 license License. See ![LICENSE](https://img.shields.io/github/license/brblacky/lavamusic?style=social) for more information. +Distributed under the GPL-3.0 license. See ![LICENSE](https://img.shields.io/github/license/brblacky/lavamusic?style=social) for more information. ## ☕ Donate diff --git a/docker-compose.yml b/docker-compose.yml index 3e0c2c38a..c7be8b2c0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -40,7 +40,6 @@ services: volumes: # mount .env from the same directory or use environment variables - .env:/opt/lavamusic/.env - - ./database:/opt/lavamusic/database restart: on-failure depends_on: lavalink: diff --git a/src/commands/info/About.ts b/src/commands/info/About.ts index b609ee467..9cf646191 100644 --- a/src/commands/info/About.ts +++ b/src/commands/info/About.ts @@ -1,4 +1,5 @@ import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js'; + import { Command, Context, Lavamusic } from '../../structures/index.js'; export default class About extends Command { @@ -83,5 +84,4 @@ export default class About extends Command { components: [row], }); } - } - +} diff --git a/src/commands/music/PlayNext.ts b/src/commands/music/PlayNext.ts index b827ac7fd..e9a151bc4 100644 --- a/src/commands/music/PlayNext.ts +++ b/src/commands/music/PlayNext.ts @@ -123,7 +123,9 @@ export default class PlayNext extends Command { embeds: [ embed .setColor(this.client.color.main) - .setDescription(`Added ${res.data.tracks.length} songs to play next in the queue.`), + .setDescription( + `Added ${res.data.tracks.length} songs to play next in the queue.` + ), ], }); break; diff --git a/src/events/client/GuildDelete.ts b/src/events/client/GuildDelete.ts index b5c668a99..949f235ef 100644 --- a/src/events/client/GuildDelete.ts +++ b/src/events/client/GuildDelete.ts @@ -24,13 +24,20 @@ export default class GuildDelete extends Event { } const embed = new EmbedBuilder() .setColor(this.client.config.color.red) - .setAuthor({ name: guild.name || 'Unknown Guild', iconURL: guild.iconURL({ extension: 'jpeg' }) }) + .setAuthor({ + name: guild.name || 'Unknown Guild', + iconURL: guild.iconURL({ extension: 'jpeg' }), + }) .setDescription(`**${guild.name}** has been removed from my guilds!`) .setThumbnail(guild.iconURL({ extension: 'jpeg' })) .addFields( { name: 'Owner', value: owner.user.tag, inline: true }, - { name: 'Members', value: guild.memberCount ? guild.memberCount.toString() : 'Unknown', inline: true }, + { + name: 'Members', + value: guild.memberCount ? guild.memberCount.toString() : 'Unknown', + inline: true, + }, { name: 'Created At', value: ``, diff --git a/src/events/client/SetupButtons.ts b/src/events/client/SetupButtons.ts index e748cf4a4..1a816ad22 100644 --- a/src/events/client/SetupButtons.ts +++ b/src/events/client/SetupButtons.ts @@ -151,17 +151,17 @@ export default class SetupButtons extends Event { embeds: [ embed .setFooter({ - text: `Stopped by ${interaction.member.displayName}`, - iconURL: interaction.member.displayAvatarURL({}), - - }) + text: `Stopped by ${interaction.member.displayName}`, + iconURL: interaction.member.displayAvatarURL({}), + }) .setDescription(`Nothing playing right now`) .setImage(this.client.config.links.img) .setAuthor({ - name: this.client.user.username, - iconURL: this.client.user.displayAvatarURL({ extension: 'png' }), - - }), + name: this.client.user.username, + iconURL: this.client.user.displayAvatarURL({ + extension: 'png', + }), + }), ], }); break; diff --git a/src/events/player/NodeDestroy.ts b/src/events/player/NodeDestroy.ts index 81bb3e071..5dc8f41d4 100644 --- a/src/events/player/NodeDestroy.ts +++ b/src/events/player/NodeDestroy.ts @@ -9,6 +9,10 @@ export default class NodeDestroy extends Event { } 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') + 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 index 58cdf7ca2..3eb4863b3 100644 --- a/src/events/player/NodeDisconnect.ts +++ b/src/events/player/NodeDisconnect.ts @@ -9,6 +9,6 @@ export default class NodeDisconnect extends Event { } 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') + 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 index 1ae5e8e1a..7e6bf2309 100644 --- a/src/events/player/NodeError.ts +++ b/src/events/player/NodeError.ts @@ -9,6 +9,6 @@ export default class NodeError extends Event { } 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') + 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 index cd3d8b23a..39b9d2a04 100644 --- a/src/events/player/NodeRaw.ts +++ b/src/events/player/NodeRaw.ts @@ -1,6 +1,6 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ import { Event, Lavamusic } from '../../structures/index.js'; - export default class NodeRaw extends Event { constructor(client: Lavamusic, file: string) { super(client, file, { @@ -10,4 +10,4 @@ export default class NodeRaw extends Event { 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 index e98e66779..55e0d8ff0 100644 --- a/src/events/player/NodeReconnect.ts +++ b/src/events/player/NodeReconnect.ts @@ -9,6 +9,6 @@ export default class NodeReconnect extends Event { } public async run(node: string): Promise { this.client.logger.warn(`Node ${node} reconnected`); - BotLog.send(this.client, `Node ${node} reconnected`, 'warn') + BotLog.send(this.client, `Node ${node} reconnected`, 'warn'); } -} \ No newline at end of file +} diff --git a/src/events/player/TrackStart.ts b/src/events/player/TrackStart.ts index 9f2f1098a..06a3e3a68 100644 --- a/src/events/player/TrackStart.ts +++ b/src/events/player/TrackStart.ts @@ -17,7 +17,6 @@ import { Song } from '../../structures/Dispatcher.js'; import { Dispatcher, Event, Lavamusic } from '../../structures/index.js'; import { trackStart } from '../../utils/SetupSystem.js'; - export default class TrackStart extends Event { constructor(client: Lavamusic, file: string) { super(client, file, { diff --git a/src/plugin/plugins/updateStatus.ts b/src/plugin/plugins/updateStatus.ts index 92f18250e..db5e7b054 100644 --- a/src/plugin/plugins/updateStatus.ts +++ b/src/plugin/plugins/updateStatus.ts @@ -14,7 +14,6 @@ const updateStatusPlugin: BotPlugin = { export default updateStatusPlugin; - /** * Project: lavamusic * Author: Blacky diff --git a/src/structures/Lavamusic.ts b/src/structures/Lavamusic.ts index 97413f776..26eb2b336 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 index 4aacc27b4..f76fc7d47 100644 --- a/src/utils/BotLog.ts +++ b/src/utils/BotLog.ts @@ -1,6 +1,6 @@ import { TextChannel } from 'discord.js'; -import { Lavamusic } from '../structures/index.js'; +import { Lavamusic } from '../structures/index.js'; export default class BotLog { public static send(client: Lavamusic, message: string, type: string): void { @@ -27,11 +27,10 @@ export default class BotLog { color = 0x000000; break; } - const embed = client.embed() - .setColor(color) - .setDescription(message) - .setTimestamp(); - - channel.send({ embeds: [embed] }).catch(() => {null}); + const embed = client.embed().setColor(color).setDescription(message).setTimestamp(); + + channel.send({ embeds: [embed] }).catch(() => { + null; + }); } -} \ No newline at end of file +} diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index c14ec7e42..90e89cf72 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -8,8 +8,8 @@ import { TextChannel, } from 'discord.js'; -import { Context, Lavamusic } from '../structures/index.js'; import config from '../config.js'; +import { Context, Lavamusic } from '../structures/index.js'; export class Utils { public static formatTime(ms: number): string { @@ -147,13 +147,13 @@ export class Utils { if (ctx.isInteraction) { msg = ctx.deferred ? await ctx.interaction.followUp({ - ...msgOptions, - fetchReply: true as boolean, - }) + ...msgOptions, + fetchReply: true as boolean, + }) : await ctx.interaction.reply({ - ...msgOptions, - fetchReply: true, - }); + ...msgOptions, + fetchReply: true, + }); } else { msg = await (ctx.channel as TextChannel).send({ ...msgOptions, diff --git a/tsconfig.json b/tsconfig.json index 89c9c0801..a4d6e3c1a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -15,8 +15,6 @@ "skipLibCheck": true, "forceConsistentCasingInFileNames": true }, - "include": [ - "src/**/*.ts" - ], + "include": ["src/**/*.ts"], "exclude": ["dist", "node_modules", "tests", "dashboard"] }