Archiviert
1
0

Add DiscordRanks

Dieser Commit ist enthalten in:
yoyosource 2021-07-28 20:29:48 +02:00
Ursprung c9a5f468da
Commit 2579e7adcb
3 geänderte Dateien mit 68 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -47,6 +47,7 @@ public class SteamwarDiscordBotConfig {
public static String TICKET_CREATED;
public static String TICKET_LOG;
public static Map<String, DiscordTicketType> TICKET_TYPES;
public static Map<String, String> RANKS;
public static void loadConfig(Configuration config) {
TOKEN = config.getString("token");
@ -96,5 +97,11 @@ public class SteamwarDiscordBotConfig {
type.getString("color"),
type.getString("pre")));
}
RANKS = new HashMap<>();
Configuration ranksSections = config.getSection("ranks");
for (String type : ranksSections.getKeys()) {
RANKS.put(type, ranksSections.getString(type));
}
}
}

Datei anzeigen

@ -0,0 +1,58 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2020 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.bungeecore.bot.util;
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
import de.steamwar.bungeecore.sql.SteamwarUser;
import de.steamwar.bungeecore.sql.UserGroup;
import lombok.experimental.UtilityClass;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import java.util.HashSet;
import java.util.Set;
@UtilityClass
public class DiscordRanks {
public void update(SteamwarUser steamwarUser) {
if (steamwarUser.getDiscordId() == null) {
return;
}
Guild guild = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD);
Member member = guild.getMemberById(steamwarUser.getDiscordId());
if (member == null) {
return;
}
Set<String> toRemove = new HashSet<>(SteamwarDiscordBotConfig.RANKS.keySet());
if (steamwarUser.getUserGroup() != UserGroup.Member) {
toRemove.remove(steamwarUser.getUserGroup().name().toLowerCase());
}
for (String s : toRemove) {
String roleId = SteamwarDiscordBotConfig.RANKS.get(s);
guild.removeRoleFromMember(member, guild.getRoleById(roleId)).complete();
}
if (steamwarUser.getUserGroup() != UserGroup.Member) {
guild.addRoleToMember(member, guild.getRoleById(SteamwarDiscordBotConfig.RANKS.get(steamwarUser.getUserGroup().name())));
}
}
}

Datei anzeigen

@ -23,6 +23,7 @@ import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.Servertype;
import de.steamwar.bungeecore.Subserver;
import de.steamwar.bungeecore.bot.util.DiscordRanks;
import de.steamwar.bungeecore.commands.ChallengeCommand;
import de.steamwar.bungeecore.commands.CheckCommand;
import de.steamwar.bungeecore.commands.MsgCommand;
@ -94,6 +95,8 @@ public class ConnectionListener extends BasicListener {
Message.broadcast("JOIN_FIRST", player.getName());
newPlayers.remove(player.getUniqueId());
}
DiscordRanks.update(user);
}
/** To redirect players to the lobby in case of server closure. */