use of net.dv8tion.jda.api.audit.AuditLogEntry in project Gary by help-chat.
the class MessageDelete method send.
@Override
protected MessageEmbed send() throws Exception {
User user = users.get(0);
TextChannel channel = textChannels.get(0);
String string = strings.get(0);
Long aLong = longs.get(0);
CompletableFuture<String> deleter = new CompletableFuture<>();
guild.retrieveAuditLogs().limit(1).type(ActionType.MESSAGE_DELETE).queue(l -> {
for (AuditLogEntry entry : l) {
User entryUser = entry.getUser();
if (entryUser != null && entry.getTargetIdLong() == user.getIdLong() && entry.getUser().getIdLong() != user.getIdLong()) {
deleter.complete(entry.getUser().getAsMention());
} else {
deleter.complete("self");
}
}
});
// noinspection StatementWithEmptyBody
while (!deleter.isDone()) {
}
return new EmbedBuilder().setAuthor(user.getName() + "#" + user.getDiscriminator(), null, user.getEffectiveAvatarUrl()).setColor(Constants.RED).setDescription("**Message sent by " + user.getAsMention() + " deleted in " + channel.getAsMention() + " by " + deleter.get() + ".**\n" + string).setFooter("ID: " + aLong, null).setTimestamp(ZonedDateTime.now()).build();
}
use of net.dv8tion.jda.api.audit.AuditLogEntry in project Sx4 by sx4-discord-bot.
the class LoggerHandler method onMessageBulkDelete.
public void onMessageBulkDelete(MessageBulkDeleteEvent event) {
List<String> messageIds = event.getMessageIds();
TextChannel textChannel = event.getChannel();
Guild guild = event.getGuild();
LoggerEvent loggerEvent = LoggerEvent.MESSAGE_DELETE;
this.bot.getMongo().aggregateLoggers(this.getPipeline(guild.getIdLong())).whenComplete((documents, exception) -> {
if (ExceptionUtility.sendErrorMessage(exception)) {
return;
}
if (documents.isEmpty()) {
return;
}
Document data = documents.get(0);
if (guild.getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS)) {
this.retrieveAuditLogsDelayed(guild, ActionType.MESSAGE_BULK_DELETE).whenComplete((logs, auditException) -> {
this.messageCache.putIfAbsent(guild.getIdLong(), new TLongIntHashMap());
TLongIntMap guildCache = this.messageCache.get(guild.getIdLong());
AuditLogEntry entry = logs == null ? null : logs.stream().filter(e -> Duration.between(e.getTimeCreated(), ZonedDateTime.now(ZoneOffset.UTC)).toMinutes() <= 5).filter(e -> {
int count = Integer.parseInt(e.getOptionByName("count"));
int oldCount = guildCache.get(e.getIdLong());
guildCache.put(e.getIdLong(), count);
return (count == messageIds.size() && count != oldCount) || count > oldCount;
}).findFirst().orElse(null);
this.handleBulkMessages(textChannel, messageIds, data.getList("loggers", Document.class), loggerEvent, entry == null ? null : entry.getUser());
});
return;
}
this.handleBulkMessages(textChannel, messageIds, data.getList("loggers", Document.class), loggerEvent, null);
});
}
use of net.dv8tion.jda.api.audit.AuditLogEntry in project Sx4 by sx4-discord-bot.
the class LoggerHandler method onGuildBan.
public void onGuildBan(GuildBanEvent event) {
Guild guild = event.getGuild();
User user = event.getUser();
LoggerEvent loggerEvent = LoggerEvent.MEMBER_BANNED;
LoggerContext loggerContext = new LoggerContext().setUser(user);
WebhookEmbedBuilder embed = new WebhookEmbedBuilder();
embed.setDescription(String.format("`%s` has been banned", user.getName()));
embed.setColor(this.bot.getConfig().getRed());
embed.setTimestamp(Instant.now());
embed.setAuthor(new EmbedAuthor(user.getAsTag(), user.getEffectiveAvatarUrl(), null));
embed.setFooter(new EmbedFooter(String.format("User ID: %s", user.getId()), null));
this.bot.getMongo().aggregateLoggers(this.getPipeline(guild.getIdLong())).whenComplete((documents, exception) -> {
if (ExceptionUtility.sendErrorMessage(exception)) {
return;
}
if (documents.isEmpty()) {
return;
}
Document data = documents.get(0);
List<Document> loggers = LoggerUtility.getValidLoggers(data.getList("loggers", Document.class), loggerEvent, loggerContext);
if (loggers.isEmpty()) {
return;
}
if (guild.getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS)) {
this.retrieveAuditLogsDelayed(guild, ActionType.BAN).whenComplete((logs, auditException) -> {
User moderator = logs == null ? null : logs.stream().filter(e -> Duration.between(e.getTimeCreated(), ZonedDateTime.now(ZoneOffset.UTC)).toSeconds() <= 5).filter(e -> e.getTargetIdLong() == user.getIdLong()).map(AuditLogEntry::getUser).findFirst().orElse(null);
if (moderator != null) {
loggerContext.setModerator(moderator);
embed.setDescription(String.format("`%s` has been banned by **%s**", user.getName(), moderator.getAsTag()));
}
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
});
} else {
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
}
});
}
use of net.dv8tion.jda.api.audit.AuditLogEntry in project Sx4 by sx4-discord-bot.
the class LoggerHandler method onRoleUpdatePermissions.
public void onRoleUpdatePermissions(RoleUpdatePermissionsEvent event) {
Guild guild = event.getGuild();
Role role = event.getRole();
LoggerEvent loggerEvent = LoggerEvent.ROLE_PERMISSION_UPDATE;
LoggerContext loggerContext = new LoggerContext().setRole(role);
String permissionMessage = LoggerUtility.getRolePermissionDifference(event.getOldPermissionsRaw(), event.getNewPermissionsRaw());
if (permissionMessage.isEmpty()) {
return;
}
WebhookEmbedBuilder embed = new WebhookEmbedBuilder();
embed.setColor(this.bot.getConfig().getOrange());
embed.setTimestamp(Instant.now());
embed.setAuthor(new EmbedAuthor(guild.getName(), guild.getIconUrl(), null));
embed.setFooter(new EmbedFooter(String.format("Role ID: %s", role.getId()), null));
this.bot.getMongo().aggregateLoggers(this.getPipeline(guild.getIdLong())).whenComplete((documents, exception) -> {
if (ExceptionUtility.sendErrorMessage(exception)) {
return;
}
if (documents.isEmpty()) {
return;
}
Document data = documents.get(0);
List<Document> loggers = LoggerUtility.getValidLoggers(data.getList("loggers", Document.class), loggerEvent, loggerContext);
if (loggers.isEmpty()) {
return;
}
StringBuilder description = new StringBuilder(String.format("The role %s has had permission changes made", role.getAsMention()));
if (guild.getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS)) {
this.retrieveAuditLogsDelayed(guild, ActionType.ROLE_UPDATE).whenComplete((logs, auditException) -> {
User moderator = logs == null ? null : logs.stream().filter(e -> Duration.between(e.getTimeCreated(), ZonedDateTime.now(ZoneOffset.UTC)).toSeconds() <= 5).filter(e -> e.getTargetIdLong() == role.getIdLong()).filter(e -> e.getChangeByKey(AuditLogKey.ROLE_PERMISSIONS) != null).map(AuditLogEntry::getUser).findFirst().orElse(null);
if (moderator != null) {
loggerContext.setModerator(moderator);
description.append(String.format(" by **%s**", moderator.getAsTag()));
}
description.append(permissionMessage);
embed.setDescription(description.toString());
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
});
} else {
description.append(permissionMessage);
embed.setDescription(description.toString());
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
}
});
}
use of net.dv8tion.jda.api.audit.AuditLogEntry in project Sx4 by sx4-discord-bot.
the class LoggerHandler method onGuildVoiceGuildDeafen.
public void onGuildVoiceGuildDeafen(GuildVoiceGuildDeafenEvent event) {
Guild guild = event.getGuild();
Member member = event.getMember();
User user = member.getUser();
GuildVoiceState voiceState = event.getVoiceState();
VoiceChannel channel = voiceState.getChannel();
boolean deafened = voiceState.isGuildDeafened();
LoggerEvent loggerEvent = deafened ? LoggerEvent.MEMBER_SERVER_VOICE_DEAFEN : LoggerEvent.MEMBER_SERVER_VOICE_UNDEAFEN;
LoggerContext loggerContext = new LoggerContext().setChannel(channel == null ? 0L : channel.getIdLong()).setUser(user);
WebhookEmbedBuilder embed = new WebhookEmbedBuilder();
embed.setDescription(String.format("`%s` has been %s", member.getEffectiveName(), deafened ? "deafened" : "undeafened"));
embed.setTimestamp(Instant.now());
embed.setAuthor(new EmbedAuthor(member.getUser().getAsTag(), member.getUser().getEffectiveAvatarUrl(), null));
embed.setFooter(new EmbedFooter(String.format("User ID: %s", user.getId()), null));
embed.setColor(deafened ? this.bot.getConfig().getRed() : this.bot.getConfig().getGreen());
this.bot.getMongo().aggregateLoggers(this.getPipeline(guild.getIdLong())).whenComplete((documents, exception) -> {
if (ExceptionUtility.sendErrorMessage(exception)) {
return;
}
if (documents.isEmpty()) {
return;
}
Document data = documents.get(0);
List<Document> loggers = LoggerUtility.getValidLoggers(data.getList("loggers", Document.class), loggerEvent, loggerContext);
if (loggers.isEmpty()) {
return;
}
if (guild.getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS)) {
this.retrieveAuditLogsDelayed(guild, ActionType.MEMBER_UPDATE).whenComplete((logs, auditException) -> {
User moderator = logs == null ? null : logs.stream().filter(e -> Duration.between(e.getTimeCreated(), ZonedDateTime.now(ZoneOffset.UTC)).toSeconds() <= 5).filter(e -> e.getTargetIdLong() == member.getUser().getIdLong()).filter(e -> e.getChangeByKey(AuditLogKey.MEMBER_DEAF) != null).map(AuditLogEntry::getUser).findFirst().orElse(null);
if (moderator != null) {
loggerContext.setModerator(moderator);
embed.setDescription(String.format("`%s` has been %s by **%s**", member.getEffectiveName(), deafened ? "deafened" : "undeafened", moderator.getAsTag()));
}
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
});
} else {
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
}
});
}
Aggregations