forked from SteamWar/SteamWar
Merge pull request 'Fix for Role Lookup in CouncilChannel' (#11) from VelocityCore/CouncilChannel into main
Reviewed-on: SteamWar/SteamWar#11 Reviewed-by: Lixfel <lixfel@noreply.localhost>
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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<Role, CouncilChannel> channels = new HashMap<>();
|
||||
private static final Set<CouncilChannel> channels = new HashSet<>();
|
||||
|
||||
public static void update(List<Role> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user