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