Search in sources :

Example 1 with GuildUpdateExplicitContentLevelEvent

use of net.dv8tion.jda.core.events.guild.update.GuildUpdateExplicitContentLevelEvent 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 2 with GuildUpdateExplicitContentLevelEvent

use of net.dv8tion.jda.core.events.guild.update.GuildUpdateExplicitContentLevelEvent in project FlareBot by FlareBot.

the class ModlogEvents method onEvent.

@Override
public void onEvent(Event event) {
    if (!(event instanceof GenericGuildEvent) && !(event instanceof GenericRoleEvent) && !(event instanceof GenericTextChannelEvent) && !(event instanceof GenericVoiceChannelEvent) && !(event instanceof GenericMessageEvent))
        return;
    Guild g = null;
    if (event instanceof GenericGuildEvent && ((GenericGuildEvent) event).getGuild() != null)
        g = ((GenericGuildEvent) event).getGuild();
    else if (event instanceof GenericRoleEvent && ((GenericRoleEvent) event).getGuild() != null)
        g = ((GenericRoleEvent) event).getGuild();
    else if (event instanceof GenericTextChannelEvent && ((GenericTextChannelEvent) event).getGuild() != null)
        g = ((GenericTextChannelEvent) event).getGuild();
    else if (event instanceof GenericVoiceChannelEvent && ((GenericVoiceChannelEvent) event).getGuild() != null)
        g = ((GenericVoiceChannelEvent) event).getGuild();
    else if (event instanceof GenericMessageEvent && ((GenericMessageEvent) event).getGuild() != null)
        g = ((GenericMessageEvent) event).getGuild();
    if (g == null)
        return;
    GuildWrapper guildWrapper = FlareBotManager.instance().getGuild(g.getId());
    if (guildWrapper == null)
        return;
    // GUILD
    if (event instanceof GuildBanEvent)
        onGuildBan((GuildBanEvent) event, guildWrapper);
    else if (event instanceof GuildMemberJoinEvent)
        onGuildMemberJoin((GuildMemberJoinEvent) event, guildWrapper);
    else if (event instanceof GuildMemberLeaveEvent)
        onGuildMemberLeave((GuildMemberLeaveEvent) event, guildWrapper);
    else if (event instanceof GuildVoiceJoinEvent)
        onGuildVoiceJoin((GuildVoiceJoinEvent) event, guildWrapper);
    else if (event instanceof GuildVoiceLeaveEvent)
        onGuildVoiceLeave((GuildVoiceLeaveEvent) event, guildWrapper);
    else // ROLES
    if (event instanceof RoleCreateEvent)
        onRoleCreate((RoleCreateEvent) event, guildWrapper);
    else if (event instanceof RoleDeleteEvent)
        onRoleDelete((RoleDeleteEvent) event, guildWrapper);
    else if (event instanceof GenericRoleUpdateEvent)
        onGenericRoleUpdate((GenericRoleUpdateEvent) event, guildWrapper);
    else if (event instanceof GuildMemberRoleAddEvent)
        onGuildMemberRoleAdd((GuildMemberRoleAddEvent) event, guildWrapper);
    else if (event instanceof GuildMemberRoleRemoveEvent)
        onGuildMemberRoleRemove((GuildMemberRoleRemoveEvent) event, guildWrapper);
    else // CHANNEL
    if (event instanceof TextChannelCreateEvent)
        onTextChannelCreate((TextChannelCreateEvent) event, guildWrapper);
    else if (event instanceof VoiceChannelCreateEvent)
        onVoiceChannelCreate((VoiceChannelCreateEvent) event, guildWrapper);
    else if (event instanceof TextChannelDeleteEvent)
        onTextChannelDelete((TextChannelDeleteEvent) event, guildWrapper);
    else if (event instanceof VoiceChannelDeleteEvent)
        onVoiceChannelDelete((VoiceChannelDeleteEvent) event, guildWrapper);
    else /*else if (event instanceof GuildMessageReceivedEvent)
            onGuildMessageReceived((GuildMessageReceivedEvent) event, guildWrapper);*/
    if (event instanceof MessageUpdateEvent)
        onMessageUpdate((MessageUpdateEvent) event, guildWrapper);
    else if (event instanceof MessageDeleteEvent)
        onMessageDelete((MessageDeleteEvent) event, guildWrapper);
    else // GUILD
    if (event instanceof GuildUpdateExplicitContentLevelEvent)
        onGuildUpdateExplicitContentLevel((GuildUpdateExplicitContentLevelEvent) event, guildWrapper);
    else if (event instanceof GuildMemberNickChangeEvent)
        onGuildMemberNickChange((GuildMemberNickChangeEvent) event, guildWrapper);
    else if (event instanceof GenericGuildUpdateEvent)
        onGenericGuildUpdate((GenericGuildUpdateEvent) event, guildWrapper);
    else if (event instanceof GuildVoiceMoveEvent)
        onGuildVoiceMove((GuildVoiceMoveEvent) event, guildWrapper);
}
Also used : GuildVoiceLeaveEvent(net.dv8tion.jda.core.events.guild.voice.GuildVoiceLeaveEvent) VoiceChannelCreateEvent(net.dv8tion.jda.core.events.channel.voice.VoiceChannelCreateEvent) GenericVoiceChannelEvent(net.dv8tion.jda.core.events.channel.voice.GenericVoiceChannelEvent) MessageUpdateEvent(net.dv8tion.jda.core.events.message.MessageUpdateEvent) Guild(net.dv8tion.jda.core.entities.Guild) GenericMessageEvent(net.dv8tion.jda.core.events.message.GenericMessageEvent) TextChannelDeleteEvent(net.dv8tion.jda.core.events.channel.text.TextChannelDeleteEvent) GuildVoiceMoveEvent(net.dv8tion.jda.core.events.guild.voice.GuildVoiceMoveEvent) GuildWrapper(stream.flarebot.flarebot.objects.GuildWrapper) GenericRoleEvent(net.dv8tion.jda.core.events.role.GenericRoleEvent) RoleDeleteEvent(net.dv8tion.jda.core.events.role.RoleDeleteEvent) GenericGuildEvent(net.dv8tion.jda.core.events.guild.GenericGuildEvent) GenericRoleUpdateEvent(net.dv8tion.jda.core.events.role.update.GenericRoleUpdateEvent) GenericGuildUpdateEvent(net.dv8tion.jda.core.events.guild.update.GenericGuildUpdateEvent) TextChannelCreateEvent(net.dv8tion.jda.core.events.channel.text.TextChannelCreateEvent) GuildUpdateExplicitContentLevelEvent(net.dv8tion.jda.core.events.guild.update.GuildUpdateExplicitContentLevelEvent) VoiceChannelDeleteEvent(net.dv8tion.jda.core.events.channel.voice.VoiceChannelDeleteEvent) RoleCreateEvent(net.dv8tion.jda.core.events.role.RoleCreateEvent) GuildBanEvent(net.dv8tion.jda.core.events.guild.GuildBanEvent) GuildVoiceJoinEvent(net.dv8tion.jda.core.events.guild.voice.GuildVoiceJoinEvent) GenericTextChannelEvent(net.dv8tion.jda.core.events.channel.text.GenericTextChannelEvent) MessageDeleteEvent(net.dv8tion.jda.core.events.message.MessageDeleteEvent)

Aggregations

GuildUpdateExplicitContentLevelEvent (net.dv8tion.jda.core.events.guild.update.GuildUpdateExplicitContentLevelEvent)2 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)1 AuditLogChange (net.dv8tion.jda.core.audit.AuditLogChange)1 AuditLogEntry (net.dv8tion.jda.core.audit.AuditLogEntry)1 Guild (net.dv8tion.jda.core.entities.Guild)1 GenericTextChannelEvent (net.dv8tion.jda.core.events.channel.text.GenericTextChannelEvent)1 TextChannelCreateEvent (net.dv8tion.jda.core.events.channel.text.TextChannelCreateEvent)1 TextChannelDeleteEvent (net.dv8tion.jda.core.events.channel.text.TextChannelDeleteEvent)1 GenericVoiceChannelEvent (net.dv8tion.jda.core.events.channel.voice.GenericVoiceChannelEvent)1 VoiceChannelCreateEvent (net.dv8tion.jda.core.events.channel.voice.VoiceChannelCreateEvent)1 VoiceChannelDeleteEvent (net.dv8tion.jda.core.events.channel.voice.VoiceChannelDeleteEvent)1 GenericGuildEvent (net.dv8tion.jda.core.events.guild.GenericGuildEvent)1 GuildBanEvent (net.dv8tion.jda.core.events.guild.GuildBanEvent)1 GenericGuildUpdateEvent (net.dv8tion.jda.core.events.guild.update.GenericGuildUpdateEvent)1 GuildVoiceJoinEvent (net.dv8tion.jda.core.events.guild.voice.GuildVoiceJoinEvent)1 GuildVoiceLeaveEvent (net.dv8tion.jda.core.events.guild.voice.GuildVoiceLeaveEvent)1 GuildVoiceMoveEvent (net.dv8tion.jda.core.events.guild.voice.GuildVoiceMoveEvent)1 GenericMessageEvent (net.dv8tion.jda.core.events.message.GenericMessageEvent)1 MessageDeleteEvent (net.dv8tion.jda.core.events.message.MessageDeleteEvent)1 MessageUpdateEvent (net.dv8tion.jda.core.events.message.MessageUpdateEvent)1