File tree Expand file tree Collapse file tree 6 files changed +32
-10
lines changed
me/duncte123/skybot/audio
kotlin/me/duncte123/skybot Expand file tree Collapse file tree 6 files changed +32
-10
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ plugins {
3636
3737val pmdVersion = " 7.0.0-rc4"
3838
39- val numberVersion = " 3.109.1 "
39+ val numberVersion = " 3.109.2 "
4040
4141project.group = " me.duncte123.skybot"
4242project.version = " ${numberVersion} _${getGitHash()} "
Original file line number Diff line number Diff line change @@ -105,7 +105,17 @@ public boolean isConnected(Guild guild) {
105105 }
106106
107107 public boolean isConnected (long guildId ) {
108- return !isEnabled () || lavalink .getLink (guildId ).getState () == LinkState .CONNECTED ;
108+ if (!isEnabled ()) {
109+ return false ;
110+ }
111+
112+ final var link = lavalink .getLinkIfCached (guildId );
113+
114+ if (link == null ) {
115+ return false ;
116+ }
117+
118+ return link .getState () == LinkState .CONNECTED ;
109119 }
110120
111121 @ SuppressWarnings ("ConstantConditions" ) // cache is enabled
Original file line number Diff line number Diff line change 2727import net .dv8tion .jda .api .entities .channel .middleman .MessageChannel ;
2828
2929import javax .annotation .Nonnull ;
30+ import javax .annotation .Nullable ;
3031import java .util .Optional ;
3132import java .util .concurrent .atomic .AtomicLong ;
3233import java .util .function .Supplier ;
@@ -81,14 +82,19 @@ public Optional<MessageChannel> getLatestChannel() {
8182 );
8283 }
8384
85+ @ Nullable
8486 public Link getLink () {
85- return LavalinkManager .INS .getLavalink ().getLink (this .guildId );
87+ return LavalinkManager .INS .getLavalink ().getLinkIfCached (this .guildId );
8688 }
8789
8890 public Optional <LavalinkPlayer > getPlayer () {
89- return Optional .ofNullable (
90- this .getLink ().getCachedPlayer ()
91- );
91+ final var link = this .getLink ();
92+
93+ if (link == null ) {
94+ return Optional .empty ();
95+ }
96+
97+ return Optional .ofNullable (link .getCachedPlayer ());
9298 }
9399
94100 public long getGuildId () {
Original file line number Diff line number Diff line change @@ -70,7 +70,7 @@ class LyricsCommand : MusicCommand() {
7070 return
7171 }
7272
73- loadLyricsFromLavalink(mng.link) {
73+ loadLyricsFromLavalink(mng.link!! ) {
7474 if (it == null ) {
7575 sendMsg(ctx, " There where no lyrics found for `${playingTrack.info.title} `" )
7676 return @loadLyricsFromLavalink
@@ -106,7 +106,7 @@ class LyricsCommand : MusicCommand() {
106106
107107 event.deferReply().queue()
108108
109- loadLyricsFromLavalink(mng.link) {
109+ loadLyricsFromLavalink(mng.link!! ) {
110110 if (it == null ) {
111111 event.hook.sendMessage(" There where no lyrics found for `${playingTrack.info.title} `" )
112112 .queue()
Original file line number Diff line number Diff line change @@ -170,6 +170,11 @@ open class PlayCommand(private val skipParsing: Boolean = false) : MusicCommand(
170170 }
171171
172172 override fun handleEvent (event : SlashCommandInteractionEvent , variables : Variables ) {
173+ if (! event.member!! .voiceState!! .inAudioChannel()) {
174+ event.reply(" Auto-join is not yet supported for slash commands. Sorry about that" ).queue()
175+ return
176+ }
177+
173178 var toPlay = event.getOption(" item" )!! .asString
174179
175180 if (toPlay.contains(pornhubRegex.toRegex()) && ! event.channel.isNSFW) {
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ package me.duncte123.skybot.objects
2020
2121import me.duncte123.skybot.Variables
2222import net.dv8tion.jda.api.JDA
23- import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion
23+ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel
2424import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
2525
2626data class AudioData (
@@ -31,7 +31,8 @@ data class AudioData(
3131 val jda : JDA ,
3232 val variables : Variables ,
3333) {
34- fun getChannel () = jda.getChannelById(MessageChannelUnion ::class .java, channelId)!!
34+ val channel: MessageChannel
35+ get() = jda.getChannelById(MessageChannel ::class .java, channelId)!!
3536
3637 companion object {
3738 fun fromSlash (event : SlashCommandInteractionEvent , variables : Variables ): AudioData = AudioData (
You can’t perform that action at this time.
0 commit comments