From 41697fe2c85bcbd55255bdb6675c1014ec8c5ddd Mon Sep 17 00:00:00 2001 From: appujet Date: Sun, 15 Sep 2024 22:31:24 +0530 Subject: [PATCH] added filters --- .husky/commit-msg | 1 - .husky/pre-commit | 1 - commitlint.config.js | 1 - package.json | 9 ---- src/commands/config/247.ts | 2 +- src/commands/filters/NightCore.ts | 2 +- src/commands/filters/Pitch.ts | 81 +++++++++++++++++++++++++++++++ src/commands/filters/Rate.ts | 81 +++++++++++++++++++++++++++++++ src/commands/filters/Reset.ts | 57 ++++++++++++++++++++++ src/commands/filters/Rotation.ts | 68 ++++++++++++++++++++++++++ src/commands/filters/Speed.ts | 81 +++++++++++++++++++++++++++++++ src/commands/filters/Tremolo.ts | 70 ++++++++++++++++++++++++++ src/commands/filters/Vibrato.ts | 70 ++++++++++++++++++++++++++ src/commands/music/Join.ts | 2 +- src/commands/music/Play.ts | 5 +- src/commands/music/PlayNext.ts | 2 +- src/commands/music/Search.ts | 2 +- src/commands/playlist/Load.ts | 2 +- src/events/client/SetupSystem.ts | 10 ++-- src/events/node/Connect.ts | 2 +- src/events/player/QueueEnd.ts | 4 +- src/structures/LavalinkClient.ts | 3 +- 22 files changed, 526 insertions(+), 30 deletions(-) delete mode 100644 .husky/commit-msg delete mode 100644 .husky/pre-commit delete mode 100644 commitlint.config.js create mode 100644 src/commands/filters/Pitch.ts create mode 100644 src/commands/filters/Rate.ts create mode 100644 src/commands/filters/Reset.ts create mode 100644 src/commands/filters/Rotation.ts create mode 100644 src/commands/filters/Speed.ts create mode 100644 src/commands/filters/Tremolo.ts create mode 100644 src/commands/filters/Vibrato.ts diff --git a/.husky/commit-msg b/.husky/commit-msg deleted file mode 100644 index 34eed8b28..000000000 --- a/.husky/commit-msg +++ /dev/null @@ -1 +0,0 @@ -npx --no -- commitlint --edit $1 \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit deleted file mode 100644 index d0a778429..000000000 --- a/.husky/pre-commit +++ /dev/null @@ -1 +0,0 @@ -npx lint-staged \ No newline at end of file diff --git a/commitlint.config.js b/commitlint.config.js deleted file mode 100644 index 5073c20db..000000000 --- a/commitlint.config.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { extends: ["@commitlint/config-conventional"] }; diff --git a/package.json b/package.json index b5e7c72ef..273edc850 100644 --- a/package.json +++ b/package.json @@ -34,13 +34,9 @@ "homepage": "https://github.com/appujet/lavamusic#readme", "devDependencies": { "@biomejs/biome": "^1.9.0", - "@commitlint/cli": "^19.5.0", - "@commitlint/config-conventional": "^19.5.0", "@types/i18n": "^0.13.12", "@types/node": "^22.5.5", "@types/signale": "^1.4.7", - "husky": "^9.1.6", - "lint-staged": "^15.2.10", "prisma": "^5.19.1", "tslib": "^2.7.0", "typescript": "^5.6.2" @@ -59,11 +55,6 @@ "undici": "^6.19.8", "zod": "^3.23.8" }, - "lint-staged": { - "*.ts": [ - "biome check --write" - ] - }, "signale": { "displayScope": true, "displayBadge": true, diff --git a/src/commands/config/247.ts b/src/commands/config/247.ts index 7d123b046..32b60c6fb 100644 --- a/src/commands/config/247.ts +++ b/src/commands/config/247.ts @@ -56,7 +56,7 @@ export default class _247 extends Command { textChannelId: ctx.channel.id, selfMute: false, selfDeaf: true, - instaUpdateFiltersFix: true, + vcRegion: member.voice.channel.rtcRegion, }); } diff --git a/src/commands/filters/NightCore.ts b/src/commands/filters/NightCore.ts index b25b63eb9..baa4d7ce8 100644 --- a/src/commands/filters/NightCore.ts +++ b/src/commands/filters/NightCore.ts @@ -35,7 +35,7 @@ export default class NightCore extends Command { const filterEnabled = player.filterManager.filters.nightcore; if (filterEnabled) { - await player.filterManager.toggleNightcore(); + await player.filterManager.toggleTremolo(); await ctx.sendMessage({ embeds: [ { diff --git a/src/commands/filters/Pitch.ts b/src/commands/filters/Pitch.ts new file mode 100644 index 000000000..2e61a8c07 --- /dev/null +++ b/src/commands/filters/Pitch.ts @@ -0,0 +1,81 @@ +import { Command, type Context, type Lavamusic } from "../../structures/index.js"; + +export default class Pitch extends Command { + constructor(client: Lavamusic) { + super(client, { + name: "pitch", + description: { + content: "cmd.pitch.description", + examples: ["pitch 1", "pitch 1.5", "pitch 1,5"], + usage: "pitch ", + }, + category: "filters", + aliases: ["ph"], + cooldown: 3, + args: true, + vote: false, + player: { + voice: true, + dj: true, + active: true, + djPerm: null, + }, + permissions: { + dev: false, + client: ["SendMessages", "ReadMessageHistory", "ViewChannel", "EmbedLinks"], + user: [], + }, + slashCommand: true, + options: [ + { + name: "pitch", + description: "cmd.pitch.options.pitch", + type: 3, + required: true, + }, + ], + }); + } + + public async run(client: Lavamusic, ctx: Context, args: string[]): Promise { + const player = client.manager.getPlayer(ctx.guild!.id); + const pitchString = args[0].replace(",", "."); + const isValidNumber = /^[0-9]*\.?[0-9]+$/.test(pitchString); + const pitch = parseFloat(pitchString); + + if (!isValidNumber || isNaN(pitch) || pitch < 0.5 || pitch > 5) { + await ctx.sendMessage({ + embeds: [ + { + description: ctx.locale("cmd.pitch.errors.invalid_number"), + color: this.client.color.red, + }, + ], + }); + return; + } + + await player.filterManager.setPitch(pitch); + return await ctx.sendMessage({ + embeds: [ + { + description: ctx.locale("cmd.pitch.messages.pitch_set", { + pitch, + }), + color: this.client.color.main, + }, + ], + }); + } +} + +/** + * 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 + */ \ No newline at end of file diff --git a/src/commands/filters/Rate.ts b/src/commands/filters/Rate.ts new file mode 100644 index 000000000..9c734a714 --- /dev/null +++ b/src/commands/filters/Rate.ts @@ -0,0 +1,81 @@ +import { Command, type Context, type Lavamusic } from "../../structures/index.js"; + +export default class Rate extends Command { + constructor(client: Lavamusic) { + super(client, { + name: "rate", + description: { + content: "cmd.rate.description", + examples: ["rate 1", "rate 1.5", "rate 1,5"], + usage: "rate ", + }, + category: "filters", + aliases: ["rt"], + cooldown: 3, + args: true, + vote: false, + player: { + voice: true, + dj: true, + active: true, + djPerm: null, + }, + permissions: { + dev: false, + client: ["SendMessages", "ReadMessageHistory", "ViewChannel", "EmbedLinks"], + user: [], + }, + slashCommand: true, + options: [ + { + name: "rate", + description: "cmd.rate.options.rate", + type: 3, + required: true, + }, + ], + }); + } + + public async run(client: Lavamusic, ctx: Context, args: string[]): Promise { + const player = client.manager.getPlayer(ctx.guild!.id); + const rateString = args[0].replace(",", "."); + const isValidNumber = /^[0-9]*\.?[0-9]+$/.test(rateString); + const rate = parseFloat(rateString); + + if (!isValidNumber || isNaN(rate) || rate < 0.5 || rate > 5) { + await ctx.sendMessage({ + embeds: [ + { + description: ctx.locale("cmd.rate.errors.invalid_number"), + color: this.client.color.red, + }, + ], + }); + return; + } + + await player.filterManager.setRate(rate); + await ctx.sendMessage({ + embeds: [ + { + description: ctx.locale("cmd.rate.messages.rate_set", { + rate, + }), + color: this.client.color.main, + }, + ], + }); + } +} + +/** + * 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 + */ \ No newline at end of file diff --git a/src/commands/filters/Reset.ts b/src/commands/filters/Reset.ts new file mode 100644 index 000000000..cb07b92dd --- /dev/null +++ b/src/commands/filters/Reset.ts @@ -0,0 +1,57 @@ +import { Command, type Context, type Lavamusic } from "../../structures/index.js"; + +export default class Reset extends Command { + constructor(client: Lavamusic) { + super(client, { + name: "reset", + description: { + content: "cmd.reset.description", + examples: ["reset"], + usage: "reset", + }, + category: "filters", + aliases: ["rs"], + cooldown: 3, + args: false, + vote: false, + player: { + voice: true, + dj: true, + active: false, + djPerm: null, + }, + permissions: { + dev: false, + client: ["SendMessages", "ReadMessageHistory", "ViewChannel", "EmbedLinks"], + user: [], + }, + slashCommand: true, + options: [], + }); + } + + public async run(client: Lavamusic, ctx: Context): Promise { + const player = client.manager.getPlayer(ctx.guild!.id); + player.filterManager.resetFilters(); + player.filterManager.clearEQ(); + await ctx.sendMessage({ + embeds: [ + { + description: ctx.locale("cmd.reset.messages.filters_reset"), + color: this.client.color.main, + }, + ], + }); + } +} + +/** + * 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 + */ \ No newline at end of file diff --git a/src/commands/filters/Rotation.ts b/src/commands/filters/Rotation.ts new file mode 100644 index 000000000..b1bb461ab --- /dev/null +++ b/src/commands/filters/Rotation.ts @@ -0,0 +1,68 @@ +import { Command, type Context, type Lavamusic } from "../../structures/index.js"; + +export default class Rotation extends Command { + constructor(client: Lavamusic) { + super(client, { + name: "rotation", + description: { + content: "cmd.rotation.description", + examples: ["rotation"], + usage: "rotation", + }, + category: "filters", + aliases: ["rt"], + cooldown: 3, + args: false, + vote: false, + player: { + voice: true, + dj: true, + active: true, + djPerm: null, + }, + permissions: { + dev: false, + client: ["SendMessages", "ReadMessageHistory", "ViewChannel", "EmbedLinks"], + user: [], + }, + slashCommand: true, + options: [], + }); + } + + public async run(client: Lavamusic, ctx: Context): Promise { + const player = client.manager.getPlayer(ctx.guild!.id); + if (player.filterManager.filters.rotation) { + player.filterManager.toggleRotation(); + await ctx.sendMessage({ + embeds: [ + { + description: ctx.locale("cmd.rotation.messages.disabled"), + color: this.client.color.main, + }, + ], + }); + } else { + player.filterManager.toggleRotation(); + await ctx.sendMessage({ + embeds: [ + { + description: ctx.locale("cmd.rotation.messages.enabled"), + color: this.client.color.main, + }, + ], + }); + } + } +} + +/** + * 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 + */ \ No newline at end of file diff --git a/src/commands/filters/Speed.ts b/src/commands/filters/Speed.ts new file mode 100644 index 000000000..022bb8e27 --- /dev/null +++ b/src/commands/filters/Speed.ts @@ -0,0 +1,81 @@ +import { Command, type Context, type Lavamusic } from "../../structures/index.js"; + +export default class Speed extends Command { + constructor(client: Lavamusic) { + super(client, { + name: "speed", + description: { + content: "cmd.speed.description", + examples: ["speed 1.5", "speed 1,5"], + usage: "speed ", + }, + category: "filters", + aliases: ["spd"], + cooldown: 3, + args: true, + vote: false, + player: { + voice: true, + dj: true, + active: true, + djPerm: null, + }, + permissions: { + dev: false, + client: ["SendMessages", "ReadMessageHistory", "ViewChannel", "EmbedLinks"], + user: [], + }, + slashCommand: true, + options: [ + { + name: "speed", + description: "cmd.speed.options.speed", + type: 3, + required: true, + }, + ], + }); + } + + public async run(client: Lavamusic, ctx: Context, args: string[]): Promise { + const player = client.manager.getPlayer(ctx.guild!.id); + const speedString = args[0].replace(",", "."); + const isValidNumber = /^[0-9]*\.?[0-9]+$/.test(speedString); + const speed = parseFloat(speedString); + + if (!isValidNumber || isNaN(speed) || speed < 0.5 || speed > 5) { + await ctx.sendMessage({ + embeds: [ + { + description: ctx.locale("cmd.speed.messages.invalid_number"), + color: this.client.color.red, + }, + ], + }); + return; + } + + player.filterManager.setSpeed(speed); + await ctx.sendMessage({ + embeds: [ + { + description: ctx.locale("cmd.speed.messages.set_speed", { + speed, + }), + color: this.client.color.main, + }, + ], + }); + } +} + +/** + * 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 + */ \ No newline at end of file diff --git a/src/commands/filters/Tremolo.ts b/src/commands/filters/Tremolo.ts new file mode 100644 index 000000000..f0b98fdee --- /dev/null +++ b/src/commands/filters/Tremolo.ts @@ -0,0 +1,70 @@ +import { Command, type Context, type Lavamusic } from "../../structures/index.js"; + +export default class Tremolo extends Command { + constructor(client: Lavamusic) { + super(client, { + name: "tremolo", + description: { + content: "cmd.tremolo.description", + examples: ["tremolo"], + usage: "tremolo", + }, + category: "filters", + aliases: ["tr"], + cooldown: 3, + args: false, + vote: false, + player: { + voice: true, + dj: true, + active: true, + djPerm: null, + }, + permissions: { + dev: false, + client: ["SendMessages", "ReadMessageHistory", "ViewChannel", "EmbedLinks"], + user: [], + }, + slashCommand: true, + options: [], + }); + } + + public async run(client: Lavamusic, ctx: Context): Promise { + const player = client.manager.getPlayer(ctx.guild!.id); + const tremoloEnabled = player.filterManager.filters.tremolo + + if (tremoloEnabled) { + player.filterManager.toggleTremolo(); + await ctx.sendMessage({ + embeds: [ + { + description: ctx.locale("cmd.tremolo.messages.disabled"), + color: this.client.color.main, + }, + ], + }); + } else { + player.filterManager.toggleTremolo(); + await ctx.sendMessage({ + embeds: [ + { + description: ctx.locale("cmd.tremolo.messages.enabled"), + color: this.client.color.main, + }, + ], + }); + } + } +} + +/** + * 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 + */ \ No newline at end of file diff --git a/src/commands/filters/Vibrato.ts b/src/commands/filters/Vibrato.ts new file mode 100644 index 000000000..64391000d --- /dev/null +++ b/src/commands/filters/Vibrato.ts @@ -0,0 +1,70 @@ +import { Command, type Context, type Lavamusic } from "../../structures/index.js"; + +export default class Vibrato extends Command { + constructor(client: Lavamusic) { + super(client, { + name: "vibrato", + description: { + content: "cmd.vibrato.description", + examples: ["vibrato"], + usage: "vibrato", + }, + category: "filters", + aliases: ["vb"], + cooldown: 3, + args: false, + vote: false, + player: { + voice: true, + dj: true, + active: true, + djPerm: null, + }, + permissions: { + dev: false, + client: ["SendMessages", "ReadMessageHistory", "ViewChannel", "EmbedLinks"], + user: [], + }, + slashCommand: true, + options: [], + }); + } + + public async run(client: Lavamusic, ctx: Context): Promise { + const player = client.manager.getPlayer(ctx.guild!.id); + const vibratoEnabled = player.filterManager.filters.vibrato + + if (vibratoEnabled) { + player.filterManager.toggleVibrato(); + await ctx.sendMessage({ + embeds: [ + { + description: ctx.locale("cmd.vibrato.messages.disabled"), + color: this.client.color.main, + }, + ], + }); + } else { + player.filterManager.toggleVibrato(); + await ctx.sendMessage({ + embeds: [ + { + description: ctx.locale("cmd.vibrato.messages.enabled"), + color: this.client.color.main, + }, + ], + }); + } + } +} + +/** + * 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 + */ \ No newline at end of file diff --git a/src/commands/music/Join.ts b/src/commands/music/Join.ts index 62214373a..2dadd812c 100644 --- a/src/commands/music/Join.ts +++ b/src/commands/music/Join.ts @@ -60,7 +60,7 @@ export default class Join extends Command { textChannelId: ctx.channel.id, selfMute: false, selfDeaf: true, - instaUpdateFiltersFix: true, + vcRegion: memberVoiceChannel.rtcRegion, }); if (!player.connected) await player.connect(); diff --git a/src/commands/music/Play.ts b/src/commands/music/Play.ts index c36809eb6..9c3b40627 100644 --- a/src/commands/music/Play.ts +++ b/src/commands/music/Play.ts @@ -58,7 +58,6 @@ export default class Play extends Command { textChannelId: ctx.channel.id, selfMute: false, selfDeaf: true, - instaUpdateFiltersFix: true, vcRegion: memberVoiceChannel.rtcRegion, }); if (!player.connected) await player.connect(); @@ -103,7 +102,7 @@ export default class Play extends Command { const focusedValue = interaction.options.getFocused(); if (!focusedValue) { - return; + return interaction.respond([]).catch(() => { null }); } const res = await this.client.manager.search(focusedValue, interaction.user); @@ -119,7 +118,7 @@ export default class Play extends Command { }); } - return await interaction.respond(songs).catch(console.error); + return await interaction.respond(songs).catch(() => { null }); } } diff --git a/src/commands/music/PlayNext.ts b/src/commands/music/PlayNext.ts index 31e4a9603..22404edee 100644 --- a/src/commands/music/PlayNext.ts +++ b/src/commands/music/PlayNext.ts @@ -57,7 +57,7 @@ export default class PlayNext extends Command { textChannelId: ctx.channel.id, selfMute: false, selfDeaf: true, - instaUpdateFiltersFix: true, + vcRegion: memberVoiceChannel.rtcRegion, }); if (!player.connected) await player.connect(); diff --git a/src/commands/music/Search.ts b/src/commands/music/Search.ts index 17b6edf38..e44ea220b 100644 --- a/src/commands/music/Search.ts +++ b/src/commands/music/Search.ts @@ -52,7 +52,7 @@ export default class Search extends Command { textChannelId: ctx.channel.id, selfMute: false, selfDeaf: true, - instaUpdateFiltersFix: true, + vcRegion: memberVoiceChannel.rtcRegion, }); if (!player.connected) await player.connect(); diff --git a/src/commands/playlist/Load.ts b/src/commands/playlist/Load.ts index d6e44a524..3b69cae23 100644 --- a/src/commands/playlist/Load.ts +++ b/src/commands/playlist/Load.ts @@ -74,7 +74,7 @@ export default class LoadPlaylist extends Command { textChannelId: ctx.channel.id, selfMute: false, selfDeaf: true, - instaUpdateFiltersFix: true, + vcRegion: member.voice.channel.rtcRegion, }); if (!player.connected) await player.connect(); diff --git a/src/events/client/SetupSystem.ts b/src/events/client/SetupSystem.ts index b033c07ce..179cdfeb9 100644 --- a/src/events/client/SetupSystem.ts +++ b/src/events/client/SetupSystem.ts @@ -16,7 +16,7 @@ export default class SetupSystem extends Event { if (!(channel instanceof TextChannel)) return; if (!message.member?.voice.channel) { await oops(channel, T(locale, "event.message.no_voice_channel_queue")); - await message.delete().catch(() => {}); + await message.delete().catch(() => { }); return; } @@ -31,7 +31,7 @@ export default class SetupSystem extends Event { channel: voiceChannel.id, }), ); - await message.delete().catch(() => {}); + await message.delete().catch(() => { }); return; } @@ -42,7 +42,7 @@ export default class SetupSystem extends Event { channel: clientMember.voice.channelId, }), ); - await message.delete().catch(() => {}); + await message.delete().catch(() => { }); return; } @@ -54,14 +54,14 @@ export default class SetupSystem extends Event { textChannelId: message.channelId, selfMute: false, selfDeaf: true, - instaUpdateFiltersFix: true, + vcRegion: voiceChannel.rtcRegion, }); if (!player.connected) await player.connect(); } await setupStart(this.client, message.content, player, message); - await message.delete().catch(() => {}); + await message.delete().catch(() => { }); } } diff --git a/src/events/node/Connect.ts b/src/events/node/Connect.ts index 201cf77bc..a234824d7 100644 --- a/src/events/node/Connect.ts +++ b/src/events/node/Connect.ts @@ -35,7 +35,7 @@ export default class Connect extends Event { textChannelId: channel.id, selfDeaf: true, selfMute: false, - instaUpdateFiltersFix: true, + }); if (!player.connected) await player.connect(); } catch (error) { diff --git a/src/events/player/QueueEnd.ts b/src/events/player/QueueEnd.ts index c25e808f2..d489603e8 100644 --- a/src/events/player/QueueEnd.ts +++ b/src/events/player/QueueEnd.ts @@ -20,11 +20,11 @@ export default class QueueEnd extends Event { const channel = guild.channels.cache.get(player.textChannelId) as TextChannel; if (!channel) return; - const message = await channel.messages.fetch(messageId).catch(() => {}); + const message = await channel.messages.fetch(messageId).catch(() => { }); if (!message) return; if (message.editable) { - await message.edit({ components: [] }).catch(() => {}); + await message.edit({ components: [] }).catch(() => { }); } } } diff --git a/src/structures/LavalinkClient.ts b/src/structures/LavalinkClient.ts index 6e323306f..dd475e881 100644 --- a/src/structures/LavalinkClient.ts +++ b/src/structures/LavalinkClient.ts @@ -14,7 +14,8 @@ export default class LavalinkClient extends LavalinkManager { playerOptions: { defaultSearchPlatform: client.env.SEARCH_ENGINE, onDisconnect: { - destroyPlayer: true, + autoReconnect: true, + destroyPlayer: false }, requesterTransformer: requesterTransformer, onEmptyQueue: {