Compare commits
2 commits
589997c29e
...
e1fdc954ce
Author | SHA1 | Date | |
---|---|---|---|
e1fdc954ce | |||
a2ce58010a |
3 changed files with 21 additions and 25 deletions
|
@ -36,7 +36,7 @@ version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_
|
|||
?: "6.5.1"
|
||||
|
||||
val kordver = "1.7.1-SNAPSHOT"
|
||||
val lavaver = "4.0.0"
|
||||
val lavaver = "6.0.0"
|
||||
val coroutinesver = "1.1.0"
|
||||
|
||||
val mavenArtifact = "Botendo"
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue