use of sx.blah.discord.handle.impl.events.guild.member.UserBanEvent in project DiscordSailv2 by Vaerys-Dawn.
the class LoggingHandler method doBanLog.
public static void doBanLog(UserBanEvent event) {
IGuild guild = event.getGuild();
GuildObject guildObject = Globals.getGuildContent(guild.getLongID());
if (!guildObject.config.banLogging || !GuildHandler.testForPerms(Client.getClient().getOurUser(), guild, Permissions.VIEW_AUDIT_LOG))
return;
StringHandler output = new StringHandler("> **@%s#%s** was banned");
output.setContent(String.format(output.toString(), event.getUser().getName(), event.getUser().getDiscriminator()));
// get recent bans
List<TargetedEntry> recentBans = event.getGuild().getAuditLog(ActionType.MEMBER_BAN_ADD).getEntriesByTarget(event.getUser().getLongID());
if (recentBans.size() == 0)
return;
// and sort them. last entry is most recent.
recentBans.sort(Comparator.comparingLong(o -> DiscordUtils.getSnowflakeTimeFromID(o.getLongID()).toEpochMilli()));
AuditLogEntry lastBan = recentBans.get(recentBans.size() - 1);
output.appendFormatted(" by **@%s#%s**", lastBan.getResponsibleUser().getName(), lastBan.getResponsibleUser().getDiscriminator());
String reason = lastBan.getReason().isPresent() ? lastBan.getReason().get() : "No reason provided";
output.appendFormatted(" with reason `%s`", reason);
Utility.sendLog(output.toString(), guildObject, true);
}
Aggregations