|
26 | 26 | import java.util.stream.IntStream;
|
27 | 27 | import java.util.stream.Stream;
|
28 | 28 |
|
| 29 | +/** |
| 30 | + * {@link DynamicVoiceListener} is a feature that dynamically manages voice channels within a |
| 31 | + * Discord guild based on user activity. |
| 32 | + * <p> |
| 33 | + * It is designed to handle events related to voice channel updates (e.g. when users join or leave |
| 34 | + * voice channels). It dynamically creates or deletes voice channels to ensure there is always |
| 35 | + * <i>one</i> available empty channel for users to join, and removes duplicate empty channels to |
| 36 | + * avoid clutter. |
| 37 | + * <p> |
| 38 | + * This feature relies on configurations provided at initialization to determine the patterns for |
| 39 | + * channel names it should manage. The configuration is expected to provide a list of regular |
| 40 | + * expression patterns for these channel names. |
| 41 | + */ |
29 | 42 | public class DynamicVoiceListener extends VoiceReceiverAdapter {
|
30 | 43 |
|
31 | 44 | private final Map<String, Predicate<String>> channelPredicates = new HashMap<>();
|
32 | 45 | private static final Pattern channelTopicPattern = Pattern.compile("(\\s+\\d+)$");
|
| 46 | + |
| 47 | + /** Map of event queues for each channel topic. */ |
33 | 48 | private static final Map<String, Queue<GuildVoiceUpdateEvent>> eventQueues = new HashMap<>();
|
| 49 | + |
| 50 | + /** Map to track if an event queue is currently being processed for each channel topic. */ |
34 | 51 | private static final Map<String, AtomicBoolean> activeQueuesMap = new HashMap<>();
|
35 | 52 |
|
| 53 | + /** |
| 54 | + * Initializes a new {@link DynamicVoiceListener} with the specified configuration. |
| 55 | + * |
| 56 | + * @param config the configuration containing dynamic voice channel patterns |
| 57 | + */ |
36 | 58 | public DynamicVoiceListener(Config config) {
|
37 | 59 | config.getDynamicVoiceChannelPatterns().forEach(pattern -> {
|
38 | 60 | channelPredicates.put(pattern, Pattern.compile(pattern).asMatchPredicate());
|
|
0 commit comments