Skip to content

Commit 0309044

Browse files
tj-wazeisurajkumar
andauthored
fix: DynamicVoiceChat deleting channel without checking if members are in there (#1395)
Co-authored-by: Suraj Kumar <[email protected]>
1 parent a62f773 commit 0309044

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

application/src/main/java/org/togetherjava/tjbot/features/voicechat/DynamicVoiceChat.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ private void handleVoiceChannelLeave(AudioChannelUnion channelLeft) {
8181
if (!eventHappenOnDynamicRootChannel(channelLeft)) {
8282
logger.debug("Event happened on left channel {}", channelLeft);
8383

84+
if (hasMembers(channelLeft)) {
85+
logger.debug("Voice channel {} not empty, so not doing anything.",
86+
channelLeft.getName());
87+
return;
88+
}
89+
8490
channelLeft.asVoiceChannel().getHistory().retrievePast(2).queue(messages -> {
8591
if (messages.size() > 1) {
8692
archiveDynamicVoiceChannel(channelLeft);
@@ -124,16 +130,13 @@ private void moveMember(Guild guild, Member member, AudioChannel channel) {
124130
member.getNickname(), channel.getName(), error));
125131
}
126132

133+
private boolean hasMembers(AudioChannelUnion channel) {
134+
return !channel.getMembers().isEmpty();
135+
}
136+
127137
private void archiveDynamicVoiceChannel(AudioChannelUnion channel) {
128-
int memberCount = channel.getMembers().size();
129138
String channelName = channel.getName();
130139

131-
if (memberCount > 0) {
132-
logger.debug("Voice channel {} not empty ({} members), so not removing.", channelName,
133-
memberCount);
134-
return;
135-
}
136-
137140
Optional<Category> archiveCategoryOptional = channel.getGuild()
138141
.getCategoryCache()
139142
.stream()

0 commit comments

Comments
 (0)