diff --git a/gradle.properties b/gradle.properties index 7d02ac1..5124242 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ grgit_version=4.0.2 shadow_version=6.0.0 -jda_version=4.2.0_168 +jda_version=4.2.0_207 nightconfig_version=3.6.3 jopt_version=6.0-alpha-3 guava_version=29.0-jre diff --git a/src/main/java/sciwhiz12/janitor/commands/moderation/KickCommand.java b/src/main/java/sciwhiz12/janitor/commands/moderation/KickCommand.java index e2bb62f..f9faf83 100644 --- a/src/main/java/sciwhiz12/janitor/commands/moderation/KickCommand.java +++ b/src/main/java/sciwhiz12/janitor/commands/moderation/KickCommand.java @@ -78,8 +78,9 @@ public class KickCommand extends BaseCommand { } target.getUser().openPrivateChannel() .flatMap(dm -> getBot().getMessages().MODERATION.kickedDM(dm, performer, target, reason)) - .flatMap(v -> ModerationHelper.kickUser(target.getGuild(), performer, target, reason)) - .flatMap(v -> getBot().getMessages().MODERATION.kickUser(channel, performer, target, reason)) + .mapToResult() + .flatMap(res -> ModerationHelper.kickUser(target.getGuild(), performer, target, reason) + .flatMap(v -> getBot().getMessages().MODERATION.kickUser(channel, performer, target, reason, res.isSuccess()))) .queue(); return 1; } diff --git a/src/main/java/sciwhiz12/janitor/msg/Messages.java b/src/main/java/sciwhiz12/janitor/msg/Messages.java index 5ff2767..99108b5 100644 --- a/src/main/java/sciwhiz12/janitor/msg/Messages.java +++ b/src/main/java/sciwhiz12/janitor/msg/Messages.java @@ -14,8 +14,6 @@ import sciwhiz12.janitor.JanitorBot; import java.util.EnumSet; import java.util.stream.Collectors; -import static sciwhiz12.janitor.utils.Util.nameFor; - public class Messages { private final JanitorBot bot; public final General GENERAL; @@ -75,7 +73,7 @@ public class Messages { new EmbedBuilder() .setTitle(translate("general.cannot_interact.title")) .setDescription(translate("general.cannot_interact.desc")) - .addField(translate("general.cannot_interact.field.target"), nameFor(target.getUser()), true) + .addField(translate("general.cannot_interact.field.target"), target.getUser().getAsMention(), true) .setColor(General.FAILURE_COLOR) .build() ); @@ -95,7 +93,8 @@ public class Messages { new EmbedBuilder() .setTitle(translate("moderation.insufficient_permissions.title")) .setDescription(translate("moderation.insufficient_permissions.desc")) - .addField(translate("moderation.insufficient_permissions.field.performer"), nameFor(performer.getUser()), + .addField(translate("moderation.insufficient_permissions.field.performer"), + performer.getUser().getAsMention(), true) .addField(new MessageEmbed.Field( translate("moderation.insufficient_permissions.field.permissions"), @@ -111,18 +110,20 @@ public class Messages { new EmbedBuilder() .setTitle(translate("moderation.cannot_interact.title")) .setDescription(translate("moderation.cannot_interact.desc")) - .addField(translate("moderation.cannot_interact.field.performer"), nameFor(performer.getUser()), true) - .addField(translate("moderation.cannot_interact.field.target"), nameFor(target.getUser()), true) + .addField(translate("moderation.cannot_interact.field.performer"), performer.getUser().getAsMention(), true) + .addField(translate("moderation.cannot_interact.field.target"), target.getUser().getAsMention(), true) .setColor(General.FAILURE_COLOR) .build() ); } - public MessageAction kickUser(MessageChannel channel, Member performer, Member target, @Nullable String reason) { + public MessageAction kickUser(MessageChannel channel, Member performer, Member target, @Nullable String reason, + boolean sentDM) { final EmbedBuilder embed = new EmbedBuilder() .setAuthor(translate("moderation.kick.info.author"), null, GAVEL_ICON_URL) - .addField(translate("moderation.kick.info.field.performer"), nameFor(performer.getUser()), true) - .addField(translate("moderation.kick.info.field.target"), nameFor(target.getUser()), true); + .addField(translate("moderation.kick.info.field.performer"), performer.getUser().getAsMention(), true) + .addField(translate("moderation.kick.info.field.target"), target.getUser().getAsMention(), true) + .addField(translate("moderation.kick.info.field.sent_private_message"), sentDM ? "✅" : "❌", true); if (reason != null) embed.addField(translate("moderation.kick.info.field.reason"), reason, false); return channel.sendMessage(embed.setColor(MODERATION_COLOR).build()); @@ -132,7 +133,7 @@ public class Messages { final EmbedBuilder embed = new EmbedBuilder() .setAuthor(performer.getGuild().getName(), null, performer.getGuild().getIconUrl()) .setTitle(translate("moderation.kick.dm.title")) - .addField(translate("moderation.kick.dm.field.performer"), nameFor(performer.getUser()), true); + .addField(translate("moderation.kick.dm.field.performer"), performer.getUser().getAsMention(), true); if (reason != null) embed.addField(translate("moderation.kick.dm.field.reason"), reason, false); return channel.sendMessage(embed.setColor(MODERATION_COLOR).build()); diff --git a/src/main/java/sciwhiz12/janitor/utils/Util.java b/src/main/java/sciwhiz12/janitor/utils/Util.java index 47c8f5d..57ec9aa 100644 --- a/src/main/java/sciwhiz12/janitor/utils/Util.java +++ b/src/main/java/sciwhiz12/janitor/utils/Util.java @@ -1,11 +1,16 @@ package sciwhiz12.janitor.utils; -import net.dv8tion.jda.api.entities.*; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.GuildChannel; +import net.dv8tion.jda.api.entities.ISnowflake; +import net.dv8tion.jda.api.entities.MessageChannel; +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.User; -import javax.annotation.Nullable; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Supplier; +import javax.annotation.Nullable; public class Util { public static T make(Supplier creator, Consumer configurator) { @@ -14,18 +19,17 @@ public class Util { return obj; } -// public static String toString(final MessageAuthor author) { -// return author.asUser().map(Util::toString).orElseGet(() -> String.format("{MessageAuthor,%s}:%s", author.getDiscriminatedName(), author.getId())); -// } - public static String toString(@Nullable final User user) { - return user != null ? String.format("{User,%s#%s}:%s", user.getName(), user.getDiscriminator(), getID(user)) : "unknown"; + return user != null ? + String.format("{User,%s#%s}:%s", user.getName(), user.getDiscriminator(), getID(user)) : + "unknown"; } public static String toString(final MessageChannel channel) { if (channel instanceof GuildChannel) { GuildChannel gc = (GuildChannel) channel; - return String.format("[GuildChannel:%s,%s@%s]%s", gc.getType(), gc.getName(), toString(gc.getGuild()), getID(channel)); + return String + .format("[GuildChannel:%s,%s@%s]%s", gc.getType(), gc.getName(), toString(gc.getGuild()), getID(channel)); } // TextChannel vs PrivateChannel return String.format("[MessageChannel]:%s", getID(channel)); @@ -52,7 +56,7 @@ public class Util { } public static BiConsumer handle(final Consumer success, - final Consumer exceptionally) { + final Consumer exceptionally) { return (suc, ex) -> { if (ex == null) { success.accept(suc); diff --git a/src/main/resources/english.json b/src/main/resources/english.json index 57d314f..1e72cd8 100644 --- a/src/main/resources/english.json +++ b/src/main/resources/english.json @@ -21,6 +21,7 @@ "moderation.kick.info.field.performer": "Performer", "moderation.kick.info.field.target": "Target", "moderation.kick.info.field.reason": "Reason", + "moderation.kick.info.field.sent_private_message": "Sent DM", "moderation.kick.dm.title": "You were kicked from this server.", "moderation.kick.dm.field.performer": "Moderator", "moderation.kick.dm.field.reason": "Reason"