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