Fix Bot class and update CheckLinkSync constants
Removed unused imports and redundant methods in Bot.java for cleaner code. Updated CheckLinkSync.java to use new constants from BotConfig.DISCORD.
This commit is contained in:
parent
3b4a4660d0
commit
abd5578be4
|
|
@ -1,12 +1,9 @@
|
||||||
package com.alttd.proxydiscordlink.bot;
|
package com.alttd.proxydiscordlink.bot;
|
||||||
|
|
||||||
import com.alttd.proxydiscordlink.JDAListener;
|
import com.alttd.proxydiscordlink.JDAListener;
|
||||||
import com.alttd.proxydiscordlink.bot.commandManager.CommandManager;
|
|
||||||
import com.alttd.proxydiscordlink.DiscordLink;
|
import com.alttd.proxydiscordlink.DiscordLink;
|
||||||
import com.alttd.proxydiscordlink.bot.listeners.DiscordMessageListener;
|
|
||||||
import com.alttd.proxydiscordlink.bot.listeners.DiscordRoleListener;
|
import com.alttd.proxydiscordlink.bot.listeners.DiscordRoleListener;
|
||||||
import com.alttd.proxydiscordlink.bot.tasks.CheckLinkSync;
|
import com.alttd.proxydiscordlink.bot.tasks.CheckLinkSync;
|
||||||
import com.alttd.proxydiscordlink.bot.tasks.CheckLinkSync;
|
|
||||||
import com.alttd.proxydiscordlink.config.BotConfig;
|
import com.alttd.proxydiscordlink.config.BotConfig;
|
||||||
import com.alttd.proxydiscordlink.util.ALogger;
|
import com.alttd.proxydiscordlink.util.ALogger;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
|
|
@ -20,16 +17,13 @@ import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||||
import net.dv8tion.jda.api.exceptions.HierarchyException;
|
import net.dv8tion.jda.api.exceptions.HierarchyException;
|
||||||
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
|
import net.dv8tion.jda.api.exceptions.InsufficientPermissionException;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
|
||||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||||
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
import net.dv8tion.jda.api.utils.MemberCachePolicy;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import javax.security.auth.login.LoginException;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class Bot {
|
public class Bot {
|
||||||
private JDA jda = null;
|
private JDA jda = null;
|
||||||
|
|
@ -45,16 +39,12 @@ public class Bot {
|
||||||
jda.setAutoReconnect(true);
|
jda.setAutoReconnect(true);
|
||||||
jda.awaitReady();
|
jda.awaitReady();
|
||||||
jda.addEventListener(
|
jda.addEventListener(
|
||||||
new DiscordMessageListener(),
|
|
||||||
new DiscordRoleListener(),
|
new DiscordRoleListener(),
|
||||||
new JDAListener(jda)));
|
new JDAListener(jda));
|
||||||
DiscordCommand.loadCommands();
|
|
||||||
DiscordLink.getPlugin().getProxy().getScheduler().buildTask(DiscordLink.getPlugin(), new CheckLinkSync())
|
DiscordLink.getPlugin().getProxy().getScheduler().buildTask(DiscordLink.getPlugin(), new CheckLinkSync())
|
||||||
.delay(120, TimeUnit.SECONDS)
|
.delay(120, TimeUnit.SECONDS)
|
||||||
.repeat(12, TimeUnit.HOURS)
|
.repeat(12, TimeUnit.HOURS)
|
||||||
.schedule();
|
.schedule();
|
||||||
} catch (LoginException e) {
|
|
||||||
jda = null;
|
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
@ -265,8 +255,4 @@ public class Bot {
|
||||||
|
|
||||||
return guild.getMembers().stream().filter(member -> member.getRoles().contains(role)).toList();
|
return guild.getMembers().stream().filter(member -> member.getRoles().contains(role)).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addListener(ListenerAdapter listenerAdapter) {
|
|
||||||
jda.addEventListener(listenerAdapter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ public class CheckLinkSync implements Runnable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
List<Member> members = bot.getMembersWithRole(BotConfig.GUILD_ID, BotConfig.LINKED_ROLE_ID);
|
List<Member> members = bot.getMembersWithRole(BotConfig.DISCORD.GUILD_ID, BotConfig.DISCORD.LINKED_ROLE_ID);
|
||||||
HashSet<Long> dbIdSet = plugin.getDatabase().getLinkedUsers();
|
HashSet<Long> dbIdSet = plugin.getDatabase().getLinkedUsers();
|
||||||
HashSet<Long> membersIdSet = members.stream().map(Member::getIdLong).collect(Collectors.toCollection(HashSet::new));
|
HashSet<Long> membersIdSet = members.stream().map(Member::getIdLong).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user