Skip to content

Commit

Permalink
Update dependencies and and update to lavalink v4, shoukaku v4
Browse files Browse the repository at this point in the history
  • Loading branch information
appujet committed Dec 26, 2023
1 parent 83b4132 commit 3e64d45
Show file tree
Hide file tree
Showing 24 changed files with 208 additions and 152 deletions.
37 changes: 18 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"name": "lavamusic",
"version": "4.0.1",
"version": "4.0.2",
"description": "LavaMusic is a music bot for Discord, written in JavaScript using the Discord.js, Typescript, Shoukaku (Lavalink) library.",
"main": "dist/index.js",
"type": "module",
"scripts": {
"start": "npm run start:bot",
"prisma:generate": "npx prisma generate",
"start:bot": "npm run build && node dist/index.js",
"dev": "nodemon --watch src --exec npm run start:bot",
"start": "npm run build && node dist/index.js",
"dev": "npm run build && nodemon --watch dist --exec node dist/index.js",
"build": "tsc --project tsconfig.json",
"clean": "rm -rf dist",
"lint": "eslint . --cache --ext .js,.jsx,.ts,.tsx",
Expand Down Expand Up @@ -37,27 +36,27 @@
},
"homepage": "https://github.com/brblacky/lavamusic#readme",
"devDependencies": {
"@types/node": "^20.8.7",
"@types/signale": "^1.4.6",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"eslint": "^8.52.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-unicorn": "^48.0.1",
"prettier": "^3.0.3",
"prisma": "^5.5.2",
"ts-node": "^10.9.1",
"typescript": "^5.2.2"
"@types/node": "^20.10.5",
"@types/signale": "^1.4.7",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"eslint": "^8.56.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-unicorn": "^50.0.1",
"prettier": "^3.1.1",
"prisma": "^5.7.1",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"dependencies": {
"@prisma/client": "^5.5.2",
"discord.js": "^14.12.1",
"@prisma/client": "^5.7.1",
"discord.js": "^14.14.1",
"dotenv": "^16.3.1",
"shoukaku": "^3.4.0",
"shoukaku": "^4.0.1",
"signale": "^1.4.0",
"socket.io": "^4.7.2",
"tslib": "^2.6.2",
"undici": "^5.26.4"
"undici": "^6.2.1"
},
"signale": {
"displayScope": true,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/config/247.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class _247 extends Command {
ctx.guild,
vc.voice.channel,
ctx.channel,
client.shoukaku.getNode()
client.shoukaku.options.nodeResolver(client.shoukaku.nodes)
);
return await ctx.sendMessage({
embeds: [
Expand Down
43 changes: 42 additions & 1 deletion src/commands/dev/Eval.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
import { fetch } from 'undici';

import { Command, Context, Lavamusic } from '../../structures/index.js';

export default class Eval extends Command {
Expand Down Expand Up @@ -33,8 +36,46 @@ export default class Eval extends Command {
const code = args.join(' ');
try {
let evaled = eval(code);

if (evaled == client.config) evaled = 'Nice try';

const button = new ButtonBuilder()
.setStyle(ButtonStyle.Danger)
.setLabel('Delete')
.setCustomId('eval-delete');
const row = new ActionRowBuilder().addComponents(button);

if (typeof evaled !== 'string') evaled = (await import('node:util')).inspect(evaled);
ctx.sendMessage(`\`\`\`js\n${evaled}\n\`\`\``);

if (evaled.length > 2000) {
const response = await fetch('https://hasteb.in/post', {
method: 'POST',
headers: {
'Content-Type': 'text/plain',
},
body: evaled,
})

const json = await response.json() as { key: string };
evaled = `https://hasteb.in/${json.key}`;
return await ctx.sendMessage({
content: evaled,
});
} else {
const msg = await ctx.sendMessage({
content: `\`\`\`js\n${evaled}\n\`\`\``,
components: [row],
});
const filter = (i): boolean => i.customId === 'eval-delete' && i.user.id === ctx.author.id;
const collector = msg.createMessageComponentCollector({
time: 60000,
filter: filter,
});
collector.on('collect', async (i) => {
await i.deferUpdate();
await msg.delete();
});
}
} catch (e) {
ctx.sendMessage(`\`\`\`js\n${e}\n\`\`\``);
}
Expand Down
8 changes: 3 additions & 5 deletions src/commands/music/Grab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,10 @@ export default class Grab extends Command {
.embed()
.setTitle(`**${song.info.title}**`)
.setURL(song.info.uri)
.setThumbnail(song.info.thumbnail)
.setThumbnail(song.info.artworkUrl)
.setDescription(
`**Duration:** ${
song.info.isStream ? 'LIVE' : client.utils.formatTime(song.info.length)
}\n**Requested by:** ${song.info.requester}\n**Link:** [Click here](${
song.info.uri
`**Duration:** ${song.info.isStream ? 'LIVE' : client.utils.formatTime(song.info.length)
}\n**Requested by:** ${song.info.requester}\n**Link:** [Click here](${song.info.uri
})`
)
.setColor(client.color.main);
Expand Down
6 changes: 3 additions & 3 deletions src/commands/music/Join.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ export default class Join extends Command {
ctx.guild,
vc.voice.channel,
ctx.channel,
client.shoukaku.getNode()
client.shoukaku.options.nodeResolver(client.shoukaku.nodes)
);
return await ctx.sendMessage({
embeds: [
embed
.setColor(this.client.color.main)
.setDescription(`Joined <#${player.player.connection.channelId}>`),
.setDescription(`Joined <#${player.node.manager.connections.get(ctx.guild.id).channelId}>`),
],
});
} else {
Expand All @@ -52,7 +52,7 @@ export default class Join extends Command {
embed
.setColor(this.client.color.main)
.setDescription(
`I'm already connected to <#${player.player.connection.channelId}>`
`I'm already connected to <#${player.node.manager.connections.get(ctx.guild.id).channelId}>`
),
],
});
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/Leave.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class Leave extends Command {
embeds: [
embed
.setColor(this.client.color.main)
.setDescription(`Left <#${player.player.connection.channelId}>`),
.setDescription(`Left <#${player.node.manager.connections.get(ctx.guild.id).channelId}>`),
],
});
player.destroy();
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/Nowplaying.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class Nowplaying extends Command {
.embed()
.setColor(this.client.color.main)
.setAuthor({ name: 'Now Playing', iconURL: ctx.guild.iconURL({}) })
.setThumbnail(track.info.thumbnail)
.setThumbnail(track.info.artworkUrl)
.setDescription(
`[${track.info.title}](${track.info.uri}) - Request By: ${track.info.requester}\n\n\`${bar}\``
)
Expand Down
31 changes: 17 additions & 14 deletions src/commands/music/Play.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { LoadType } from 'shoukaku';

import { Command, Context, Lavamusic } from '../../structures/index.js';

export default class Play extends Command {
Expand Down Expand Up @@ -47,14 +49,13 @@ export default class Play extends Command {
player = await client.queue.create(
ctx.guild,
vc.voice.channel,
ctx.channel,
client.shoukaku.getNode()
ctx.channel
);

const res = await this.client.queue.search(query);
const embed = this.client.embed();
switch (res.loadType) {
case 'LOAD_FAILED':
case LoadType.ERROR:
ctx.sendMessage({
embeds: [
embed
Expand All @@ -63,7 +64,7 @@ export default class Play extends Command {
],
});
break;
case 'NO_MATCHES':
case LoadType.EMPTY:
ctx.sendMessage({
embeds: [
embed
Expand All @@ -72,8 +73,8 @@ export default class Play extends Command {
],
});
break;
case 'TRACK_LOADED': {
const track = player.buildTrack(res.tracks[0], ctx.author);
case LoadType.TRACK: {
const track = player.buildTrack(res.data[0], ctx.author);
if (player.queue.length > client.config.maxQueueSize)
return await ctx.sendMessage({
embeds: [
Expand All @@ -91,14 +92,14 @@ export default class Play extends Command {
embed
.setColor(this.client.color.main)
.setDescription(
`Added [${res.tracks[0].info.title}](${res.tracks[0].info.uri}) to the queue.`
`Added [${res.data[0].info.title}](${res.data[0].info.uri}) to the queue.`
),
],
});
break;
}
case 'PLAYLIST_LOADED':
if (res.length > client.config.maxPlaylistSize)
case LoadType.PLAYLIST: {
if (res.data.tracks.length > client.config.maxPlaylistSize)
return await ctx.sendMessage({
embeds: [
embed
Expand All @@ -108,7 +109,7 @@ export default class Play extends Command {
),
],
});
for (const track of res.tracks) {
for (const track of res.data.tracks) {
const pl = player.buildTrack(track, ctx.author);
if (player.queue.length > client.config.maxQueueSize)
return await ctx.sendMessage({
Expand All @@ -127,12 +128,14 @@ export default class Play extends Command {
embeds: [
embed
.setColor(this.client.color.main)
.setDescription(`Added ${res.tracks.length} songs to the queue.`),
.setDescription(`Added ${res.data.tracks.length} songs to the queue.`),
],
});
break;
case 'SEARCH_RESULT': {
const track1 = player.buildTrack(res.tracks[0], ctx.author);
}
case LoadType.SEARCH: {

const track1 = player.buildTrack(res.data[0], ctx.author);
if (player.queue.length > client.config.maxQueueSize)
return await ctx.sendMessage({
embeds: [
Expand All @@ -150,7 +153,7 @@ export default class Play extends Command {
embed
.setColor(this.client.color.main)
.setDescription(
`Added [${res.tracks[0].info.title}](${res.tracks[0].info.uri}) to the queue.`
`Added [${res.data[0].info.title}](${res.data[0].info.uri}) to the queue.`
),
],
});
Expand Down
18 changes: 9 additions & 9 deletions src/commands/music/Search.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js';
import { LoadType } from 'shoukaku';

import { Song } from '../../structures/Dispatcher.js';
import { Command, Context, Lavamusic } from '../../structures/index.js';
Expand Down Expand Up @@ -48,7 +49,7 @@ export default class Search extends Command {
ctx.guild,
vc.voice.channel,
ctx.channel,
client.shoukaku.getNode()
client.shoukaku.options.nodeResolver(client.shoukaku.nodes)
);
}
const res = await this.client.queue.search(query);
Expand All @@ -64,7 +65,7 @@ export default class Search extends Command {
new ButtonBuilder().setCustomId('5').setLabel('5').setStyle(ButtonStyle.Primary)
);
switch (res.loadType) {
case 'LOAD_FAILED':
case LoadType.ERROR:
ctx.sendMessage({
embeds: [
embed
Expand All @@ -73,7 +74,7 @@ export default class Search extends Command {
],
});
break;
case 'NO_MATCHES':
case LoadType.EMPTY:
ctx.sendMessage({
embeds: [
embed
Expand All @@ -82,12 +83,11 @@ export default class Search extends Command {
],
});
break;
case 'SEARCH_RESULT': {
const tracks = res.tracks.slice(0, 5);
case LoadType.SEARCH: {
const tracks = res.data.slice(0, 5);
const embeds = tracks.map(
(track: Song, index: number) =>
`${index + 1}. [${track.info.title}](${track.info.uri}) - \`${
track.info.author
`${index + 1}. [${track.info.title}](${track.info.uri}) - \`${track.info.author
}\``
);
await ctx.sendMessage({
Expand All @@ -104,9 +104,9 @@ export default class Search extends Command {
idle: 60000 / 2,
});
collector.on('collect', async (int: any) => {
for (let i = 0; i < res.tracks.length; i++) {
for (let i = 0; i < res.data.length; i++) {
if (int.customId === `${i + 1}`) {
let track = res.tracks[i];
let track = res.data[i];
track = player.buildTrack(track, ctx.author);
player.queue.push(track);
player.isPlaying();
Expand Down
4 changes: 2 additions & 2 deletions src/commands/music/Volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ export default class Volume extends Command {
.setDescription('The volume can\'t be lower than 0.'),
],
});
player.player.setVolume(number / 100);
player.player.setGlobalVolume(number);
return await ctx.sendMessage({
embeds: [
embed
.setColor(this.client.color.main)
.setDescription(`Set the volume to ${(player.volume * 100).toFixed()}`),
.setDescription(`Set the volume to ${(player.volume).toFixed()}`),
],
});
}
Expand Down
8 changes: 7 additions & 1 deletion src/commands/playlist/Add.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ApplicationCommandOptionType } from 'discord.js';
import { LoadType } from 'shoukaku';

import { Command, Context, Lavamusic } from '../../structures/index.js';

Expand Down Expand Up @@ -94,7 +95,12 @@ export default class Add extends Command {
},
],
});
const trackStrings = res.tracks.map(track => JSON.stringify(track));
let trackStrings;
if (res.loadType === LoadType.PLAYLIST) {
trackStrings = res.data.tracks.map((track) => JSON.stringify(track));
} else {
trackStrings = [JSON.stringify(res.data[0])];
}
await client.prisma.playlist.update({
where: {
id: playlistData.id,
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 @@ -62,7 +62,7 @@ export default class Load extends Command {
ctx.guild,
vc.voice.channel,
ctx.channel,
client.shoukaku.getNode()
client.shoukaku.options.nodeResolver(client.shoukaku.nodes)
);

const track = player.buildTrack(song, ctx.author);
Expand Down
Loading

0 comments on commit 3e64d45

Please sign in to comment.