Fix channel position
This commit is contained in:
parent
023afb7323
commit
1a4899c1cf
@ -17,12 +17,14 @@ import net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent;
|
||||
import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent;
|
||||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent;
|
||||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent;
|
||||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent;
|
||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
|
||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||
import net.dv8tion.jda.api.managers.GuildManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.awt.*;
|
||||
@ -149,6 +151,13 @@ public class BotListener extends ListenerAdapter {
|
||||
autoVoiceChannel.leave(event.getChannelLeft());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuildVoiceMove(@NotNull GuildVoiceMoveEvent event) {
|
||||
super.onGuildVoiceMove(event);
|
||||
AutoVoiceChannel autoVoiceChannel = AutoVoiceChannel.getInstance(event.getGuild());
|
||||
autoVoiceChannel.leave(event.getChannelLeft());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(MessageReceivedEvent event) {
|
||||
|
||||
@ -206,6 +215,7 @@ public class BotListener extends ListenerAdapter {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onGuildJoin(GuildJoinEvent event) {
|
||||
logger.info("Join new guild! (" + event.getGuild().getName() + " " + event.getGuild().getMembers().size() + " Members)");
|
||||
|
@ -36,13 +36,14 @@ public class AutoVoiceChannel {
|
||||
if (guild == null)
|
||||
return;
|
||||
GuildPreferenceEntity pref = SettingsUtils.getInstance().getPreference(guild);
|
||||
if ( pref.isAutoVoice() && voiceChannel.getId().equals(pref.getAutoVoiceChannelID())) {
|
||||
if (pref.isAutoVoice() && voiceChannel.getId().equals(pref.getAutoVoiceChannelID())) {
|
||||
logger.info("Creating new voice channel for Guild : " + guild.getName());
|
||||
VoiceChannel newChannel = voiceChannel.createCopy().complete();
|
||||
int next = getNextNumber();
|
||||
String title = pref.getAutoVoiceChannelTitle();
|
||||
title = title.replace("@count", Integer.toString(next));
|
||||
newChannel.getManager().setName(title).queue();
|
||||
newChannel.getManager().setName(title).setPosition(voiceChannel.getPosition()).queue();
|
||||
|
||||
createdChannels.put(next, newChannel.getId());
|
||||
moveMembers(voiceChannel.getMembers(), newChannel);
|
||||
}
|
||||
@ -50,10 +51,10 @@ public class AutoVoiceChannel {
|
||||
}
|
||||
|
||||
public void leave(VoiceChannel voiceChannel) {
|
||||
if (voiceChannel.getMembers().isEmpty()){
|
||||
if (voiceChannel.getMembers().isEmpty()) {
|
||||
String id = voiceChannel.getId();
|
||||
for(Map.Entry<Integer, String> entry : createdChannels.entrySet()) {
|
||||
if (entry.getValue().equals(id)){
|
||||
for (Map.Entry<Integer, String> entry : createdChannels.entrySet()) {
|
||||
if (entry.getValue().equals(id)) {
|
||||
logger.info("Auto created channel is empty, deleting it ...");
|
||||
voiceChannel.delete().reason("Auto-remove empty voice channel").queue();
|
||||
}
|
||||
@ -71,15 +72,15 @@ public class AutoVoiceChannel {
|
||||
return 999;
|
||||
}
|
||||
|
||||
private void moveMembers(List<Member> members, VoiceChannel destination){
|
||||
private void moveMembers(List<Member> members, VoiceChannel destination) {
|
||||
logger.debug("Moving Members to new voice channel...");
|
||||
RestAction<Void> restAction = null;
|
||||
for(Member member : members){
|
||||
for (Member member : members) {
|
||||
if (restAction == null)
|
||||
restAction = destination.getGuild().moveVoiceMember(member, destination);
|
||||
restAction = restAction.and(destination.getGuild().moveVoiceMember(member, destination));
|
||||
}
|
||||
if(restAction != null){
|
||||
if (restAction != null) {
|
||||
restAction.queue();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user