From 02fd7eb96540b39913df406371e82b2aa85ad10d Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 22 Apr 2022 10:36:28 +0200 Subject: [PATCH] Fix discord targets Signed-off-by: Lixfel --- src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java | 5 +++-- .../bungeecore/bot/listeners/DiscordChatListener.java | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java index 36e9c3e..3811c18 100644 --- a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java +++ b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java @@ -29,6 +29,7 @@ import de.steamwar.bungeecore.bot.util.DiscordRolesMessage; import de.steamwar.bungeecore.bot.util.DiscordRulesMessage; import de.steamwar.bungeecore.bot.util.DiscordTicketMessage; import de.steamwar.bungeecore.sql.Event; +import de.steamwar.messages.ChatSender; import lombok.Getter; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; @@ -111,8 +112,8 @@ public class SteamwarDiscordBot { new DiscordEventListener(); new PrivateMessageListener(); announcementListener = new AnnouncementListener(); - ingameChatListener = new DiscordChatListener(SteamwarDiscordBotConfig.INGAME_CHANNEL, "CHAT_DISCORD_GLOBAL"); - serverTeamChatListener = new DiscordChatListener(SteamwarDiscordBotConfig.SERVER_TEAM_CHANNEL, "CHAT_SERVERTEAM"); + ingameChatListener = new DiscordChatListener(SteamwarDiscordBotConfig.INGAME_CHANNEL, "CHAT_DISCORD_GLOBAL", ChatSender::globalReceivers); + serverTeamChatListener = new DiscordChatListener(SteamwarDiscordBotConfig.SERVER_TEAM_CHANNEL, "CHAT_SERVERTEAM", ChatSender::serverteamReceivers); new SlashCommandListener(); jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).queue()); diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java index 63fc644..5317b7b 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/DiscordChatListener.java @@ -31,14 +31,20 @@ import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; import org.jetbrains.annotations.NotNull; +import java.util.function.Supplier; +import java.util.stream.Stream; + public class DiscordChatListener extends BasicDiscordListener { private final String channel; private final String format; - public DiscordChatListener(String channel, String format) { + private final Supplier> targets; + + public DiscordChatListener(String channel, String format, Supplier> targets) { this.channel = channel; this.format = format; + this.targets = targets; } @Override @@ -51,7 +57,7 @@ public class DiscordChatListener extends BasicDiscordListener { if (steamwarUser == null || event.getMessage().getContentRaw().length() > 250 || steamwarUser.isPunished(Punishment.PunishmentType.Ban)) { event.getMessage().delete().queue(); } else { - ChatListener.sendChat(ChatSender.of(event.getMessage(), steamwarUser), ChatSender.globalReceivers(), format, event.getMessage().getContentDisplay().replace('§', '&').replace('\n', ' ')); + ChatListener.sendChat(ChatSender.of(event.getMessage(), steamwarUser), targets.get(), format, event.getMessage().getContentDisplay().replace('§', '&').replace('\n', ' ')); } }