Skip to content

Commit

Permalink
Merge pull request #232 from Pan-nav/master
Browse files Browse the repository at this point in the history
More bug fixes
  • Loading branch information
joshbker authored Feb 17, 2024
2 parents 4db1eba + 87ab60c commit 8f9dc38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ NEWS_CHANNEL_ID=
COUNTING_CHANNEL_ID=
VOICE_CHANNEL_ID=

CHAT_CATEGORY=

STUDENT_ROLE_ID=
SUPPORT_ROLE_ID=
STAFF_ROLE_ID=
Expand Down
15 changes: 8 additions & 7 deletions src/main/kotlin/com/learnspigot/bot/voicechat/VCListener.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package com.learnspigot.bot.voicechat

import com.learnspigot.bot.Environment
import io.github.cdimascio.dotenv.dotenv
import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion
import net.dv8tion.jda.api.entities.Widget.VoiceChannel
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent
import net.dv8tion.jda.api.hooks.ListenerAdapter

class VCListener : ListenerAdapter() {

override fun onGuildVoiceUpdate(event: GuildVoiceUpdateEvent){
val guild = event.guild
val voiceChannel = guild.getVoiceChannelById(dotenv().get("VOICE_CHANNEL_ID"))
val joinedChannel: AudioChannelUnion? = event.channelJoined
val voiceChannel = guild.getVoiceChannelById(Environment.get("VOICE_CHANNEL_ID"))
val joinedChannel = event.channelJoined
val leftChannel = event.channelLeft

val oldChannel = event.oldValue

if (joinedChannel != null && joinedChannel == voiceChannel){
if (joinedChannel !is VoiceChannel || joinedChannel.parentCategoryId != Environment.get("CHAT_CATEGORY")) return
if (joinedChannel == voiceChannel){

if (oldChannel != null && oldChannel.members.isEmpty()){
if ((oldChannel != null) && oldChannel.members.isEmpty()){
oldChannel.delete().queue()
}

Expand All @@ -31,5 +31,6 @@ class VCListener : ListenerAdapter() {
leftChannel.delete().queue()
}
}

}
}

0 comments on commit 8f9dc38

Please sign in to comment.