Compare commits
No commits in common. "acefe1b71239fa8bf055c961b72c7d2e6b220653" and "589997c29ef99f5f6efb48d8fba4b27ce53ef402" have entirely different histories.
acefe1b712
...
589997c29e
9 changed files with 79 additions and 86 deletions
|
@ -35,10 +35,9 @@ version = System.getenv("CI_COMMIT_TAG")?.let { "$it-${System.getenv("CI_COMMIT_
|
|||
?: System.getenv("CI_COMMIT_SHORT_SHA")?.let { "$it-dev" }
|
||||
?: "6.5.1"
|
||||
|
||||
val kordext_ver = "1.7.1-SNAPSHOT"
|
||||
val lavakord_ver = "6.0.0"
|
||||
val coroutines_ver = "1.7.3"
|
||||
val slf4j_ver = "2.0.9"
|
||||
val kordver = "1.7.1-SNAPSHOT"
|
||||
val lavaver = "4.0.0"
|
||||
val coroutinesver = "1.1.0"
|
||||
|
||||
val mavenArtifact = "Botendo"
|
||||
project.base.archivesName.set(mavenArtifact)
|
||||
|
@ -87,15 +86,15 @@ implementation.extendsFrom(shadow)
|
|||
|
||||
dependencies {
|
||||
//Discord
|
||||
shadow("com.kotlindiscord.kord.extensions:kord-extensions:$kordext_ver")
|
||||
shadow("dev.schlaubi.lavakord:kord:$lavakord_ver")
|
||||
shadow("com.kotlindiscord.kord.extensions:kord-extensions:$kordver")
|
||||
shadow("dev.schlaubi.lavakord:kord:$lavaver")
|
||||
|
||||
//Util
|
||||
shadow("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_ver")
|
||||
shadow("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesver")
|
||||
|
||||
//Logging
|
||||
shadow("org.slf4j:slf4j-api:$slf4j_ver")
|
||||
shadow("org.slf4j:slf4j-simple:$slf4j_ver")
|
||||
shadow("org.slf4j:slf4j-api:2.0.3")
|
||||
shadow("org.slf4j:slf4j-simple:2.0.3")
|
||||
}
|
||||
|
||||
|
||||
|
@ -105,9 +104,9 @@ val templateDest = project.buildDir.resolve("generated/templates")
|
|||
val templateProps = mapOf(
|
||||
"version" to project.version as String,
|
||||
"ownerID" to ownerID,
|
||||
"kordversion" to kordext_ver,
|
||||
"lavaversion" to lavakord_ver,
|
||||
"coroutinesversion" to coroutines_ver
|
||||
"kordversion" to kordver,
|
||||
"lavaversion" to lavaver,
|
||||
"coroutinesversion" to coroutinesver
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -58,7 +58,8 @@ class QueueButton : net.moonleay.botendo.buttons.Button("btn.music.queue") {
|
|||
return
|
||||
}
|
||||
|
||||
if (player.playingTrack == null) {
|
||||
val track = player.playingTrack
|
||||
if (track == null) {
|
||||
response.respond {
|
||||
this.embed {
|
||||
this.color = Color(0xE0311A)
|
||||
|
@ -71,11 +72,10 @@ class QueueButton : net.moonleay.botendo.buttons.Button("btn.music.queue") {
|
|||
}
|
||||
return
|
||||
}
|
||||
val track = player.playingTrack!!.info
|
||||
val gts = MusicManager.getGuildTrackScheduler(guild.asGuild(), player)
|
||||
val q = gts.getQueue()
|
||||
var desc =
|
||||
"""${"**" + track.title + " - " + TimeUtil.getTimeFormatedShortend(track.length)} (${track.author})**""" + "\n"
|
||||
"""${"**" + track.title + " - " + TimeUtil.getTimeFormatedShortend(track.length.inWholeMilliseconds)} (${track.author})**""" + "\n"
|
||||
for ((i, tr) in q.withIndex()) {
|
||||
if (i >= 14)
|
||||
continue
|
||||
|
|
|
@ -83,7 +83,8 @@ class SkipButton : net.moonleay.botendo.buttons.Button("btn.music.skip") {
|
|||
}
|
||||
return
|
||||
}
|
||||
if (player.playingTrack == null) {
|
||||
var track = player.playingTrack
|
||||
if (track == null) {
|
||||
response.respond {
|
||||
this.embed {
|
||||
this.color = Color(0xE0311A)
|
||||
|
@ -96,10 +97,9 @@ class SkipButton : net.moonleay.botendo.buttons.Button("btn.music.skip") {
|
|||
}
|
||||
return
|
||||
}
|
||||
var track = player.playingTrack!!.info
|
||||
val gts = MusicManager.getGuildTrackScheduler(guild.asGuild(), player)
|
||||
if (!gts.isEmpty()) {
|
||||
track = gts.getHead().info
|
||||
track = gts.getHead().toTrack()
|
||||
gts.playNext(link)
|
||||
response.respond {
|
||||
this.embed {
|
||||
|
@ -107,7 +107,7 @@ class SkipButton : net.moonleay.botendo.buttons.Button("btn.music.skip") {
|
|||
this.title = "Skipped song; now playing"
|
||||
this.description = "**${track.title}**\n*Now Playing*\nby ${track.author} :: ${
|
||||
TimeUtil.getTimeFormatedRaw(
|
||||
track.length
|
||||
track.length.inWholeMilliseconds
|
||||
)
|
||||
}\n" +
|
||||
">>>${track.uri}"
|
||||
|
|
|
@ -75,23 +75,21 @@ class NowPlayingExtension : Extension() {
|
|||
this.embed {
|
||||
this.color = Color(0x52E01A)
|
||||
this.title = "Currently playing"
|
||||
this.description = "**${track.info.title}**\n*Now Playing*\nby ${track.info.author} ; ${
|
||||
this.description = "**${track.title}**\n*Now Playing*\nby ${track.author} ; ${
|
||||
TimeUtil.getTimeFormatedRaw(
|
||||
player.position
|
||||
)
|
||||
}: ${
|
||||
TimeUtil.getTimeFormatedRaw(
|
||||
track.info.length
|
||||
track.length.inWholeMilliseconds
|
||||
)
|
||||
}\n" +
|
||||
">>>${track.info.uri}"
|
||||
">>>${track.uri}"
|
||||
this.footer {
|
||||
this.text = MessageUtil.getFooter(u)
|
||||
}
|
||||
if(track.info.uri == null){
|
||||
this.thumbnail {
|
||||
this.url = "https://img.youtube.com/vi/" + UrlUtil.getYtThumbnailUrl(track.info.uri!!) + "/maxresdefault.jpg"
|
||||
}
|
||||
this.url = "https://img.youtube.com/vi/" + UrlUtil.getYtThumbnailUrl(track.uri.toString()) + "/maxresdefault.jpg"
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,6 @@ import com.kotlindiscord.kord.extensions.extensions.Extension
|
|||
import com.kotlindiscord.kord.extensions.extensions.publicSlashCommand
|
||||
import dev.kord.common.Color
|
||||
import dev.kord.rest.builder.component.ActionRowBuilder
|
||||
import dev.kord.rest.builder.message.EmbedBuilder.Limits.title
|
||||
import dev.kord.rest.builder.message.actionRow
|
||||
import dev.kord.rest.builder.message.create.actionRow
|
||||
import dev.kord.rest.builder.message.embed
|
||||
|
@ -75,7 +74,7 @@ class QueueExtension : Extension() {
|
|||
val gts = MusicManager.getGuildTrackScheduler(this.guild!!.asGuild(), player)
|
||||
val q = gts.getQueue()
|
||||
var desc =
|
||||
"""${"**" + track.info.title + " - " + TimeUtil.getTimeFormatedShortend(track.info.length)} (${track.info.author})**""" + "\n"
|
||||
"""${"**" + track.title + " - " + TimeUtil.getTimeFormatedShortend(track.length.inWholeMilliseconds)} (${track.author})**""" + "\n"
|
||||
for ((i, tr) in q.withIndex()) {
|
||||
if (i >= 14)
|
||||
continue
|
||||
|
|
|
@ -82,7 +82,8 @@ class SeekExtension : Extension() {
|
|||
}
|
||||
return@action
|
||||
}
|
||||
if (player.playingTrack == null) {
|
||||
var track = player.playingTrack
|
||||
if (track == null) {
|
||||
this.respond {
|
||||
this.embed {
|
||||
this.color = Color(0xE0311A)
|
||||
|
@ -95,10 +96,9 @@ class SeekExtension : Extension() {
|
|||
}
|
||||
return@action
|
||||
}
|
||||
var track = player.playingTrack!!.info
|
||||
val gts = MusicManager.getGuildTrackScheduler(this.guild!!.asGuild(), player)
|
||||
val targetPos = TimeUtil.getTimeUnformated(this.arguments.position)
|
||||
if (player.playingTrack!!.info.length > targetPos && targetPos >= 0) {
|
||||
if (player.playingTrack!!.length.inWholeMilliseconds > targetPos && targetPos >= 0) {
|
||||
player.seekTo(targetPos)
|
||||
} else {
|
||||
this.respond {
|
||||
|
@ -125,7 +125,7 @@ class SeekExtension : Extension() {
|
|||
)
|
||||
}: ${
|
||||
TimeUtil.getTimeFormatedRaw(
|
||||
track.length
|
||||
track.length.inWholeMilliseconds
|
||||
)
|
||||
}\n" +
|
||||
">>>${track.uri}"
|
||||
|
|
|
@ -82,7 +82,7 @@ class SkipExtension : Extension() {
|
|||
}
|
||||
return@action
|
||||
}
|
||||
var track = player.playingTrack!!.info
|
||||
var track = player.playingTrack
|
||||
if (track == null) {
|
||||
this.respond {
|
||||
this.embed {
|
||||
|
@ -98,7 +98,7 @@ class SkipExtension : Extension() {
|
|||
}
|
||||
val gts = MusicManager.getGuildTrackScheduler(this.guild!!.asGuild(), player)
|
||||
if (!gts.isEmpty()) {
|
||||
track = gts.getHead().info
|
||||
track = gts.getHead().toTrack()
|
||||
gts.playNext(link)
|
||||
} else {
|
||||
player.stopTrack()
|
||||
|
@ -111,7 +111,7 @@ class SkipExtension : Extension() {
|
|||
this.title = "Skipped song; now playing"
|
||||
this.description = "**${track.title}**\n*Now Playing*\nby ${track.author} ;: ${
|
||||
TimeUtil.getTimeFormatedRaw(
|
||||
track.length
|
||||
track.length.inWholeMilliseconds
|
||||
)
|
||||
}\n" +
|
||||
">>>${track.uri}"
|
||||
|
|
|
@ -19,22 +19,21 @@
|
|||
|
||||
package net.moonleay.botendo.extensions.music.components
|
||||
|
||||
import dev.arbjerg.lavalink.protocol.v4.LoadResult
|
||||
import dev.arbjerg.lavalink.protocol.v4.Track
|
||||
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<Track> = 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: Track, type: MusicManager.AddType) {
|
||||
suspend fun queue(track: PartialTrack, type: MusicManager.AddType) {
|
||||
if (this.pl.playingTrack == null) {
|
||||
play(track)
|
||||
return
|
||||
|
@ -45,7 +44,7 @@ class GuildTrackScheduler(val pl: Player) {
|
|||
}
|
||||
|
||||
MusicManager.AddType.UPSERT -> {
|
||||
val nq = LinkedBlockingQueue<Track>()
|
||||
val nq = LinkedBlockingQueue<PartialTrack>()
|
||||
nq.offer(track)
|
||||
for (t in queue.toList()) {
|
||||
nq.offer(t)
|
||||
|
@ -57,7 +56,7 @@ class GuildTrackScheduler(val pl: Player) {
|
|||
|
||||
suspend fun playNext(link: Link) {
|
||||
if (!queue.isEmpty())
|
||||
this.pl.playTrack(track = queue.poll())
|
||||
this.pl.playTrack(queue.poll())
|
||||
else {
|
||||
this.pl.stopTrack()
|
||||
link.destroy()
|
||||
|
@ -65,8 +64,8 @@ class GuildTrackScheduler(val pl: Player) {
|
|||
}
|
||||
}
|
||||
|
||||
private suspend fun play(track: Track) {
|
||||
this.pl.playTrack(track)
|
||||
private suspend fun play(tr: PartialTrack) {
|
||||
this.pl.playTrack(tr)
|
||||
}
|
||||
|
||||
fun addEvents() {
|
||||
|
@ -93,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...")
|
||||
|
@ -103,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() {
|
||||
|
@ -117,11 +116,11 @@ class GuildTrackScheduler(val pl: Player) {
|
|||
queue.clear()
|
||||
}
|
||||
|
||||
fun getQueue(): List<Track> {
|
||||
fun getQueue(): List<PartialTrack> {
|
||||
return queue.toList()
|
||||
}
|
||||
|
||||
fun getHead(): Track {
|
||||
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.LoadResult
|
||||
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 {
|
||||
|
@ -67,32 +68,32 @@ object MusicManager {
|
|||
silent: Boolean
|
||||
) {
|
||||
val player = link.player
|
||||
val item = link.loadItem(search)
|
||||
val gts = getGuildTrackScheduler(ctx.guild!!.asGuild(), player)
|
||||
val u = ctx.user.asUser()
|
||||
|
||||
gts.addEvents()
|
||||
|
||||
when (val itm = link.loadItem(search)) {
|
||||
is LoadResult.TrackLoaded -> {
|
||||
gts.queue(itm.data, type)
|
||||
when (item.loadType) {
|
||||
TrackResponse.LoadType.TRACK_LOADED -> {
|
||||
gts.queue(item.track, type)
|
||||
if (!silent)
|
||||
ctx.respond {
|
||||
this.embed {
|
||||
this.color = Color(0x52E01A)
|
||||
this.title = "${type.s} track from link"
|
||||
this.description = "**${itm.data.info.title}**\n*Queue*\nby ${itm.data.info.author} ;: ${
|
||||
this.description = "**${item.track.info.title}**\n*Queue*\nby ${item.track.info.author} ;: ${
|
||||
TimeUtil.getTimeFormatedRaw(
|
||||
itm.data.info.length
|
||||
item.track.info.length
|
||||
)
|
||||
}\n" +
|
||||
">>>${itm.data.info.uri}"
|
||||
">>>${item.track.info.uri}"
|
||||
this.footer {
|
||||
this.text = MessageUtil.getFooter(u)
|
||||
}
|
||||
if (itm.data.info.uri != null) {
|
||||
this.thumbnail {
|
||||
this.url =
|
||||
"https://img.youtube.com/vi/" + UrlUtil.getYtThumbnailUrl(itm.data.info.uri!!) + "/maxresdefault.jpg"
|
||||
}
|
||||
"https://img.youtube.com/vi/" + UrlUtil.getYtThumbnailUrl(item.track.info.uri) + "/maxresdefault.jpg"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,9 +107,9 @@ object MusicManager {
|
|||
})
|
||||
}
|
||||
}
|
||||
is LoadResult.PlaylistLoaded -> {
|
||||
player.playTrack(track = itm.data.tracks.first())
|
||||
val l= itm.data.tracks.toList().reversed()
|
||||
|
||||
TrackResponse.LoadType.PLAYLIST_LOADED -> {
|
||||
val l = item.tracks.reversed()
|
||||
for (partialTrack in l) {
|
||||
gts.queue(partialTrack, type)
|
||||
}
|
||||
|
@ -117,20 +118,18 @@ object MusicManager {
|
|||
this.embed {
|
||||
this.color = Color(0x52E01A)
|
||||
this.title = "${type.s} playlist from link"
|
||||
this.description = "**${itm.data.tracks.first().info.title}**\n*${itm.data.info.name}*\nby ${itm.data.tracks.first().info.author} ;: ${
|
||||
this.description = "**${item.tracks.first().info.title}**\n*${item.playlistInfo.name}*\nby ${item.tracks.first().info.author} ;: ${
|
||||
TimeUtil.getTimeFormatedRaw(
|
||||
itm.data.tracks.first().info.length
|
||||
item.tracks.first().info.length
|
||||
)
|
||||
}\n" +
|
||||
">>>${itm.data.tracks.first().info.uri}"
|
||||
">>>${item.tracks.first().info.uri}"
|
||||
this.footer {
|
||||
this.text = MessageUtil.getFooter(u)
|
||||
}
|
||||
if (itm.data.tracks.first().info.uri != null) {
|
||||
this.thumbnail {
|
||||
this.url =
|
||||
"https://img.youtube.com/vi/" + UrlUtil.getYtThumbnailUrl(itm.data.tracks.first().info.uri!!) + "/maxresdefault.jpg"
|
||||
}
|
||||
"https://img.youtube.com/vi/" + UrlUtil.getYtThumbnailUrl(item.tracks.first().info.uri) + "/maxresdefault.jpg"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -143,29 +142,27 @@ object MusicManager {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
is LoadResult.SearchResult -> {
|
||||
gts.queue(itm.data.tracks.first(), type)
|
||||
|
||||
TrackResponse.LoadType.SEARCH_RESULT -> {
|
||||
gts.queue(item.tracks.first(), type)
|
||||
if (!silent)
|
||||
ctx.respond {
|
||||
this.embed {
|
||||
this.color = Color(0x52E01A)
|
||||
this.title = "${type.s} track from query"
|
||||
this.description = "**${itm.data.tracks.first().info.title}**\n*Queue*\nby ${itm.data.tracks.first().info.author} ;: ${
|
||||
this.description = "**${item.tracks.first().info.title}**\n*Queue*\nby ${item.tracks.first().info.author} ;: ${
|
||||
TimeUtil.getTimeFormatedRaw(
|
||||
itm.data.tracks.first().info.length
|
||||
item.tracks.first().info.length
|
||||
)
|
||||
}\n" +
|
||||
">>>${itm.data.tracks.first().info.uri}"
|
||||
">>>${item.tracks.first().info.uri}"
|
||||
this.footer {
|
||||
this.text = MessageUtil.getFooter(u)
|
||||
}
|
||||
if (itm.data.tracks.first().info.uri != null) {
|
||||
this.thumbnail {
|
||||
this.url =
|
||||
"https://img.youtube.com/vi/" + UrlUtil.getYtThumbnailUrl(itm.data.tracks.first().info.uri!!) + "/maxresdefault.jpg"
|
||||
}
|
||||
"https://img.youtube.com/vi/" + UrlUtil.getYtThumbnailUrl(item.tracks.first().info.uri) + "/maxresdefault.jpg"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -178,9 +175,9 @@ object MusicManager {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
is LoadResult.NoMatches -> {
|
||||
|
||||
TrackResponse.LoadType.NO_MATCHES -> {
|
||||
if (!silent)
|
||||
ctx.respond {
|
||||
this.embed {
|
||||
|
@ -193,7 +190,8 @@ object MusicManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
is LoadResult.LoadFailed -> {
|
||||
|
||||
TrackResponse.LoadType.LOAD_FAILED -> {
|
||||
if (!silent)
|
||||
ctx.respond {
|
||||
this.embed {
|
||||
|
@ -208,9 +206,9 @@ object MusicManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class AddType(val s: String) {
|
||||
QUEUE("Added"),
|
||||
UPSERT("Upserted")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue