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"
|
?: "6.5.1"
|
||||||
|
|
||||||
val kordver = "1.7.1-SNAPSHOT"
|
val kordver = "1.7.1-SNAPSHOT"
|
||||||
val lavaver = "6.0.0"
|
val lavaver = "4.0.0"
|
||||||
val coroutinesver = "1.1.0"
|
val coroutinesver = "1.1.0"
|
||||||
|
|
||||||
val mavenArtifact = "Botendo"
|
val mavenArtifact = "Botendo"
|
||||||
|
|
|
@ -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<LoadResult> = LinkedBlockingQueue()
|
private var queue: BlockingQueue<PartialTrack> = 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: LoadResult, type: MusicManager.AddType) {
|
suspend fun queue(track: PartialTrack, 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<LoadResult>()
|
val nq = LinkedBlockingQueue<PartialTrack>()
|
||||||
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(track = queue.poll().data)
|
this.pl.playTrack(queue.poll())
|
||||||
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(trd: LoadResult) {
|
private suspend fun play(tr: PartialTrack) {
|
||||||
this.pl.playTrack(track = trd.data)
|
this.pl.playTrack(tr)
|
||||||
}
|
}
|
||||||
|
|
||||||
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.track.copy())
|
this.pl.playTrack(e.getTrack().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.track.copy())
|
this.pl.playTrack(e.getTrack().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.track.copy())
|
this.pl.playTrack(e.getTrack().copy())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clear() {
|
fun clear() {
|
||||||
|
@ -116,11 +116,11 @@ class GuildTrackScheduler(val pl: Player) {
|
||||||
queue.clear()
|
queue.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getQueue(): List<LoadResult> {
|
fun getQueue(): List<PartialTrack> {
|
||||||
return queue.toList()
|
return queue.toList()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getHead(): LoadResult {
|
fun getHead(): PartialTrack {
|
||||||
return queue.first()
|
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.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 {
|
||||||
|
@ -73,10 +74,9 @@ object MusicManager {
|
||||||
|
|
||||||
gts.addEvents()
|
gts.addEvents()
|
||||||
|
|
||||||
|
|
||||||
when (item.loadType) {
|
when (item.loadType) {
|
||||||
ResultStatus.TRACK -> {
|
TrackResponse.LoadType.TRACK_LOADED -> {
|
||||||
gts.queue(item, type)
|
gts.queue(item.track, type)
|
||||||
if (!silent)
|
if (!silent)
|
||||||
ctx.respond {
|
ctx.respond {
|
||||||
this.embed {
|
this.embed {
|
||||||
|
@ -107,7 +107,8 @@ 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)
|
||||||
|
@ -142,7 +143,8 @@ 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 {
|
||||||
|
@ -174,7 +176,8 @@ object MusicManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ResultStatus.NONE -> {
|
|
||||||
|
TrackResponse.LoadType.NO_MATCHES -> {
|
||||||
if (!silent)
|
if (!silent)
|
||||||
ctx.respond {
|
ctx.respond {
|
||||||
this.embed {
|
this.embed {
|
||||||
|
@ -187,7 +190,8 @@ object MusicManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ResultStatus.ERROR -> {
|
|
||||||
|
TrackResponse.LoadType.LOAD_FAILED -> {
|
||||||
if (!silent)
|
if (!silent)
|
||||||
ctx.respond {
|
ctx.respond {
|
||||||
this.embed {
|
this.embed {
|
||||||
|
|
Loading…
Reference in a new issue