Skip to content

Commit 162a1b1

Browse files
committed
Add channel binding
1 parent 05cd935 commit 162a1b1

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/main/java/dev/JustRed23/jdautils/music/AudioManager.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import net.dv8tion.jda.api.entities.Guild;
1313
import net.dv8tion.jda.api.entities.Member;
1414
import net.dv8tion.jda.api.entities.User;
15+
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
1516
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
1617
import net.dv8tion.jda.api.entities.channel.unions.AudioChannelUnion;
1718
import net.dv8tion.jda.internal.utils.Checks;
@@ -66,6 +67,8 @@ public static void destroyAll() {
6667
private AudioModifier audioModifier;
6768
private TrackControls controls;
6869

70+
private TextChannel boundChannel;
71+
6972
private AudioManager(@NotNull AudioPlayer player, @NotNull Guild guild) {
7073
this.guild = guild;
7174

@@ -76,6 +79,16 @@ private AudioManager(@NotNull AudioPlayer player, @NotNull Guild guild) {
7679
guild.getAudioManager().setSendingHandler(new JDASendHandler(player));
7780
}
7881

82+
/**
83+
* Binds the audio manager to the specified text channel, this essentially does nothing but can be useful for blocking access in other channels
84+
* <br><b>Note - The bound channel will automatically be reset if {@link #disconnect()} is called</b>
85+
* @param channel The text channel to bind to, must not be null
86+
* @see #isBoundChannel(TextChannel)
87+
*/
88+
public void bindTextChannel(@NotNull TextChannel channel) {
89+
boundChannel = channel;
90+
}
91+
7992
/**
8093
* Makes the bot join the specified voice channel
8194
* @param channel The voice channel to join, must not be null
@@ -96,6 +109,8 @@ public void disconnect() {
96109

97110
if (isConnected())
98111
scheduler.getGuild().getAudioManager().closeAudioConnection();
112+
113+
boundChannel = null;
99114
}
100115

101116
/**
@@ -214,4 +229,12 @@ public boolean isConnected() {
214229
public Guild getGuild() {
215230
return guild;
216231
}
232+
233+
public TextChannel getBoundChannel() {
234+
return boundChannel;
235+
}
236+
237+
public boolean isBoundChannel(TextChannel channel) {
238+
return boundChannel != null && boundChannel.equals(channel);
239+
}
217240
}

0 commit comments

Comments
 (0)