Search in sources :

Example 6 with AuditLogEntry

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

the class ModlogEvents method onMessageDelete.

private void onMessageDelete(MessageDeleteEvent event, @Nonnull GuildWrapper wrapper) {
    if (cannotHandle(wrapper, ModlogEvent.MESSAGE_DELETE))
        return;
    AuditLogEntry entry = event.getGuild().getAuditLogs().type(ActionType.MESSAGE_DELETE).complete().get(0);
    if (entry.getUser().isBot())
        return;
    User responsible = null;
    if (FlareBot.instance().getEvents().getRemovedByMeList().contains(event.getMessageIdLong())) {
        FlareBot.instance().getEvents().getRemovedByMeList().remove(event.getMessageIdLong());
        return;
    }
    if (!RedisController.exists(event.getMessageId()))
        return;
    RedisMessage deleted = GeneralUtils.toRedisMessage(RedisController.get(event.getMessageId()));
    if (entry.getTargetId().equals(deleted.getAuthorID())) {
        if (entry.getUser().isBot())
            return;
        responsible = entry.getUser();
    }
    User sender = GuildUtils.getUser(deleted.getAuthorID());
    ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.MESSAGE_DELETE, sender, (responsible != null ? new MessageEmbed.Field("Deleted By", MessageUtils.getUserAndId(responsible), true) : null), new MessageEmbed.Field("Message", FormatUtils.truncate(1024, deleted.getContent(), true), true), new MessageEmbed.Field("Channel", event.getTextChannel().getName() + " (" + deleted.getChannelID() + ")", true), new MessageEmbed.Field("Sent", FormatUtils.formatTime(Instant.ofEpochMilli(deleted.getTimestamp()).atZone(ZoneId.systemDefault()).toLocalDateTime()), true));
    RedisController.del(event.getMessageId());
}
Also used : RedisMessage(stream.flarebot.flarebot.database.RedisMessage) User(net.dv8tion.jda.core.entities.User) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) AuditLogEntry(net.dv8tion.jda.core.audit.AuditLogEntry)

Example 7 with AuditLogEntry

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

the class ModlogEvents method onRoleDelete.

private void onRoleDelete(RoleDeleteEvent event, @Nonnull GuildWrapper wrapper) {
    if (cannotHandle(wrapper, ModlogEvent.ROLE_DELETE))
        return;
    event.getGuild().getAuditLogs().queue(auditLog -> {
        AuditLogEntry entry = auditLog.get(0);
        ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.ROLE_DELETE, 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)

Example 8 with AuditLogEntry

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

the class ModlogEvents method onGuildMemberRoleAdd.

private void onGuildMemberRoleAdd(GuildMemberRoleAddEvent event, @Nonnull GuildWrapper wrapper) {
    if (cannotHandle(wrapper, ModlogEvent.MEMBER_ROLE_GIVE))
        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("$add");
        @SuppressWarnings("unchecked") HashMap<String, String> role = ((ArrayList<HashMap<String, String>>) change.getNewValue()).get(0);
        if (wrapper.getAutoAssignRoles().contains(role.get("id")) && ((System.currentTimeMillis() / 1000) - event.getMember().getJoinDate().toEpochSecond()) < 10) {
            return;
        }
        ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.MEMBER_ROLE_GIVE, 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 9 with AuditLogEntry

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

the class ModlogEvents method handleChannelDelete.

private void handleChannelDelete(GuildWrapper wrapper, Channel channel) {
    if (wrapper == null)
        return;
    if (cannotHandle(wrapper, ModlogEvent.CHANNEL_DELETE))
        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_DELETE, entry.getUser(), builder);
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) AuditLogEntry(net.dv8tion.jda.core.audit.AuditLogEntry)

Example 10 with AuditLogEntry

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

the class ModlogEvents method onGuildBan.

private void onGuildBan(GuildBanEvent event, @Nonnull GuildWrapper wrapper) {
    if (cannotHandle(wrapper, ModlogEvent.USER_BANNED))
        return;
    event.getGuild().getAuditLogs().limit(1).type(ActionType.BAN).queue(auditLogEntries -> {
        AuditLogEntry entry = auditLogEntries.get(0);
        // We don't want dupes.
        if (entry.getUser().getIdLong() == FlareBot.instance().getClient().getSelfUser().getIdLong())
            return;
        boolean validEntry = entry.getTargetId().equals(event.getUser().getId());
        ModlogHandler.getInstance().postToModlog(wrapper, ModlogEvent.USER_BANNED, event.getUser(), validEntry ? entry.getUser() : null, validEntry ? entry.getReason() : null);
    });
}
Also used : 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