mirror of
https://github.com/sciwhiz12/Janitor.git
synced 2024-11-14 04:21:25 +00:00
Add timestamps to messages, fix unban cmd's ambiguous members message not sending
This commit is contained in:
parent
805ae844ed
commit
8f9601a9c7
|
@ -63,7 +63,7 @@ public class UnbanCommand extends BaseCommand {
|
||||||
.collect(Collectors.toList()))
|
.collect(Collectors.toList()))
|
||||||
.queue(bans -> {
|
.queue(bans -> {
|
||||||
if (bans.size() > 1)
|
if (bans.size() > 1)
|
||||||
messages().GENERAL.ambiguousMember(channel);
|
messages().GENERAL.ambiguousMember(channel).queue();
|
||||||
else if (bans.size() == 1)
|
else if (bans.size() == 1)
|
||||||
tryUnban(channel, guild, performer, bans.get(0).getUser());
|
tryUnban(channel, guild, performer, bans.get(0).getUser());
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,12 +6,19 @@ import net.dv8tion.jda.api.entities.User;
|
||||||
import net.dv8tion.jda.api.requests.restaction.AuditableRestAction;
|
import net.dv8tion.jda.api.requests.restaction.AuditableRestAction;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
import static sciwhiz12.janitor.utils.Util.nameFor;
|
import static sciwhiz12.janitor.utils.Util.nameFor;
|
||||||
|
|
||||||
public class ModerationHelper {
|
public class ModerationHelper {
|
||||||
public static AuditableRestAction<Void> kickUser(Guild guild, Member performer, Member target, @Nullable String reason) {
|
public static AuditableRestAction<Void> kickUser(Guild guild, Member performer, Member target, @Nullable String reason) {
|
||||||
StringBuilder auditReason = new StringBuilder();
|
StringBuilder auditReason = new StringBuilder();
|
||||||
auditReason.append("Kicked by ").append(nameFor(performer.getUser()));
|
auditReason.append("Kicked by ")
|
||||||
|
.append(nameFor(performer.getUser()))
|
||||||
|
.append(" on ")
|
||||||
|
.append(Instant.now().atOffset(ZoneOffset.UTC).format(DateTimeFormatter.RFC_1123_DATE_TIME));
|
||||||
if (reason != null)
|
if (reason != null)
|
||||||
auditReason.append(" for reason: ").append(reason);
|
auditReason.append(" for reason: ").append(reason);
|
||||||
return guild.kick(target, auditReason.toString());
|
return guild.kick(target, auditReason.toString());
|
||||||
|
@ -20,7 +27,10 @@ public class ModerationHelper {
|
||||||
public static AuditableRestAction<Void> banUser(Guild guild, Member performer, Member target, int deleteDuration,
|
public static AuditableRestAction<Void> banUser(Guild guild, Member performer, Member target, int deleteDuration,
|
||||||
@Nullable String reason) {
|
@Nullable String reason) {
|
||||||
StringBuilder auditReason = new StringBuilder();
|
StringBuilder auditReason = new StringBuilder();
|
||||||
auditReason.append("Banned by ").append(nameFor(performer.getUser()));
|
auditReason.append("Banned by ")
|
||||||
|
.append(nameFor(performer.getUser()))
|
||||||
|
.append(" on ")
|
||||||
|
.append(Instant.now().atOffset(ZoneOffset.UTC).format(DateTimeFormatter.RFC_1123_DATE_TIME));
|
||||||
if (reason != null)
|
if (reason != null)
|
||||||
auditReason.append(" for reason: ").append(reason);
|
auditReason.append(" for reason: ").append(reason);
|
||||||
return guild.ban(target, deleteDuration, auditReason.toString());
|
return guild.ban(target, deleteDuration, auditReason.toString());
|
||||||
|
|
|
@ -12,6 +12,8 @@ import net.dv8tion.jda.api.requests.restaction.MessageAction;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import sciwhiz12.janitor.JanitorBot;
|
import sciwhiz12.janitor.JanitorBot;
|
||||||
|
|
||||||
|
import java.time.Clock;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -41,6 +43,7 @@ public class Messages {
|
||||||
.setTitle(translate("general.guild_only_command.title"))
|
.setTitle(translate("general.guild_only_command.title"))
|
||||||
.setDescription(translate("general.guild_only_command.desc"))
|
.setDescription(translate("general.guild_only_command.desc"))
|
||||||
.setColor(FAILURE_COLOR)
|
.setColor(FAILURE_COLOR)
|
||||||
|
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -55,6 +58,7 @@ public class Messages {
|
||||||
permissions.stream().map(Permission::getName).collect(Collectors.joining(", ")),
|
permissions.stream().map(Permission::getName).collect(Collectors.joining(", ")),
|
||||||
false))
|
false))
|
||||||
.setColor(FAILURE_COLOR)
|
.setColor(FAILURE_COLOR)
|
||||||
|
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -65,6 +69,7 @@ public class Messages {
|
||||||
.setTitle(translate("general.ambiguous_member.title"))
|
.setTitle(translate("general.ambiguous_member.title"))
|
||||||
.setDescription(translate("general.ambiguous_member.desc"))
|
.setDescription(translate("general.ambiguous_member.desc"))
|
||||||
.setColor(FAILURE_COLOR)
|
.setColor(FAILURE_COLOR)
|
||||||
|
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -76,6 +81,7 @@ public class Messages {
|
||||||
.setDescription(translate("general.cannot_interact.desc"))
|
.setDescription(translate("general.cannot_interact.desc"))
|
||||||
.addField(translate("general.cannot_interact.field.target"), target.getUser().getAsMention(), true)
|
.addField(translate("general.cannot_interact.field.target"), target.getUser().getAsMention(), true)
|
||||||
.setColor(General.FAILURE_COLOR)
|
.setColor(General.FAILURE_COLOR)
|
||||||
|
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -86,6 +92,7 @@ public class Messages {
|
||||||
.setTitle(translate("general.cannot_action_self.title"))
|
.setTitle(translate("general.cannot_action_self.title"))
|
||||||
.setDescription(translate("general.cannot_action_self.desc"))
|
.setDescription(translate("general.cannot_action_self.desc"))
|
||||||
.setColor(General.FAILURE_COLOR)
|
.setColor(General.FAILURE_COLOR)
|
||||||
|
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -98,6 +105,7 @@ public class Messages {
|
||||||
.addField(translate("general.cannot_action_performer.field.performer"), performer.getUser().getAsMention(),
|
.addField(translate("general.cannot_action_performer.field.performer"), performer.getUser().getAsMention(),
|
||||||
true)
|
true)
|
||||||
.setColor(General.FAILURE_COLOR)
|
.setColor(General.FAILURE_COLOR)
|
||||||
|
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -124,6 +132,7 @@ public class Messages {
|
||||||
permissions.stream().map(Permission::getName).collect(Collectors.joining(", ")),
|
permissions.stream().map(Permission::getName).collect(Collectors.joining(", ")),
|
||||||
true))
|
true))
|
||||||
.setColor(General.FAILURE_COLOR)
|
.setColor(General.FAILURE_COLOR)
|
||||||
|
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -136,6 +145,7 @@ public class Messages {
|
||||||
.addField(translate("moderation.cannot_interact.field.performer"), performer.getUser().getAsMention(), true)
|
.addField(translate("moderation.cannot_interact.field.performer"), performer.getUser().getAsMention(), true)
|
||||||
.addField(translate("moderation.cannot_interact.field.target"), target.getUser().getAsMention(), true)
|
.addField(translate("moderation.cannot_interact.field.target"), target.getUser().getAsMention(), true)
|
||||||
.setColor(General.FAILURE_COLOR)
|
.setColor(General.FAILURE_COLOR)
|
||||||
|
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -149,7 +159,8 @@ public class Messages {
|
||||||
.addField(translate("moderation.kick.info.field.sent_private_message"), sentDM ? "✅" : "❌", true);
|
.addField(translate("moderation.kick.info.field.sent_private_message"), sentDM ? "✅" : "❌", true);
|
||||||
if (reason != null)
|
if (reason != null)
|
||||||
embed.addField(translate("moderation.kick.info.field.reason"), reason, false);
|
embed.addField(translate("moderation.kick.info.field.reason"), reason, false);
|
||||||
return channel.sendMessage(embed.setColor(MODERATION_COLOR).build());
|
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) {
|
public MessageAction kickedDM(MessageChannel channel, Member performer, Member target, @Nullable String reason) {
|
||||||
|
@ -159,7 +170,8 @@ public class Messages {
|
||||||
.addField(translate("moderation.kick.dm.field.performer"), performer.getUser().getAsMention(), true);
|
.addField(translate("moderation.kick.dm.field.performer"), performer.getUser().getAsMention(), true);
|
||||||
if (reason != null)
|
if (reason != null)
|
||||||
embed.addField(translate("moderation.kick.dm.field.reason"), reason, false);
|
embed.addField(translate("moderation.kick.dm.field.reason"), reason, false);
|
||||||
return channel.sendMessage(embed.setColor(MODERATION_COLOR).build());
|
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,
|
public MessageAction banUser(MessageChannel channel, Member performer, Member target, @Nullable String reason,
|
||||||
|
@ -174,7 +186,8 @@ public class Messages {
|
||||||
String.valueOf(deletionDays).concat(" day(s)"), true);
|
String.valueOf(deletionDays).concat(" day(s)"), true);
|
||||||
if (reason != null)
|
if (reason != null)
|
||||||
embed.addField(translate("moderation.ban.info.field.reason"), reason, false);
|
embed.addField(translate("moderation.ban.info.field.reason"), reason, false);
|
||||||
return channel.sendMessage(embed.setColor(MODERATION_COLOR).build());
|
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) {
|
public MessageAction bannedDM(MessageChannel channel, Member performer, Member target, @Nullable String reason) {
|
||||||
|
@ -184,7 +197,8 @@ public class Messages {
|
||||||
.addField(translate("moderation.ban.dm.field.performer"), performer.getUser().getAsMention(), true);
|
.addField(translate("moderation.ban.dm.field.performer"), performer.getUser().getAsMention(), true);
|
||||||
if (reason != null)
|
if (reason != null)
|
||||||
embed.addField(translate("moderation.ban.dm.field.reason"), reason, false);
|
embed.addField(translate("moderation.ban.dm.field.reason"), reason, false);
|
||||||
return channel.sendMessage(embed.setColor(MODERATION_COLOR).build());
|
return channel
|
||||||
|
.sendMessage(embed.setColor(MODERATION_COLOR).setTimestamp(OffsetDateTime.now(Clock.systemUTC())).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public MessageAction unbanUser(MessageChannel channel, Member performer, User target) {
|
public MessageAction unbanUser(MessageChannel channel, Member performer, User target) {
|
||||||
|
@ -194,6 +208,7 @@ public class Messages {
|
||||||
.addField(translate("moderation.unban.info.field.performer"), performer.getUser().getAsMention(), true)
|
.addField(translate("moderation.unban.info.field.performer"), performer.getUser().getAsMention(), true)
|
||||||
.addField(translate("moderation.unban.info.field.target"), target.getAsMention(), true)
|
.addField(translate("moderation.unban.info.field.target"), target.getAsMention(), true)
|
||||||
.setColor(MODERATION_COLOR)
|
.setColor(MODERATION_COLOR)
|
||||||
|
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user