From c766f8a7a684f3673614bba6a09f549689cd32b0 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 9 Oct 2018 20:30:07 +0200 Subject: [PATCH] clear command improvement --- pom.xml | 2 +- .../codersclash/bot/commands/ClearCommand.java | 11 ++++++++--- .../codersclash/bot/core/Main.java | 1 - .../codersclash/bot/entities/PieChart.java | 4 ++-- .../codersclash/bot/entities/Vote.java | 4 ++-- .../codersclash/bot/util/Roles.java | 1 + 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 6c06ae5..4477853 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,7 @@ net.dv8tion JDA - 3.7.1_390 + 3.8.0_436 mysql diff --git a/src/main/java/de/unhandledexceptions/codersclash/bot/commands/ClearCommand.java b/src/main/java/de/unhandledexceptions/codersclash/bot/commands/ClearCommand.java index e54b029..607eeea 100644 --- a/src/main/java/de/unhandledexceptions/codersclash/bot/commands/ClearCommand.java +++ b/src/main/java/de/unhandledexceptions/codersclash/bot/commands/ClearCommand.java @@ -5,12 +5,15 @@ import de.unhandledexceptions.codersclash.bot.core.Bot; import de.unhandledexceptions.codersclash.bot.core.Main; import de.unhandledexceptions.codersclash.bot.core.Permissions; +import de.unhandledexceptions.codersclash.bot.util.Messages; import de.unhandledexceptions.codersclash.bot.util.Messages.*; import de.unhandledexceptions.codersclash.bot.util.Regex; import net.dv8tion.jda.core.Permission; import net.dv8tion.jda.core.entities.Member; import net.dv8tion.jda.core.entities.TextChannel; +import net.dv8tion.jda.core.requests.RequestFuture; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; @@ -32,7 +35,8 @@ public void onCommand(CommandEvent event, Member member, TextChannel channel, St if (Permissions.getPermissionLevel(member) >= 4) { // Benötigtes Permission level überprüfen if (args.length == 1 && Regex.argsMatch(args, "[1-9]\\d{0,3}")) { int amount = Integer.parseInt(args[0]); - Main.otherThread(() -> event.getMessage().delete().queue((v) -> this.clear(channel, amount), defaultFailure(channel))); + channel.getIterableHistory().takeAsync(amount).thenAccept( + (l) -> RequestFuture.allOf(channel.purgeMessages(l)).thenAccept((v) -> Messages.sendMessage(channel, Type.SUCCESS, "Deleted `" + amount + "` messages.").queue())); } else if (args.length == 1){ sendMessage(channel, Type.WARNING, format("`%s` is not a valid number!", args[0])).queue((msg) -> msg.delete().queueAfter(7, TimeUnit.SECONDS)); } else { @@ -43,7 +47,8 @@ public void onCommand(CommandEvent event, Member member, TextChannel channel, St } } - private void clear(TextChannel channel, int amount) { + // dieser e shit ist jetzt redundant + /*private void clear(TextChannel channel, int amount) { long twoWeeksAgo = (System.currentTimeMillis() - (14 * 24 * 60 * 60 * 1000)); // System der JDA, die Zeit zu messen channel.getHistory().retrievePast(amount > 100 ? 100 : amount).queue((messages) -> { // Wenn amount größer als 100 ist, retrieve 100, ansonsten amount // filter die messages, die man löschen kann, heraus @@ -67,7 +72,7 @@ private void clear(TextChannel channel, int amount) { } } }); - } + }*/ // Standard success callback private void success(TextChannel channel) { diff --git a/src/main/java/de/unhandledexceptions/codersclash/bot/core/Main.java b/src/main/java/de/unhandledexceptions/codersclash/bot/core/Main.java index 7eb27f0..6bbd7fb 100644 --- a/src/main/java/de/unhandledexceptions/codersclash/bot/core/Main.java +++ b/src/main/java/de/unhandledexceptions/codersclash/bot/core/Main.java @@ -20,7 +20,6 @@ public static void main(String[] args) { final var config = new Config("./config.json"); - if (!config.fileExists()) { config.create(); logger.info("config.json has been created."); diff --git a/src/main/java/de/unhandledexceptions/codersclash/bot/entities/PieChart.java b/src/main/java/de/unhandledexceptions/codersclash/bot/entities/PieChart.java index 8cbe22c..f614201 100644 --- a/src/main/java/de/unhandledexceptions/codersclash/bot/entities/PieChart.java +++ b/src/main/java/de/unhandledexceptions/codersclash/bot/entities/PieChart.java @@ -1,10 +1,10 @@ package de.unhandledexceptions.codersclash.bot.entities; -import org.apache.commons.collections4.set.ListOrderedSet; import org.jfree.chart.ChartFactory; import org.jfree.chart.JFreeChart; import org.jfree.data.general.DefaultPieDataset; +import java.util.LinkedHashSet; import java.util.Set; /** @@ -24,7 +24,7 @@ public class PieChart { public PieChart(String title) { this.title = title; - this.tiles = new ListOrderedSet<>(); + this.tiles = new LinkedHashSet<>(); } public void create() diff --git a/src/main/java/de/unhandledexceptions/codersclash/bot/entities/Vote.java b/src/main/java/de/unhandledexceptions/codersclash/bot/entities/Vote.java index 4a741ea..5782544 100644 --- a/src/main/java/de/unhandledexceptions/codersclash/bot/entities/Vote.java +++ b/src/main/java/de/unhandledexceptions/codersclash/bot/entities/Vote.java @@ -6,9 +6,9 @@ import net.dv8tion.jda.core.entities.TextChannel; import net.dv8tion.jda.core.entities.User; import net.dv8tion.jda.core.requests.RestAction; -import org.apache.commons.collections4.set.ListOrderedSet; import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.concurrent.ScheduledFuture; @@ -38,7 +38,7 @@ public class Vote { public Vote(Guild guild, TextChannel setupChannel, ShardManager shardManager) { this.usersVoted = new ArrayList<>(); - this.emotes = new ListOrderedSet<>(); + this.emotes = new LinkedHashSet<>(); this.voteAnswers = new ArrayList<>(); this.guildId = guild.getIdLong(); this.setupChannelId = setupChannel.getIdLong(); diff --git a/src/main/java/de/unhandledexceptions/codersclash/bot/util/Roles.java b/src/main/java/de/unhandledexceptions/codersclash/bot/util/Roles.java index 55202a9..c732638 100644 --- a/src/main/java/de/unhandledexceptions/codersclash/bot/util/Roles.java +++ b/src/main/java/de/unhandledexceptions/codersclash/bot/util/Roles.java @@ -4,6 +4,7 @@ import net.dv8tion.jda.core.Permission; import net.dv8tion.jda.core.entities.Guild; import net.dv8tion.jda.core.entities.Role; +import net.dv8tion.jda.core.requests.restaction.order.RoleOrderAction; import java.awt.*; import java.util.function.Consumer;