Search in sources :

Example 1 with UserBanEvent

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);
}
Also used : GuildObject(com.github.vaerys.masterobjects.GuildObject) GuildMemberEvent(sx.blah.discord.handle.impl.events.guild.member.GuildMemberEvent) ChannelUpdateEvent(sx.blah.discord.handle.impl.events.guild.channel.ChannelUpdateEvent) UserBanEvent(sx.blah.discord.handle.impl.events.guild.member.UserBanEvent) ZonedDateTime(java.time.ZonedDateTime) ChannelSetting(com.github.vaerys.enums.ChannelSetting) LoggerFactory(org.slf4j.LoggerFactory) Client(com.github.vaerys.main.Client) MessageUpdateEvent(sx.blah.discord.handle.impl.events.guild.channel.message.MessageUpdateEvent) ArrayList(java.util.ArrayList) DiscordUtils(sx.blah.discord.api.internal.DiscordUtils) AuditLogEntry(sx.blah.discord.handle.audit.entry.AuditLogEntry) TargetedEntry(sx.blah.discord.handle.audit.entry.TargetedEntry) ActionType(sx.blah.discord.handle.audit.ActionType) ZoneOffset(java.time.ZoneOffset) CommandObject(com.github.vaerys.commands.CommandObject) Globals(com.github.vaerys.main.Globals) Logger(org.slf4j.Logger) ChannelCreateEvent(sx.blah.discord.handle.impl.events.guild.channel.ChannelCreateEvent) EmbedObject(sx.blah.discord.api.internal.json.objects.EmbedObject) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) List(java.util.List) sx.blah.discord.handle.obj(sx.blah.discord.handle.obj) ChannelDeleteEvent(sx.blah.discord.handle.impl.events.guild.channel.ChannelDeleteEvent) Comparator(java.util.Comparator) Utility(com.github.vaerys.main.Utility) UserRoleUpdateEvent(sx.blah.discord.handle.impl.events.guild.member.UserRoleUpdateEvent) GuildObject(com.github.vaerys.masterobjects.GuildObject) AuditLogEntry(sx.blah.discord.handle.audit.entry.AuditLogEntry) TargetedEntry(sx.blah.discord.handle.audit.entry.TargetedEntry)

Aggregations

CommandObject (com.github.vaerys.commands.CommandObject)1 ChannelSetting (com.github.vaerys.enums.ChannelSetting)1 Client (com.github.vaerys.main.Client)1 Globals (com.github.vaerys.main.Globals)1 Utility (com.github.vaerys.main.Utility)1 GuildObject (com.github.vaerys.masterobjects.GuildObject)1 Instant (java.time.Instant)1 ZoneOffset (java.time.ZoneOffset)1 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 DiscordUtils (sx.blah.discord.api.internal.DiscordUtils)1 EmbedObject (sx.blah.discord.api.internal.json.objects.EmbedObject)1 ActionType (sx.blah.discord.handle.audit.ActionType)1 AuditLogEntry (sx.blah.discord.handle.audit.entry.AuditLogEntry)1 TargetedEntry (sx.blah.discord.handle.audit.entry.TargetedEntry)1