forked from SteamWar/SteamWar
Update CouncilChannel every hour
This commit is contained in:
@@ -24,7 +24,10 @@ import de.steamwar.messages.Chatter;
|
|||||||
import de.steamwar.sql.Event;
|
import de.steamwar.sql.Event;
|
||||||
import de.steamwar.velocitycore.VelocityCore;
|
import de.steamwar.velocitycore.VelocityCore;
|
||||||
import de.steamwar.velocitycore.discord.channels.*;
|
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 de.steamwar.velocitycore.discord.util.AuthManager;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
import net.dv8tion.jda.api.EmbedBuilder;
|
||||||
@@ -183,12 +186,19 @@ public class DiscordBot {
|
|||||||
}
|
}
|
||||||
}).repeat(30, TimeUnit.SECONDS).schedule();
|
}).repeat(30, TimeUnit.SECONDS).schedule();
|
||||||
|
|
||||||
|
VelocityCore.schedule(() -> {
|
||||||
|
try {
|
||||||
|
CouncilChannel.updateAll();
|
||||||
|
} catch (ErrorResponseException e) {
|
||||||
|
//ignored
|
||||||
|
}
|
||||||
|
}).repeat(1, TimeUnit.HOURS).schedule();
|
||||||
|
|
||||||
jda.addEventListener(
|
jda.addEventListener(
|
||||||
new DiscordTicketHandler(),
|
new DiscordTicketHandler(),
|
||||||
new DiscordTeamEvent(),
|
new DiscordTeamEvent(),
|
||||||
new ChannelListener(),
|
new ChannelListener(),
|
||||||
new DiscordSchemUpload(),
|
new DiscordSchemUpload()
|
||||||
new RoleListener()
|
|
||||||
);
|
);
|
||||||
|
|
||||||
commandSetup(jda.retrieveCommands().complete(), jda.updateCommands());
|
commandSetup(jda.retrieveCommands().complete(), jda.updateCommands());
|
||||||
|
|||||||
@@ -20,30 +20,24 @@
|
|||||||
package de.steamwar.velocitycore.discord.channels;
|
package de.steamwar.velocitycore.discord.channels;
|
||||||
|
|
||||||
import de.steamwar.sql.SteamwarUser;
|
import de.steamwar.sql.SteamwarUser;
|
||||||
import de.steamwar.velocitycore.VelocityCore;
|
|
||||||
import de.steamwar.velocitycore.discord.DiscordBot;
|
import de.steamwar.velocitycore.discord.DiscordBot;
|
||||||
import it.unimi.dsi.fastutil.Pair;
|
import it.unimi.dsi.fastutil.Pair;
|
||||||
import net.dv8tion.jda.api.EmbedBuilder;
|
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.Role;
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
|
import net.dv8tion.jda.api.entities.channel.concrete.ThreadChannel;
|
||||||
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
import net.dv8tion.jda.api.utils.messages.MessageCreateBuilder;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Comparator;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.HashSet;
|
||||||
import java.util.stream.Collectors;
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class CouncilChannel extends StaticMessageChannel {
|
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) {
|
public static void updateAll() {
|
||||||
VelocityCore.schedule(() -> {
|
channels.forEach(StaticMessageChannel::update);
|
||||||
roles.stream()
|
|
||||||
.filter(channels::containsKey)
|
|
||||||
.map(channels::get)
|
|
||||||
.forEach(CouncilChannel::update);
|
|
||||||
}).delay(1, TimeUnit.SECONDS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CouncilChannel(Role role, ThreadChannel threadChannel) {
|
public CouncilChannel(Role role, ThreadChannel threadChannel) {
|
||||||
@@ -70,7 +64,6 @@ public class CouncilChannel extends StaticMessageChannel {
|
|||||||
return messageCreateBuilder;
|
return messageCreateBuilder;
|
||||||
}, event -> {});
|
}, 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