Skip to content

Commit

Permalink
fix: play request
Browse files Browse the repository at this point in the history
This commit fixes play request method, as it would fail on NodeLink because it's marked as deprecated by LavaLink.
  • Loading branch information
ThePedroo committed Dec 31, 2023
1 parent 4246db2 commit a0d2c0c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = FastLink
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 2.3.5
PROJECT_NUMBER = 2.3.6

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
26 changes: 21 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,24 +154,36 @@ client.on('messageCreate', async (message) => {
return;
}

if (track.loadType == 'playlist') {
player.update({ encodedTracks: track.data.tracks.map((track) => track.encoded) })
if ([ 'playlist', 'album', 'station' ].includes(track.loadType)) {
player.update({
tracks: {
encodeds: track.data.tracks.map((track) => track.encoded)
}
})

message.channel.send(`Added ${track.data.tracks.length} songs to the queue, and playing ${track.data.tracks[0].info.title}.`)

return;
}

if (track.loadType == 'track' || track.loadType == 'short') {
player.update({ encodedTrack: track.data.encoded, })
player.update({
track: {
encoded: track.data.encoded
}
})

message.channel.send(`Playing ${track.data.info.title} from ${track.data.info.sourceName} from url search.`)

return;
}

if (track.loadType == 'search') {
player.update({ encodedTrack: track.data[0].encoded })
player.update({
track: {
encoded: track.data[0].encoded
}
})

message.channel.send(`Playing ${track.data[0].info.title} from ${track.data[0].info.sourceName} from search.`)

Expand Down Expand Up @@ -255,7 +267,11 @@ client.on('messageCreate', async (message) => {
return;
}

player.update({ encodedTrack: null })
player.update({
track: {
encoded: null
}
})

message.channel.send('Stopped the player.')

Expand Down
30 changes: 20 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function connectNodes(nodes, config) {
Authorization: node.password,
'Num-Shards': config.shards,
'User-Id': config.botId,
'Client-Name': 'FastLink/2.3.5'
'Client-Name': 'FastLink/2.3.6'
}
})

Expand Down Expand Up @@ -243,24 +243,30 @@ class Player {
if (!body) throw new Error('No body provided.')
if (typeof body != 'object') throw new Error('Body must be an object.')

if (body.encodedTrack && Config.queue) {
Players[this.guildId].queue.push(body.encodedTrack)
if (body.track?.encoded && Config.queue) {
Players[this.guildId].queue.push(body.track.encoded)

if (Players[this.guildId].queue.length != 1) return;
} else if (body.encodedTrack !== undefined) Players[this.guildId].queue = []
} else if (body.track?.encoded === null) Players[this.guildId].queue = []

if (body.encodedTracks) {
if (body.tracks?.encodeds) {
if (!Config.queue)
throw new Error('Queue is disabled.')

if (Players[this.guildId].queue.length == 0) {
Players[this.guildId].queue = body.encodedTracks
Players[this.guildId].queue = body.tracks.encodeds

this.makeRequest(`/sessions/${Nodes[this.node].sessionId}/players/${this.guildId}`, {
body: { encodedTrack: body.encodedTracks[0] },
body: {
...body,
track: {
...body.track,
encoded: body.tracks.encodeds[0]
}
},
method: 'PATCH'
})
} else body.encodedTracks.forEach((track) => Players[this.guildId].queue.push(track))
} else Players[this.guildId].queue.push(...body.tracks.encodeds)

return;
}
Expand Down Expand Up @@ -330,7 +336,11 @@ class Player {
Players[this.guildId].queue.shift()

this.makeRequest(`/sessions/${Nodes[this.node].sessionId}/players/${this.guildId}`, {
body: { encodedTrack: Players[this.guildId].queue[0] },
body: {
track: {
encoded: Players[this.guildId].queue[0]
}
},
method: 'PATCH'
})

Expand Down Expand Up @@ -383,7 +393,7 @@ class Player {
Authorization: Nodes[this.node].password,
'user-id': Config.botId,
'guild-id': this.guildId,
'Client-Name': 'FastLink/2.3.5'
'Client-Name': 'FastLink/2.3.6'
}
})

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@performanc/fastlink",
"version": "2.3.5",
"version": "2.3.6",
"description": "Low-level Lavalink/NodeLink wrapper.",
"main": "index.js",
"type": "module",
Expand Down

0 comments on commit a0d2c0c

Please sign in to comment.