Compare commits

..

No commits in common. "9b51693a757c3b0a765a515bf22776f98cac5433" and "ae507dc4aa6382689f6a16c6ae033d513e3fb1ed" have entirely different histories.

3 changed files with 3 additions and 52 deletions

View file

@ -21,25 +21,18 @@ package net.moonleay.botendo
import com.kotlindiscord.kord.extensions.ExtensibleBot import com.kotlindiscord.kord.extensions.ExtensibleBot
import dev.kord.common.Color import dev.kord.common.Color
import dev.kord.common.entity.Snowflake
import dev.kord.core.behavior.getChannelOf
import dev.kord.core.behavior.interaction.response.respond import dev.kord.core.behavior.interaction.response.respond
import dev.kord.core.entity.channel.VoiceChannel
import dev.kord.core.event.interaction.ButtonInteractionCreateEvent import dev.kord.core.event.interaction.ButtonInteractionCreateEvent
import dev.kord.core.event.user.VoiceStateUpdateEvent
import dev.kord.core.on import dev.kord.core.on
import dev.kord.rest.builder.message.embed import dev.kord.rest.builder.message.embed
import dev.schlaubi.lavakord.LavaKord import dev.schlaubi.lavakord.LavaKord
import dev.schlaubi.lavakord.audio.Link
import dev.schlaubi.lavakord.kord.getLink
import dev.schlaubi.lavakord.kord.lavakord import dev.schlaubi.lavakord.kord.lavakord
import kotlinx.coroutines.flow.count
import net.moonleay.botendo.data.CredentialManager import net.moonleay.botendo.data.CredentialManager
import net.moonleay.botendo.extensions.music.* import net.moonleay.botendo.extensions.music.*
import net.moonleay.botendo.extensions.music.components.MusicManager
import net.moonleay.botendo.extensions.util.InfoExtension import net.moonleay.botendo.extensions.util.InfoExtension
import net.moonleay.botendo.util.Logger import net.moonleay.botendo.util.Logger
import net.moonleay.botendo.util.MessageUtil import net.moonleay.botendo.util.MessageUtil
import net.moonleay.botendo.util.UserUtil
object Bot { object Bot {
//The kord object gets set at app launch //The kord object gets set at app launch
@ -76,7 +69,7 @@ object Bot {
} }
this.presence { this.presence {
this.streaming("music", "https://twitch.tv/moonleaytv") this.streaming("music", "https://twitch.tv/limited_dev")
} }
} }
@ -98,7 +91,6 @@ object Bot {
b.onInteraction(response, g, u) b.onInteraction(response, g, u)
return@on return@on
} }
// Button not found
response.respond { response.respond {
this.embed { this.embed {
this.color = Color(0xE0311A) this.color = Color(0xE0311A)
@ -111,34 +103,6 @@ object Bot {
} }
} }
// Allow the bot to leave the VC if there are no users in the VC
bot.kordRef.on<VoiceStateUpdateEvent> {
if (this.state.userId == bot.kordRef.selfId) {
// Ignore self
return@on
}
val g = this.state.getGuild().asGuild()
val link = lava.getLink(g.id)
if (link.state != Link.State.CONNECTED) {
// Ignore if not connected
return@on
}
val myChannel = link.lastChannelId!!
if (g.getChannelOrNull(Snowflake(myChannel)) == null) {
// Ignore if channel cannot be found
return@on
}
val ch = g.getChannelOf<VoiceChannel>(Snowflake(myChannel))
if (ch.voiceStates.count() > 1) {
// Ignore if there are other users in the channel
return@on
}
// Stop playing if there are no users in the channel
val pl = MusicManager.getMusicManager(g)!!.pl
pl.stopTrack()
link.destroy()
}
//Start the bot //Start the bot
bot.start() bot.start()
} }

View file

@ -25,7 +25,6 @@ import dev.kord.common.Color
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.kord.getLink import dev.schlaubi.lavakord.kord.getLink
import net.moonleay.botendo.Bot
import net.moonleay.botendo.extensions.music.components.LinkArguments import net.moonleay.botendo.extensions.music.components.LinkArguments
import net.moonleay.botendo.extensions.music.components.MusicManager import net.moonleay.botendo.extensions.music.components.MusicManager
import net.moonleay.botendo.util.MessageUtil import net.moonleay.botendo.util.MessageUtil
@ -42,7 +41,7 @@ class PlayExtension : Extension() {
description = "Play music" description = "Play music"
this.action { this.action {
val guildId = this.guild!!.id val guildId = this.guild!!.id
val link = Bot.lava.getLink(guildId) val link = net.moonleay.botendo.Bot.lava.getLink(guildId)
val u = this.user val u = this.user
val vcsUser = u.asMember(guildId).getVoiceStateOrNull() val vcsUser = u.asMember(guildId).getVoiceStateOrNull()
if (vcsUser == null) { if (vcsUser == null) {

View file

@ -36,10 +36,6 @@ import net.moonleay.botendo.util.*
object MusicManager { object MusicManager {
private var musicManagerMap: MutableMap<Snowflake, GuildTrackScheduler> = mutableMapOf() private var musicManagerMap: MutableMap<Snowflake, GuildTrackScheduler> = mutableMapOf()
fun getMusicManager(guild: Guild): GuildTrackScheduler? {
return musicManagerMap[guild.id]
}
fun getGuildTrackScheduler(guild: Guild, player: Player): GuildTrackScheduler { fun getGuildTrackScheduler(guild: Guild, player: Player): GuildTrackScheduler {
return musicManagerMap.computeIfAbsent(guild.id) { return musicManagerMap.computeIfAbsent(guild.id) {
GuildTrackScheduler(player) GuildTrackScheduler(player)
@ -185,10 +181,6 @@ object MusicManager {
} }
is LoadResult.NoMatches -> { is LoadResult.NoMatches -> {
if(gts.isEmpty()) {
player.stopTrack()
link.destroy()
}
if (!silent) if (!silent)
ctx.respond { ctx.respond {
this.embed { this.embed {
@ -202,10 +194,6 @@ object MusicManager {
} }
} }
is LoadResult.LoadFailed -> { is LoadResult.LoadFailed -> {
if (gts.isEmpty()) {
player.stopTrack()
link.destroy()
}
if (!silent) if (!silent)
ctx.respond { ctx.respond {
this.embed { this.embed {