Skip to content

Commit bc97033

Browse files
committed
Add permission check before joining a channel
1 parent aa58021 commit bc97033

File tree

5 files changed

+26
-13
lines changed

5 files changed

+26
-13
lines changed

foxy/src/main/kotlin/net/cakeyfox/foxy/interactions/vanilla/music/QueueExecutor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class QueueExecutor : UnleashedCommandExecutor() {
7878

7979
it.edit {
8080
embed {
81-
color = Colors.AQUA
81+
color = Colors.BLUE
8282
title = pretty(FoxyEmotes.FoxyPlush, context.locale["music.queue.currentQueue"])
8383
description = context.locale["music.queue.queueCleared"]
8484
thumbnail = Constants.FOXY_FUMO

foxy/src/main/kotlin/net/cakeyfox/foxy/listeners/lavalink/LavalinkMajorListener.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ class LavalinkMajorListener(lavalink: LavalinkClient, val foxy: FoxyInstance) :
1717
logger.info { "Node '${event.node.name}' is ready, session id is '${event.sessionId}'!" }
1818
}
1919

20-
lavalink.on<StatsEvent>().subscribe({ event ->
21-
logger.info { "Node '${event.node.name}' has stats, current players: ${event.playingPlayers}/${event.players}" }
22-
}) { err ->
23-
err.printStackTrace()
24-
}
25-
2620
lavalink.on<TrackStartEvent>().subscribe { event ->
2721
logger.info { "Node '${event.node.name}' started playing a track in guild ${event.guildId}!" }
2822
}

foxy/src/main/kotlin/net/cakeyfox/foxy/utils/JDAExtensions.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import net.cakeyfox.serializable.data.cluster.RelayEmbed
77
import net.cakeyfox.serializable.data.cluster.RelayEmbedAuthor
88
import net.cakeyfox.serializable.data.cluster.RelayEmbedField
99
import net.cakeyfox.serializable.data.cluster.RelayEmbedFooter
10+
import net.dv8tion.jda.api.Permission
1011
import net.dv8tion.jda.api.components.buttons.Button
1112
import net.dv8tion.jda.api.components.buttons.ButtonStyle
1213
import net.dv8tion.jda.api.entities.MessageEmbed
@@ -28,7 +29,23 @@ suspend fun joinInAVoiceChannel(context: CommandContext): Channel? {
2829

2930
if (botVoiceChannel != null && botVoiceChannel != memberVoiceChannel) {
3031
context.reply(true) {
31-
content = pretty(FoxyEmotes.FoxyDrinkingCoffee, context.locale["music.play.alreadyConnectedInAnotherChannel", botVoiceChannel.asMention])
32+
content = pretty(
33+
FoxyEmotes.FoxyDrinkingCoffee,
34+
context.locale["music.play.alreadyConnectedInAnotherChannel", botVoiceChannel.asMention]
35+
)
36+
}
37+
return null
38+
}
39+
40+
val hasJoinAndSpeak = selfMember.hasPermission(
41+
memberVoiceChannel,
42+
Permission.VOICE_CONNECT,
43+
Permission.VOICE_SPEAK
44+
)
45+
46+
if (!hasJoinAndSpeak) {
47+
context.reply(true) {
48+
content = pretty(FoxyEmotes.FoxyRage, context.locale["music.play.missingPermissions"])
3249
}
3350
return null
3451
}

foxy/src/main/kotlin/net/cakeyfox/foxy/utils/music/AudioLoader.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class AudioLoader(val context: CommandContext, val manager: GuildMusicManager) :
9999

100100
override fun ontrackLoaded(result: TrackLoaded) {
101101
val track = result.track
102+
val trackTitle = track.info.title
103+
val trackAuthor = track.info.author
102104
val sourceName = track.info.sourceName
103105
val emote = FoxyEmotes::class.memberProperties
104106
.firstOrNull { it.name.equals(sourceName, ignoreCase = true) }
@@ -111,10 +113,6 @@ class AudioLoader(val context: CommandContext, val manager: GuildMusicManager) :
111113
val currentPlaying = link.cachedPlayer?.track
112114
val isFirstTrack = currentPlaying == null && manager.scheduler.queue.isEmpty()
113115

114-
this.manager.scheduler.enqueue(track)
115-
val trackTitle = track.info.title
116-
val trackAuthor = track.info.author
117-
118116
replyScope.launch {
119117
context.reply {
120118
if (isFirstTrack) {
@@ -146,5 +144,8 @@ class AudioLoader(val context: CommandContext, val manager: GuildMusicManager) :
146144
}
147145
}
148146
}
147+
148+
149+
this.manager.scheduler.enqueue(track)
149150
}
150151
}

foxy/src/main/resources/locales/pt-br/commands.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ music:
3636
source: "Fonte:"
3737
queueLimitReached: "Você só pode adicionar até **{0}** músicas na fila!"
3838
youMustProvideASong: "Você precisa fornecer o nome ou a URL do SoundCloud ou do Discord! :3"
39+
missingPermissions: "Eu não tenho permissão para falar ou conectar no seu canal de voz!"
3940
stop:
40-
stopped: "Pare de me torturar! Saindo do canal de voz..."
41+
stopped: "Saindo do canal... Até mais!"
4142
nothingPlaying: "Não há nada tocando no momento!"
4243
queue:
4344
currentQueue: "Fila atual"

0 commit comments

Comments
 (0)