Compare commits
No commits in common. "e1fdc954ce16e7df36e990ac390ce86262e6c185" and "589997c29ef99f5f6efb48d8fba4b27ce53ef402" have entirely different histories.
e1fdc954ce
...
589997c29e
3 changed files with 25 additions and 21 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 = "6.0.0"
|
||||
val lavaver = "4.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<LoadResult> = LinkedBlockingQueue()
|
||||
private var queue: BlockingQueue<PartialTrack> = 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: LoadResult, type: MusicManager.AddType) {
|
||||
suspend fun queue(track: PartialTrack, 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<LoadResult>()
|
||||
val nq = LinkedBlockingQueue<PartialTrack>()
|
||||
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(track = queue.poll().data)
|
||||
this.pl.playTrack(queue.poll())
|
||||
else {
|
||||
this.pl.stopTrack()
|
||||
link.destroy()
|
||||
|
@ -64,8 +64,8 @@ class GuildTrackScheduler(val pl: Player) {
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun play(trd: LoadResult) {
|
||||
this.pl.playTrack(track = trd.data)
|
||||
private suspend fun play(tr: PartialTrack) {
|
||||
this.pl.playTrack(tr)
|
||||
}
|
||||
|
||||
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.track.copy())
|
||||
this.pl.playTrack(e.getTrack().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.track.copy())
|
||||
this.pl.playTrack(e.getTrack().copy())
|
||||
}
|
||||
|
||||
private suspend fun onTrackExc(e: TrackExceptionEvent) {
|
||||
Logger.out("Track had an exception, retrying...")
|
||||
this.pl.playTrack(e.track.copy())
|
||||
this.pl.playTrack(e.getTrack().copy())
|
||||
}
|
||||
|
||||
fun clear() {
|
||||
|
@ -116,11 +116,11 @@ class GuildTrackScheduler(val pl: Player) {
|
|||
queue.clear()
|
||||
}
|
||||
|
||||
fun getQueue(): List<LoadResult> {
|
||||
fun getQueue(): List<PartialTrack> {
|
||||
return queue.toList()
|
||||
}
|
||||
|
||||
fun getHead(): LoadResult {
|
||||
fun getHead(): PartialTrack {
|
||||
return queue.first()
|
||||
}
|
||||
|
||||
|
|
|
@ -21,16 +21,17 @@ 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 {
|
||||
|
@ -73,10 +74,9 @@ object MusicManager {
|
|||
|
||||
gts.addEvents()
|
||||
|
||||
|
||||
when (item.loadType) {
|
||||
ResultStatus.TRACK -> {
|
||||
gts.queue(item, type)
|
||||
TrackResponse.LoadType.TRACK_LOADED -> {
|
||||
gts.queue(item.track, type)
|
||||
if (!silent)
|
||||
ctx.respond {
|
||||
this.embed {
|
||||
|
@ -107,7 +107,8 @@ object MusicManager {
|
|||
})
|
||||
}
|
||||
}
|
||||
ResultStatus.PLAYLIST -> {
|
||||
|
||||
TrackResponse.LoadType.PLAYLIST_LOADED -> {
|
||||
val l = item.tracks.reversed()
|
||||
for (partialTrack in l) {
|
||||
gts.queue(partialTrack, type)
|
||||
|
@ -142,7 +143,8 @@ object MusicManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
ResultStatus.SEARCH -> {
|
||||
|
||||
TrackResponse.LoadType.SEARCH_RESULT -> {
|
||||
gts.queue(item.tracks.first(), type)
|
||||
if (!silent)
|
||||
ctx.respond {
|
||||
|
@ -174,7 +176,8 @@ object MusicManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
ResultStatus.NONE -> {
|
||||
|
||||
TrackResponse.LoadType.NO_MATCHES -> {
|
||||
if (!silent)
|
||||
ctx.respond {
|
||||
this.embed {
|
||||
|
@ -187,7 +190,8 @@ object MusicManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
ResultStatus.ERROR -> {
|
||||
|
||||
TrackResponse.LoadType.LOAD_FAILED -> {
|
||||
if (!silent)
|
||||
ctx.respond {
|
||||
this.embed {
|
||||
|
|
Loading…
Reference in a new issue