Skip to content

Commit

Permalink
chore: update & play(next)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasB25 committed Sep 15, 2024
1 parent be6ec29 commit 196f30d
Show file tree
Hide file tree
Showing 29 changed files with 243 additions and 78 deletions.
2 changes: 0 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ BOT_ACTIVITY=" Lavamusic" # Your bot activity.
DATABASE_URL= "" # Your database url (If you want to use sqlite, then you can leave it blank.).
AUTO_NODE=" false" # true for auto node. It is given from lavainfo-api (https://lavainfo-api.deno.dev).
SEARCH_ENGINE= "YouTubeMusic" # Search engine to be used when playing the song. You can use: YouTube, YouTubeMusic, SoundCloud, Spotify, Apple, Deezer, Yandex and JioSaavn
MAX_PLAYLIST_SIZE= "100" # Max playlist size.
MAX_QUEUE_SIZE= "100" # Max queue size.
GENIUS_API= "" # Sign up and get your own api at (https://genius.com/) to fetch your lyrics (CLIENT TOKEN)
NODES=[{"id":"main","host":"localhost","port":2333,"authorization":"youshallnotpass"}]
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = { extends: ["@commitlint/config-conventional"] };
module.exports = { extends: ["@commitlint/config-conventional"] };
12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lavamusic",
"version": "4.6.7",
"version": "5.0.0-beta",
"description": "LavaMusic is a music bot for Discord, written in JavaScript using the Discord.js, Typescript, lavalink-client (Lavalink) library.",
"main": "dist/index.js",
"scripts": {
Expand Down Expand Up @@ -36,9 +36,9 @@
"devDependencies": {
"@biomejs/biome": "^1.9.0",
"@types/i18n": "^0.13.12",
"@types/node": "^22.5.4",
"@commitlint/cli": "^19.4.0",
"@commitlint/config-conventional": "^19.2.2",
"@types/node": "^22.5.5",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@types/signale": "^1.4.7",
"husky": "^9.1.6",
"lint-staged": "^15.2.10",
Expand All @@ -61,9 +61,7 @@
"zod": "^3.23.8"
},
"lint-staged": {
"*.ts": [
"biome check --write"
]
"*.ts": ["biome check --write"]
},
"signale": {
"displayScope": true,
Expand Down
11 changes: 11 additions & 0 deletions scripts/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ async function clean() {
}

clean();

/**
* 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
*/
11 changes: 11 additions & 0 deletions scripts/restart.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,14 @@ async function startLavamusic() {
}

setTimeout(startLavamusic, 5000);

/**
* 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
*/
4 changes: 2 additions & 2 deletions src/commands/config/247.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default class _247 extends Command {

public async run(client: Lavamusic, ctx: Context): Promise<any> {
const embed = this.client.embed();
let player = client.manager.getPlayer(ctx.guild.id)
let player = client.manager.getPlayer(ctx.guild.id);
try {
const data = await client.db.get_247(ctx.guild!.id);
const member = ctx.member as GuildMember;
Expand All @@ -58,7 +58,7 @@ export default class _247 extends Command {
selfDeaf: true,
instaUpdateFiltersFix: true,
vcRegion: member.voice.channel.rtcRegion,
})
});
}
if (!player.connected) await player.connect();
return await ctx.sendMessage({
Expand Down
11 changes: 11 additions & 0 deletions src/commands/config/Language.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,14 @@ export default class LanguageCommand extends Command {
await interaction.respond(filtered.slice(0, 25)).catch(console.error);
}
}

/**
* 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
*/
4 changes: 2 additions & 2 deletions src/commands/music/Join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class Join extends Command {
});
}

const memberVoiceChannel = (ctx.member as any).voice.channel as VoiceChannel
const memberVoiceChannel = (ctx.member as any).voice.channel as VoiceChannel;
if (!memberVoiceChannel) {
return await ctx.sendMessage({
embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("cmd.join.no_voice_channel"))],
Expand All @@ -62,7 +62,7 @@ export default class Join extends Command {
selfDeaf: true,
instaUpdateFiltersFix: true,
vcRegion: memberVoiceChannel.rtcRegion,
})
});
if (!player.connected) await player.connect();
return await ctx.sendMessage({
embeds: [
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/Loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class Loop extends Command {

switch (player?.repeatMode) {
case "off":
player.setRepeatMode("track")
player.setRepeatMode("track");
loopMessage = ctx.locale("cmd.loop.looping_song");
break;
case "track":
Expand Down
42 changes: 25 additions & 17 deletions src/commands/music/Play.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AutocompleteInteraction, VoiceChannel } from "discord.js";
import { Command, type Context, type Lavamusic } from "../../structures/index";
import type { SearchResult } from "lavalink-client/dist/types";
import { Command, type Context, type Lavamusic } from "../../structures/index";

export default class Play extends Command {
constructor(client: Lavamusic) {
Expand Down Expand Up @@ -49,20 +49,21 @@ export default class Play extends Command {
const query = args.join(" ");
await ctx.sendDeferMessage(ctx.locale("cmd.play.loading"));
let player = client.manager.getPlayer(ctx.guild!.id);
const memberVoiceChannel = (ctx.member as any).voice.channel as VoiceChannel
const memberVoiceChannel = (ctx.member as any).voice.channel as VoiceChannel;

if (!player) player = client.manager.createPlayer({
guildId: ctx.guild!.id,
voiceChannelId: memberVoiceChannel.id,
textChannelId: ctx.channel.id,
selfMute: false,
selfDeaf: true,
instaUpdateFiltersFix: true,
vcRegion: memberVoiceChannel.rtcRegion,
})
if (!player)
player = client.manager.createPlayer({
guildId: ctx.guild!.id,
voiceChannelId: memberVoiceChannel.id,
textChannelId: ctx.channel.id,
selfMute: false,
selfDeaf: true,
instaUpdateFiltersFix: true,
vcRegion: memberVoiceChannel.rtcRegion,
});
if (!player.connected) await player.connect();

const response = await player.search({ query: query }, ctx.author) as SearchResult;
const response = (await player.search({ query: query }, ctx.author)) as SearchResult;
const embed = this.client.embed();

if (!response || response.tracks?.length === 0) {
Expand All @@ -73,7 +74,7 @@ export default class Play extends Command {
}

await player.queue.add(response.loadType === "playlist" ? response.tracks : response.tracks[0]);

if (response.loadType === "playlist") {
await ctx.editMessage({
content: "",
Expand All @@ -87,9 +88,12 @@ export default class Play extends Command {
await ctx.editMessage({
content: "",
embeds: [
embed
.setColor(this.client.color.main)
.setDescription(ctx.locale("cmd.play.added_to_queue", { title: response.tracks[0].info.title, uri: response.tracks[0].info.uri })),
embed.setColor(this.client.color.main).setDescription(
ctx.locale("cmd.play.added_to_queue", {
title: response.tracks[0].info.title,
uri: response.tracks[0].info.uri,
}),
),
],
});
}
Expand All @@ -98,6 +102,10 @@ export default class Play extends Command {
public async autocomplete(interaction: AutocompleteInteraction): Promise<void> {
const focusedValue = interaction.options.getFocused();

if (!focusedValue) {
return;
}

const res = await this.client.manager.search(focusedValue, interaction.user);
const songs = [];

Expand All @@ -108,7 +116,7 @@ export default class Play extends Command {
name: name.length > 100 ? `${name.substring(0, 97)}...` : name,
value: track.info.uri,
});
})
});
}

return await interaction.respond(songs).catch(console.error);
Expand Down
43 changes: 25 additions & 18 deletions src/commands/music/PlayNext.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AutocompleteInteraction, VoiceChannel } from "discord.js";
import { Command, type Context, type Lavamusic } from "../../structures/index";
import type { SearchResult } from "lavalink-client/dist/types";
import { Command, type Context, type Lavamusic } from "../../structures/index";

export default class PlayNext extends Command {
constructor(client: Lavamusic) {
Expand Down Expand Up @@ -48,22 +48,23 @@ export default class PlayNext extends Command {
public async run(client: Lavamusic, ctx: Context, args: string[]): Promise<any> {
const query = args.join(" ");
let player = client.manager.getPlayer(ctx.guild!.id);
const memberVoiceChannel = (ctx.member as any).voice.channel as VoiceChannel
const memberVoiceChannel = (ctx.member as any).voice.channel as VoiceChannel;

if (!player) player = client.manager.createPlayer({
guildId: ctx.guild!.id,
voiceChannelId: memberVoiceChannel.id,
textChannelId: ctx.channel.id,
selfMute: false,
selfDeaf: true,
instaUpdateFiltersFix: true,
vcRegion: memberVoiceChannel.rtcRegion,
})
if (!player)
player = client.manager.createPlayer({
guildId: ctx.guild!.id,
voiceChannelId: memberVoiceChannel.id,
textChannelId: ctx.channel.id,
selfMute: false,
selfDeaf: true,
instaUpdateFiltersFix: true,
vcRegion: memberVoiceChannel.rtcRegion,
});
if (!player.connected) await player.connect();

await ctx.sendDeferMessage(ctx.locale("cmd.playnext.loading"));
const response = await player.search({ query: query }, ctx.author) as SearchResult;

const response = (await player.search({ query: query }, ctx.author)) as SearchResult;
const embed = this.client.embed();

if (!response || response.tracks?.length === 0) {
Expand All @@ -87,18 +88,24 @@ export default class PlayNext extends Command {
await ctx.editMessage({
content: "",
embeds: [
embed
.setColor(this.client.color.main)
.setDescription(ctx.locale("cmd.playnext.added_to_play_next", { title: response.tracks[0].info.title, uri: response.tracks[0].info.uri })),
embed.setColor(this.client.color.main).setDescription(
ctx.locale("cmd.playnext.added_to_play_next", {
title: response.tracks[0].info.title,
uri: response.tracks[0].info.uri,
}),
),
],
});
}
if (!player.playing) await player.play({ paused: false });

}
public async autocomplete(interaction: AutocompleteInteraction): Promise<void> {
const focusedValue = interaction.options.getFocused();

if (!focusedValue) {
return;
}

const res = await this.client.manager.search(focusedValue, interaction.user);
const songs = [];

Expand All @@ -109,7 +116,7 @@ export default class PlayNext extends Command {
name: name.length > 100 ? `${name.substring(0, 97)}...` : name,
value: track.info.uri,
});
})
});
}

return await interaction.respond(songs).catch(console.error);
Expand Down
25 changes: 13 additions & 12 deletions src/commands/music/Search.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, type VoiceChannel } from "discord.js";
import { Command, type Context, type Lavamusic } from "../../structures/index";
import type { SearchResult, Track } from "lavalink-client/dist/types";
import { Command, type Context, type Lavamusic } from "../../structures/index";

export default class Search extends Command {
constructor(client: Lavamusic) {
Expand Down Expand Up @@ -43,19 +43,20 @@ export default class Search extends Command {
const embed = this.client.embed().setColor(this.client.color.main);
let player = client.manager.getPlayer(ctx.guild!.id);
const query = args.join(" ");
const memberVoiceChannel = (ctx.member as any).voice.channel as VoiceChannel
const memberVoiceChannel = (ctx.member as any).voice.channel as VoiceChannel;

if (!player) player = client.manager.createPlayer({
guildId: ctx.guild!.id,
voiceChannelId: memberVoiceChannel.id,
textChannelId: ctx.channel.id,
selfMute: false,
selfDeaf: true,
instaUpdateFiltersFix: true,
vcRegion: memberVoiceChannel.rtcRegion,
})
if (!player)
player = client.manager.createPlayer({
guildId: ctx.guild!.id,
voiceChannelId: memberVoiceChannel.id,
textChannelId: ctx.channel.id,
selfMute: false,
selfDeaf: true,
instaUpdateFiltersFix: true,
vcRegion: memberVoiceChannel.rtcRegion,
});
if (!player.connected) await player.connect();
const response = await player.search({ query: query }, ctx.author) as SearchResult;
const response = (await player.search({ query: query }, ctx.author)) as SearchResult;
if (!response || response.tracks?.length === 0) {
return await ctx.sendMessage({
embeds: [embed.setDescription(ctx.locale("cmd.search.errors.no_results")).setColor(this.client.color.red)],
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/Shuffle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class Shuffle extends Command {
embeds: [embed.setColor(this.client.color.red).setDescription(ctx.locale("player.errors.no_song"))],
});
}
player.queue.shuffle()
player.queue.shuffle();
return await ctx.sendMessage({
embeds: [embed.setColor(this.client.color.main).setDescription(ctx.locale("cmd.shuffle.messages.shuffled"))],
});
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/Stop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class Stop extends Command {
const player = client.manager.getPlayer(ctx.guild!.id);
const embed = this.client.embed();

player.stopPlaying(true, false)
player.stopPlaying(true, false);

return await ctx.sendMessage({
embeds: [embed.setColor(this.client.color.main).setDescription(ctx.locale("cmd.stop.messages.stopped"))],
Expand Down
2 changes: 1 addition & 1 deletion src/commands/playlist/Load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class LoadPlaylist extends Command {
selfDeaf: true,
instaUpdateFiltersFix: true,
vcRegion: member.voice.channel.rtcRegion,
})
});
if (!player.connected) await player.connect();
}

Expand Down
2 changes: 1 addition & 1 deletion src/database/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export default class ServerData {
},
});
} else {
throw new Error('Existing tracks are not in an array format.');
throw new Error("Existing tracks are not in an array format.");
}
} else {
// If no playlist exists, create a new one with the provided tracks
Expand Down
11 changes: 11 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,14 @@ for (const key in env) {
throw new Error(`Missing env variable: ${key}`);
}
}

/**
* 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
*/
Loading

0 comments on commit 196f30d

Please sign in to comment.