From de591b7a5f7040cc6164fe4dfba20437664478de Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 22 Jan 2025 09:39:10 +0100 Subject: [PATCH 1/3] Update CouncilChannel --- .../discord/channels/CouncilChannel.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java index 7ac28228..16a42be1 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java @@ -20,6 +20,7 @@ package de.steamwar.velocitycore.discord.channels; import de.steamwar.sql.SteamwarUser; +import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.discord.DiscordBot; import it.unimi.dsi.fastutil.Pair; import net.dv8tion.jda.api.EmbedBuilder; @@ -29,6 +30,7 @@ import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; public class CouncilChannel extends StaticMessageChannel { @@ -36,11 +38,12 @@ public class CouncilChannel extends StaticMessageChannel { private static final Map channels = new HashMap<>(); public static void update(List roles) { - for(Role role : roles) { - if (channels.containsKey(role)) { - channels.get(role).update(); - } - } + VelocityCore.schedule(() -> { + roles.stream() + .filter(channels::containsKey) + .map(channels::get) + .forEach(CouncilChannel::update); + }).delay(1, TimeUnit.SECONDS); } public CouncilChannel(Role role, ThreadChannel threadChannel) { From aa5fcd38114d8f79fa62cb427d3d94c2700d78a3 Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Wed, 22 Jan 2025 19:52:16 +0100 Subject: [PATCH 2/3] Update CouncilChannel every hour --- .../velocitycore/discord/DiscordBot.java | 16 ++++++-- .../discord/channels/CouncilChannel.java | 23 ++++------- .../discord/listeners/RoleListener.java | 38 ------------------- 3 files changed, 21 insertions(+), 56 deletions(-) delete mode 100644 VelocityCore/src/de/steamwar/velocitycore/discord/listeners/RoleListener.java diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index d2f7419a..2dd455ab 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -24,7 +24,10 @@ import de.steamwar.messages.Chatter; import de.steamwar.sql.Event; import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.discord.channels.*; -import de.steamwar.velocitycore.discord.listeners.*; +import de.steamwar.velocitycore.discord.listeners.ChannelListener; +import de.steamwar.velocitycore.discord.listeners.DiscordSchemUpload; +import de.steamwar.velocitycore.discord.listeners.DiscordTeamEvent; +import de.steamwar.velocitycore.discord.listeners.DiscordTicketHandler; import de.steamwar.velocitycore.discord.util.AuthManager; import lombok.Getter; import net.dv8tion.jda.api.EmbedBuilder; @@ -183,12 +186,19 @@ public class DiscordBot { } }).repeat(30, TimeUnit.SECONDS).schedule(); + VelocityCore.schedule(() -> { + try { + CouncilChannel.updateAll(); + } catch (ErrorResponseException e) { + //ignored + } + }).repeat(1, TimeUnit.HOURS).schedule(); + jda.addEventListener( new DiscordTicketHandler(), new DiscordTeamEvent(), new ChannelListener(), - new DiscordSchemUpload(), - new RoleListener() + new DiscordSchemUpload() ); commandSetup(jda.retrieveCommands().complete(), jda.updateCommands()); diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java index 16a42be1..e5129f24 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java @@ -20,30 +20,24 @@ package de.steamwar.velocitycore.discord.channels; import de.steamwar.sql.SteamwarUser; -import de.steamwar.velocitycore.VelocityCore; import de.steamwar.velocitycore.discord.DiscordBot; import it.unimi.dsi.fastutil.Pair; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; -import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; +import java.util.Comparator; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; public class CouncilChannel extends StaticMessageChannel { - private static final Map channels = new HashMap<>(); + private static final Set channels = new HashSet<>(); - public static void update(List roles) { - VelocityCore.schedule(() -> { - roles.stream() - .filter(channels::containsKey) - .map(channels::get) - .forEach(CouncilChannel::update); - }).delay(1, TimeUnit.SECONDS); + public static void updateAll() { + channels.forEach(StaticMessageChannel::update); } public CouncilChannel(Role role, ThreadChannel threadChannel) { @@ -70,7 +64,6 @@ public class CouncilChannel extends StaticMessageChannel { return messageCreateBuilder; }, event -> {}); - channels.put(role, this); + channels.add(this); } - } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/RoleListener.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/RoleListener.java deleted file mode 100644 index 75063344..00000000 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/RoleListener.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * This file is a part of the SteamWar software. - * - * Copyright (C) 2025 SteamWar.de-Serverteam - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -package de.steamwar.velocitycore.discord.listeners; - -import de.steamwar.velocitycore.discord.channels.CouncilChannel; -import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent; -import net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent; -import net.dv8tion.jda.api.hooks.ListenerAdapter; -import org.jetbrains.annotations.NotNull; - -public class RoleListener extends ListenerAdapter { - @Override - public void onGuildMemberRoleAdd(@NotNull GuildMemberRoleAddEvent event) { - CouncilChannel.update(event.getRoles()); - } - - @Override - public void onGuildMemberRoleRemove(@NotNull GuildMemberRoleRemoveEvent event) { - CouncilChannel.update(event.getRoles()); - } -} From 4db5c50b0685c4021d6a7fd496da598c3ef0220f Mon Sep 17 00:00:00 2001 From: YoyoNow Date: Fri, 24 Jan 2025 08:21:47 +0100 Subject: [PATCH 3/3] Fix PR stuff --- .../src/de/steamwar/velocitycore/discord/DiscordBot.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index 2dd455ab..ecdc5a53 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -186,13 +186,7 @@ public class DiscordBot { } }).repeat(30, TimeUnit.SECONDS).schedule(); - VelocityCore.schedule(() -> { - try { - CouncilChannel.updateAll(); - } catch (ErrorResponseException e) { - //ignored - } - }).repeat(1, TimeUnit.HOURS).schedule(); + VelocityCore.schedule(CouncilChannel::updateAll).repeat(1, TimeUnit.HOURS).schedule(); jda.addEventListener( new DiscordTicketHandler(),