1
0
mirror of https://github.com/sciwhiz12/Janitor.git synced 2024-11-10 03:21:26 +00:00

Add user mention to messages, add Sent DM field

This commit is contained in:
Arnold Alejo Nunag 2020-09-30 06:00:13 +08:00
parent 3c13b559e3
commit e0e0cb448a
Signed by: sciwhiz12
GPG Key ID: 622CF446534317E1
5 changed files with 29 additions and 22 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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());

View File

@ -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> T make(Supplier<T> creator, Consumer<T> 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 <Success, Error> BiConsumer<Success, Error> handle(final Consumer<Success> success,
final Consumer<Error> exceptionally) {
final Consumer<Error> exceptionally) {
return (suc, ex) -> {
if (ex == null) {
success.accept(suc);

View File

@ -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"