Skip to content

Commit 85c79c1

Browse files
committed
Address code review comments from @Zabuzard
- docs(calculateSubscribeTarget): improve JavaDocs - refactor: rename to DynamicVoiceChannelListener Signed-off-by: Chris Sdogkos <work@chris-sdogkos.com>
1 parent 1b166af commit 85c79c1

3 files changed

Lines changed: 34 additions & 14 deletions

File tree

application/src/main/java/org/togetherjava/tjbot/features/Features.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.togetherjava.tjbot.features.code.CodeMessageAutoDetection;
2121
import org.togetherjava.tjbot.features.code.CodeMessageHandler;
2222
import org.togetherjava.tjbot.features.code.CodeMessageManualDetection;
23-
import org.togetherjava.tjbot.features.dynamicvc.DynamicVoiceListener;
23+
import org.togetherjava.tjbot.features.dynamicvc.DynamicVoiceChannelListener;
2424
import org.togetherjava.tjbot.features.filesharing.FileSharingMessageListener;
2525
import org.togetherjava.tjbot.features.github.GitHubCommand;
2626
import org.togetherjava.tjbot.features.github.GitHubReference;
@@ -163,7 +163,7 @@ public static Collection<Feature> createFeatures(JDA jda, Database database, Con
163163
features.add(new PinnedNotificationRemover(config));
164164

165165
// Voice receivers
166-
features.add(new DynamicVoiceListener(config));
166+
features.add(new DynamicVoiceChannelListener(config));
167167

168168
// Event receivers
169169
features.add(new RejoinModerationRoleListener(actionsStore, config));

application/src/main/java/org/togetherjava/tjbot/features/dynamicvc/DynamicVoiceListener.java renamed to application/src/main/java/org/togetherjava/tjbot/features/dynamicvc/DynamicVoiceChannelListener.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import java.util.stream.Stream;
3232

3333
/**
34-
* {@link DynamicVoiceListener} is a feature that dynamically manages voice channels within a
34+
* {@link DynamicVoiceChannelListener} is a feature that dynamically manages voice channels within a
3535
* Discord guild based on user activity.
3636
* <p>
3737
* It is designed to handle events related to voice channel updates (e.g. when users join or leave
@@ -43,9 +43,9 @@
4343
* channel names it should manage. The configuration is expected to provide a list of regular
4444
* expression patterns for these channel names.
4545
*/
46-
public class DynamicVoiceListener extends VoiceReceiverAdapter {
46+
public class DynamicVoiceChannelListener extends VoiceReceiverAdapter {
4747

48-
private final Logger logger = LoggerFactory.getLogger(DynamicVoiceListener.class);
48+
private final Logger logger = LoggerFactory.getLogger(DynamicVoiceChannelListener.class);
4949

5050
private final Map<String, Predicate<String>> channelPredicates = new HashMap<>();
5151

@@ -64,11 +64,11 @@ public class DynamicVoiceListener extends VoiceReceiverAdapter {
6464
private static final int CONGESTION_THRESHOLD = 5;
6565

6666
/**
67-
* Initializes a new {@link DynamicVoiceListener} with the specified configuration.
67+
* Initializes a new {@link DynamicVoiceChannelListener} with the specified configuration.
6868
*
6969
* @param config the configuration containing dynamic voice channel patterns
7070
*/
71-
public DynamicVoiceListener(Config config) {
71+
public DynamicVoiceChannelListener(Config config) {
7272
config.getDynamicVoiceChannelPatterns().forEach(pattern -> {
7373
channelPredicates.put(pattern, Pattern.compile(pattern).asMatchPredicate());
7474
activeQueuesMap.put(pattern, new AtomicBoolean(false));

application/src/main/java/org/togetherjava/tjbot/features/system/BotCore.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,18 +256,38 @@ public void onMessageDelete(final MessageDeleteEvent event) {
256256
}
257257

258258
/**
259-
* @param joinChannel the join channel
260-
* @param leftChannel the leave channel
259+
* Calculates the correct voice channel to act upon.
260+
*
261+
* <p>
262+
* If there is a <code>channelJoined</code> and a <code>channelLeft</code>, then the
263+
* <code>channelJoined</code> is prioritized and returned. Otherwise, it returns
264+
* <code>channelLeft</code>.
265+
*
266+
* <p>
267+
* This is an essential method due to the need of updating both channel categories that a member
268+
* utilizes. For example, take the scenario of a user browsing through voice channels:
269+
*
270+
* <pre>
271+
* - User joins General -> channelJoined = General | channelLeft = null
272+
* - User switches to Gaming -> channelJoined = Gaming | channelLeft = General
273+
* - User leaves Discord -> channelJoined = null | channelLeft = Gaming
274+
* </pre>
275+
*
276+
* <p>
277+
* This way, we make sure that all relevant voice channels are updated.
278+
*
279+
* @param channelJoined the channel that the member has connected to, if any
280+
* @param channelLeft the channel that the member left from, if any
261281
* @return the join channel if not null, otherwise the leave channel, otherwise an empty
262282
* optional
263283
*/
264-
private Optional<Channel> calculateSubscribeTarget(@Nullable AudioChannelUnion joinChannel,
265-
@Nullable AudioChannelUnion leftChannel) {
266-
if (joinChannel != null) {
267-
return Optional.of(joinChannel);
284+
private Optional<Channel> calculateSubscribeTarget(@Nullable AudioChannelUnion channelJoined,
285+
@Nullable AudioChannelUnion channelLeft) {
286+
if (channelJoined != null) {
287+
return Optional.of(channelJoined);
268288
}
269289

270-
return Optional.ofNullable(leftChannel);
290+
return Optional.ofNullable(channelLeft);
271291
}
272292

273293
@Override

0 commit comments

Comments
 (0)