diff --git a/src/de/steamwar/bungeecore/bot/events/EventManager.java b/src/de/steamwar/bungeecore/bot/events/EventManager.java index 53daa79..56f982c 100644 --- a/src/de/steamwar/bungeecore/bot/events/EventManager.java +++ b/src/de/steamwar/bungeecore/bot/events/EventManager.java @@ -47,7 +47,7 @@ public class EventManager { textChannel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.EVENTS_CHANNEL); assert textChannel != null; if(textChannel.hasLatestMessage()) { - textChannel.getIterableHistory().complete().forEach(message -> message.delete().complete()); + message = textChannel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null); } } diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java b/src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java index deb65ed..baa8801 100644 --- a/src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java +++ b/src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java @@ -21,22 +21,26 @@ package de.steamwar.bungeecore.bot.util; import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; +import lombok.experimental.UtilityClass; import net.dv8tion.jda.api.MessageBuilder; +import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.Button; -import net.dv8tion.jda.api.requests.restaction.MessageAction; import java.util.ArrayList; import java.util.List; +@UtilityClass public class DiscordRolesMessage { - public static void sendMessage() { + + public void sendMessage() { TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.ROLES_CHANNEL); assert channel != null; + Message message = null; if(channel.hasLatestMessage()) { - channel.getIterableHistory().complete().forEach(message -> message.delete().complete()); + message = channel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null); } MessageBuilder builder = new MessageBuilder(); @@ -45,7 +49,10 @@ public class DiscordRolesMessage { SteamwarDiscordBotConfig.ROLES.forEach(discordRole -> buttons.add(discordRole.toButton())); builder.setActionRows(ActionRow.of(buttons)); - MessageAction message = channel.sendMessage(builder.build()); - message.complete(); + if (message != null) { + message.editMessage(builder.build()).complete(); + } else { + channel.sendMessage(builder.build()).complete(); + } } } diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java b/src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java index 0ef229b..b2be022 100644 --- a/src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java +++ b/src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java @@ -24,6 +24,8 @@ import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.MessageBuilder; import net.dv8tion.jda.api.entities.Emoji; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.Button; @@ -37,8 +39,9 @@ public class DiscordRulesMessage { public static void sendMessage() { TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.RULES_CHANNEL); assert channel != null; + Message message = null; if(channel.hasLatestMessage()) { - channel.getIterableHistory().complete().forEach(message -> message.delete().complete()); + message = channel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null); } EmbedBuilder builder = new EmbedBuilder(); @@ -55,6 +58,10 @@ public class DiscordRulesMessage { MessageBuilder messageBuilder = new MessageBuilder(); messageBuilder.setEmbeds(builder.build()); messageBuilder.setActionRows(ActionRow.of(buttons), ActionRow.of(authButton)); - channel.sendMessage(messageBuilder.build()).complete(); + if (message != null) { + message.editMessage(messageBuilder.build()).complete(); + } else { + channel.sendMessage(messageBuilder.build()).complete(); + } } } diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java b/src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java index 34454eb..207b9a7 100644 --- a/src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java +++ b/src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java @@ -23,6 +23,7 @@ import de.steamwar.bungeecore.bot.SteamwarDiscordBot; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.MessageBuilder; +import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.Button; @@ -36,8 +37,9 @@ public class DiscordTicketMessage { public static void sendMessage() { TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.TICKET_CHANNEL); assert channel != null; + Message message = null; if(channel.hasLatestMessage()) { - channel.getIterableHistory().complete().forEach(message -> message.delete().complete()); + message = channel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null); } EmbedBuilder builder = new EmbedBuilder(); @@ -51,6 +53,10 @@ public class DiscordTicketMessage { MessageBuilder messageBuilder = new MessageBuilder(); messageBuilder.setEmbeds(builder.build()); messageBuilder.setActionRows(ActionRow.of(buttons)); - channel.sendMessage(messageBuilder.build()).complete(); + if (message != null) { + message.editMessage(messageBuilder.build()).complete(); + } else { + channel.sendMessage(messageBuilder.build()).complete(); + } } }