diff --git a/build-number.txt b/build-number.txt index 8a6d441a..c2caf7c1 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -3354 \ No newline at end of file +3358 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/Configuration.java b/src/main/java/me/chayapak1/chomens_bot/Configuration.java index 11877d36..ed09fddf 100644 --- a/src/main/java/me/chayapak1/chomens_bot/Configuration.java +++ b/src/main/java/me/chayapak1/chomens_bot/Configuration.java @@ -153,7 +153,7 @@ public class Configuration { public int port; public String username; public String serverName; - public String discordChannel; + public String discordChannelId; public String ircChannel; public boolean hidden = false; public boolean useCore = true; diff --git a/src/main/java/me/chayapak1/chomens_bot/Main.java b/src/main/java/me/chayapak1/chomens_bot/Main.java index afe0fc46..457ac7d0 100644 --- a/src/main/java/me/chayapak1/chomens_bot/Main.java +++ b/src/main/java/me/chayapak1/chomens_bot/Main.java @@ -208,7 +208,7 @@ public class Main { for (final Bot bot : copiedList) { try { if (discordEnabled) { - final String channelId = Main.discord.findChannelId(bot.options.discordChannel); + final String channelId = bot.options.discordChannelId; final MessageCreateAction messageAction = Main.discord.sendMessageInstantly(stoppingMessage, channelId, false); diff --git a/src/main/java/me/chayapak1/chomens_bot/commands/ConsoleCommand.java b/src/main/java/me/chayapak1/chomens_bot/commands/ConsoleCommand.java index b5164f63..b715aa51 100644 --- a/src/main/java/me/chayapak1/chomens_bot/commands/ConsoleCommand.java +++ b/src/main/java/me/chayapak1/chomens_bot/commands/ConsoleCommand.java @@ -81,7 +81,7 @@ public class ConsoleCommand extends Command { throw new CommandException(Component.translatable("commands.generic.error.discord_disabled")); } - final String channelId = Main.discord.findChannelId(context.bot.options.discordChannel); + final String channelId = context.bot.options.discordChannelId; if (channelId == null) return null; diff --git a/src/main/java/me/chayapak1/chomens_bot/discord/GuildMessageEventHandler.java b/src/main/java/me/chayapak1/chomens_bot/discord/GuildMessageEventHandler.java index b19cdc9f..0b1e6fa8 100644 --- a/src/main/java/me/chayapak1/chomens_bot/discord/GuildMessageEventHandler.java +++ b/src/main/java/me/chayapak1/chomens_bot/discord/GuildMessageEventHandler.java @@ -51,7 +51,7 @@ public class GuildMessageEventHandler extends ListenerAdapter { if (event.getAuthor().getId().equals(jda.getSelfUser().getId())) return; for (final Bot bot : Main.bots) { - final String channelId = Main.discord.findChannelId(bot.options.discordChannel); + final String channelId = bot.options.discordChannelId; if (channelId == null || !event.getChannel().getId().equals(channelId)) continue; diff --git a/src/main/java/me/chayapak1/chomens_bot/discord/SlashCommandHandler.java b/src/main/java/me/chayapak1/chomens_bot/discord/SlashCommandHandler.java index 9125035c..21792340 100644 --- a/src/main/java/me/chayapak1/chomens_bot/discord/SlashCommandHandler.java +++ b/src/main/java/me/chayapak1/chomens_bot/discord/SlashCommandHandler.java @@ -60,7 +60,7 @@ public class SlashCommandHandler extends ListenerAdapter { boolean found = false; for (final Bot bot : Main.bots) { - final String channelId = Main.discord.findChannelId(bot.options.discordChannel); + final String channelId = bot.options.discordChannelId; if (channelId == null || !event.getChannel().getId().equals(channelId)) continue; diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java index 735b8062..8f824b61 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/DiscordPlugin.java @@ -1,5 +1,6 @@ package me.chayapak1.chomens_bot.plugins; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import me.chayapak1.chomens_bot.Bot; import me.chayapak1.chomens_bot.Configuration; import me.chayapak1.chomens_bot.Main; @@ -15,7 +16,6 @@ import me.chayapak1.chomens_bot.util.LoggerUtilities; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.entities.Activity; -import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.requests.GatewayIntent; @@ -26,11 +26,8 @@ import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.format.NamedTextColor; import org.geysermc.mcprotocollib.network.event.session.ConnectedEvent; import org.geysermc.mcprotocollib.network.event.session.DisconnectedEvent; -import org.jetbrains.annotations.Nullable; -import java.util.List; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; @@ -94,7 +91,7 @@ public class DiscordPlugin { Main.EXECUTOR.scheduleAtFixedRate(this::onDiscordTick, 0, 50, TimeUnit.MILLISECONDS); for (final Bot bot : Main.bots) { - final String channelId = findChannelId(bot.options.discordChannel); + final String channelId = bot.options.discordChannelId; if (channelId == null) continue; @@ -166,20 +163,8 @@ public class DiscordPlugin { } } - public @Nullable String findChannelId (final String channelName) { - if (channelName == null) return null; - - final Guild guild = jda.getGuildById(serverId); - if (guild == null) return null; - - final List channels = guild.getTextChannelsByName(channelName, true); - if (channels.isEmpty()) return null; - - return channels.getFirst().getId(); - } - // based from HBot (and modified quite a bit) - private final Map logData = new ConcurrentHashMap<>(); + private final Map logData = new Object2ObjectOpenHashMap<>(); public void sendMessage (final String message, final String channelId) { final LogData data = logData.get(channelId); @@ -230,7 +215,7 @@ public class DiscordPlugin { public void onDiscordTick () { for (final Bot bot : Main.bots) { - final String channelId = findChannelId(bot.options.discordChannel); + final String channelId = bot.options.discordChannelId; if (channelId == null) continue; diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/GrepLogPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/GrepLogPlugin.java index ebfc28a3..331d9b0c 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/GrepLogPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/GrepLogPlugin.java @@ -87,7 +87,7 @@ public class GrepLogPlugin { if (matches == 0) throw new CommandException(Component.translatable("commands.greplog.error.no_matches_found")); - final String channelId = Main.discord.findChannelId(bot.options.discordChannel); + final String channelId = bot.options.discordChannelId; if (channelId == null) return; final TextChannel logChannel = Main.discord.jda.getTextChannelById(channelId); diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index 3b7d752b..d276f1df 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -132,8 +132,8 @@ selfCare: bots: # username - optional, if not specified it will just use a random username # serverName - name it whatever you like, it will be used as server name in trusted broadcast and in console - # discordChannel - the channel name like `localhost` (without #) for use with discord - # ircChannel - same as discordChannel but for irc + # discordChannelId - the channel ID for use with discord + # ircChannel - same as discordChannelId but for irc and is a channel name # hidden - if enabled, the server address will not show anywhere in the bot, including discord, netmsg, etc., except console # useCore - if enabled it just sends the command using chat instead of using core. recommended to enable useChat too when this is disabled # useCorePlaceBlock - uses the place block core instead of the main core. only used if useCore is enabled @@ -148,7 +148,7 @@ bots: - host: 'localhost' port: 25565 serverName: 'Localhost' - # be sure to set discordChannel and/or ircChannel here if you use the discord integration + # be sure to set discordChannelId and/or ircChannel here if you use the discord integration reconnectDelay: 2000 chatQueueDelay: 125 @@ -157,7 +157,7 @@ bots: # port: 25565 # username: 'ChomeNS_Bot' # serverName: 'Localhost' - # discordChannel: 'localhost' + # discordChannelId: '1234567890' # ircChannel: '#chomens/localhost' # hidden: false # useCore: true