Compare commits

...

2 commits

Author SHA1 Message Date
e1fdc954ce
WIP: started working on fixing errors 2023-12-13 15:15:29 +01:00
a2ce58010a
chore: bump lavakord version 2023-12-13 15:15:13 +01:00
3 changed files with 21 additions and 25 deletions

View file

@ -36,7 +36,7 @@ version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_
?: "6.5.1" ?: "6.5.1"
val kordver = "1.7.1-SNAPSHOT" val kordver = "1.7.1-SNAPSHOT"
val lavaver = "4.0.0" val lavaver = "6.0.0"
val coroutinesver = "1.1.0" val coroutinesver = "1.1.0"
val mavenArtifact = "Botendo" val mavenArtifact = "Botendo"

View file

@ -19,21 +19,21 @@
package net.moonleay.botendo.extensions.music.components package net.moonleay.botendo.extensions.music.components
import dev.arbjerg.lavalink.protocol.v4.LoadResult
import dev.schlaubi.lavakord.audio.* import dev.schlaubi.lavakord.audio.*
import dev.schlaubi.lavakord.audio.player.Player import dev.schlaubi.lavakord.audio.player.Player
import dev.schlaubi.lavakord.rest.models.PartialTrack
import net.moonleay.botendo.util.Logger import net.moonleay.botendo.util.Logger
import java.util.concurrent.BlockingQueue import java.util.concurrent.BlockingQueue
import java.util.concurrent.LinkedBlockingQueue import java.util.concurrent.LinkedBlockingQueue
class GuildTrackScheduler(val pl: Player) { class GuildTrackScheduler(val pl: Player) {
private var queue: BlockingQueue<PartialTrack> = LinkedBlockingQueue() private var queue: BlockingQueue<LoadResult> = LinkedBlockingQueue()
var repeating = false var repeating = false
private var hasRegisteredEvents = false private var hasRegisteredEvents = false
///Add a track to queue and start playing, if there is no song currently playing ///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) { if (this.pl.playingTrack == null) {
play(track) play(track)
return return
@ -44,7 +44,7 @@ class GuildTrackScheduler(val pl: Player) {
} }
MusicManager.AddType.UPSERT -> { MusicManager.AddType.UPSERT -> {
val nq = LinkedBlockingQueue<PartialTrack>() val nq = LinkedBlockingQueue<LoadResult>()
nq.offer(track) nq.offer(track)
for (t in queue.toList()) { for (t in queue.toList()) {
nq.offer(t) nq.offer(t)
@ -56,7 +56,7 @@ class GuildTrackScheduler(val pl: Player) {
suspend fun playNext(link: Link) { suspend fun playNext(link: Link) {
if (!queue.isEmpty()) if (!queue.isEmpty())
this.pl.playTrack(queue.poll()) this.pl.playTrack(track = queue.poll().data)
else { else {
this.pl.stopTrack() this.pl.stopTrack()
link.destroy() link.destroy()
@ -64,8 +64,8 @@ class GuildTrackScheduler(val pl: Player) {
} }
} }
private suspend fun play(tr: PartialTrack) { private suspend fun play(trd: LoadResult) {
this.pl.playTrack(tr) this.pl.playTrack(track = trd.data)
} }
fun addEvents() { fun addEvents() {
@ -92,7 +92,7 @@ class GuildTrackScheduler(val pl: Player) {
if (e.reason.mayStartNext) { if (e.reason.mayStartNext) {
if (repeating) { if (repeating) {
Logger.out("Repeating track...") Logger.out("Repeating track...")
this.pl.playTrack(e.getTrack().copy()) this.pl.playTrack(e.track.copy())
return return
} }
Logger.out("Track has ended; Playing next...") Logger.out("Track has ended; Playing next...")
@ -102,12 +102,12 @@ class GuildTrackScheduler(val pl: Player) {
private suspend fun onTrackStuck(e: TrackStuckEvent) { private suspend fun onTrackStuck(e: TrackStuckEvent) {
Logger.out("Track is stuck, retrying...") Logger.out("Track is stuck, retrying...")
this.pl.playTrack(e.getTrack().copy()) this.pl.playTrack(e.track.copy())
} }
private suspend fun onTrackExc(e: TrackExceptionEvent) { private suspend fun onTrackExc(e: TrackExceptionEvent) {
Logger.out("Track had an exception, retrying...") Logger.out("Track had an exception, retrying...")
this.pl.playTrack(e.getTrack().copy()) this.pl.playTrack(e.track.copy())
} }
fun clear() { fun clear() {
@ -116,11 +116,11 @@ class GuildTrackScheduler(val pl: Player) {
queue.clear() queue.clear()
} }
fun getQueue(): List<PartialTrack> { fun getQueue(): List<LoadResult> {
return queue.toList() return queue.toList()
} }
fun getHead(): PartialTrack { fun getHead(): LoadResult {
return queue.first() 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.commands.application.slash.PublicSlashCommandContext
import com.kotlindiscord.kord.extensions.components.forms.ModalForm import com.kotlindiscord.kord.extensions.components.forms.ModalForm
import dev.arbjerg.lavalink.protocol.v4.ResultStatus
import dev.kord.common.Color import dev.kord.common.Color
import dev.kord.common.entity.Snowflake import dev.kord.common.entity.Snowflake
import dev.kord.core.entity.Guild import dev.kord.core.entity.Guild
import dev.kord.rest.builder.component.ActionRowBuilder import dev.kord.rest.builder.component.ActionRowBuilder
import dev.kord.rest.builder.message.actionRow import dev.kord.rest.builder.message.actionRow
import dev.kord.rest.builder.message.create.actionRow
import dev.kord.rest.builder.message.embed import dev.kord.rest.builder.message.embed
import dev.schlaubi.lavakord.audio.Link import dev.schlaubi.lavakord.audio.Link
import dev.schlaubi.lavakord.audio.player.Player import dev.schlaubi.lavakord.audio.player.Player
import dev.schlaubi.lavakord.rest.loadItem import dev.schlaubi.lavakord.rest.loadItem
import dev.schlaubi.lavakord.rest.models.TrackResponse
import net.moonleay.botendo.util.* import net.moonleay.botendo.util.*
object MusicManager { object MusicManager {
@ -74,9 +73,10 @@ object MusicManager {
gts.addEvents() gts.addEvents()
when (item.loadType) { when (item.loadType) {
TrackResponse.LoadType.TRACK_LOADED -> { ResultStatus.TRACK -> {
gts.queue(item.track, type) gts.queue(item, type)
if (!silent) if (!silent)
ctx.respond { ctx.respond {
this.embed { this.embed {
@ -107,8 +107,7 @@ object MusicManager {
}) })
} }
} }
ResultStatus.PLAYLIST -> {
TrackResponse.LoadType.PLAYLIST_LOADED -> {
val l = item.tracks.reversed() val l = item.tracks.reversed()
for (partialTrack in l) { for (partialTrack in l) {
gts.queue(partialTrack, type) gts.queue(partialTrack, type)
@ -143,8 +142,7 @@ object MusicManager {
} }
} }
} }
ResultStatus.SEARCH -> {
TrackResponse.LoadType.SEARCH_RESULT -> {
gts.queue(item.tracks.first(), type) gts.queue(item.tracks.first(), type)
if (!silent) if (!silent)
ctx.respond { ctx.respond {
@ -176,8 +174,7 @@ object MusicManager {
} }
} }
} }
ResultStatus.NONE -> {
TrackResponse.LoadType.NO_MATCHES -> {
if (!silent) if (!silent)
ctx.respond { ctx.respond {
this.embed { this.embed {
@ -190,8 +187,7 @@ object MusicManager {
} }
} }
} }
ResultStatus.ERROR -> {
TrackResponse.LoadType.LOAD_FAILED -> {
if (!silent) if (!silent)
ctx.respond { ctx.respond {
this.embed { this.embed {