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);
});
}
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);
}
Aggregations