aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Kohls <mattkohls13@gmail.com>2018-04-07 19:48:59 -0400
committerMatt Kohls <mattkohls13@gmail.com>2018-04-07 19:48:59 -0400
commit8849e2f373a09e5d505979376a41935a722ca347 (patch)
tree86e03a7232d8c0a10ed5cbb816e2bed9e2ccdd8d
parenta7d690c352bb718dfe74368d2973e2798617fc62 (diff)
downloadSoundChan-8849e2f373a09e5d505979376a41935a722ca347.tar.gz
SoundChan-8849e2f373a09e5d505979376a41935a722ca347.tar.bz2
SoundChan-8849e2f373a09e5d505979376a41935a722ca347.zip
Bot Following
Sound Chan now follows a specific user, and when they change voice channels, she follows
-rw-r--r--src/main/java/soundchan/Main.java25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/main/java/soundchan/Main.java b/src/main/java/soundchan/Main.java
index 326285f..210f9d0 100644
--- a/src/main/java/soundchan/Main.java
+++ b/src/main/java/soundchan/Main.java
@@ -14,8 +14,11 @@ import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.entities.MessageChannel;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.VoiceChannel;
+import net.dv8tion.jda.core.events.channel.voice.update.GenericVoiceChannelUpdateEvent;
+import net.dv8tion.jda.core.events.guild.voice.GuildVoiceMoveEvent;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.client.events.call.voice.CallVoiceJoinEvent;
+import net.dv8tion.jda.core.events.user.GenericUserPresenceEvent;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
import net.dv8tion.jda.core.managers.AudioManager;
@@ -34,6 +37,7 @@ public class Main extends ListenerAdapter {
.buildBlocking();
jda.addEventListener(new Main());
+ followingUser = properties.getProperty("followingUser");
}
private static Properties LoadProperties(){
@@ -57,6 +61,7 @@ public class Main extends ListenerAdapter {
private long monitoredGuildId = -1;
private Guild monitoredGuild;
+ private static String followingUser;
private final AudioPlayerManager playerManager;
private final Map<Long, GuildMusicManager> musicManagers;
@@ -101,6 +106,18 @@ public class Main extends ListenerAdapter {
}
+
+ @Override
+ public void onGuildVoiceMove(GuildVoiceMoveEvent event) {
+ if(event.getMember().getEffectiveName().compareTo(followingUser) == 0) {
+ AudioManager audioManager = monitoredGuild.getAudioManager();
+ if(!audioManager.isAttemptingToConnect()) {
+ audioManager.openAudioConnection(event.getChannelJoined());
+ }
+ }
+ super.onGuildVoiceMove(event);
+ }
+
@Override
public void onMessageReceived(MessageReceivedEvent event) {
String[] command = event.getMessage().getContentRaw().split(" ", 2);
@@ -213,8 +230,12 @@ public class Main extends ListenerAdapter {
private static void connectToFirstVoiceChannel(AudioManager audioManager) {
if (!audioManager.isConnected() && !audioManager.isAttemptingToConnect()) {
for (VoiceChannel voiceChannel : audioManager.getGuild().getVoiceChannels()) {
- audioManager.openAudioConnection(voiceChannel);
- break;
+ for(int i = 0; i < voiceChannel.getMembers().size(); i++) {
+ if(voiceChannel.getMembers().get(i).getEffectiveName().compareTo(followingUser) == 0) {
+ audioManager.openAudioConnection(voiceChannel);
+ break;
+ }
+ }
}
}
}