WIP: started working on fixing errors

This commit is contained in:
moonleay 2023-12-13 15:15:29 +01:00
parent a2ce58010a
commit e1fdc954ce
Signed by: moonleay
GPG key ID: 82667543CCD715FB
2 changed files with 20 additions and 24 deletions

View file

@ -19,21 +19,21 @@
package net.moonleay.botendo.extensions.music.components
import dev.arbjerg.lavalink.protocol.v4.LoadResult
import dev.schlaubi.lavakord.audio.*
import dev.schlaubi.lavakord.audio.player.Player
import dev.schlaubi.lavakord.rest.models.PartialTrack
import net.moonleay.botendo.util.Logger
import java.util.concurrent.BlockingQueue
import java.util.concurrent.LinkedBlockingQueue
class GuildTrackScheduler(val pl: Player) {
private var queue: BlockingQueue<PartialTrack> = LinkedBlockingQueue()
private var queue: BlockingQueue<LoadResult> = LinkedBlockingQueue()
var repeating = false
private var hasRegisteredEvents = false
///Add a track to queue and start playing, if there is no song currently playing
suspend fun queue(track: PartialTrack, type: MusicManager.AddType) {
suspend fun queue(track: LoadResult, type: MusicManager.AddType) {
if (this.pl.playingTrack == null) {
play(track)
return
@ -44,7 +44,7 @@ class GuildTrackScheduler(val pl: Player) {
}
MusicManager.AddType.UPSERT -> {
val nq = LinkedBlockingQueue<PartialTrack>()
val nq = LinkedBlockingQueue<LoadResult>()
nq.offer(track)
for (t in queue.toList()) {
nq.offer(t)
@ -56,7 +56,7 @@ class GuildTrackScheduler(val pl: Player) {
suspend fun playNext(link: Link) {
if (!queue.isEmpty())
this.pl.playTrack(queue.poll())
this.pl.playTrack(track = queue.poll().data)
else {
this.pl.stopTrack()
link.destroy()
@ -64,8 +64,8 @@ class GuildTrackScheduler(val pl: Player) {
}
}
private suspend fun play(tr: PartialTrack) {
this.pl.playTrack(tr)
private suspend fun play(trd: LoadResult) {
this.pl.playTrack(track = trd.data)
}
fun addEvents() {
@ -92,7 +92,7 @@ class GuildTrackScheduler(val pl: Player) {
if (e.reason.mayStartNext) {
if (repeating) {
Logger.out("Repeating track...")
this.pl.playTrack(e.getTrack().copy())
this.pl.playTrack(e.track.copy())
return
}
Logger.out("Track has ended; Playing next...")
@ -102,12 +102,12 @@ class GuildTrackScheduler(val pl: Player) {
private suspend fun onTrackStuck(e: TrackStuckEvent) {
Logger.out("Track is stuck, retrying...")
this.pl.playTrack(e.getTrack().copy())
this.pl.playTrack(e.track.copy())
}
private suspend fun onTrackExc(e: TrackExceptionEvent) {
Logger.out("Track had an exception, retrying...")
this.pl.playTrack(e.getTrack().copy())
this.pl.playTrack(e.track.copy())
}
fun clear() {
@ -116,11 +116,11 @@ class GuildTrackScheduler(val pl: Player) {
queue.clear()
}
fun getQueue(): List<PartialTrack> {
fun getQueue(): List<LoadResult> {
return queue.toList()
}
fun getHead(): PartialTrack {
fun getHead(): LoadResult {
return queue.first()
}

View file

@ -21,17 +21,16 @@ package net.moonleay.botendo.extensions.music.components
import com.kotlindiscord.kord.extensions.commands.application.slash.PublicSlashCommandContext
import com.kotlindiscord.kord.extensions.components.forms.ModalForm
import dev.arbjerg.lavalink.protocol.v4.ResultStatus
import dev.kord.common.Color
import dev.kord.common.entity.Snowflake
import dev.kord.core.entity.Guild
import dev.kord.rest.builder.component.ActionRowBuilder
import dev.kord.rest.builder.message.actionRow
import dev.kord.rest.builder.message.create.actionRow
import dev.kord.rest.builder.message.embed
import dev.schlaubi.lavakord.audio.Link
import dev.schlaubi.lavakord.audio.player.Player
import dev.schlaubi.lavakord.rest.loadItem
import dev.schlaubi.lavakord.rest.models.TrackResponse
import net.moonleay.botendo.util.*
object MusicManager {
@ -74,9 +73,10 @@ object MusicManager {
gts.addEvents()
when (item.loadType) {
TrackResponse.LoadType.TRACK_LOADED -> {
gts.queue(item.track, type)
ResultStatus.TRACK -> {
gts.queue(item, type)
if (!silent)
ctx.respond {
this.embed {
@ -107,8 +107,7 @@ object MusicManager {
})
}
}
TrackResponse.LoadType.PLAYLIST_LOADED -> {
ResultStatus.PLAYLIST -> {
val l = item.tracks.reversed()
for (partialTrack in l) {
gts.queue(partialTrack, type)
@ -143,8 +142,7 @@ object MusicManager {
}
}
}
TrackResponse.LoadType.SEARCH_RESULT -> {
ResultStatus.SEARCH -> {
gts.queue(item.tracks.first(), type)
if (!silent)
ctx.respond {
@ -176,8 +174,7 @@ object MusicManager {
}
}
}
TrackResponse.LoadType.NO_MATCHES -> {
ResultStatus.NONE -> {
if (!silent)
ctx.respond {
this.embed {
@ -190,8 +187,7 @@ object MusicManager {
}
}
}
TrackResponse.LoadType.LOAD_FAILED -> {
ResultStatus.ERROR -> {
if (!silent)
ctx.respond {
this.embed {