From 038f54c3b31d9dbab3e0d00d0340728d01297bd1 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 9 Apr 2025 09:03:07 +0200 Subject: [PATCH] Make it buildable and reduce complexity --- .../discord/channels/ChecklistChannel.java | 2 +- .../discord/channels/DiscordChannel.java | 14 +++++++++----- .../discord/channels/StaticMessageChannel.java | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/ChecklistChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/ChecklistChannel.java index 6f19f34e..18bbff4a 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/ChecklistChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/ChecklistChannel.java @@ -32,7 +32,7 @@ public class ChecklistChannel extends DiscordChannel { private final List lastSchematics = new ArrayList<>(); public ChecklistChannel(String channel) { - super(channel); + super(channel, 0); } public void update() { diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java index 08b2b3cd..eab85cc1 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java @@ -68,8 +68,16 @@ public class DiscordChannel extends Chatter.PlayerlessChatter { public DiscordChannel(MessageChannel channel, int maxNumberOfWebhooks) { this(maxNumberOfWebhooks, SteamwarUser.get(-1), channel); ChannelListener.getChannels().put(this.channel, this); + if (channel instanceof TextChannel) { - webhooks.addAll(((TextChannel) channel).retrieveWebhooks().complete()); + TextChannel textChannel = (TextChannel) channel; + webhooks.addAll(textChannel.retrieveWebhooks().complete()); + while (webhooks.size() > maxNumberOfWebhooks) { + webhooks.remove().delete().queue(); + } + while (webhooks.size() < maxNumberOfWebhooks) { + webhooks.add(textChannel.createWebhook(DiscordBot.getInstance().getJda().getSelfUser().getName()).complete()); + } } } @@ -102,10 +110,6 @@ public class DiscordChannel extends Chatter.PlayerlessChatter { avatarUrl = DiscordBot.getInstance().getJda().getSelfUser().getAvatarUrl(); } - TextChannel textChannel = (TextChannel) getChannel(); - if (webhooks.size() < maxNumberOfWebhooks) { - webhooks.add(textChannel.createWebhook(DiscordBot.getInstance().getJda().getSelfUser().getName() + "_" + webhooks.size()).complete()); - } Webhook webhook = webhooks.poll(); webhooks.add(webhook); diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java index 69549d38..9ab2920e 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java @@ -46,14 +46,14 @@ public class StaticMessageChannel extends DiscordChannel { } public StaticMessageChannel(String channel, Supplier supplier, Consumer interaction) { - super(channel); + super(channel, 0); this.supplier = supplier; this.interaction = interaction; init(); } public StaticMessageChannel(MessageChannel channel, Supplier supplier, Consumer interaction) { - super(channel); + super(channel, 0); this.supplier = supplier; this.interaction = interaction; init();