Project Discussion

A thread for discussing #lavaclient & related stufff
V
viztea272d ago
Since Lavalink v4 is right around the corner I should probably start brainstorming some ideas for the new api
T
topi272d ago
*Since Lavalink V4 is here I should ...
V
viztea272d ago
Nodes & Clusters A Node is a connection to a single lavalink instance while a Cluster is a collection of Nodes, both Cluster & Node implement a shared interface named Client which is the public facing api.
const client = new Node({ ...options... })
= new Cluster([ "...", "..." ]);

await client.connect("<user id>");
const client = new Node({ ...options... })
= new Cluster([ "...", "..." ]);

await client.connect("<user id>");
Note: Instead of uri: string, options: ... you can just pass in a single object like in lavaclient v4.
Manage Players
// get player
const player = client.players.resolve("<guild id>");

// get player from cache or api request to /sessions/:sid/players/:g
const player = await client.players.fetch("<guild id>", force=boolean);

// create a player, however, the returned player makes no guarantee whether
// lavalink actually has a player for the given guild id
const player = client.players.create("<guild id");
// get player
const player = client.players.resolve("<guild id>");

// get player from cache or api request to /sessions/:sid/players/:g
const player = await client.players.fetch("<guild id>", force=boolean);

// create a player, however, the returned player makes no guarantee whether
// lavalink actually has a player for the given guild id
const player = client.players.create("<guild id");
Note: Similar to discord.js managers you can just access the underlying cache map via <Client>.players.cache
Player Usage
// listen to events
player.on("trackStart/End/Stuck/Failed", callback);
player.on("updated", callback);

// access voice methods/info
player.voice.latency
.connected

await player.voice.connect("<channel id>");
await player.voice.disconnect();

// access the api endpoints for this specific player.
await player.api.update({ ...request... });
await player.api.*

// or use convenience methods (similar to lavaclient v4)
await player.play(track, { ...options... });
await player.*
// listen to events
player.on("trackStart/End/Stuck/Failed", callback);
player.on("updated", callback);

// access voice methods/info
player.voice.latency
.connected

await player.voice.connect("<channel id>");
await player.voice.disconnect();

// access the api endpoints for this specific player.
await player.api.update({ ...request... });
await player.api.*

// or use convenience methods (similar to lavaclient v4)
await player.play(track, { ...options... });
await player.*
Other Discord Libraries Since lavaclient will be remaining as a discord-library agnostic library I will be creating some connector libraries for a quicker, more streamlined experience when using libraries like discord.js. Runtimes All of these changes will be brought to the deno client when lavaclient v5 drops @asszx @zapteryx @justapie06 @tijmenh. @ivioleti Sorry for the pings! Since all of you have created threads in this channel & remained in the server I wouldn't mind some feedback on this if you're still using my client :3 I will be mentioning the @lavaclient user from here on out so if you want more updates please use <id:customize> to give yourself the role
M
max272d ago
heya i have no objections to any of the changes but i assume there'll be a more thorough document or readme indicating breaking changes between v4 and v5?
V
viztea272d ago
more than likely
M
max272d ago
if yes then im fine with it 👍 looking forward to it as well
V
viztea272d ago
npm
lavalink-protocol
Type-safe validation for the Lavalink protocol.. Latest version: 1.0.0-rc.4, last published: 2 hours ago. Start using lavalink-protocol in your project by running npm i lavalink-protocol. There are 2 other projects in the npm registry using lavalink-protocol.
npm
lavalink-ws-client
Type-safe WebSocket client for Lavalink. Latest version: 1.0.0-rc.1, last published: 2 hours ago. Start using lavalink-ws-client in your project by running npm i lavalink-ws-client. There are no other projects in the npm registry using lavalink-ws-client.
npm
lavalink-api-client
Type-safe API client for Lavalink. Latest version: 1.0.0-rc.5, last published: 2 hours ago. Start using lavalink-api-client in your project by running npm i lavalink-api-client. There is 1 other project in the npm registry using lavalink-api-client.
V
viztea257d ago
@dastormer not sure if you still use lavaclient for StormBeatz but pinging you just in case and if you don't maybe some of those new packages will interest you once they're finished @lavaclient user Published the first alpha version since it works™️. However, some stuff hasn't been implemented yet since i'm tired asf 1. clustering 2. most node events API This is basically what will be released in v5. If you have any objections please send a constructive message :D Refer to types & this message for api usage: https://canary.discord.com/channels/323365823572082690/1137317796821336085/1137321192626335754 Installation https://www.npmjs.com/package/lavaclient/v/5.0.0-alpha.1 pnpm/npm install lavaclient@alpha yarn add lavaclient@alpha
D
DaStormer250d ago
yep, still using lavaclient, thanks for the update i'll check it out soon
V
viztea240d ago
@lavaclient user Plugin Updates 2 new plugins are being added to the family (but i have yet to publish them) Simplified Filter Management Allows for easier filter management through "effects"
import { type PlayerEffect, load } from "@lavaclient/plugin-effects";

load()

const nightcore: PlayerEffect = {
id: "nightcore",
filters: {
timescale: { rate: 1.123456789 },
},
};

const slowed: PlayerEffect = {
id: "slowed",
filters: {
timescale: { rate: 0.75 },
},
};

// 1.
await player.effects.toggle(nightcore);

// 2.
await player.effects.toggle(slowed);
import { type PlayerEffect, load } from "@lavaclient/plugin-effects";

load()

const nightcore: PlayerEffect = {
id: "nightcore",
filters: {
timescale: { rate: 1.123456789 },
},
};

const slowed: PlayerEffect = {
id: "slowed",
filters: {
timescale: { rate: 0.75 },
},
};

// 1.
await player.effects.toggle(nightcore);

// 2.
await player.effects.toggle(slowed);
1. This will apply 'nightcore' and any previously toggled effects. 2. Since 'nightcore' and 'slowed' both use the timescale filter the plugin will automatically disable 'nightcore' and keep 'slowed' Better LavaSearch Integration Better API client integration with the LavaSearch plugin by Topi
import "@lavaclient/plugin-lavasearch/register";

// 1.
await node.api.loadSearch("spsearch:Odetari", "track", "artist", "album");

// 2.
await node.api.loadSearchOrNull("spsearch:Odetari", "track", "artist", "album");
import "@lavaclient/plugin-lavasearch/register";

// 1.
await node.api.loadSearch("spsearch:Odetari", "track", "artist", "album");

// 2.
await node.api.loadSearchOrNull("spsearch:Odetari", "track", "artist", "album");
1. Loads a LavaSearch result with tracks, artists, and albums. Throws an exception if nothing was found. 2. Does the same thing as 1 but returns null if nothing was found. Misc. - The queue plugin is also getting a rework. - If Topi finishes the LavaQueue lavalink plugin I may write an integration plugin Other Updates - Clustering has been implemented - LavalinkAPIClient has been renamed to LavalinkHTTPClient
M
max240d ago
👍 lgtm
V
viztea70d ago
@lavaclient user https://www.npmjs.com/package/lavaclient/v/5.0.0-rc.1 lavalink-protocol & lavalink-api/ws-client all have 1.0 releases now, plugins are still a wip
npm
lavaclient
A simple, easy-to-use, and flexible lavalink client for node.js. Latest version: 4.1.1, last published: 2 years ago. Start using lavaclient in your project by running npm i lavaclient. There are no other projects in the npm registry using lavaclient.
B
Bloxs70d ago
all of those errors are now fixed, now I just need to fix my play cmd as everythings broken :SadCat2:
V
viztea54d ago
oh and I want to add cluster-wide config for stuff like ws & api options @lavaclient user active v5 users i want to know if you've had any problems migrating or experienced any bugs/issues with the new api oh yeah react with the emoji if you read this message btw
M
max52d ago
@gino i assume there's no way to use lavaclient v5 in conjunction with the queue plugin at this moment?
V
viztea52d ago
no but i can port it real quick
M
max52d ago
ah that'd be great, i've finished migrating to lavaclient v5 but the only thing stopping it from working is the queue LOL
V
viztea52d ago
lavaclient & lavalink-protocol will get two new versions along side this port @lavaclient user released updates to some packages lavaclient@5.0.0-rc.2 switched from typed-emitter to tiny-typed-emitter so that plugins could add events lavalink-protocol@1.0.1 added mayStartNext object
M
max52d ago
sick
V
viztea52d ago
and for those who use the queue plugin, an almost compatible port is available at @lavaclient/plugin-queue the 1.0 will use the new userData track field and have some general improvements
M
max52d ago
👌 tysm
B
Bloxs52d ago
you guys have it easy with pre made queue plugins, I had to make my own bad queue system
V
viztea52d ago
it's not even that good tbh
B
Bloxs52d ago
probably better than mine
M
max52d ago
@gino oh yeah is the spotify plugin gonna be made compatible too?
V
viztea52d ago
no use lavasrc
M
max52d ago
👍
V
viztea52d ago
i might make a plugin like lavasrc for client side stuff if people don’t know java but it won’t have anything built in
M
max52d ago
i've managed to get everything ported over, looks good so far but i'm just getting ERR_MODULE_NOT_FOUND for import '@lavaclient/plugin-queue/register'; now
V
viztea52d ago
:hmm: are you using esm?
M
max52d ago
yup
V
viztea52d ago
that may be why i don't have esm exports
M
max52d ago
ah i see
V
viztea52d ago
:ImDead: erm you can try to load it manually, there's a load export
M
max52d ago
gotcha lemme give that a shot aight thanks man i think it worked but just some issues with my code now
V
viztea52d ago
why can't i delete that 💀 discord moment
R
redbuls81.py51d ago
Did you solve this error?
V
viztea51d ago
.
M
max51d ago
yea i did, idk whats up with my code now but the queue refuses to start hm
V
viztea51d ago
i didn't really do an extensive test, but I assumed everything was fine since this code worked
M
max51d ago
ah wth ty for that LOL i was still using Node#createPlayer which was able to create the player but queue refused to start switching to PlayerManager#create fixed it
V
viztea51d ago
createplayer should be private ? well its marked as internal hmmmm maybe i should make it clearer that
M
max51d ago
hmm im not sure, ts wasn't saying anything and it was still working but ty! works fine now i've ported to v5
V
viztea51d ago
well its public for people who want to change what player class is used but its only meant for internal use
M
max51d ago
ah i see
V
viztea51d ago
iydmma, are you porting quaver?
M
max50d ago
sorry i missed your message, yep i've been busy the past few months but i have some free time at the moment and youtube was constantly throwing errors for the last lavalink version so i upgraded lavalink and ported to lavaclient v5
V
viztea50d ago
https://github.com/ZPTXDev/Quaver/blob/master/src/lib/PlayerHandler.ts#L270-L273 lmao i should improve the effects api it's basically a port of @Keia Development's effect management stuff and I haven't had to explicitly "set" an effect's state
M
max50d ago
LMFAO i was writing bandaid solutions at that point i just wanted to get everything working cuz quaver was non-functional for like 2 or 3 days at that point ahh i see, makes sense
V
viztea50d ago
V
viztea50d ago
wait i do allow explicitly oops ahahahaah that's funny ok
M
max50d ago
LOL
V
viztea50d ago
i have no excuses then
M
max50d ago
ahem it's alright i mean as long as it gets the job done i was planning to rewrite quaver for some time actually but never found the time for it
V
viztea50d ago
this is why everything is a release candidate rn
M
max50d ago
mhm mhm makes sense
V
viztea50d ago
the client itself seems fine though
M
max50d ago
yup, so far no issues whatsoever i think it's all good i like the better defined properties in v5 everything makes more sense
V
viztea50d ago
that was the goal :Tired: the new packages help a lot too, i spent quite a bit of time on the lavalink api, ws, and protocol packages everything is type-safe and validated at runtime
M
max50d ago
i think the effort paid off, everything just works™️
V
viztea50d ago
now you just gotta fix the site
M
max50d ago
yeah LOL i got an issue with that it's not really a code issue but rather cert issue also turns out i forgot to load the effects plugin in my port whoops fixed it and nightcore works but seems like bassboost isn't working
V
viztea50d ago
makes sense
M
max50d ago
2024-03-14T08:35:08.860Z ERROR Quaver Unable to encode request body
LavalinkHTTPError: Unable to encode request body
at D:\ZPTX Dev\Quaver\node_modules\lavalink-api-client\dist\endpoint\factory.js:42:19
at PlayerAPI.update (D:\ZPTX Dev\Quaver\node_modules\lavalink-api-client\dist\api\player.js:33:51)
at Player.update (D:\ZPTX Dev\Quaver\node_modules\lavaclient\dist\player.js:97:37)
at Player.setFilters (D:\ZPTX Dev\Quaver\node_modules\lavaclient\dist\player.js:78:25)
at PlayerEffectManager.apply (D:\ZPTX Dev\Quaver\node_modules\@lavaclient\plugin-effects\dist\effects.js:51:27)
at PlayerEffectManager.toggle (D:\ZPTX Dev\Quaver\node_modules\@lavaclient\plugin-effects\dist\effects.js:39:20)
at PlayerHandler.bassboost (file:///D:/ZPTX%20Dev/Quaver/dist/lib/PlayerHandler.js:190:52)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.execute (file:///D:/ZPTX%20Dev/Quaver/dist/commands/bassboost.js:26:26)
2024-03-14T08:35:08.860Z ERROR Quaver Unable to encode request body
LavalinkHTTPError: Unable to encode request body
at D:\ZPTX Dev\Quaver\node_modules\lavalink-api-client\dist\endpoint\factory.js:42:19
at PlayerAPI.update (D:\ZPTX Dev\Quaver\node_modules\lavalink-api-client\dist\api\player.js:33:51)
at Player.update (D:\ZPTX Dev\Quaver\node_modules\lavaclient\dist\player.js:97:37)
at Player.setFilters (D:\ZPTX Dev\Quaver\node_modules\lavaclient\dist\player.js:78:25)
at PlayerEffectManager.apply (D:\ZPTX Dev\Quaver\node_modules\@lavaclient\plugin-effects\dist\effects.js:51:27)
at PlayerEffectManager.toggle (D:\ZPTX Dev\Quaver\node_modules\@lavaclient\plugin-effects\dist\effects.js:39:20)
at PlayerHandler.bassboost (file:///D:/ZPTX%20Dev/Quaver/dist/lib/PlayerHandler.js:190:52)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.execute (file:///D:/ZPTX%20Dev/Quaver/dist/commands/bassboost.js:26:26)
hm
V
viztea50d ago
there are only 14 bands
V
viztea50d ago
GitHub
Quaver/src/lib/PlayerHandler.ts at master · ZPTXDev/Quaver
Simple-to-use music bot with features such as bass boost, nightcore, seek, search, and more. - ZPTXDev/Quaver
V
viztea50d ago
should be length: 9 :SmileyCat: runtime validation at work
M
max50d ago
ah ty LOL
V
viztea50d ago
your logger could use some work i think the validation error is the error cause but it doesn't seem to have been rendered
M
max50d ago
yeah i'll rework it in my rewrite as for this it's just that i'm using letsencrypt's certs and they renew every 3 months or so, i needa symlink the cert to quaver's container but that's not quite possible (at least from what i've tried) so yeah it's quite a pain im also sure there's way better ways for me to do what im doing but i have not had time to figure any of that out unfortunately
V
viztea50d ago
yeah fair that's why i use a reverse proxy that does it for me traefik my beloved
M
max50d ago
i'll have to look into that sometime length 9 still didn't fix it tho hm strange
V
viztea50d ago
you build ?
M
max50d ago
yep the js shows 9 too
V
viztea50d ago
my bad there are 15 bands 14 is the highest index :Lols:
M
max50d ago
oh LOL hmm
V
viztea50d ago
M
max50d ago
ah.
V
viztea50d ago
...(Array.from({ length: 10 }).map(
(_, i): { band: number; gain: number } => ({
band: i + 5,
gain: -0.05,
}),
)),
...(Array.from({ length: 10 }).map(
(_, i): { band: number; gain: number } => ({
band: i + 5,
gain: -0.05,
}),
)),
M
max50d ago
yep that fixed it, thanks! not the first time i've messed that up 😔
V
viztea50d ago
:Nice:
R
redbuls81.py49d ago
@lavaclient/plugin-lavasearch has esm support but I can't use the loadSearch function : interactionRun: guild.client.music.api.loadSearch is not a function
R
redbuls81.py49d ago
Yes, I loaded it, but I cannot access the function.
require("@lavaclient/plugin-lavasearch/register");
const pluginQueue = require("@lavaclient/plugin-queue");
pluginQueue.load();
const pluginEffects = require("@lavaclient/plugin-effects");
pluginEffects.load();
require("@lavaclient/plugin-lavasearch/register");
const pluginQueue = require("@lavaclient/plugin-queue");
pluginQueue.load();
const pluginEffects = require("@lavaclient/plugin-effects");
pluginEffects.load();
V
viztea49d ago
one sec create a post