-
-
Notifications
You must be signed in to change notification settings - Fork 91
Dynamically create and delete voice channels based on activity #1114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
christolis
wants to merge
4
commits into
Together-Java:develop
Choose a base branch
from
christolis:feat/dynamic-vcs
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+509
−2
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a1039f9
feat(dynamic-vcs): add VoiceReceiver and config changes
christolis 4bca50e
feat(dynamic-vcs): add DynamicVoiceListener code
christolis 66aa74d
refactor: use variable type instead of 'var'
christolis 0287536
refactor: improve variable naming and log message
christolis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
69 changes: 69 additions & 0 deletions
69
application/src/main/java/org/togetherjava/tjbot/features/VoiceReceiver.java
This file contains hidden or 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,69 @@ | ||
package org.togetherjava.tjbot.features; | ||
|
||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceDeafenEvent; | ||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceMuteEvent; | ||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceStreamEvent; | ||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent; | ||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceVideoEvent; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Receives incoming Discord guild events from voice channels matching a given pattern. | ||
* <p> | ||
* All voice receivers have to implement this interface. For convenience, there is a | ||
* {@link VoiceReceiverAdapter} available that implemented most methods already. A new receiver can | ||
* then be registered by adding it to {@link Features}. | ||
* <p> | ||
* <p> | ||
* After registration, the system will notify a receiver whenever a new event was sent or an | ||
* existing event was updated in any channel matching the {@link #getChannelNamePattern()} the bot | ||
* is added to. | ||
*/ | ||
public interface VoiceReceiver extends Feature { | ||
/** | ||
* Retrieves the pattern matching the names of channels of which this receiver is interested in | ||
* receiving events from. Called by the core system once during the startup in order to register | ||
* the receiver accordingly. | ||
* <p> | ||
* Changes on the pattern returned by this method afterwards will not be picked up. | ||
* | ||
* @return the pattern matching the names of relevant channels | ||
*/ | ||
Pattern getChannelNamePattern(); | ||
|
||
/** | ||
* Triggered by the core system whenever a member joined, left or moved voice channels. | ||
* | ||
* @param event the event that triggered this | ||
*/ | ||
void onVoiceUpdate(GuildVoiceUpdateEvent event); | ||
|
||
/** | ||
* Triggered by the core system whenever a member toggled their camera in a voice channel. | ||
* | ||
* @param event the event that triggered this | ||
*/ | ||
void onVideoToggle(GuildVoiceVideoEvent event); | ||
|
||
/** | ||
* Triggered by the core system whenever a member started or stopped a stream. | ||
* | ||
* @param event the event that triggered this | ||
*/ | ||
void onStreamToggle(GuildVoiceStreamEvent event); | ||
|
||
/** | ||
* Triggered by the core system whenever a member toggled their mute status. | ||
* | ||
* @param event the event that triggered this | ||
*/ | ||
void onMuteToggle(GuildVoiceMuteEvent event); | ||
|
||
/** | ||
* Triggered by the core system whenever a member toggled their deafened status. | ||
* | ||
* @param event the event that triggered this | ||
*/ | ||
void onDeafenToggle(GuildVoiceDeafenEvent event); | ||
} |
52 changes: 52 additions & 0 deletions
52
application/src/main/java/org/togetherjava/tjbot/features/VoiceReceiverAdapter.java
This file contains hidden or 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,52 @@ | ||
package org.togetherjava.tjbot.features; | ||
|
||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceDeafenEvent; | ||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceMuteEvent; | ||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceStreamEvent; | ||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent; | ||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceVideoEvent; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public class VoiceReceiverAdapter implements VoiceReceiver { | ||
|
||
private final Pattern channelNamePattern; | ||
|
||
protected VoiceReceiverAdapter() { | ||
this(Pattern.compile(".*")); | ||
} | ||
|
||
protected VoiceReceiverAdapter(Pattern channelNamePattern) { | ||
this.channelNamePattern = channelNamePattern; | ||
} | ||
|
||
@Override | ||
public Pattern getChannelNamePattern() { | ||
return channelNamePattern; | ||
} | ||
|
||
@Override | ||
public void onVoiceUpdate(GuildVoiceUpdateEvent event) { | ||
// Adapter does not react by default, subclasses may change this behavior | ||
} | ||
|
||
@Override | ||
public void onVideoToggle(GuildVoiceVideoEvent event) { | ||
// Adapter does not react by default, subclasses may change this behavior | ||
} | ||
|
||
@Override | ||
public void onStreamToggle(GuildVoiceStreamEvent event) { | ||
// Adapter does not react by default, subclasses may change this behavior | ||
} | ||
|
||
@Override | ||
public void onMuteToggle(GuildVoiceMuteEvent event) { | ||
// Adapter does not react by default, subclasses may change this behavior | ||
} | ||
|
||
@Override | ||
public void onDeafenToggle(GuildVoiceDeafenEvent event) { | ||
// Adapter does not react by default, subclasses may change this behavior | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id rename the feature to
DynamicVoiceChannelListener
, i.e. addChannel
to signal that it deals with managing channels, not voice itself