|
|
|
@ -26,16 +26,28 @@ public class JoinCommand extends Command |
|
|
|
|
VoiceChannel channel = null; |
|
|
|
|
if (args.isEmpty() || args.get(0).isBlank()) |
|
|
|
|
{ |
|
|
|
|
GuildVoiceState voiceState = event.getMember().getVoiceState(); |
|
|
|
|
if (voiceState != null && voiceState.inVoiceChannel()) |
|
|
|
|
channel = voiceState.getChannel(); |
|
|
|
|
else |
|
|
|
|
final Member member = event.getMessage().getMember(); |
|
|
|
|
if (member != null) |
|
|
|
|
{ |
|
|
|
|
GuildVoiceState voiceState = member.getVoiceState(); |
|
|
|
|
if (voiceState != null && voiceState.inVoiceChannel()) |
|
|
|
|
channel = voiceState.getChannel(); |
|
|
|
|
} |
|
|
|
|
if (channel == null) |
|
|
|
|
{ |
|
|
|
|
Guild guild = event.getMessage().getGuild(); |
|
|
|
|
List<VoiceChannel> voiceChannels = guild.getVoiceChannels(); |
|
|
|
|
Optional<VoiceChannel> findFirst = voiceChannels.stream().filter((t) -> !t.getMembers().isEmpty()).findFirst(); |
|
|
|
|
channel = findFirst.orElseThrow(() -> new RuntimeException("Cannot find any voice channels with people in!")); |
|
|
|
|
System.out.println("Finding channel to join..."); |
|
|
|
|
for (VoiceChannel voiceChannel : voiceChannels) |
|
|
|
|
{ |
|
|
|
|
List<Member> members = voiceChannel.getMembers(); |
|
|
|
|
if (!members.isEmpty()) |
|
|
|
|
channel = voiceChannel; |
|
|
|
|
System.out.println("\t" + voiceChannel.getName() + " " + members.size()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (channel == null) |
|
|
|
|
throw new RuntimeException("Cannot find any voice channels with people in!"); |
|
|
|
|
} else |
|
|
|
|
{ |
|
|
|
|
String arg0 = args.get(0); |
|
|
|
|