From f0e7f52fd65a8975ba50c9898d7ca3ecd3467d66 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Sat, 4 Sep 2021 22:18:38 +0200 Subject: [PATCH 1/3] -21s Start time. Signed-off-by: Lixfel --- .../bungeecore/bot/SteamwarDiscordBot.java | 6 +++--- .../bot/util/DiscordRolesMessage.java | 17 ++++++++++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java index 7c5f1db..57d67f5 100644 --- a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java +++ b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java @@ -103,10 +103,10 @@ public class SteamwarDiscordBot { 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()); + guild.retrieveCommands().complete().forEach(command -> guild.deleteCommandById(command.getId()).queue()); CommandListUpdateAction commands = jda.getGuildById(SteamwarDiscordBotConfig.GUILD).updateCommands(); addCommand(commands, new MuteCommand()); addCommand(commands, new BanCommand()); @@ -114,7 +114,7 @@ public class SteamwarDiscordBot { addCommand(commands, new TeamCommand()); addCommand(commands, new ListCommand()); addCommand(commands, new UnbanCommand()); - commands.complete(); + commands.queue(); } private void addCommand(CommandListUpdateAction commands, BasicDiscordCommand basicDiscordCommand) { diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java b/src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java index baa8801..1486deb 100644 --- a/src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java +++ b/src/de/steamwar/bungeecore/bot/util/DiscordRolesMessage.java @@ -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(); } } } -- 2.39.2 From a0ac0a0be25d56d7ec6dfe96ce61c96720ca4d20 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Sat, 4 Sep 2021 23:15:08 +0200 Subject: [PATCH 2/3] Async (TM) Signed-off-by: Chaoscaot --- .../steamwar/bungeecore/bot/AuthManager.java | 10 +-- .../bungeecore/bot/SteamwarDiscordBot.java | 64 ++++++++++--------- .../bungeecore/bot/commands/BanCommand.java | 6 +- .../bot/commands/BasicDiscordCommand.java | 2 +- .../bungeecore/bot/commands/ListCommand.java | 2 +- .../bungeecore/bot/commands/MuteCommand.java | 2 +- .../bungeecore/bot/commands/TeamCommand.java | 10 +-- .../bungeecore/bot/commands/UnbanCommand.java | 7 +- .../bungeecore/bot/commands/WhoisCommand.java | 2 +- .../bungeecore/bot/events/EventManager.java | 2 +- .../bot/events/SchematicsManager.java | 2 +- .../bot/listeners/AnnouncementListener.java | 2 +- .../bot/listeners/DiscordAuthListener.java | 10 +-- .../bot/listeners/DiscordTicketListener.java | 16 ++--- .../bot/listeners/IngameChatListener.java | 6 +- .../RolesInteractionButtonListener.java | 4 +- .../bot/listeners/ServerTeamChatListener.java | 1 - .../bungeecore/bot/util/DiscordRanks.java | 48 +++++++------- .../bot/util/DiscordRulesMessage.java | 4 +- .../bot/util/DiscordTicketMessage.java | 4 +- 20 files changed, 101 insertions(+), 103 deletions(-) diff --git a/src/de/steamwar/bungeecore/bot/AuthManager.java b/src/de/steamwar/bungeecore/bot/AuthManager.java index 1502b68..7d8b005 100644 --- a/src/de/steamwar/bungeecore/bot/AuthManager.java +++ b/src/de/steamwar/bungeecore/bot/AuthManager.java @@ -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 } diff --git a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java index 57d67f5..381720e 100644 --- a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java +++ b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java @@ -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()).queue()); + 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()).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(); + 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) { diff --git a/src/de/steamwar/bungeecore/bot/commands/BanCommand.java b/src/de/steamwar/bungeecore/bot/commands/BanCommand.java index 7d3772f..e55b97e 100644 --- a/src/de/steamwar/bungeecore/bot/commands/BanCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/BanCommand.java @@ -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(); } } diff --git a/src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java b/src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java index a767eba..29bbe85 100644 --- a/src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/BasicDiscordCommand.java @@ -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; diff --git a/src/de/steamwar/bungeecore/bot/commands/ListCommand.java b/src/de/steamwar/bungeecore/bot/commands/ListCommand.java index 2050180..3b014f9 100644 --- a/src/de/steamwar/bungeecore/bot/commands/ListCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/ListCommand.java @@ -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(); } } diff --git a/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java b/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java index 700baac..1c0bc96 100644 --- a/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/MuteCommand.java @@ -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(); } } diff --git a/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java b/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java index 53d7039..e0b3545 100644 --- a/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/TeamCommand.java @@ -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; } } diff --git a/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java b/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java index 7147108..925423f 100644 --- a/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/UnbanCommand.java @@ -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(); } } diff --git a/src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java b/src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java index b40c049..8608047 100644 --- a/src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java +++ b/src/de/steamwar/bungeecore/bot/commands/WhoisCommand.java @@ -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(); } } diff --git a/src/de/steamwar/bungeecore/bot/events/EventManager.java b/src/de/steamwar/bungeecore/bot/events/EventManager.java index 56f982c..d40a80c 100644 --- a/src/de/steamwar/bungeecore/bot/events/EventManager.java +++ b/src/de/steamwar/bungeecore/bot/events/EventManager.java @@ -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(); } diff --git a/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java b/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java index 64809e1..82a8370 100644 --- a/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java +++ b/src/de/steamwar/bungeecore/bot/events/SchematicsManager.java @@ -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(); } diff --git a/src/de/steamwar/bungeecore/bot/listeners/AnnouncementListener.java b/src/de/steamwar/bungeecore/bot/listeners/AnnouncementListener.java index 2877fbd..ab4be19 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/AnnouncementListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/AnnouncementListener.java @@ -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(); } } diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java index 514b193..8ad3428 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/DiscordAuthListener.java @@ -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(); } } } diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java index 1ac4920..fab5aaa 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java @@ -21,6 +21,7 @@ package de.steamwar.bungeecore.bot.listeners; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; +import de.steamwar.bungeecore.SpecialPermissions; import de.steamwar.bungeecore.bot.config.DiscordTicketType; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.sql.SteamwarUser; @@ -114,7 +115,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 +127,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()); } }); } diff --git a/src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java b/src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java index ce635f3..7163985 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/IngameChatListener.java @@ -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', ' ')); diff --git a/src/de/steamwar/bungeecore/bot/listeners/RolesInteractionButtonListener.java b/src/de/steamwar/bungeecore/bot/listeners/RolesInteractionButtonListener.java index 035cd77..ae0e44d 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/RolesInteractionButtonListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/RolesInteractionButtonListener.java @@ -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(); } } } diff --git a/src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java b/src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java index 0f82673..816da82 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/ServerTeamChatListener.java @@ -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; diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java b/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java index dedf0a5..7224576 100644 --- a/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java +++ b/src/de/steamwar/bungeecore/bot/util/DiscordRanks.java @@ -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 roleList = member.getRoles(); - Set 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 roleList = member.getRoles(); + Set 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); + } + } + }); } } diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java b/src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java index a1cb6fb..a061d66 100644 --- a/src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java +++ b/src/de/steamwar/bungeecore/bot/util/DiscordRulesMessage.java @@ -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(); } } } diff --git a/src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java b/src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java index ab93000..ea6cea3 100644 --- a/src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java +++ b/src/de/steamwar/bungeecore/bot/util/DiscordTicketMessage.java @@ -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(); } } } -- 2.39.2 From 12186e4f783477ebaeb0d1fc9a4e3fe0663e029c Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 7 Sep 2021 13:37:13 +0200 Subject: [PATCH 3/3] Fixing Signed-off-by: Chaoscaot --- .../steamwar/bungeecore/bot/listeners/DiscordTicketListener.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java b/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java index fab5aaa..8c8c4fa 100644 --- a/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java +++ b/src/de/steamwar/bungeecore/bot/listeners/DiscordTicketListener.java @@ -21,7 +21,6 @@ package de.steamwar.bungeecore.bot.listeners; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Message; -import de.steamwar.bungeecore.SpecialPermissions; import de.steamwar.bungeecore.bot.config.DiscordTicketType; import de.steamwar.bungeecore.bot.config.SteamwarDiscordBotConfig; import de.steamwar.bungeecore.sql.SteamwarUser; -- 2.39.2