1
0
mirror of https://github.com/sciwhiz12/Janitor.git synced 2024-11-09 22:51:26 +00:00

Add timestamps to messages, fix unban cmd's ambiguous members message not sending

This commit is contained in:
Arnold Alejo Nunag 2020-09-30 08:13:31 +08:00
parent 805ae844ed
commit 8f9601a9c7
Signed by: sciwhiz12
GPG Key ID: 622CF446534317E1
3 changed files with 32 additions and 7 deletions

View File

@ -63,7 +63,7 @@ public class UnbanCommand extends BaseCommand {
.collect(Collectors.toList()))
.queue(bans -> {
if (bans.size() > 1)
messages().GENERAL.ambiguousMember(channel);
messages().GENERAL.ambiguousMember(channel).queue();
else if (bans.size() == 1)
tryUnban(channel, guild, performer, bans.get(0).getUser());
});

View File

@ -6,12 +6,19 @@ import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.requests.restaction.AuditableRestAction;
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;
public class ModerationHelper {
public static AuditableRestAction<Void> kickUser(Guild guild, Member performer, Member target, @Nullable String reason) {
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)
auditReason.append(" for reason: ").append(reason);
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,
@Nullable String reason) {
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)
auditReason.append(" for reason: ").append(reason);
return guild.ban(target, deleteDuration, auditReason.toString());

View File

@ -12,6 +12,8 @@ import net.dv8tion.jda.api.requests.restaction.MessageAction;
import org.checkerframework.checker.nullness.qual.Nullable;
import sciwhiz12.janitor.JanitorBot;
import java.time.Clock;
import java.time.OffsetDateTime;
import java.util.EnumSet;
import java.util.stream.Collectors;
@ -41,6 +43,7 @@ public class Messages {
.setTitle(translate("general.guild_only_command.title"))
.setDescription(translate("general.guild_only_command.desc"))
.setColor(FAILURE_COLOR)
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
.build()
);
}
@ -55,6 +58,7 @@ public class Messages {
permissions.stream().map(Permission::getName).collect(Collectors.joining(", ")),
false))
.setColor(FAILURE_COLOR)
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
.build()
);
}
@ -65,6 +69,7 @@ public class Messages {
.setTitle(translate("general.ambiguous_member.title"))
.setDescription(translate("general.ambiguous_member.desc"))
.setColor(FAILURE_COLOR)
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
.build()
);
}
@ -76,6 +81,7 @@ public class Messages {
.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()
);
}
@ -86,6 +92,7 @@ public class Messages {
.setTitle(translate("general.cannot_action_self.title"))
.setDescription(translate("general.cannot_action_self.desc"))
.setColor(General.FAILURE_COLOR)
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
.build()
);
}
@ -98,6 +105,7 @@ public class Messages {
.addField(translate("general.cannot_action_performer.field.performer"), performer.getUser().getAsMention(),
true)
.setColor(General.FAILURE_COLOR)
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
.build()
);
}
@ -124,6 +132,7 @@ public class Messages {
permissions.stream().map(Permission::getName).collect(Collectors.joining(", ")),
true))
.setColor(General.FAILURE_COLOR)
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
.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.target"), target.getUser().getAsMention(), true)
.setColor(General.FAILURE_COLOR)
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
.build()
);
}
@ -149,7 +159,8 @@ public class Messages {
.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());
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) {
@ -159,7 +170,8 @@ public class Messages {
.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());
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,
@ -174,7 +186,8 @@ public class Messages {
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).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) {
@ -184,7 +197,8 @@ public class Messages {
.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).build());
return channel
.sendMessage(embed.setColor(MODERATION_COLOR).setTimestamp(OffsetDateTime.now(Clock.systemUTC())).build());
}
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.target"), target.getAsMention(), true)
.setColor(MODERATION_COLOR)
.setTimestamp(OffsetDateTime.now(Clock.systemUTC()))
.build()
);
}