-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent the bot from joining afk channels (#46)
Co-authored-by: yuua <yuuahp@icloud.com>
- Loading branch information
Showing
6 changed files
with
67 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/com/jaoafa/vcspeaker/events/SelfVoiceJoinEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.jaoafa.vcspeaker.events | ||
|
||
import com.jaoafa.vcspeaker.VCSpeaker | ||
import com.jaoafa.vcspeaker.tools.discord.DiscordExtensions.asChannelOf | ||
import com.jaoafa.vcspeaker.tools.discord.DiscordExtensions.getSettings | ||
import com.jaoafa.vcspeaker.tools.discord.DiscordExtensions.isAfk | ||
import com.jaoafa.vcspeaker.tools.discord.VoiceExtensions.join | ||
import com.kotlindiscord.kord.extensions.extensions.Extension | ||
import com.kotlindiscord.kord.extensions.extensions.event | ||
import dev.kord.core.entity.channel.TextChannel | ||
import dev.kord.core.event.user.VoiceStateUpdateEvent | ||
|
||
class SelfVoiceJoinEvent : Extension() { | ||
override val name = this::class.simpleName!! | ||
|
||
override suspend fun setup() { | ||
event<VoiceStateUpdateEvent> { | ||
check { | ||
failIf(event.state.getMember().id != VCSpeaker.kord.selfId) | ||
failIf(!(event.state.getChannelOrNull()?.isAfk() ?: false)) | ||
} | ||
|
||
action { | ||
val guild = event.state.getGuildOrNull() ?: return@action // checked | ||
val channelLeft = event.old?.getChannelOrNull() | ||
val textChannel = guild.getSettings().channelId?.asChannelOf<TextChannel>() | ||
|
||
channelLeft?.join { | ||
textChannel?.createMessage( | ||
"**:zzz: AFK チャンネルには接続できないので、${channelLeft.mention} に戻りました。**" | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters