Search in sources :

Example 1 with AuditLogEntry

use of net.dv8tion.jda.core.audit.AuditLogEntry in project FlareBot by FlareBot.

the class ModlogEvents method handleChannelCreate.

private void handleChannelCreate(GuildWrapper wrapper, Channel channel) {
    if (cannotHandle(wrapper, ModlogEvent.CHANNEL_CREATE))
        return;
    AuditLogEntry entry = wrapper.getGuild().getAuditLogs().complete().get(0);
    EmbedBuilder builder = new EmbedBuilder().addField("Type", channel.getType().name().toLowerCase(), true).addField("Name", channel.getName(), true);
    if (channel.getParent() != null) {
        builder.addField("Category", channel.getParent().getName(), true);
    }
    ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.CHANNEL_CREATE, entry.getUser(), builder);
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) AuditLogEntry(net.dv8tion.jda.core.audit.AuditLogEntry)

Example 2 with AuditLogEntry

use of net.dv8tion.jda.core.audit.AuditLogEntry in project FlareBot by FlareBot.

the class ModlogEvents method onGenericRoleUpdate.

private void onGenericRoleUpdate(GenericRoleUpdateEvent event, @Nonnull GuildWrapper wrapper) {
    if (cannotHandle(wrapper, ModlogEvent.ROLE_EDIT))
        return;
    if (event instanceof RoleUpdatePositionEvent) {
        return;
    }
    if (event.getResponseNumber() == roleResponseNumber) {
        return;
    }
    roleResponseNumber = event.getResponseNumber();
    event.getGuild().getAuditLogs().limit(1).queue(auditLogs -> {
        AuditLogEntry entry = auditLogs.get(0);
        Map<String, AuditLogChange> changes = entry.getChanges();
        EmbedBuilder permissionsBuilder = new EmbedBuilder();
        permissionsBuilder.addField("Role", event.getRole().getName() + " (" + event.getRole().getId() + ")", true);
        if (changes.containsKey("permissions")) {
            AuditLogChange change = changes.get("permissions");
            Map<Boolean, List<Permission>> permChanges = GeneralUtils.getChanged(Permission.getPermissions(((Integer) change.getOldValue()).longValue()), Permission.getPermissions(((Integer) change.getNewValue()).longValue()));
            if (permChanges.get(true).size() > 0) {
                StringBuilder added = new StringBuilder();
                for (Permission addedPerm : permChanges.get(true)) {
                    added.append(addedPerm.getName()).append("\n");
                }
                permissionsBuilder.addField("Added Perms", "```\n" + added.toString() + "```", false);
            }
            if (permChanges.get(false).size() > 0) {
                StringBuilder removed = new StringBuilder();
                for (Permission removedPerm : permChanges.get(false)) {
                    removed.append(removedPerm.getName()).append("\n");
                }
                permissionsBuilder.addField("Removed Perms", "```\n" + removed.toString() + "```", false);
            }
        }
        if (changes.containsKey("name")) {
            AuditLogChange change = changes.get("name");
            permissionsBuilder.addField("Name Change", "`" + change.getOldValue() + "` -> `" + change.getNewValue() + "`", true);
        }
        if (changes.containsKey("mentionable")) {
            AuditLogChange change = changes.get("mentionable");
            permissionsBuilder.addField("Mentionable", "`" + change.getNewValue() + "`", true);
        }
        if (changes.containsKey("hoist")) {
            AuditLogChange change = changes.get("hoist");
            permissionsBuilder.addField("Displayed Separately", "`" + change.getNewValue() + "`", true);
        }
        if (changes.containsKey("color")) {
            AuditLogChange change = changes.get("color");
            permissionsBuilder.addField("Color Change", "`#" + Integer.toHexString(change.getOldValue()) + "` -> `#" + Integer.toHexString(change.getNewValue()) + "`", true);
        }
        ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.ROLE_EDIT, entry.getUser(), permissionsBuilder);
    });
}
Also used : RoleUpdatePositionEvent(net.dv8tion.jda.core.events.role.update.RoleUpdatePositionEvent) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) AuditLogEntry(net.dv8tion.jda.core.audit.AuditLogEntry) AuditLogChange(net.dv8tion.jda.core.audit.AuditLogChange) Permission(net.dv8tion.jda.core.Permission) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with AuditLogEntry

use of net.dv8tion.jda.core.audit.AuditLogEntry in project FlareBot by FlareBot.

the class ModlogEvents method onGenericGuildUpdate.

private void onGenericGuildUpdate(GenericGuildUpdateEvent event, @Nonnull GuildWrapper wrapper) {
    if (event instanceof GuildUpdateExplicitContentLevelEvent) {
        return;
    }
    if (cannotHandle(wrapper, ModlogEvent.GUILD_UPDATE))
        return;
    if (event.getResponseNumber() == guildResponseNumber) {
        return;
    }
    guildResponseNumber = event.getResponseNumber();
    event.getGuild().getAuditLogs().limit(1).queue(auditLogs -> {
        AuditLogEntry entry = auditLogs.get(0);
        Map<String, AuditLogChange> changes = entry.getChanges();
        EmbedBuilder embedBuilder = new EmbedBuilder();
        if (changes.containsKey("region")) {
            embedBuilder.addField("Region change", "`" + changes.get("region").getOldValue() + "` -> `" + changes.get("region").getNewValue() + "`", true);
        }
        if (changes.containsKey("name")) {
            embedBuilder.addField("Name", "`" + changes.get("name").getOldValue() + "` -> `" + changes.get("name").getNewValue() + "`", true);
        }
        if (changes.containsKey("afk_channel_id")) {
            AuditLogChange change = changes.get("afk_channel_id");
            String oldChannel;
            String newChannel;
            if (change.getOldValue() == null) {
                oldChannel = "none";
            } else {
                oldChannel = event.getGuild().getVoiceChannelById(change.getOldValue()).getName();
            }
            if (change.getNewValue() == null) {
                newChannel = "none";
            } else {
                newChannel = event.getGuild().getVoiceChannelById(change.getNewValue()).getName();
            }
            embedBuilder.addField("AFK channel", "`" + oldChannel + "` -> `" + newChannel + "`", true);
        }
        if (changes.containsKey("afk_timeout")) {
            embedBuilder.addField("AFK timeout (minutes)", "`" + ((int) changes.get("afk_timeout").getOldValue() / 60) + "` -> `" + ((int) changes.get("afk_timeout").getNewValue() / 60) + "`", true);
        }
        if (changes.containsKey("system_channel_id")) {
            AuditLogChange change = changes.get("system_channel_id");
            String oldChannel;
            String newChannel;
            if (change.getOldValue() == null) {
                oldChannel = "none";
            } else {
                oldChannel = event.getGuild().getTextChannelById(change.getOldValue()).getName();
            }
            if (change.getNewValue() == null) {
                newChannel = "none";
            } else {
                newChannel = event.getGuild().getTextChannelById(change.getNewValue()).getName();
            }
            embedBuilder.addField("Welcome channel", "`" + oldChannel + "` -> `" + newChannel + "`", true);
        }
        if (changes.containsKey("default_message_notifications")) {
            String oldValue;
            String newValue;
            if ((int) changes.get("default_message_notifications").getOldValue() == 0) {
                oldValue = "All messages";
                newValue = "Only mentions";
            } else {
                oldValue = "Only mentions";
                newValue = "All messages";
            }
            embedBuilder.addField("Notification", "`" + oldValue + "` -> `" + newValue + "`", true);
        }
        if (changes.containsKey("verification_level")) {
            embedBuilder.addField("Verification level", "`" + GeneralUtils.getVerificationString(Guild.VerificationLevel.fromKey(changes.get("verification_level").getOldValue())) + " ` -> `" + GeneralUtils.getVerificationString(Guild.VerificationLevel.fromKey(changes.get("verification_level").getNewValue())) + "`", true);
        }
        if (changes.containsKey("mfa_level")) {
            boolean tfa = false;
            if ((int) changes.get("mfa_level").getOldValue() == 0) {
                tfa = true;
            }
            embedBuilder.addField("Two Factor authorization required", tfa ? "Yes" : "No", true);
        }
        ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.GUILD_UPDATE, entry.getUser(), embedBuilder);
    });
}
Also used : GuildUpdateExplicitContentLevelEvent(net.dv8tion.jda.core.events.guild.update.GuildUpdateExplicitContentLevelEvent) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) AuditLogEntry(net.dv8tion.jda.core.audit.AuditLogEntry) AuditLogChange(net.dv8tion.jda.core.audit.AuditLogChange)

Example 4 with AuditLogEntry

use of net.dv8tion.jda.core.audit.AuditLogEntry in project FlareBot by FlareBot.

the class ModlogEvents method onGuildUpdateExplicitContentLevel.

private void onGuildUpdateExplicitContentLevel(GuildUpdateExplicitContentLevelEvent e, @Nonnull GuildWrapper wrapper) {
    if (cannotHandle(wrapper, ModlogEvent.GUILD_EXPLICIT_FILTER_CHANGE))
        return;
    AuditLogEntry entry = e.getGuild().getAuditLogs().complete().get(0);
    AuditLogChange levelChange = entry.getChanges().get("explicit_content_filter");
    ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.GUILD_EXPLICIT_FILTER_CHANGE, entry.getUser(), new MessageEmbed.Field("Old level", Guild.ExplicitContentLevel.fromKey(levelChange.getOldValue()).getDescription(), true), new MessageEmbed.Field("New level", Guild.ExplicitContentLevel.fromKey(levelChange.getNewValue()).getDescription(), true));
}
Also used : MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) AuditLogEntry(net.dv8tion.jda.core.audit.AuditLogEntry) AuditLogChange(net.dv8tion.jda.core.audit.AuditLogChange)

Example 5 with AuditLogEntry

use of net.dv8tion.jda.core.audit.AuditLogEntry in project FlareBot by FlareBot.

the class ModlogEvents method onRoleCreate.

private void onRoleCreate(RoleCreateEvent event, @Nonnull GuildWrapper wrapper) {
    if (event.getGuild() == null)
        return;
    if (cannotHandle(wrapper, ModlogEvent.ROLE_CREATE))
        return;
    event.getGuild().getAuditLogs().queue(auditLog -> {
        AuditLogEntry entry = auditLog.get(0);
        ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.ROLE_CREATE, entry.getUser(), new MessageEmbed.Field("Role", event.getRole().getName() + " (" + event.getRole().getId() + ")", true));
    });
}
Also used : MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) AuditLogEntry(net.dv8tion.jda.core.audit.AuditLogEntry)

Aggregations

AuditLogEntry (net.dv8tion.jda.core.audit.AuditLogEntry)12 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)6 AuditLogChange (net.dv8tion.jda.core.audit.AuditLogChange)5 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)4 ArrayList (java.util.ArrayList)3 User (net.dv8tion.jda.core.entities.User)2 List (java.util.List)1 Permission (net.dv8tion.jda.core.Permission)1 GuildUpdateExplicitContentLevelEvent (net.dv8tion.jda.core.events.guild.update.GuildUpdateExplicitContentLevelEvent)1 RoleUpdatePositionEvent (net.dv8tion.jda.core.events.role.update.RoleUpdatePositionEvent)1 RedisMessage (stream.flarebot.flarebot.database.RedisMessage)1