mirror of
https://github.com/sciwhiz12/Janitor.git
synced 2024-11-12 23:51:25 +00:00
Move message inner classes to package classes, reorganize message embeds
This commit is contained in:
parent
99ca3b101a
commit
25bb970766
|
@ -87,12 +87,12 @@ public class BanCommand extends BaseCommand {
|
|||
else if (!guild.getSelfMember().canInteract(target))
|
||||
messages().GENERAL.cannotInteract(channel, target).queue();
|
||||
else if (!performer.hasPermission(BAN_PERMISSION))
|
||||
messages().MODERATION.performerInsufficientPermissions(channel, performer, BAN_PERMISSION).queue();
|
||||
messages().MODERATION.ERRORS.performerInsufficientPermissions(channel, performer, BAN_PERMISSION).queue();
|
||||
else if (!performer.canInteract(target))
|
||||
messages().MODERATION.cannotModerate(channel, performer, target).queue();
|
||||
messages().MODERATION.ERRORS.cannotModerate(channel, performer, target).queue();
|
||||
else
|
||||
target.getUser().openPrivateChannel()
|
||||
.flatMap(dm -> messages().MODERATION.bannedDM(dm, performer, target, reason))
|
||||
.flatMap(dm -> messages().MODERATION.bannedDM(dm, performer, reason))
|
||||
.mapToResult()
|
||||
.flatMap(res -> ModerationHelper.banUser(target.getGuild(), performer, target, days, reason)
|
||||
.flatMap(
|
||||
|
|
|
@ -69,9 +69,9 @@ public class KickCommand extends BaseCommand {
|
|||
else if (!guild.getSelfMember().canInteract(target))
|
||||
messages().GENERAL.cannotInteract(channel, target).queue();
|
||||
else if (!performer.hasPermission(KICK_PERMISSION))
|
||||
messages().MODERATION.performerInsufficientPermissions(channel, performer, KICK_PERMISSION).queue();
|
||||
messages().MODERATION.ERRORS.performerInsufficientPermissions(channel, performer, KICK_PERMISSION).queue();
|
||||
else if (!performer.canInteract(target))
|
||||
messages().MODERATION.cannotModerate(channel, performer, target).queue();
|
||||
messages().MODERATION.ERRORS.cannotModerate(channel, performer, target).queue();
|
||||
else
|
||||
target.getUser().openPrivateChannel()
|
||||
.flatMap(dm -> messages().MODERATION.kickedDM(dm, performer, target, reason))
|
||||
|
|
|
@ -107,12 +107,12 @@ public class NoteCommand extends BaseCommand {
|
|||
else if (performer.equals(target))
|
||||
messages().GENERAL.cannotActionPerformer(channel, performer).queue();
|
||||
else if (!performer.hasPermission(NOTE_PERMISSION))
|
||||
messages().MODERATION.performerInsufficientPermissions(channel, performer, NOTE_PERMISSION).queue();
|
||||
messages().MODERATION.ERRORS.performerInsufficientPermissions(channel, performer, NOTE_PERMISSION).queue();
|
||||
else {
|
||||
final NoteStorage storage = NoteStorage.get(getBot().getStorage(), guild);
|
||||
final int maxAmount = config().NOTES_MAX_AMOUNT_PER_MOD.get();
|
||||
if (storage.getAmountOfNotes(target.getUser()) >= maxAmount) {
|
||||
messages().MODERATION.maxAmountOfNotes(channel, performer, target, maxAmount).queue();
|
||||
messages().MODERATION.ERRORS.maxAmountOfNotes(channel, performer, target, maxAmount).queue();
|
||||
} else {
|
||||
int noteID = storage.addNote(new NoteEntry(performer.getUser(), target.getUser(), dateTime, noteContents));
|
||||
messages().MODERATION.addNote(channel, performer, target, noteContents, dateTime, noteID).queue();
|
||||
|
@ -161,7 +161,7 @@ public class NoteCommand extends BaseCommand {
|
|||
final OffsetDateTime dateTime = OffsetDateTime.now();
|
||||
|
||||
if (!performer.hasPermission(NOTE_PERMISSION))
|
||||
messages().MODERATION.performerInsufficientPermissions(channel, performer, NOTE_PERMISSION).queue();
|
||||
messages().MODERATION.ERRORS.performerInsufficientPermissions(channel, performer, NOTE_PERMISSION).queue();
|
||||
else
|
||||
messages().MODERATION.noteList(channel, NoteStorage.get(getBot().getStorage(), guild)
|
||||
.getNotes()
|
||||
|
@ -184,13 +184,13 @@ public class NoteCommand extends BaseCommand {
|
|||
final OffsetDateTime dateTime = OffsetDateTime.now();
|
||||
|
||||
if (!performer.hasPermission(NOTE_PERMISSION))
|
||||
messages().MODERATION.performerInsufficientPermissions(channel, performer, NOTE_PERMISSION).queue();
|
||||
messages().MODERATION.ERRORS.performerInsufficientPermissions(channel, performer, NOTE_PERMISSION).queue();
|
||||
else {
|
||||
final NoteStorage storage = NoteStorage.get(getBot().getStorage(), guild);
|
||||
@Nullable
|
||||
final NoteEntry entry = storage.getNote(noteID);
|
||||
if (entry == null)
|
||||
messages().MODERATION.noNoteFound(channel, performer, noteID).queue();
|
||||
messages().MODERATION.ERRORS.noNoteFound(channel, performer, noteID).queue();
|
||||
else {
|
||||
storage.removeNote(noteID);
|
||||
messages().MODERATION.removeNote(channel, performer, noteID, entry).queue();
|
||||
|
|
|
@ -100,7 +100,7 @@ public class UnbanCommand extends BaseCommand {
|
|||
if (!guild.getSelfMember().hasPermission(UNBAN_PERMISSION))
|
||||
messages().GENERAL.insufficientPermissions(channel, UNBAN_PERMISSION).queue();
|
||||
else if (!performer.hasPermission(UNBAN_PERMISSION))
|
||||
messages().MODERATION.performerInsufficientPermissions(channel, performer, UNBAN_PERMISSION).queue();
|
||||
messages().MODERATION.ERRORS.performerInsufficientPermissions(channel, performer, UNBAN_PERMISSION).queue();
|
||||
else
|
||||
ModerationHelper.unbanUser(guild, target)
|
||||
.flatMap(v -> messages().MODERATION.unbanUser(channel, performer, target))
|
||||
|
|
|
@ -55,21 +55,21 @@ public class UnwarnCommand extends BaseCommand {
|
|||
final OffsetDateTime dateTime = OffsetDateTime.now();
|
||||
|
||||
if (!performer.hasPermission(WARN_PERMISSION))
|
||||
messages().MODERATION.performerInsufficientPermissions(channel, performer, WARN_PERMISSION).queue();
|
||||
messages().MODERATION.ERRORS.performerInsufficientPermissions(channel, performer, WARN_PERMISSION).queue();
|
||||
else {
|
||||
final WarningStorage storage = WarningStorage.get(getBot().getStorage(), guild);
|
||||
@Nullable
|
||||
final WarningEntry entry = storage.getWarning(caseID);
|
||||
Member temp;
|
||||
if (entry == null)
|
||||
messages().MODERATION.noWarnWithID(channel, performer, caseID).queue();
|
||||
messages().MODERATION.ERRORS.noWarnWithID(channel, performer, caseID).queue();
|
||||
else if (entry.getWarned().getIdLong() == performer.getIdLong()
|
||||
&& !config().WARNINGS_REMOVE_SELF_WARNINGS.get())
|
||||
messages().MODERATION.cannotUnwarnSelf(channel, performer, caseID, entry).queue();
|
||||
messages().MODERATION.ERRORS.cannotUnwarnSelf(channel, performer, caseID, entry).queue();
|
||||
else if (config().WARNINGS_RESPECT_MOD_ROLES.get()
|
||||
&& (temp = guild.getMember(entry.getPerformer())) != null
|
||||
&& !performer.canInteract(temp))
|
||||
messages().MODERATION.cannotRemoveHigherModerated(channel, performer, caseID, entry).queue();
|
||||
messages().MODERATION.ERRORS.cannotRemoveHigherModerated(channel, performer, caseID, entry).queue();
|
||||
else {
|
||||
storage.removeWarning(caseID);
|
||||
messages().MODERATION.unwarn(channel, performer, caseID, entry).queue();
|
||||
|
|
|
@ -68,11 +68,11 @@ public class WarnCommand extends BaseCommand {
|
|||
else if (performer.equals(target))
|
||||
messages().GENERAL.cannotActionPerformer(channel, performer).queue();
|
||||
else if (!performer.hasPermission(WARN_PERMISSION))
|
||||
messages().MODERATION.performerInsufficientPermissions(channel, performer, WARN_PERMISSION).queue();
|
||||
messages().MODERATION.ERRORS.performerInsufficientPermissions(channel, performer, WARN_PERMISSION).queue();
|
||||
else if (!performer.canInteract(target))
|
||||
messages().MODERATION.cannotModerate(channel, performer, target).queue();
|
||||
messages().MODERATION.ERRORS.cannotModerate(channel, performer, target).queue();
|
||||
else if (target.hasPermission(WARN_PERMISSION) && config().WARNINGS_PREVENT_WARNING_MODS.get())
|
||||
messages().MODERATION.cannotWarnMods(channel, performer, target).queue();
|
||||
messages().MODERATION.ERRORS.cannotWarnMods(channel, performer, target).queue();
|
||||
else
|
||||
target.getUser().openPrivateChannel()
|
||||
.flatMap(dm -> messages().MODERATION.warnDM(dm, performer, target, reason, dateTime))
|
||||
|
|
|
@ -91,7 +91,7 @@ public class WarnListCommand extends BaseCommand {
|
|||
final OffsetDateTime dateTime = OffsetDateTime.now();
|
||||
|
||||
if (!performer.hasPermission(WARN_PERMISSION))
|
||||
messages().MODERATION.performerInsufficientPermissions(channel, performer, WARN_PERMISSION).queue();
|
||||
messages().MODERATION.ERRORS.performerInsufficientPermissions(channel, performer, WARN_PERMISSION).queue();
|
||||
else
|
||||
messages().MODERATION.warnList(channel, WarningStorage.get(getBot().getStorage(), guild)
|
||||
.getWarnings()
|
||||
|
|
79
src/main/java/sciwhiz12/janitor/msg/General.java
Normal file
79
src/main/java/sciwhiz12/janitor/msg/General.java
Normal file
|
@ -0,0 +1,79 @@
|
|||
package sciwhiz12.janitor.msg;
|
||||
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.requests.RestAction;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public final class General {
|
||||
private final Messages messages;
|
||||
|
||||
General(Messages messages) {
|
||||
this.messages = messages;
|
||||
}
|
||||
|
||||
private String translate(String key, Object... args) {
|
||||
return messages.translate(key, args);
|
||||
}
|
||||
|
||||
public RestAction<Message> guildOnlyCommand(MessageChannel channel) {
|
||||
return channel.sendMessage(
|
||||
messages.failureEmbed(translate("general.guild_only_command.title"))
|
||||
.setDescription(translate("general.guild_only_command.desc"))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public RestAction<Message> insufficientPermissions(MessageChannel channel, EnumSet<Permission> permissions) {
|
||||
return channel.sendMessage(
|
||||
messages.failureEmbed(translate("general.insufficient_permissions.title"))
|
||||
.setDescription(translate("general.insufficient_permissions.desc"))
|
||||
.addField(new MessageEmbed.Field(
|
||||
translate("general.insufficient_permissions.field.permissions"),
|
||||
permissions.stream().map(Permission::getName).collect(Collectors.joining(", ")),
|
||||
false))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public RestAction<Message> ambiguousMember(MessageChannel channel) {
|
||||
return channel.sendMessage(
|
||||
messages.failureEmbed(translate("general.ambiguous_member.title"))
|
||||
.setDescription(translate("general.ambiguous_member.desc"))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public RestAction<Message> cannotInteract(MessageChannel channel, Member target) {
|
||||
return channel.sendMessage(
|
||||
messages.failureEmbed(translate("general.cannot_interact.title"))
|
||||
.setDescription(translate("general.cannot_interact.desc"))
|
||||
.addField(translate("general.cannot_interact.field.target"), target.getAsMention(), true)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public RestAction<Message> cannotActionSelf(MessageChannel channel) {
|
||||
return channel.sendMessage(
|
||||
messages.failureEmbed(translate("general.cannot_action_self.title"))
|
||||
.setDescription(translate("general.cannot_action_self.desc"))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public RestAction<Message> cannotActionPerformer(MessageChannel channel, Member performer) {
|
||||
return channel.sendMessage(
|
||||
messages.failureEmbed(translate("general.cannot_action_performer.title"))
|
||||
.setDescription(translate("general.cannot_action_performer.desc"))
|
||||
.addField(translate("general.cannot_action_performer.field.performer"),
|
||||
performer.getUser().getAsMention(),
|
||||
true)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,421 +1,32 @@
|
|||
package sciwhiz12.janitor.msg;
|
||||
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.requests.RestAction;
|
||||
import net.dv8tion.jda.api.requests.restaction.MessageAction;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import sciwhiz12.janitor.JanitorBot;
|
||||
import sciwhiz12.janitor.moderation.notes.NoteEntry;
|
||||
import sciwhiz12.janitor.moderation.warns.WarningEntry;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
public class Messages {
|
||||
public static final int FAILURE_COLOR = 0xF73132;
|
||||
|
||||
private final JanitorBot bot;
|
||||
public final General GENERAL;
|
||||
public final Moderation MODERATION;
|
||||
|
||||
public Messages(JanitorBot bot) {
|
||||
this.bot = bot;
|
||||
this.GENERAL = new General();
|
||||
this.MODERATION = new Moderation();
|
||||
this.GENERAL = new General(this);
|
||||
this.MODERATION = new Moderation(this);
|
||||
}
|
||||
|
||||
public String translate(String key, Object... args) {
|
||||
return bot.getTranslations().translate(key, args);
|
||||
}
|
||||
|
||||
public final class General {
|
||||
public static final int FAILURE_COLOR = 0xF73132;
|
||||
|
||||
private General() {}
|
||||
|
||||
public RestAction<Message> guildOnlyCommand(MessageChannel channel) {
|
||||
return channel.sendMessage(
|
||||
new EmbedBuilder()
|
||||
.setTitle(translate("general.guild_only_command.title"))
|
||||
.setDescription(translate("general.guild_only_command.desc"))
|
||||
.setColor(FAILURE_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public RestAction<Message> insufficientPermissions(MessageChannel channel, EnumSet<Permission> permissions) {
|
||||
return channel.sendMessage(
|
||||
new EmbedBuilder()
|
||||
.setTitle(translate("general.insufficient_permissions.title"))
|
||||
.setDescription(translate("general.insufficient_permissions.desc"))
|
||||
.addField(new MessageEmbed.Field(
|
||||
translate("general.insufficient_permissions.field.permissions"),
|
||||
permissions.stream().map(Permission::getName).collect(Collectors.joining(", ")),
|
||||
false))
|
||||
.setColor(FAILURE_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public RestAction<Message> ambiguousMember(MessageChannel channel) {
|
||||
return channel.sendMessage(
|
||||
new EmbedBuilder()
|
||||
.setTitle(translate("general.ambiguous_member.title"))
|
||||
.setDescription(translate("general.ambiguous_member.desc"))
|
||||
.setColor(FAILURE_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public RestAction<Message> cannotInteract(MessageChannel channel, Member target) {
|
||||
return channel.sendMessage(
|
||||
new EmbedBuilder()
|
||||
.setTitle(translate("general.cannot_interact.title"))
|
||||
.setDescription(translate("general.cannot_interact.desc"))
|
||||
.addField(translate("general.cannot_interact.field.target"), target.getUser().getAsMention(), true)
|
||||
.setColor(General.FAILURE_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public RestAction<Message> cannotActionSelf(MessageChannel channel) {
|
||||
return channel.sendMessage(
|
||||
new EmbedBuilder()
|
||||
.setTitle(translate("general.cannot_action_self.title"))
|
||||
.setDescription(translate("general.cannot_action_self.desc"))
|
||||
.setColor(General.FAILURE_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public RestAction<Message> cannotActionPerformer(MessageChannel channel, Member performer) {
|
||||
return channel.sendMessage(
|
||||
new EmbedBuilder()
|
||||
.setTitle(translate("general.cannot_action_performer.title"))
|
||||
.setDescription(translate("general.cannot_action_performer.desc"))
|
||||
.addField(translate("general.cannot_action_performer.field.performer"), performer.getUser().getAsMention(),
|
||||
true)
|
||||
.setColor(General.FAILURE_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
public EmbedBuilder failureEmbed(String title) {
|
||||
return new EmbedBuilder()
|
||||
.setTitle(title)
|
||||
.setColor(FAILURE_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(ZoneOffset.UTC));
|
||||
}
|
||||
|
||||
public final class Moderation {
|
||||
public static final int MODERATION_COLOR = 0xF1BD25;
|
||||
public static final String GAVEL_ICON_URL = "https://cdn.discordapp.com/attachments/738478941760782526" +
|
||||
"/760463743330549760/gavel.png";
|
||||
|
||||
private Moderation() {}
|
||||
|
||||
public MessageAction performerInsufficientPermissions(MessageChannel channel, Member performer,
|
||||
EnumSet<Permission> permissions) {
|
||||
return channel.sendMessage(
|
||||
new EmbedBuilder()
|
||||
.setTitle(translate("moderation.insufficient_permissions.title"))
|
||||
.setDescription(translate("moderation.insufficient_permissions.desc"))
|
||||
.addField(translate("moderation.insufficient_permissions.field.performer"),
|
||||
performer.getUser().getAsMention(),
|
||||
true)
|
||||
.addField(new MessageEmbed.Field(
|
||||
translate("moderation.insufficient_permissions.field.permissions"),
|
||||
permissions.stream().map(Permission::getName).collect(Collectors.joining(", ")),
|
||||
true))
|
||||
.setColor(General.FAILURE_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction cannotModerate(MessageChannel channel, Member performer, Member target) {
|
||||
return channel.sendMessage(
|
||||
new EmbedBuilder()
|
||||
.setTitle(translate("moderation.cannot_interact.title"))
|
||||
.setDescription(translate("moderation.cannot_interact.desc"))
|
||||
.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)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
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"), 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).setTimestamp(OffsetDateTime.now(Clock.systemUTC())).build());
|
||||
}
|
||||
|
||||
public MessageAction kickedDM(MessageChannel channel, Member performer, Member target, @Nullable String reason) {
|
||||
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"), performer.getUser().getAsMention(), true);
|
||||
if (reason != null)
|
||||
embed.addField(translate("moderation.kick.dm.field.reason"), reason, false);
|
||||
return channel
|
||||
.sendMessage(embed.setColor(MODERATION_COLOR).setTimestamp(OffsetDateTime.now(Clock.systemUTC())).build());
|
||||
}
|
||||
|
||||
public MessageAction banUser(MessageChannel channel, Member performer, Member target, @Nullable String reason,
|
||||
int deletionDays, boolean sentDM) {
|
||||
final EmbedBuilder embed = new EmbedBuilder()
|
||||
.setAuthor(translate("moderation.ban.info.author"), null, GAVEL_ICON_URL)
|
||||
.addField(translate("moderation.ban.info.field.performer"), performer.getUser().getAsMention(), true)
|
||||
.addField(translate("moderation.ban.info.field.target"), target.getUser().getAsMention(), true)
|
||||
.addField(translate("moderation.ban.info.field.sent_private_message"), sentDM ? "✅" : "❌", true);
|
||||
if (deletionDays != 0)
|
||||
embed.addField(translate("moderation.ban.info.field.delete_duration"),
|
||||
String.valueOf(deletionDays).concat(" day(s)"), true);
|
||||
if (reason != null)
|
||||
embed.addField(translate("moderation.ban.info.field.reason"), reason, false);
|
||||
return channel
|
||||
.sendMessage(embed.setColor(MODERATION_COLOR).setTimestamp(OffsetDateTime.now(Clock.systemUTC())).build());
|
||||
}
|
||||
|
||||
public MessageAction bannedDM(MessageChannel channel, Member performer, Member target, @Nullable String reason) {
|
||||
final EmbedBuilder embed = new EmbedBuilder()
|
||||
.setAuthor(performer.getGuild().getName(), null, performer.getGuild().getIconUrl())
|
||||
.setTitle(translate("moderation.ban.dm.title"))
|
||||
.addField(translate("moderation.ban.dm.field.performer"), performer.getUser().getAsMention(), true);
|
||||
if (reason != null)
|
||||
embed.addField(translate("moderation.ban.dm.field.reason"), reason, false);
|
||||
return channel
|
||||
.sendMessage(embed.setColor(MODERATION_COLOR).setTimestamp(OffsetDateTime.now(Clock.systemUTC())).build());
|
||||
}
|
||||
|
||||
public MessageAction unbanUser(MessageChannel channel, Member performer, User target) {
|
||||
return channel.sendMessage(
|
||||
new EmbedBuilder()
|
||||
.setAuthor(translate("moderation.unban.info.author"), null, GAVEL_ICON_URL)
|
||||
.addField(translate("moderation.unban.info.field.performer"), performer.getUser().getAsMention(), true)
|
||||
.addField(translate("moderation.unban.info.field.target"), target.getAsMention(), true)
|
||||
.setColor(MODERATION_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction warnUser(MessageChannel channel, Member performer, Member target, String reason,
|
||||
OffsetDateTime dateTime, int caseID, boolean sentDM) {
|
||||
final EmbedBuilder embed = new EmbedBuilder()
|
||||
.setAuthor(translate("moderation.warn.info.author"), null, GAVEL_ICON_URL)
|
||||
.addField(translate("moderation.warn.info.field.performer"), performer.getUser().getAsMention(), true)
|
||||
.addField(translate("moderation.warn.info.field.target"), target.getUser().getAsMention(), true)
|
||||
.addField(translate("moderation.warn.info.field.sent_private_message"), sentDM ? "✅" : "❌", true)
|
||||
.addField(translate("moderation.warn.info.field.case_id"), String.valueOf(caseID), true)
|
||||
.addField(translate("moderation.warn.info.field.date_time"),
|
||||
dateTime.format(RFC_1123_DATE_TIME), true)
|
||||
.addField(translate("moderation.warn.info.field.reason"), reason, false);
|
||||
return channel
|
||||
.sendMessage(embed.setColor(MODERATION_COLOR).setTimestamp(OffsetDateTime.now(Clock.systemUTC())).build());
|
||||
}
|
||||
|
||||
public MessageAction warnDM(MessageChannel channel, Member performer, Member target, String reason,
|
||||
OffsetDateTime dateTime) {
|
||||
final EmbedBuilder embed = new EmbedBuilder()
|
||||
.setAuthor(performer.getGuild().getName(), null, performer.getGuild().getIconUrl())
|
||||
.setTitle(translate("moderation.warn.dm.title"))
|
||||
.addField(translate("moderation.warn.dm.field.performer"), performer.getUser().getAsMention(), true)
|
||||
.addField(translate("moderation.warn.dm.field.date_time"),
|
||||
dateTime.format(RFC_1123_DATE_TIME), true)
|
||||
.addField(translate("moderation.warn.dm.field.reason"), reason, false);
|
||||
return channel.sendMessage(embed.build());
|
||||
}
|
||||
|
||||
public MessageAction warnList(MessageChannel channel, Map<Integer, WarningEntry> displayWarnings) {
|
||||
final EmbedBuilder embed = new EmbedBuilder()
|
||||
.setAuthor(translate("moderation.warnlist.author"), null, GAVEL_ICON_URL)
|
||||
.setColor(MODERATION_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()));
|
||||
String warningsDesc = displayWarnings.size() > 0 ? displayWarnings.entrySet().stream()
|
||||
.sorted(Collections.reverseOrder(Comparator.comparingInt(Map.Entry::getKey)))
|
||||
.limit(10)
|
||||
.map(entry ->
|
||||
translate("moderation.warnlist.entry",
|
||||
entry.getKey(),
|
||||
entry.getValue().getWarned().getAsMention(),
|
||||
entry.getValue().getPerformer().getAsMention(),
|
||||
entry.getValue().getDateTime().format(RFC_1123_DATE_TIME),
|
||||
entry.getValue().getReason() != null
|
||||
? entry.getValue().getReason()
|
||||
: translate("moderation.warnlist.entry.no_reason"))
|
||||
)
|
||||
.collect(Collectors.joining("\n"))
|
||||
: translate("moderation.warnlist.empty");
|
||||
embed.setDescription(warningsDesc);
|
||||
return channel.sendMessage(embed.build());
|
||||
}
|
||||
|
||||
public MessageAction noWarnWithID(MessageChannel channel, Member performer, int caseID) {
|
||||
final EmbedBuilder embed = new EmbedBuilder()
|
||||
.setTitle(translate("moderation.unwarn.no_case_found.title"), null)
|
||||
.setColor(General.FAILURE_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.setDescription(translate("moderation.unwarn.no_case_found.desc"))
|
||||
.addField(translate("moderation.unwarn.no_case_found.field.performer"), performer.getUser().getAsMention(),
|
||||
true)
|
||||
.addField(translate("moderation.unwarn.no_case_found.field.case_id"), String.valueOf(caseID), true);
|
||||
return channel.sendMessage(embed.build());
|
||||
}
|
||||
|
||||
public MessageAction cannotUnwarnSelf(MessageChannel channel, Member performer, int caseID, WarningEntry entry) {
|
||||
final EmbedBuilder embed = new EmbedBuilder()
|
||||
.setTitle(translate("moderation.unwarn.cannot_unwarn_self.title"), null)
|
||||
.setColor(General.FAILURE_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.setDescription(translate("moderation.unwarn.cannot_unwarn_self.desc"))
|
||||
.addField(translate("moderation.unwarn.cannot_unwarn_self.field.performer"),
|
||||
performer.getUser().getAsMention(), true)
|
||||
.addField(translate("moderation.unwarn.cannot_unwarn_self.field.original_performer"),
|
||||
entry.getPerformer().getAsMention(), true)
|
||||
.addField(translate("moderation.unwarn.cannot_unwarn_self.field.case_id"), String.valueOf(caseID), true);
|
||||
return channel.sendMessage(embed.build());
|
||||
}
|
||||
|
||||
public MessageAction unwarn(MessageChannel channel, Member performer, int caseID, WarningEntry entry) {
|
||||
final EmbedBuilder embed = new EmbedBuilder()
|
||||
.setAuthor(translate("moderation.unwarn.author"), null, GAVEL_ICON_URL)
|
||||
.setColor(MODERATION_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.addField(translate("moderation.unwarn.field.performer"), performer.getUser().getAsMention(), true)
|
||||
.addField(translate("moderation.unwarn.field.case_id"), String.valueOf(caseID), true)
|
||||
.addField(translate("moderation.unwarn.field.original_target"), entry.getWarned().getAsMention(), true)
|
||||
.addField(translate("moderation.unwarn.field.original_performer"), entry.getPerformer().getAsMention(),
|
||||
true)
|
||||
.addField(translate("moderation.unwarn.field.date_time"),
|
||||
entry.getDateTime().format(RFC_1123_DATE_TIME), true);
|
||||
if (entry.getReason() != null)
|
||||
embed.addField(translate("moderation.unwarn.field.reason"), entry.getReason(), false);
|
||||
return channel.sendMessage(embed.build());
|
||||
}
|
||||
|
||||
public MessageAction cannotWarnMods(MessageChannel channel, Member performer, Member target) {
|
||||
final EmbedBuilder embed = new EmbedBuilder()
|
||||
.setTitle(translate("moderation.warn.cannot_warn_mods.title"), null)
|
||||
.setColor(General.FAILURE_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.setDescription(translate("moderation.warn.cannot_warn_mods.desc"))
|
||||
.addField(translate("moderation.warn.cannot_warn_mods.field.performer"),
|
||||
performer.getAsMention(), true)
|
||||
.addField(translate("moderation.warn.cannot_warn_mods.field.target"),
|
||||
target.getAsMention(), true);
|
||||
return channel.sendMessage(embed.build());
|
||||
}
|
||||
|
||||
public MessageAction cannotRemoveHigherModerated(MessageChannel channel, Member performer, int caseID,
|
||||
WarningEntry entry) {
|
||||
final EmbedBuilder embed = new EmbedBuilder()
|
||||
.setTitle(translate("moderation.unwarn.cannot_remove_higher_mod.title"), null)
|
||||
.setColor(General.FAILURE_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.setDescription(translate("moderation.unwarn.cannot_remove_higher_mod.desc"))
|
||||
.addField(translate("moderation.unwarn.cannot_remove_higher_mod.field.performer"),
|
||||
performer.getUser().getAsMention(), true)
|
||||
.addField(translate("moderation.unwarn.cannot_remove_higher_mod.field.original_performer"),
|
||||
entry.getPerformer().getAsMention(), true)
|
||||
.addField(translate("moderation.unwarn.cannot_remove_higher_mod.field.case_id"), String.valueOf(caseID), true);
|
||||
return channel.sendMessage(embed.build());
|
||||
}
|
||||
|
||||
public MessageAction maxAmountOfNotes(MessageChannel channel, Member performer, Member target, int amount) {
|
||||
final EmbedBuilder embed = new EmbedBuilder()
|
||||
.setTitle(translate("moderation.note.max_amount_of_notes.title"), null)
|
||||
.setColor(General.FAILURE_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.setDescription(translate("moderation.note.max_amount_of_notes.desc"))
|
||||
.addField(translate("moderation.note.max_amount_of_notes.field.performer"), performer.getAsMention(), true)
|
||||
.addField(translate("moderation.note.max_amount_of_notes.field.target"), target.getAsMention(), true)
|
||||
.addField(translate("moderation.note.max_amount_of_notes.field.amount"), String.valueOf(amount), true);
|
||||
return channel.sendMessage(embed.build());
|
||||
}
|
||||
|
||||
public MessageAction noNoteFound(MessageChannel channel, Member performer, int noteID) {
|
||||
final EmbedBuilder embed = new EmbedBuilder()
|
||||
.setTitle(translate("moderation.note.no_note_found.title"), null)
|
||||
.setColor(General.FAILURE_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.setDescription(translate("moderation.note.no_note_found.desc"))
|
||||
.addField(translate("moderation.note.no_note_found.field.performer"), performer.getAsMention(), true)
|
||||
.addField(translate("moderation.note.no_note_found.field.note_id"), String.valueOf(noteID), true);
|
||||
return channel.sendMessage(embed.build());
|
||||
}
|
||||
|
||||
public MessageAction addNote(MessageChannel channel, Member performer, Member target, String contents,
|
||||
OffsetDateTime dateTime, int noteID) {
|
||||
final EmbedBuilder embed = new EmbedBuilder()
|
||||
.setAuthor(translate("moderation.note.add.author"), null, GAVEL_ICON_URL)
|
||||
.setColor(MODERATION_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.addField(translate("moderation.note.add.field.performer"), performer.getUser().getAsMention(), true)
|
||||
.addField(translate("moderation.note.add.field.target"), target.getUser().getAsMention(), true)
|
||||
.addField(translate("moderation.note.add.field.note_id"), String.valueOf(noteID), true)
|
||||
.addField(translate("moderation.note.add.field.date_time"), dateTime.format(RFC_1123_DATE_TIME), true)
|
||||
.addField(translate("moderation.note.add.field.contents"), contents, false);
|
||||
return channel.sendMessage(embed.build());
|
||||
}
|
||||
|
||||
public MessageAction noteList(MessageChannel channel, Map<Integer, NoteEntry> displayNotes) {
|
||||
final EmbedBuilder embed = new EmbedBuilder()
|
||||
.setAuthor(translate("moderation.note.list.author"), null, GAVEL_ICON_URL)
|
||||
.setColor(MODERATION_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()));
|
||||
String warningsDesc = displayNotes.size() > 0 ? displayNotes.entrySet().stream()
|
||||
.sorted(Collections.reverseOrder(Comparator.comparingInt(Map.Entry::getKey)))
|
||||
.limit(10)
|
||||
.map(entry ->
|
||||
translate("moderation.note.list.entry",
|
||||
entry.getKey(),
|
||||
entry.getValue().getTarget().getAsMention(),
|
||||
entry.getValue().getPerformer().getAsMention(),
|
||||
entry.getValue().getDateTime().format(RFC_1123_DATE_TIME),
|
||||
entry.getValue().getContents())
|
||||
)
|
||||
.collect(Collectors.joining("\n"))
|
||||
: translate("moderation.note.list.empty");
|
||||
embed.setDescription(warningsDesc);
|
||||
return channel.sendMessage(embed.build());
|
||||
}
|
||||
|
||||
public MessageAction removeNote(MessageChannel channel, Member performer, int noteID, NoteEntry entry) {
|
||||
final EmbedBuilder embed = new EmbedBuilder()
|
||||
.setAuthor(translate("moderation.note.remove.author"), null, GAVEL_ICON_URL)
|
||||
.setColor(MODERATION_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||
.addField(translate("moderation.note.remove.field.performer"), performer.getAsMention(), true)
|
||||
.addField(translate("moderation.note.remove.field.note_id"), String.valueOf(noteID), true)
|
||||
.addField(translate("moderation.note.remove.field.original_target"), entry.getTarget().getAsMention(), true)
|
||||
.addField(translate("moderation.note.remove.field.original_performer"), entry.getPerformer().getAsMention(),
|
||||
true)
|
||||
.addField(translate("moderation.note.remove.field.date_time"), entry.getDateTime().format(RFC_1123_DATE_TIME),
|
||||
true)
|
||||
.addField(translate("moderation.note.remove.field.contents"), entry.getContents(), false);
|
||||
return channel.sendMessage(embed.build());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
318
src/main/java/sciwhiz12/janitor/msg/Moderation.java
Normal file
318
src/main/java/sciwhiz12/janitor/msg/Moderation.java
Normal file
|
@ -0,0 +1,318 @@
|
|||
package sciwhiz12.janitor.msg;
|
||||
|
||||
import net.dv8tion.jda.api.EmbedBuilder;
|
||||
import net.dv8tion.jda.api.Permission;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.requests.restaction.MessageAction;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import sciwhiz12.janitor.moderation.notes.NoteEntry;
|
||||
import sciwhiz12.janitor.moderation.warns.WarningEntry;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME;
|
||||
|
||||
public final class Moderation {
|
||||
public static final int MODERATION_COLOR = 0xF1BD25;
|
||||
public static final String GAVEL_ICON_URL = "https://cdn.discordapp.com/attachments/738478941760782526" +
|
||||
"/760463743330549760/gavel.png";
|
||||
|
||||
private final Messages messages;
|
||||
public final Errors ERRORS;
|
||||
|
||||
Moderation(Messages messages) {
|
||||
this.messages = messages;
|
||||
ERRORS = new Errors();
|
||||
}
|
||||
|
||||
private String translate(String key, Object... args) {
|
||||
return translate(key, args);
|
||||
}
|
||||
|
||||
public EmbedBuilder moderationEmbed() {
|
||||
return new EmbedBuilder()
|
||||
.setColor(MODERATION_COLOR)
|
||||
.setTimestamp(OffsetDateTime.now(ZoneOffset.UTC));
|
||||
}
|
||||
|
||||
public EmbedBuilder moderationEmbed(String author) {
|
||||
return moderationEmbed()
|
||||
.setAuthor(author, null, GAVEL_ICON_URL);
|
||||
}
|
||||
|
||||
public class Errors {
|
||||
private Errors() {}
|
||||
|
||||
public MessageAction performerInsufficientPermissions(MessageChannel channel, Member performer,
|
||||
EnumSet<Permission> permissions) {
|
||||
return channel.sendMessage(
|
||||
messages.failureEmbed(translate("moderation.insufficient_permissions.title"))
|
||||
.setDescription(translate("moderation.insufficient_permissions.desc"))
|
||||
.addField(
|
||||
translate("moderation.insufficient_permissions.field.performer"),
|
||||
performer.getAsMention(),
|
||||
true)
|
||||
.addField(new MessageEmbed.Field(
|
||||
translate("moderation.insufficient_permissions.field.permissions"),
|
||||
permissions.stream().map(Permission::getName).collect(Collectors.joining(", ")), true))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction cannotModerate(MessageChannel channel, Member performer, Member target) {
|
||||
return channel.sendMessage(
|
||||
messages.failureEmbed(translate("moderation.cannot_interact.title"))
|
||||
.setDescription(translate("moderation.cannot_interact.desc"))
|
||||
.addField(translate("moderation.cannot_interact.field.performer"), performer.getAsMention(), true)
|
||||
.addField(translate("moderation.cannot_interact.field.target"), target.getAsMention(), true)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction cannotWarnMods(MessageChannel channel, Member performer, Member target) {
|
||||
return channel.sendMessage(
|
||||
messages.failureEmbed(translate("moderation.warn.cannot_warn_mods.title"))
|
||||
.setDescription(translate("moderation.warn.cannot_warn_mods.desc"))
|
||||
.addField(translate("moderation.warn.cannot_warn_mods.field.performer"), performer.getAsMention(), true)
|
||||
.addField(translate("moderation.warn.cannot_warn_mods.field.target"), target.getAsMention(), true).build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction cannotRemoveHigherModerated(MessageChannel channel, Member performer, int caseID,
|
||||
WarningEntry entry) {
|
||||
return channel.sendMessage(
|
||||
messages.failureEmbed(translate("moderation.unwarn.cannot_remove_higher_mod.title"))
|
||||
.setDescription(translate("moderation.unwarn.cannot_remove_higher_mod.desc"))
|
||||
.addField(translate("moderation.unwarn.cannot_remove_higher_mod.field.performer"), performer.getAsMention(),
|
||||
true)
|
||||
.addField(translate("moderation.unwarn.cannot_remove_higher_mod.field.original_performer"),
|
||||
entry.getPerformer().getAsMention(), true)
|
||||
.addField(translate("moderation.unwarn.cannot_remove_higher_mod.field.case_id"), String.valueOf(caseID),
|
||||
true)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction maxAmountOfNotes(MessageChannel channel, Member performer, Member target, int amount) {
|
||||
return channel.sendMessage(
|
||||
messages.failureEmbed(translate("moderation.note.max_amount_of_notes.title"))
|
||||
.setDescription(translate("moderation.note.max_amount_of_notes.desc"))
|
||||
.addField(translate("moderation.note.max_amount_of_notes.field.performer"), performer.getAsMention(), true)
|
||||
.addField(translate("moderation.note.max_amount_of_notes.field.target"), target.getAsMention(), true)
|
||||
.addField(translate("moderation.note.max_amount_of_notes.field.amount"), String.valueOf(amount), true)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction noNoteFound(MessageChannel channel, Member performer, int noteID) {
|
||||
return channel.sendMessage(
|
||||
messages.failureEmbed(translate("moderation.note.no_note_found.title"))
|
||||
.setDescription(translate("moderation.note.no_note_found.desc"))
|
||||
.addField(translate("moderation.note.no_note_found.field.performer"), performer.getAsMention(), true)
|
||||
.addField(translate("moderation.note.no_note_found.field.note_id"), String.valueOf(noteID), true)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction noWarnWithID(MessageChannel channel, Member performer, int caseID) {
|
||||
return channel.sendMessage(
|
||||
messages.failureEmbed(translate("moderation.unwarn.no_case_found.title"))
|
||||
.setDescription(translate("moderation.unwarn.no_case_found.desc"))
|
||||
.addField(translate("moderation.unwarn.no_case_found.field.performer"), performer.getAsMention(), true)
|
||||
.addField(translate("moderation.unwarn.no_case_found.field.case_id"), String.valueOf(caseID), true).build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction cannotUnwarnSelf(MessageChannel channel, Member performer, int caseID, WarningEntry entry) {
|
||||
return channel.sendMessage(
|
||||
messages.failureEmbed(translate("moderation.unwarn.cannot_unwarn_self.title"))
|
||||
.setDescription(translate("moderation.unwarn.cannot_unwarn_self.desc"))
|
||||
.addField(translate("moderation.unwarn.cannot_unwarn_self.field.performer"), performer.getAsMention(),
|
||||
true)
|
||||
.addField(translate("moderation.unwarn.cannot_unwarn_self.field.original_performer"),
|
||||
entry.getPerformer().getAsMention(), true)
|
||||
.addField(translate("moderation.unwarn.cannot_unwarn_self.field.case_id"), String.valueOf(caseID), true)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public MessageAction kickUser(MessageChannel channel, Member performer, Member target, @Nullable String reason,
|
||||
boolean sentDM) {
|
||||
return channel.sendMessage(
|
||||
moderationEmbed(translate("moderation.kick.info.author"))
|
||||
.addField(translate("moderation.kick.info.field.performer"), performer.getAsMention(), true)
|
||||
.addField(translate("moderation.kick.info.field.target"), target.getAsMention(), true)
|
||||
.addField(translate("moderation.kick.info.field.sent_private_message"), sentDM ? "✅" : "❌", true)
|
||||
.addField(reason != null ? translate("moderation.kick.info.field.reason") : null, reason, false)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction kickedDM(MessageChannel channel, Member performer, Member target, @Nullable String reason) {
|
||||
return channel.sendMessage(
|
||||
moderationEmbed()
|
||||
.setAuthor(performer.getGuild().getName(), null, performer.getGuild().getIconUrl())
|
||||
.setTitle(translate("moderation.kick.dm.title"))
|
||||
.addField(translate("moderation.kick.dm.field.performer"), performer.getUser().getAsMention(), true)
|
||||
.addField(reason != null ? translate("moderation.kick.dm.field.reason") : null, reason, false)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction banUser(MessageChannel channel, Member performer, Member target, @Nullable String reason,
|
||||
int deletionDays, boolean sentDM) {
|
||||
return channel.sendMessage(
|
||||
moderationEmbed(translate("moderation.ban.info.author"))
|
||||
.addField(translate("moderation.ban.info.field.performer"), performer.getAsMention(), true)
|
||||
.addField(translate("moderation.ban.info.field.target"), target.getAsMention(), true)
|
||||
.addField(translate("moderation.ban.info.field.sent_private_message"), sentDM ? "✅" : "❌", true)
|
||||
.addField(deletionDays != 0 ?
|
||||
new MessageEmbed.Field(translate("moderation.ban.info.field.delete_duration"),
|
||||
translate("moderation.ban.info.field.delete_duration.value", String.valueOf(deletionDays)), true)
|
||||
: null)
|
||||
.addField(reason != null ? translate("moderation.ban.info.field.reason") : null, reason, false)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction bannedDM(MessageChannel channel, Member performer, @Nullable String reason) {
|
||||
return channel.sendMessage(
|
||||
moderationEmbed()
|
||||
.setAuthor(performer.getGuild().getName(), null, performer.getGuild().getIconUrl())
|
||||
.setTitle(translate("moderation.ban.dm.title"))
|
||||
.addField(translate("moderation.ban.dm.field.performer"), performer.getAsMention(), true)
|
||||
.addField(reason != null ? translate("moderation.ban.dm.field.reason") : null, reason, false)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction unbanUser(MessageChannel channel, Member performer, User target) {
|
||||
return channel.sendMessage(
|
||||
moderationEmbed(translate("moderation.unban.info.author"))
|
||||
.addField(translate("moderation.unban.info.field.performer"), performer.getAsMention(), true)
|
||||
.addField(translate("moderation.unban.info.field.target"), target.getAsMention(), true)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction warnUser(MessageChannel channel, Member performer, Member target, String reason,
|
||||
OffsetDateTime dateTime, int caseID, boolean sentDM) {
|
||||
return channel.sendMessage(
|
||||
moderationEmbed(translate("moderation.warn.info.author"))
|
||||
.addField(translate("moderation.warn.info.field.performer"), performer.getAsMention(), true)
|
||||
.addField(translate("moderation.warn.info.field.target"), target.getAsMention(), true)
|
||||
.addField(translate("moderation.warn.info.field.sent_private_message"), sentDM ? "✅" : "❌", true)
|
||||
.addField(translate("moderation.warn.info.field.case_id"), String.valueOf(caseID), true)
|
||||
.addField(translate("moderation.warn.info.field.date_time"),
|
||||
dateTime.format(RFC_1123_DATE_TIME), true)
|
||||
.addField(translate("moderation.warn.info.field.reason"), reason, false).build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction warnDM(MessageChannel channel, Member performer, Member target, String reason,
|
||||
OffsetDateTime dateTime) {
|
||||
return channel.sendMessage(
|
||||
moderationEmbed()
|
||||
.setAuthor(performer.getGuild().getName(), null, performer.getGuild().getIconUrl())
|
||||
.setTitle(translate("moderation.warn.dm.title"))
|
||||
.addField(translate("moderation.warn.dm.field.performer"), performer.getUser().getAsMention(), true)
|
||||
.addField(translate("moderation.warn.dm.field.date_time"),
|
||||
dateTime.format(RFC_1123_DATE_TIME), true)
|
||||
.addField(translate("moderation.warn.dm.field.reason"), reason, false)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction warnList(MessageChannel channel, Map<Integer, WarningEntry> displayWarnings) {
|
||||
return channel.sendMessage(
|
||||
moderationEmbed(translate("moderation.warnlist.author"))
|
||||
.setDescription(displayWarnings.size() > 0 ? displayWarnings.entrySet().stream()
|
||||
.sorted(Collections.reverseOrder(Comparator.comparingInt(Map.Entry::getKey)))
|
||||
.limit(10)
|
||||
.map(entry ->
|
||||
translate("moderation.warnlist.entry",
|
||||
entry.getKey(),
|
||||
entry.getValue().getWarned().getAsMention(),
|
||||
entry.getValue().getPerformer().getAsMention(),
|
||||
entry.getValue().getDateTime().format(RFC_1123_DATE_TIME),
|
||||
entry.getValue().getReason() != null
|
||||
? entry.getValue().getReason()
|
||||
: translate("moderation.warnlist.entry.no_reason"))
|
||||
)
|
||||
.collect(Collectors.joining("\n"))
|
||||
: translate("moderation.warnlist.empty"))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction unwarn(MessageChannel channel, Member performer, int caseID, WarningEntry entry) {
|
||||
return channel.sendMessage(
|
||||
moderationEmbed(translate("moderation.unwarn.author"))
|
||||
.addField(translate("moderation.unwarn.field.performer"), performer.getAsMention(), true)
|
||||
.addField(translate("moderation.unwarn.field.case_id"), String.valueOf(caseID), true)
|
||||
.addField(translate("moderation.unwarn.field.original_target"), entry.getWarned().getAsMention(), true)
|
||||
.addField(translate("moderation.unwarn.field.original_performer"), entry.getPerformer().getAsMention(), true)
|
||||
.addField(translate("moderation.unwarn.field.date_time"), entry.getDateTime().format(RFC_1123_DATE_TIME), true)
|
||||
.addField(entry.getReason() != null ? translate("moderation.unwarn.field.reason") : null, entry.getReason(),
|
||||
false)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction addNote(MessageChannel channel, Member performer, Member target, String contents,
|
||||
OffsetDateTime dateTime, int noteID) {
|
||||
return channel.sendMessage(
|
||||
moderationEmbed(translate("moderation.note.add.author"))
|
||||
.addField(translate("moderation.note.add.field.performer"), performer.getUser().getAsMention(), true)
|
||||
.addField(translate("moderation.note.add.field.target"), target.getUser().getAsMention(), true)
|
||||
.addField(translate("moderation.note.add.field.note_id"), String.valueOf(noteID), true)
|
||||
.addField(translate("moderation.note.add.field.date_time"), dateTime.format(RFC_1123_DATE_TIME), true)
|
||||
.addField(translate("moderation.note.add.field.contents"), contents, false)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction noteList(MessageChannel channel, Map<Integer, NoteEntry> displayNotes) {
|
||||
return channel.sendMessage(moderationEmbed(translate("moderation.note.list.author"))
|
||||
.setDescription(displayNotes.size() > 0 ? displayNotes.entrySet().stream()
|
||||
.sorted(Collections.reverseOrder(Comparator.comparingInt(Map.Entry::getKey)))
|
||||
.limit(10)
|
||||
.map(entry ->
|
||||
translate("moderation.note.list.entry",
|
||||
entry.getKey(),
|
||||
entry.getValue().getTarget().getAsMention(),
|
||||
entry.getValue().getPerformer().getAsMention(),
|
||||
entry.getValue().getDateTime().format(RFC_1123_DATE_TIME),
|
||||
entry.getValue().getContents())
|
||||
)
|
||||
.collect(Collectors.joining("\n"))
|
||||
: translate("moderation.note.list.empty"))
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public MessageAction removeNote(MessageChannel channel, Member performer, int noteID, NoteEntry entry) {
|
||||
return channel.sendMessage(
|
||||
moderationEmbed(translate("moderation.note.remove.author"))
|
||||
.addField(translate("moderation.note.remove.field.performer"), performer.getAsMention(), true)
|
||||
.addField(translate("moderation.note.remove.field.note_id"), String.valueOf(noteID), true)
|
||||
.addField(translate("moderation.note.remove.field.original_target"), entry.getTarget().getAsMention(), true)
|
||||
.addField(translate("moderation.note.remove.field.original_performer"), entry.getPerformer().getAsMention(),
|
||||
true)
|
||||
.addField(translate("moderation.note.remove.field.date_time"), entry.getDateTime().format(RFC_1123_DATE_TIME),
|
||||
true)
|
||||
.addField(translate("moderation.note.remove.field.contents"), entry.getContents(), false)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -35,7 +35,8 @@
|
|||
"moderation.ban.info.field.target": "Target",
|
||||
"moderation.ban.info.field.reason": "Reason",
|
||||
"moderation.ban.info.field.sent_private_message": "Sent DM",
|
||||
"moderation.ban.info.field.delete_duration": "Days of Message Deletion",
|
||||
"moderation.ban.info.field.delete_duration": "Message Deletion",
|
||||
"moderation.ban.info.field.delete_duration.value": "%s day(s)",
|
||||
"moderation.ban.dm.title": "You were banned from this server.",
|
||||
"moderation.ban.dm.field.performer": "Moderator",
|
||||
"moderation.ban.dm.field.reason": "Reason",
|
||||
|
|
Loading…
Reference in New Issue
Block a user