Skip to content

Commit f93cd8a

Browse files
committed
Find bot owner and join that channel.
1 parent 2034540 commit f93cd8a

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/main/kotlin/dev/arbjerg/ukulele/api/PlayerController.kt

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,36 @@ class PlayerController(
6868
return guild.voiceChannels.map { VoiceChannelDto(it.id, it.name) }
6969
}
7070

71+
private fun getChannel(guild: net.dv8tion.jda.api.entities.Guild, channelId: String?): net.dv8tion.jda.api.entities.channel.middleman.AudioChannel? {
72+
if (channelId == "owner" && botProps.ownerId.isNotEmpty()) {
73+
val member = guild.getMemberById(botProps.ownerId)
74+
return member?.voiceState?.channel
75+
}
76+
return if (!channelId.isNullOrEmpty()) {
77+
guild.getVoiceChannelById(channelId)
78+
} else {
79+
guild.voiceChannels.firstOrNull()
80+
}
81+
}
82+
7183
@PostMapping("/player/{guildId}/play")
7284
suspend fun play(@PathVariable guildId: Long, @RequestBody body: Map<String, String>) {
7385
val guild = shardManager.getGuildById(guildId) ?: throw RuntimeException("Guild not found")
7486
val properties = guildPropertiesService.getAwait(guildId)
7587
val player = playerRegistry.get(guild, properties)
88+
7689
// Ensure connected to voice
7790
val channelId = body["channelId"]
7891
if (!guild.audioManager.isConnected) {
79-
val channel = if (channelId != null) {
80-
guild.getVoiceChannelById(channelId)
81-
} else {
82-
guild.voiceChannels.firstOrNull()
83-
}
84-
92+
val channel = getChannel(guild, channelId)
8593
if (channel != null) {
8694
guild.audioManager.openAudioConnection(channel)
8795
guild.audioManager.sendingHandler = player
8896
}
8997
}
9098

9199
var identifiers = (body["url"] ?: "").split("|")
100+
// ... (rest of play method logic)
92101
if (identifiers.isNotEmpty() && identifiers.first().isEmpty()) {
93102
identifiers = botProps.playlist.split("|")
94103
}
@@ -214,7 +223,7 @@ class PlayerController(
214223
suspend fun move(@PathVariable guildId: Long, @RequestBody body: Map<String, String>) {
215224
val guild = shardManager.getGuildById(guildId) ?: return
216225
val channelId = body["channelId"] ?: return
217-
val channel = guild.getVoiceChannelById(channelId)
226+
val channel = getChannel(guild, channelId)
218227
if (channel != null) {
219228
guild.audioManager.openAudioConnection(channel)
220229
}

src/main/kotlin/dev/arbjerg/ukulele/config/BotProps.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ class BotProps(
2020
var normalization: Boolean = false,
2121
var minVolume: Int = 0,
2222
var maxVolume: Int = 80,
23-
var useWebsockets: Boolean = false
23+
var useWebsockets: Boolean = false,
24+
var ownerId: String = ""
2425
)

0 commit comments

Comments
 (0)