-24s startup time. #238
@ -48,11 +48,7 @@ public class AuthManager {
|
||||
|
||||
TOKENS.put(code, member.getIdLong());
|
||||
BungeeCore.log("Created Discord Auth-Token: " + code + " for: " + member.getUser().getAsTag());
|
||||
ScheduledTask[] task = new ScheduledTask[1];
|
||||
task[0] = BungeeCore.get().getProxy().getScheduler().schedule(BungeeCore.get(), () -> {
|
||||
TOKENS.remove(code);
|
||||
task[0].cancel();
|
||||
}, 10, 10, TimeUnit.MINUTES);
|
||||
BungeeCore.get().getProxy().getScheduler().schedule(BungeeCore.get(), () -> TOKENS.remove(code), 10, TimeUnit.MINUTES);
|
||||
return code;
|
||||
}
|
||||
|
||||
@ -66,10 +62,10 @@ public class AuthManager {
|
||||
builder.setActionRows(ActionRow.of(Button.success("tada", Emoji.fromUnicode("U+1F389")), Button.danger("invalid", "Ich war das nicht")));
|
||||
|
||||
try {
|
||||
member.getUser().openPrivateChannel().complete().sendMessage(builder.build()).complete();
|
||||
member.getUser().openPrivateChannel().queue(privateChannel -> privateChannel.sendMessage(builder.build()).queue());
|
||||
if (member.getNickname() == null) {
|
||||
try {
|
||||
member.getGuild().modifyNickname(member, user.getUserName()).complete();
|
||||
member.getGuild().modifyNickname(member, user.getUserName()).queue();
|
||||
} catch (Exception e) {
|
||||
// Ignored
|
||||
}
|
||||
|
@ -78,43 +78,45 @@ public class SteamwarDiscordBot {
|
||||
} catch (LoginException e) {
|
||||
throw new SecurityException("Could not Login: " + SteamwarDiscordBotConfig.TOKEN, e);
|
||||
}
|
||||
try {
|
||||
jda.awaitReady();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
activity();
|
||||
EventManager.update();
|
||||
SchematicsManager.update();
|
||||
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
||||
ProxyServer.getInstance().getScheduler().runAsync(BungeeCore.get(), () -> {
|
||||
try {
|
||||
jda.awaitReady();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
activity();
|
||||
EventManager.update();
|
||||
SchematicsManager.update();
|
||||
}, 30, 30, TimeUnit.SECONDS);
|
||||
DiscordRolesMessage.sendMessage();
|
||||
DiscordRulesMessage.sendMessage();
|
||||
DiscordTicketMessage.sendMessage();
|
||||
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), () -> {
|
||||
activity();
|
||||
EventManager.update();
|
||||
SchematicsManager.update();
|
||||
}, 30, 30, TimeUnit.SECONDS);
|
||||
DiscordRolesMessage.sendMessage();
|
||||
DiscordRulesMessage.sendMessage();
|
||||
DiscordTicketMessage.sendMessage();
|
||||
|
||||
new RolesInteractionButtonListener();
|
||||
new DiscordTicketListener();
|
||||
new DiscordAuthListener();
|
||||
announcementListener = new AnnouncementListener();
|
||||
ingameChatListener = new IngameChatListener();
|
||||
serverTeamChatListener = new ServerTeamChatListener();
|
||||
new SlashCommandListener();
|
||||
new RolesInteractionButtonListener();
|
||||
new DiscordTicketListener();
|
||||
new DiscordAuthListener();
|
||||
announcementListener = new AnnouncementListener();
|
||||
ingameChatListener = new IngameChatListener();
|
||||
serverTeamChatListener = new ServerTeamChatListener();
|
||||
new SlashCommandListener();
|
||||
|
||||
jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).complete());
|
||||
jda.retrieveCommands().complete().forEach(command -> jda.deleteCommandById(command.getId()).queue());
|
||||
|
||||
Guild guild = jda.getGuildById(SteamwarDiscordBotConfig.GUILD);
|
||||
guild.retrieveCommands().complete().forEach(command -> guild.deleteCommandById(command.getId()).complete());
|
||||
CommandListUpdateAction commands = jda.getGuildById(SteamwarDiscordBotConfig.GUILD).updateCommands();
|
||||
addCommand(commands, new MuteCommand());
|
||||
addCommand(commands, new BanCommand());
|
||||
addCommand(commands, new WhoisCommand());
|
||||
addCommand(commands, new TeamCommand());
|
||||
addCommand(commands, new ListCommand());
|
||||
addCommand(commands, new UnbanCommand());
|
||||
commands.complete();
|
||||
Guild guild = jda.getGuildById(SteamwarDiscordBotConfig.GUILD);
|
||||
guild.retrieveCommands().queue(commands -> commands.forEach(command -> guild.deleteCommandById(command.getId()).queue()));
|
||||
CommandListUpdateAction commands = jda.getGuildById(SteamwarDiscordBotConfig.GUILD).updateCommands();
|
||||
addCommand(commands, new MuteCommand());
|
||||
addCommand(commands, new BanCommand());
|
||||
addCommand(commands, new WhoisCommand());
|
||||
addCommand(commands, new TeamCommand());
|
||||
addCommand(commands, new ListCommand());
|
||||
addCommand(commands, new UnbanCommand());
|
||||
commands.queue();
|
||||
});
|
||||
}
|
||||
|
||||
private void addCommand(CommandListUpdateAction commands, BasicDiscordCommand basicDiscordCommand) {
|
||||
|
@ -45,13 +45,13 @@ public class BanCommand extends BasicDiscordCommand {
|
||||
SteamwarUser sender = SteamwarUser.get(event.getMember().getIdLong());
|
||||
SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(event.getOption("user").getAsString());
|
||||
if (target == null) {
|
||||
event.reply("Angegebener User invalide").setEphemeral(true).complete();
|
||||
event.reply("Angegebener User invalide").setEphemeral(true).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
Timestamp time = de.steamwar.bungeecore.commands.BanCommand.parseTime(null, event.getOption("time").getAsString());
|
||||
if (time == null) {
|
||||
event.reply("Angegebene Zeit invalide").setEphemeral(true).complete();
|
||||
event.reply("Angegebene Zeit invalide").setEphemeral(true).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -60,6 +60,6 @@ public class BanCommand extends BasicDiscordCommand {
|
||||
|
||||
target.ban(time, msg, sender.getId(), isPerma);
|
||||
Message.team("BAN_TEAM_BANNED", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg);
|
||||
event.reply("Erfolgreich " + target.getUserName() + (isPerma ? " permanent" : " bis " + time) + " gebannt").setEphemeral(true).complete();
|
||||
event.reply("Erfolgreich " + target.getUserName() + (isPerma ? " permanent" : " bis " + time) + " gebannt").setEphemeral(true).queue();
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ public abstract class BasicDiscordCommand extends CommandData {
|
||||
Member member = event.getMember();
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
|
||||
if (steamwarUser == null || (!steamwarUser.getUserGroup().isTeamGroup() && steamwarUser.getUserGroup() != UserGroup.Builder)) {
|
||||
event.reply("Du hast für " + event.getName() + " keine Rechte oder es existiert keine Verknüpfung für dich.").setEphemeral(true).complete();
|
||||
event.reply("Du hast für " + event.getName() + " keine Rechte oder es existiert keine Verknüpfung für dich.").setEphemeral(true).queue();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -38,6 +38,6 @@ public class ListCommand extends BasicDiscordCommand {
|
||||
de.steamwar.bungeecore.commands.ListCommand.getPlayerMap().forEach((s, proxiedPlayers) -> {
|
||||
embedBuilder.addField(s, proxiedPlayers.stream().map(player -> "`" + player.getName() + "`").collect(Collectors.joining(", ")), true);
|
||||
});
|
||||
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).complete();
|
||||
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).queue();
|
||||
}
|
||||
}
|
||||
|
@ -61,6 +61,6 @@ public class MuteCommand extends BasicDiscordCommand {
|
||||
|
||||
target.mute(time, msg, sender.getId(), isPerma);
|
||||
Message.team("MUTE_TEAM_MUTED", new Message("PREFIX"), target.getUserName(), sender.getUserName(), new Message((isPerma ? "BAN_PERMA" : "BAN_UNTIL"), time), msg);
|
||||
event.reply("Erfolgreich " + target.getUserName() + (isPerma ? " permanent" : " bis " + time) + " gemutet").setEphemeral(true).complete();
|
||||
event.reply("Erfolgreich " + target.getUserName() + (isPerma ? " permanent" : " bis " + time) + " gemutet").setEphemeral(true).queue();
|
||||
}
|
||||
}
|
||||
|
@ -58,11 +58,11 @@ public class TeamCommand extends BasicDiscordCommand {
|
||||
Team team;
|
||||
if (optionMapping == null) {
|
||||
if (steamwarUser == null) {
|
||||
event.reply("Dein Discord ist nicht verknüpft").setEphemeral(true).complete();
|
||||
event.reply("Dein Discord ist nicht verknüpft").setEphemeral(true).queue();
|
||||
return;
|
||||
}
|
||||
if (steamwarUser.getTeam() == 0) {
|
||||
event.reply("Du bist in keinem Team").setEphemeral(true).complete();
|
||||
event.reply("Du bist in keinem Team").setEphemeral(true).queue();
|
||||
return;
|
||||
}
|
||||
team = Team.get(steamwarUser.getTeam());
|
||||
@ -70,7 +70,7 @@ public class TeamCommand extends BasicDiscordCommand {
|
||||
team = Team.get(optionMapping.getAsString());
|
||||
}
|
||||
if (team == null) {
|
||||
event.reply("Unbekanntes Team").setEphemeral(true).complete();
|
||||
event.reply("Unbekanntes Team").setEphemeral(true).queue();
|
||||
return;
|
||||
}
|
||||
EmbedBuilder embedBuilder = new EmbedBuilder();
|
||||
@ -81,10 +81,10 @@ public class TeamCommand extends BasicDiscordCommand {
|
||||
embedBuilder.addField("Leader", members.stream().filter(SteamwarUser::isLeader).map(user -> "`" + (isOnline(user) ? emoji.getAsMention() : "") + user.getUserName() + "`").collect(Collectors.joining(" ")), false);
|
||||
embedBuilder.addField("Member", members.stream().filter(user -> !user.isLeader()).map(user -> "`" + (isOnline(user) ? emoji.getAsMention() : "") + user.getUserName() + "`").collect(Collectors.joining(" ")), false);
|
||||
embedBuilder.addField("Events", "`" + TeamTeilnahme.getEvents(team.getTeamId()).stream().map(Event::getEventName).collect(Collectors.joining("` `")) + "`", false);
|
||||
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).complete();
|
||||
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).queue();
|
||||
return;
|
||||
default:
|
||||
event.reply("Unbekannter Befehl").setEphemeral(true).complete();
|
||||
event.reply("Unbekannter Befehl").setEphemeral(true).queue();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
|
||||
package de.steamwar.bungeecore.bot.commands;
|
||||
|
||||
import de.steamwar.bungeecore.Message;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.dv8tion.jda.api.events.interaction.SlashCommandEvent;
|
||||
import net.dv8tion.jda.api.interactions.commands.OptionType;
|
||||
@ -44,16 +43,16 @@ public class UnbanCommand extends BasicDiscordCommand {
|
||||
SteamwarUser sender = SteamwarUser.get(event.getMember().getIdLong());
|
||||
SteamwarUser target = SteamwarUser.getOrCreateOfflinePlayer(event.getOption("user").getAsString());
|
||||
if (target == null) {
|
||||
event.reply("Angegebener User invalide").setEphemeral(true).complete();
|
||||
event.reply("Angegebener User invalide").setEphemeral(true).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!target.isBanned()) {
|
||||
event.reply("Angegebener User ist nicht gebannt").setEphemeral(true).complete();
|
||||
event.reply("Angegebener User ist nicht gebannt").setEphemeral(true).queue();
|
||||
return;
|
||||
}
|
||||
|
||||
target.ban(Timestamp.from(new Date().toInstant()), "Unban", sender.getId(), false);
|
||||
event.reply("Erfolgreich " + target.getUserName() + " entbannt").setEphemeral(true).complete();
|
||||
event.reply("Erfolgreich " + target.getUserName() + " entbannt").setEphemeral(true).queue();
|
||||
}
|
||||
}
|
||||
|
@ -89,6 +89,6 @@ public class WhoisCommand extends BasicDiscordCommand {
|
||||
embedBuilder.addField(punishment.getType().name() + " von " + SteamwarUser.get(punishment.getPunisher()).getUserName(), "Von: " + punishment.getBantime(punishment.getStartTime(), false) + "\nBis: " + punishment.getBantime(punishment.getEndTime(), punishment.isPerma()) + "\nGrund: " + punishment.getReason(), true);
|
||||
}
|
||||
|
||||
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).complete();
|
||||
event.replyEmbeds(embedBuilder.build()).setEphemeral(true).queue();
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ public class EventManager {
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
messageBuilder.setEmbeds(embedBuilder.build());
|
||||
if (message == null) {
|
||||
message = textChannel.sendMessage(messageBuilder.build()).complete();
|
||||
textChannel.sendMessage(messageBuilder.build()).queue(message1 -> message = message1);
|
||||
} else {
|
||||
message.editMessage(messageBuilder.build()).complete();
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ public class SchematicsManager {
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
messageBuilder.setEmbeds(embedBuilder.build());
|
||||
if (message == null) {
|
||||
message = textChannel.sendMessage(messageBuilder.build()).complete();
|
||||
textChannel.sendMessage(messageBuilder.build()).queue(message1 -> message = message1);
|
||||
} else {
|
||||
message.editMessage(messageBuilder.build()).queue();
|
||||
}
|
||||
|
@ -45,6 +45,6 @@ public class AnnouncementListener extends BasicDiscordListener {
|
||||
assert textChannel != null;
|
||||
MessageBuilder messageBuilder = new MessageBuilder();
|
||||
messageBuilder.append(message.replace("&", ""));
|
||||
textChannel.sendMessage(messageBuilder.build()).complete();
|
||||
textChannel.sendMessage(messageBuilder.build()).queue();
|
||||
}
|
||||
}
|
||||
|
@ -35,23 +35,23 @@ public class DiscordAuthListener extends BasicDiscordListener {
|
||||
if(event.getChannel().getId().equals(SteamwarDiscordBotConfig.RULES_CHANNEL) && event.getComponentId().equals("auth")) {
|
||||
String authMessage = AuthManager.createDiscordAuthToken(event.getMember());
|
||||
if(authMessage != null) {
|
||||
event.reply("Gebe innerhalb der nächsten 10 Minuten ``/verify " + authMessage + "`` auf dem Minecraft Server ein").setEphemeral(true).complete();
|
||||
event.reply("Gebe innerhalb der nächsten 10 Minuten ``/verify " + authMessage + "`` auf dem Minecraft Server ein").setEphemeral(true).queue();
|
||||
} else {
|
||||
event.reply("Du hast bereits einen Code am laufen").setEphemeral(true).complete();
|
||||
event.reply("Du hast bereits einen Code am laufen").setEphemeral(true).queue();
|
||||
}
|
||||
}
|
||||
|
||||
if(event.getComponentId().equals("tada") && event.getChannelType() == ChannelType.PRIVATE) {
|
||||
event.reply(":tada:").setEphemeral(false).complete();
|
||||
event.reply(":tada:").setEphemeral(false).queue();
|
||||
}
|
||||
|
||||
if(event.getComponentId().equals("invalid") && event.getChannelType() == ChannelType.PRIVATE) {
|
||||
SteamwarUser user = SteamwarUser.get(event.getUser().getIdLong());
|
||||
if(user == null) {
|
||||
event.reply(":question: Da ist keine verknüpfung?").setEphemeral(false).complete();
|
||||
event.reply(":question: Da ist keine verknüpfung?").setEphemeral(false).queue();
|
||||
} else {
|
||||
user.setDiscordId(null);
|
||||
event.reply(":x: Die Verknüpfung wurde beendet").setEphemeral(false).complete();
|
||||
event.reply(":x: Die Verknüpfung wurde beendet").setEphemeral(false).queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,7 +114,7 @@ public class DiscordTicketListener extends BasicDiscordListener {
|
||||
logChannel.sendMessage(builder.build()).complete();
|
||||
|
||||
Message.team("DISCORD_TICKET_CLOSED", event.getTextChannel().getName());
|
||||
event.getTextChannel().delete().reason("Closed").complete();
|
||||
event.getTextChannel().delete().reason("Closed").queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -126,16 +126,15 @@ public class DiscordTicketListener extends BasicDiscordListener {
|
||||
BungeeCore.get().getProxy().getPlayers().forEach(player -> {
|
||||
if(event.getAuthor().isBot() || event.getAuthor().isSystem()) return;
|
||||
SteamwarUser user = SteamwarUser.get(player);
|
||||
boolean sendMessage;
|
||||
if(user.getDiscordId() == null) {
|
||||
if(user.getUserGroup().isTeamGroup()) {
|
||||
Message.sendPrefixless("DISCORD_TICKET_MESSAGE", player, "Zur nachricht", new ClickEvent(ClickEvent.Action.OPEN_URL, event.getMessage().getJumpUrl()), event.getChannel().getName(), event.getAuthor().getName(), event.getMessage().getContentRaw());
|
||||
}
|
||||
sendMessage = user.getUserGroup().isCheckSchematics();
|
||||
} else {
|
||||
if(event.getAuthor().getId().equals(user.getDiscordId())) return;
|
||||
Member member = event.getGuild().retrieveMemberById(user.getDiscordId()).complete();
|
||||
if(member.hasPermission(event.getChannel().getManager().getChannel(), Permission.MESSAGE_WRITE)) {
|
||||
Message.sendPrefixless("DISCORD_TICKET_MESSAGE", player, "Zur nachricht", new ClickEvent(ClickEvent.Action.OPEN_URL, event.getMessage().getJumpUrl()), event.getChannel().getName(), event.getAuthor().getName(), event.getMessage().getContentRaw());
|
||||
}
|
||||
sendMessage = user.getDiscordId().equals(event.getChannel().getTopic()) || user.getUserGroup().isCheckSchematics();
|
||||
}
|
||||
if(sendMessage) {
|
||||
Message.sendPrefixless("DISCORD_TICKET_MESSAGE", player, "Zur nachricht", new ClickEvent(ClickEvent.Action.OPEN_URL, event.getMessage().getJumpUrl()), event.getChannel().getName(), event.getAuthor().getName(), event.getMessage().getContentRaw());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -43,15 +43,15 @@ public class IngameChatListener extends BasicDiscordListener {
|
||||
Member member = event.getMember();
|
||||
SteamwarUser steamwarUser = SteamwarUser.get(member.getIdLong());
|
||||
if (steamwarUser == null || event.getMessage().getContentRaw().length() > 250) {
|
||||
event.getMessage().delete().complete();
|
||||
event.getMessage().delete().queue();
|
||||
} else {
|
||||
String s = event.getMessage().getContentDisplay();
|
||||
if (steamwarUser.getUserGroup() == UserGroup.Member && (s.contains("http") || s.contains("www"))) {
|
||||
event.getMessage().delete().complete();
|
||||
event.getMessage().delete().queue();
|
||||
return;
|
||||
}
|
||||
if (steamwarUser.isMuted() || steamwarUser.isBanned()) {
|
||||
event.getMessage().delete().complete();
|
||||
event.getMessage().delete().queue();
|
||||
return;
|
||||
}
|
||||
ChatListener.discordChat(steamwarUser, event.getMessage().getContentDisplay().replaceAll("§[a-f0-9]", "").replace('\n', ' '));
|
||||
|
@ -32,10 +32,10 @@ public class RolesInteractionButtonListener extends BasicDiscordListener {
|
||||
if(event.getType() == InteractionType.COMPONENT && event.getChannelType() == ChannelType.TEXT && event.getTextChannel().getId().equals(SteamwarDiscordBotConfig.ROLES_CHANNEL) && SteamwarDiscordBotConfig.ROLES.stream().anyMatch(discordRole -> discordRole.getRoleId().equals(event.getComponentId()))) {
|
||||
if (event.getMember().getRoles().stream().anyMatch(role -> role.getId().equals(event.getComponentId()))) {
|
||||
event.getGuild().removeRoleFromMember(event.getMember(), event.getGuild().getRoleById(event.getComponentId())).complete();
|
||||
event.reply(SteamwarDiscordBotConfig.ROLES_REMOVED.replace("%role%", event.getGuild().getRoleById(event.getComponentId()).getAsMention())).setEphemeral(true).complete();
|
||||
event.reply(SteamwarDiscordBotConfig.ROLES_REMOVED.replace("%role%", event.getGuild().getRoleById(event.getComponentId()).getAsMention())).setEphemeral(true).queue();
|
||||
} else {
|
||||
event.getGuild().addRoleToMember(event.getMember(), event.getGuild().getRoleById(event.getComponentId())).complete();
|
||||
event.reply(SteamwarDiscordBotConfig.ROLES_ADDED.replace("%role%", event.getGuild().getRoleById(event.getComponentId()).getAsMention())).setEphemeral(true).complete();
|
||||
event.reply(SteamwarDiscordBotConfig.ROLES_ADDED.replace("%role%", event.getGuild().getRoleById(event.getComponentId()).getAsMention())).setEphemeral(true).queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ package de.steamwar.bungeecore.bot.listeners;
|
||||
import de.steamwar.bungeecore.bot.SteamwarDiscordBot;
|
||||
import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig;
|
||||
import de.steamwar.bungeecore.commands.ServerTeamchatCommand;
|
||||
import de.steamwar.bungeecore.listeners.ChatListener;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import net.dv8tion.jda.api.MessageBuilder;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
|
@ -22,13 +22,11 @@ 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 net.dv8tion.jda.api.exceptions.ErrorResponseException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@ -41,27 +39,31 @@ public class DiscordRanks {
|
||||
return;
|
||||
}
|
||||
Guild guild = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD);
|
||||
Member member = guild.retrieveMemberById(steamwarUser.getDiscordId()).complete();
|
||||
if (member == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Role> roleList = member.getRoles();
|
||||
Set<String> strings = new HashSet<>(SteamwarDiscordBotConfig.RANKS.values());
|
||||
String needed = SteamwarDiscordBotConfig.RANKS.get(steamwarUser.getUserGroup());
|
||||
for (Role role : roleList) {
|
||||
if (!strings.contains(role.getId())) {
|
||||
continue;
|
||||
guild.retrieveMemberById(steamwarUser.getDiscordId()).queue(member -> {
|
||||
List<Role> roleList = member.getRoles();
|
||||
Set<String> strings = new HashSet<>(SteamwarDiscordBotConfig.RANKS.values());
|
||||
String needed = SteamwarDiscordBotConfig.RANKS.get(steamwarUser.getUserGroup());
|
||||
for (Role role : roleList) {
|
||||
if (!strings.contains(role.getId())) {
|
||||
continue;
|
||||
}
|
||||
if (role.getId().equals(needed)) {
|
||||
needed = "";
|
||||
continue;
|
||||
}
|
||||
guild.removeRoleFromMember(member, role).complete();
|
||||
}
|
||||
if (role.getId().equals(needed)) {
|
||||
needed = "";
|
||||
continue;
|
||||
}
|
||||
guild.removeRoleFromMember(member, role).complete();
|
||||
}
|
||||
|
||||
if (needed != null && !needed.isEmpty()) {
|
||||
guild.addRoleToMember(member, guild.getRoleById(needed)).complete();
|
||||
}
|
||||
if (needed != null && !needed.isEmpty()) {
|
||||
guild.addRoleToMember(member, guild.getRoleById(needed)).complete();
|
||||
}
|
||||
}, throwable -> {
|
||||
if(throwable instanceof ErrorResponseException) {
|
||||
ErrorResponseException e = (ErrorResponseException) throwable;
|
||||
if(e.getErrorCode() == 10007) {
|
||||
steamwarUser.setDiscordId(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -38,10 +38,6 @@ public class DiscordRolesMessage {
|
||||
public void sendMessage() {
|
||||
TextChannel channel = SteamwarDiscordBot.instance().getJda().getGuildById(SteamwarDiscordBotConfig.GUILD).getTextChannelById(SteamwarDiscordBotConfig.ROLES_CHANNEL);
|
||||
assert channel != null;
|
||||
Message message = null;
|
||||
if(channel.hasLatestMessage()) {
|
||||
message = channel.getIterableHistory().complete().stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
MessageBuilder builder = new MessageBuilder();
|
||||
builder.setContent(SteamwarDiscordBotConfig.ROLES_BASE_MESSAGE);
|
||||
@ -49,10 +45,17 @@ public class DiscordRolesMessage {
|
||||
SteamwarDiscordBotConfig.ROLES.forEach(discordRole -> buttons.add(discordRole.toButton()));
|
||||
builder.setActionRows(ActionRow.of(buttons));
|
||||
|
||||
if (message != null) {
|
||||
message.editMessage(builder.build()).complete();
|
||||
if(channel.hasLatestMessage()) {
|
||||
channel.getIterableHistory().queue(messages -> {
|
||||
Message message = messages.stream().filter(m -> m.getAuthor().isBot()).findFirst().orElse(null);
|
||||
if (message != null) {
|
||||
message.editMessage(builder.build()).queue();
|
||||
} else {
|
||||
channel.sendMessage(builder.build()).queue();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
channel.sendMessage(builder.build()).complete();
|
||||
channel.sendMessage(builder.build()).queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,9 +60,9 @@ public class DiscordRulesMessage {
|
||||
messageBuilder.setEmbeds(builder.build());
|
||||
messageBuilder.setActionRows(ActionRow.of(buttons), ActionRow.of(authButton));
|
||||
if (message != null) {
|
||||
message.editMessage(messageBuilder.build()).complete();
|
||||
message.editMessage(messageBuilder.build()).queue();
|
||||
} else {
|
||||
channel.sendMessage(messageBuilder.build()).complete();
|
||||
channel.sendMessage(messageBuilder.build()).queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,9 +56,9 @@ public class DiscordTicketMessage {
|
||||
messageBuilder.setEmbeds(builder.build());
|
||||
messageBuilder.setActionRows(ActionRow.of(buttons));
|
||||
if (message != null) {
|
||||
message.editMessage(messageBuilder.build()).complete();
|
||||
message.editMessage(messageBuilder.build()).queue();
|
||||
} else {
|
||||
channel.sendMessage(messageBuilder.build()).complete();
|
||||
channel.sendMessage(messageBuilder.build()).queue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren