diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index d2f7419a..ecdc5a53 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,13 @@ public class DiscordBot { } }).repeat(30, TimeUnit.SECONDS).schedule(); + VelocityCore.schedule(CouncilChannel::updateAll).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 7ac28228..e5129f24 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java @@ -23,24 +23,21 @@ import de.steamwar.sql.SteamwarUser; 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.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) { - for(Role role : roles) { - if (channels.containsKey(role)) { - channels.get(role).update(); - } - } + public static void updateAll() { + channels.forEach(StaticMessageChannel::update); } public CouncilChannel(Role role, ThreadChannel threadChannel) { @@ -67,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()); - } -}