Skip to content
This repository has been archived by the owner on Jul 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #231 from book000/feat/moved-to-afk-disconnect
Browse files Browse the repository at this point in the history
feat: 移動先がAFKで、移動元にBot以外0人になった場合は抜ける
  • Loading branch information
yuuahp authored Aug 14, 2023
2 parents 9a5b5fd + d1853cd commit 95ab6a8
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/java/com/jaoafa/jdavcspeaker/Event/AutoMove.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,26 @@ void runJoined(MoveInfo info) {
return; // Botが移動した場合は終了
}

if (isAfkChannel(newChannel)) {
return; // 移動先がAFKチャンネルの場合は終了
}

if (connectedChannel.getIdLong() != oldChannel.getIdLong()) {
return; // 移動元チャンネルに自身が入っていない
}

if (isAfkChannel(newChannel)) {
// VCに残ったユーザーが全員Bot、または誰もいなくなった
boolean existsUser = newChannel
.getMembers()
.stream()
.anyMatch(member -> !member.getUser().isBot()); // Bot以外がいるかどうか
if (!existsUser) {
return;
}

AudioManager audioManager = event.getGuild().getAudioManager();
audioManager.closeAudioConnection();

return; // 移動先がAFKチャンネルの場合は終了
}

if (connectedUsers >= newUsers) {
return; // 自身がいるチャンネルの人数より、移動先の人数の方が少ない、もしくは同じ場合終了
}
Expand Down

0 comments on commit 95ab6a8

Please sign in to comment.