Search in sources :

Example 11 with AuditLogEntry

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

the class ModlogEvents method onGuildMemberRoleRemove.

private void onGuildMemberRoleRemove(GuildMemberRoleRemoveEvent event, @Nonnull GuildWrapper wrapper) {
    if (cannotHandle(wrapper, ModlogEvent.MEMBER_ROLE_REMOVE))
        return;
    event.getGuild().getAuditLogs().queue(auditLogEntries -> {
        if (auditLogEntries.isEmpty())
            return;
        AuditLogEntry entry = auditLogEntries.get(0);
        Map<String, AuditLogChange> changes = entry.getChanges();
        AuditLogChange change = changes.get("$remove");
        @SuppressWarnings("unchecked") HashMap<String, String> role = ((ArrayList<HashMap<String, String>>) change.getNewValue()).get(0);
        ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.MEMBER_ROLE_REMOVE, event.getUser(), entry.getUser(), null, new MessageEmbed.Field("Role", role.get("name") + " (" + role.get("id") + ")", true));
    });
}
Also used : MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) AuditLogEntry(net.dv8tion.jda.core.audit.AuditLogEntry) AuditLogChange(net.dv8tion.jda.core.audit.AuditLogChange) ArrayList(java.util.ArrayList)

Example 12 with AuditLogEntry

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

the class ModlogEvents method onGuildMemberLeave.

private void onGuildMemberLeave(GuildMemberLeaveEvent event, @Nonnull GuildWrapper wrapper) {
    if (!wrapper.getModeration().isEventEnabled(wrapper, ModlogEvent.MEMBER_LEAVE) && !wrapper.getModeration().isEventEnabled(wrapper, ModlogEvent.USER_KICKED))
        return;
    boolean checkKick = event.getGuild().getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS) && wrapper.getModeration().isEventEnabled(wrapper, ModlogEvent.USER_KICKED);
    if (!checkKick) {
        if (cannotHandle(wrapper, ModlogEvent.MEMBER_LEAVE))
            return;
        ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.MEMBER_LEAVE, event.getUser());
        return;
    }
    event.getGuild().getAuditLogs().limit(1).type(ActionType.KICK).queue(auditLogEntries -> {
        AuditLogEntry entry = null;
        User responsible = null;
        String reason = null;
        if (!auditLogEntries.isEmpty())
            entry = auditLogEntries.get(0);
        if (entry != null) {
            // We don't want dupes.
            if (entry.getUser().getIdLong() == FlareBot.instance().getClient().getSelfUser().getIdLong())
                return;
            if (!entry.getTargetId().equals(event.getUser().getId()))
                return;
            responsible = entry.getUser();
            reason = entry.getReason();
        }
        boolean isKick = entry != null;
        if (isKick) {
            if (cannotHandle(wrapper, ModlogEvent.USER_KICKED))
                return;
        } else if (cannotHandle(wrapper, ModlogEvent.MEMBER_LEAVE))
            return;
        ModlogHandler.getInstance().postToModlog(wrapper, isKick ? ModlogEvent.USER_KICKED : ModlogEvent.MEMBER_LEAVE, event.getUser(), responsible, reason);
    });
}
Also used : User(net.dv8tion.jda.core.entities.User) 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