use of net.dv8tion.jda.api.events.message.guild.GuildMessageDeleteEvent in project Gary by help-chat.
the class LoggingHandler method execute.
@Override
protected void execute(GenericEvent event) {
switch(EventsEnum.fromEvent(event)) {
case MEMBER_JOIN:
GuildMemberJoinEvent e = (GuildMemberJoinEvent) event;
log(EventsEnum.MEMBER_JOIN, e.getJDA(), e.getGuild(), e.getUser());
break;
case MEMBER_LEAVE:
if (!wasBan) {
GuildMemberLeaveEvent e2 = (GuildMemberLeaveEvent) event;
log(EventsEnum.MEMBER_LEAVE, e2.getJDA(), e2.getGuild(), e2.getUser());
} else {
wasBan = false;
}
break;
case MEMBER_BANNED:
wasBan = true;
GuildBanEvent e3 = (GuildBanEvent) event;
log(EventsEnum.MEMBER_BANNED, e3.getJDA(), e3.getGuild(), e3.getUser());
break;
case MESSAGE_EDIT:
GuildMessageUpdateEvent e5 = (GuildMessageUpdateEvent) event;
if (!e5.getAuthor().isBot() && StringUtils.equalsIgnoreCase(e5.getChannel().getName(), Constants.CHANNELS)) {
log(EventsEnum.MESSAGE_EDIT, e5.getJDA(), e5.getGuild(), e5.getAuthor(), e5.getChannel(), e5.getMessage());
}
break;
case MESSAGE_DELETE:
GuildMessageDeleteEvent e6 = (GuildMessageDeleteEvent) event;
if ((StringUtils.equalsIgnoreCase(e6.getChannel().getName(), Constants.CHANNELS))) {
log(EventsEnum.MESSAGE_DELETE, e6.getJDA(), e6.getGuild(), MessageUtils.getAuthor(e6.getMessageIdLong()), e6.getChannel(), e6.getMessageIdLong(), MessageUtils.getMessage(e6.getMessageIdLong()));
}
break;
case MESSAGE_BULK_DELETE:
MessageBulkDeleteEvent e7 = (MessageBulkDeleteEvent) event;
if ((StringUtils.equalsIgnoreCase(e7.getChannel().getName(), Constants.CHANNELS))) {
log(EventsEnum.MESSAGE_BULK_DELETE, e7.getJDA(), e7.getGuild(), e7.getChannel(), e7.getMessageIds());
}
break;
case VOICE_JOIN:
GuildVoiceJoinEvent e8 = (GuildVoiceJoinEvent) event;
log(EventsEnum.VOICE_JOIN, e8.getJDA(), e8.getGuild(), e8.getMember().getUser(), e8.getChannelJoined());
break;
}
}
use of net.dv8tion.jda.api.events.message.guild.GuildMessageDeleteEvent in project Sx4 by sx4-discord-bot.
the class LoggerHandler method onGuildMessageDelete.
public void onGuildMessageDelete(GuildMessageDeleteEvent event) {
TextChannel channel = event.getChannel();
Guild guild = event.getGuild();
LoggerEvent loggerEvent = LoggerEvent.MESSAGE_DELETE;
LoggerContext loggerContext = new LoggerContext().setChannel(channel);
GuildMessage message = this.bot.getMessageCache().getMessageById(event.getMessageIdLong());
if (message != null) {
loggerContext.setUser(message.getAuthor());
}
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;
}
WebhookEmbedBuilder embed = new WebhookEmbedBuilder().setColor(this.bot.getConfig().getRed()).setTimestamp(Instant.now()).setFooter(new EmbedFooter("Message ID: " + event.getMessageId(), null));
StringBuilder description = new StringBuilder();
if (message == null) {
description.append(String.format("A message sent in %s was deleted", channel.getAsMention()));
embed.setAuthor(new EmbedAuthor(guild.getName(), guild.getIconUrl(), null));
} else {
User author = message.getAuthor();
description.append(String.format("The message sent by `%s` in %s was deleted", author.getAsTag(), channel.getAsMention()));
embed.setAuthor(new EmbedAuthor(author.getAsTag(), author.getEffectiveAvatarUrl(), null));
String content = message.getContent();
if (!content.isBlank()) {
embed.addField(new EmbedField(false, "Message", StringUtility.limit(content, MessageEmbed.VALUE_MAX_LENGTH, "...")));
}
}
if (guild.getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS)) {
this.retrieveAuditLogsDelayed(guild, ActionType.MESSAGE_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 -> Long.parseLong(e.getOptionByName("channel_id")) == channel.getIdLong()).filter(e -> {
int count = Integer.parseInt(e.getOptionByName("count"));
int oldCount = guildCache.get(e.getIdLong());
guildCache.put(e.getIdLong(), count);
return (count == 1 && count != oldCount) || count > oldCount;
}).findFirst().orElse(null);
User moderator = entry == null ? null : entry.getUser();
if (moderator != null) {
loggerContext.setModerator(moderator);
description.append(" by **").append(moderator.getAsTag()).append("**");
}
embed.setDescription(description.toString());
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
});
return;
}
embed.setDescription(description.toString());
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
});
}
Aggregations