diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java index 10cb773f..89167565 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordBot.java @@ -24,10 +24,7 @@ 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.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.listeners.*; import de.steamwar.velocitycore.discord.util.AuthManager; import lombok.Getter; import net.dv8tion.jda.api.EmbedBuilder; @@ -165,6 +162,7 @@ public class DiscordBot { .setComponents(actionRows), DiscordTicketHandler::openTicket); eventChannel = new StaticMessageChannel(config.channel("events"), EventChannel::get); checklistChannel = new ChecklistChannel(config.channel("checklist")); + config.getCouncilThread().forEach((roleId, threadId) -> new CouncilChannel(DiscordBot.getGuild().getRoleById(roleId), DiscordBot.getGuild().getThreadChannelById(threadId))); announcementChannel = new DiscordChannel(config.channel("announcement")) { @Override @@ -189,7 +187,8 @@ public class DiscordBot { new DiscordTicketHandler(), new DiscordTeamEvent(), new ChannelListener(), - new DiscordSchemUpload() + new DiscordSchemUpload(), + new RoleListener() ); commandSetup(jda.retrieveCommands().complete(), jda.updateCommands()); diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java index af930d77..7f201abb 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/DiscordConfig.java @@ -56,6 +56,8 @@ public class DiscordConfig { private String ticketcategory; + private Map councilThread; + @NoArgsConstructor public static class DiscordRole { diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java new file mode 100644 index 00000000..6a949d0b --- /dev/null +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/CouncilChannel.java @@ -0,0 +1,68 @@ +/* + * 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.channels; + +import de.steamwar.sql.SteamwarUser; +import de.steamwar.velocitycore.discord.DiscordBot; +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.HashMap; +import java.util.List; +import java.util.Map; + +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(); + } + } + } + + public CouncilChannel(Role role, ThreadChannel threadChannel) { + super(threadChannel, () -> { + MessageCreateBuilder messageCreateBuilder = new MessageCreateBuilder(); + messageCreateBuilder.setContent("# Ratsmitglieder"); + + for (Member member : DiscordBot.getGuild().getMembersWithRoles(role)) { + SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong()); + if (steamwarUser == null) + continue; + + messageCreateBuilder.addEmbeds(new EmbedBuilder() + .setTitle(steamwarUser.getUserName()) + .setImage("api.steamwar.de/data/skin/" + steamwarUser.getUUID().toString()) + .build()); + } + + return messageCreateBuilder; + }, event -> {}); + + channels.put(role, this); + } + +} diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java index 35e78714..b420f601 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/DiscordChannel.java @@ -19,11 +19,11 @@ package de.steamwar.velocitycore.discord.channels; -import de.steamwar.velocitycore.discord.DiscordBot; -import de.steamwar.velocitycore.discord.listeners.ChannelListener; import de.steamwar.messages.Chatter; import de.steamwar.messages.Message; import de.steamwar.sql.SteamwarUser; +import de.steamwar.velocitycore.discord.DiscordBot; +import de.steamwar.velocitycore.discord.listeners.ChannelListener; import lombok.AllArgsConstructor; import lombok.Getter; import net.dv8tion.jda.api.entities.User; @@ -31,7 +31,6 @@ import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; -import net.dv8tion.jda.api.utils.messages.MessageCreateData; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer; @@ -53,7 +52,11 @@ public class DiscordChannel extends Chatter.PlayerlessChatter { } public DiscordChannel(String channel) { - this(SteamwarUser.get(-1), DiscordBot.getGuild().getTextChannelById(channel)); + this(DiscordBot.getGuild().getTextChannelById(channel)); + } + + public DiscordChannel(MessageChannel channel) { + this(SteamwarUser.get(-1), channel); ChannelListener.getChannels().put(this.channel, this); } diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java index 3a165915..69549d38 100644 --- a/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/channels/StaticMessageChannel.java @@ -21,6 +21,7 @@ package de.steamwar.velocitycore.discord.channels; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.events.interaction.component.GenericComponentInteractionCreateEvent; import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder; import net.dv8tion.jda.api.utils.messages.MessageEditData; @@ -48,7 +49,17 @@ public class StaticMessageChannel extends DiscordChannel { super(channel); this.supplier = supplier; this.interaction = interaction; + init(); + } + public StaticMessageChannel(MessageChannel channel, Supplier supplier, Consumer interaction) { + super(channel); + this.supplier = supplier; + this.interaction = interaction; + init(); + } + + private void init() { if(getChannel().getLatestMessageIdLong() != 0) message = getChannel().getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null); diff --git a/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/RoleListener.java b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/RoleListener.java new file mode 100644 index 00000000..75063344 --- /dev/null +++ b/VelocityCore/src/de/steamwar/velocitycore/discord/listeners/RoleListener.java @@ -0,0 +1,38 @@ +/* + * 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()); + } +}