use of ml.duncte123.skybot.objects.user.UnknownUser in project SkyBot by duncte123.
the class MessageListener method onMessageBulkDelete.
@SuppressWarnings("PMD.UseConcurrentHashMap")
protected void onMessageBulkDelete(final MessageBulkDeleteEvent event) {
this.handlerThread.submit(() -> {
try {
final DunctebotGuild guild = new DunctebotGuild(event.getGuild(), variables);
if (!guild.getSettings().isMessageLogging()) {
// just delete the message here as we don't want to keep it around
this.redis.deleteMessages(event.getMessageIds());
return;
}
final List<MessageData> dataList = this.redis.getAndDeleteMessages(event.getMessageIds());
final StringBuilder builder = new StringBuilder();
// temporarily store the users to prevent spamming discord for the data
final Map<Long, User> tmpUsers = new HashMap<>();
final JDA jda = event.getJDA();
// reverse the list to preserve the correct order
Collections.reverse(dataList);
for (final MessageData data : dataList) {
final long authorId = data.getAuthorId();
final Consumer<User> userConsumer = (user) -> {
builder.append('[').append(data.getCratedAt().format(DateTimeFormatter.RFC_1123_DATE_TIME)).append("] (").append(user.getAsTag()).append(" - ").append(user.getIdLong()).append(") [").append(data.getMessageId()).append("]: ").append(data.getContent()).append('\n');
};
if (tmpUsers.containsKey(authorId)) {
userConsumer.accept(tmpUsers.get(authorId));
} else {
// try to fetch the user since we don't cache them
// calls are sequential making sure the messages are still in order
jda.retrieveUserById(authorId).queue((user) -> {
tmpUsers.put(authorId, user);
userConsumer.accept(user);
}, (error) -> userConsumer.accept(new UnknownUser(authorId)));
}
}
final TextChannel channel = event.getChannel();
final EmbedBuilder embed = EmbedUtils.embedField("Bulk Delete", "Bulk deleted messages from <#%s> are available in the attached file.".formatted(channel.getIdLong())).setColor(0xE67E22).setTimestamp(Instant.now());
modLog(new MessageConfig.Builder().addEmbed(true, embed).setActionConfig((action) -> action.addFile(builder.toString().getBytes(), "bulk_delete_%s.txt".formatted(System.currentTimeMillis()))), guild);
} catch (Exception e) {
LOGGER.error("Exception on message bulk delete", e);
}
});
}
use of ml.duncte123.skybot.objects.user.UnknownUser in project SkyBot by DuncteBot.
the class MessageListener method onMessageBulkDelete.
@SuppressWarnings("PMD.UseConcurrentHashMap")
protected void onMessageBulkDelete(final MessageBulkDeleteEvent event) {
this.handlerThread.submit(() -> {
try {
final DunctebotGuild guild = new DunctebotGuild(event.getGuild(), variables);
if (!guild.getSettings().isMessageLogging()) {
// just delete the message here as we don't want to keep it around
this.redis.deleteMessages(event.getMessageIds());
return;
}
final List<MessageData> dataList = this.redis.getAndDeleteMessages(event.getMessageIds());
final StringBuilder builder = new StringBuilder();
// temporarily store the users to prevent spamming discord for the data
final Map<Long, User> tmpUsers = new HashMap<>();
final JDA jda = event.getJDA();
// reverse the list to preserve the correct order
Collections.reverse(dataList);
for (final MessageData data : dataList) {
final long authorId = data.getAuthorId();
final Consumer<User> userConsumer = (user) -> {
builder.append('[').append(data.getCratedAt().format(DateTimeFormatter.RFC_1123_DATE_TIME)).append("] (").append(user.getAsTag()).append(" - ").append(user.getIdLong()).append(") [").append(data.getMessageId()).append("]: ").append(data.getContent()).append('\n');
};
if (tmpUsers.containsKey(authorId)) {
userConsumer.accept(tmpUsers.get(authorId));
} else {
// try to fetch the user since we don't cache them
// calls are sequential making sure the messages are still in order
jda.retrieveUserById(authorId).queue((user) -> {
tmpUsers.put(authorId, user);
userConsumer.accept(user);
}, (error) -> userConsumer.accept(new UnknownUser(authorId)));
}
}
final TextChannel channel = event.getChannel();
final EmbedBuilder embed = EmbedUtils.embedField("Bulk Delete", "Bulk deleted messages from <#%s> are available in the attached file.".formatted(channel.getIdLong())).setColor(0xE67E22).setTimestamp(Instant.now());
modLog(new MessageConfig.Builder().addEmbed(true, embed).setActionConfig((action) -> action.addFile(builder.toString().getBytes(), "bulk_delete_%s.txt".formatted(System.currentTimeMillis()))), guild);
} catch (Exception e) {
LOGGER.error("Exception on message bulk delete", e);
}
});
}
Aggregations