use of club.minnced.discord.webhook.send.WebhookEmbed.EmbedField in project Sx4 by sx4-discord-bot.
the class LoggerHandler method handleBulkMessages.
public void handleBulkMessages(TextChannel textChannel, List<String> messageIds, List<Document> loggers, LoggerEvent loggerEvent, User moderator) {
Guild guild = textChannel.getGuild();
for (Document logger : loggers) {
if ((logger.get("events", LoggerEvent.ALL) & loggerEvent.getRaw()) != loggerEvent.getRaw()) {
continue;
}
long channelId = logger.getLong("channelId");
TextChannel channel = guild.getTextChannelById(channelId);
if (channel == null) {
continue;
}
List<Document> entities = logger.getEmbedded(List.of("blacklist", "entities"), Collections.emptyList());
List<WebhookEmbed> embeds = new ArrayList<>();
for (String messageId : messageIds) {
WebhookEmbedBuilder embed = new WebhookEmbedBuilder().setColor(this.bot.getConfig().getRed()).setTimestamp(Instant.now()).setFooter(new EmbedFooter("Message ID: " + messageId, null));
LoggerContext loggerContext = new LoggerContext().setChannel(textChannel);
if (moderator != null) {
loggerContext.setModerator(moderator);
}
String reason = moderator == null ? "in a bulk delete" : "by **" + moderator.getAsTag() + "**";
GuildMessage message = this.bot.getMessageCache().getMessageById(messageId);
if (message == null) {
if (!LoggerUtility.isWhitelisted(entities, loggerEvent, loggerContext)) {
continue;
}
embed.setDescription(String.format("A message sent in %s was deleted %s", textChannel.getAsMention(), reason));
embed.setAuthor(new EmbedAuthor(guild.getName(), guild.getIconUrl(), null));
} else {
User author = message.getAuthor();
loggerContext.setUser(author);
if (!LoggerUtility.isWhitelisted(entities, loggerEvent, loggerContext)) {
continue;
}
embed.setDescription(String.format("The message sent by `%s` in %s was deleted %s", author.getName(), textChannel.getAsMention(), reason));
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, "...")));
}
}
embeds.add(embed.build());
}
this.getManager(channelId).queue(channel, logger, embeds);
}
}
use of club.minnced.discord.webhook.send.WebhookEmbed.EmbedField in project Sx4 by sx4-discord-bot.
the class LoggerHandler method onGuildMemberRemove.
public void onGuildMemberRemove(GuildMemberRemoveEvent event) {
Guild guild = event.getGuild();
User user = event.getUser();
Member member = event.getMember();
List<Role> roles = member == null ? Collections.emptyList() : member.getRoles();
String rolesMessage = StringUtility.joinLimited(", ", roles, Role::getAsMention, MessageEmbed.VALUE_MAX_LENGTH);
LoggerContext loggerContext = new LoggerContext().setUser(user);
WebhookEmbedBuilder embed = new WebhookEmbedBuilder();
embed.setDescription(String.format("`%s` just left the server", 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));
if (rolesMessage.length() != 0) {
embed.addField(new EmbedField(true, "Roles", rolesMessage));
}
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 = data.getList("loggers", Document.class);
if (loggers.isEmpty()) {
return;
}
if (guild.getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS)) {
this.retrieveAuditLogsDelayed(guild, ActionType.KICK).whenComplete((logs, auditException) -> {
User moderator = logs == null ? null : logs.stream().filter(e -> e.getTargetIdLong() == user.getIdLong()).filter(e -> Duration.between(e.getTimeCreated(), ZonedDateTime.now(ZoneOffset.UTC)).toSeconds() <= 5).map(AuditLogEntry::getUser).findFirst().orElse(null);
LoggerEvent loggerEvent = moderator == null ? LoggerEvent.MEMBER_LEAVE : LoggerEvent.MEMBER_KICKED;
if (moderator != null) {
loggerContext.setModerator(moderator);
embed.setDescription(String.format("`%s` has been kicked by **%s**", user.getName(), moderator.getAsTag()));
}
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
});
return;
}
LoggerEvent loggerEvent = LoggerEvent.MEMBER_LEAVE;
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
});
}
use of club.minnced.discord.webhook.send.WebhookEmbed.EmbedField in project Sx4 by sx4-discord-bot.
the class ConnectionHandler method getEmbed.
public WebhookEmbed getEmbed(JDA jda, String state, CloseCode closeCode, OffsetDateTime disconnectTime, int colour) {
ShardInfo shardInfo = jda.getShardInfo();
WebhookEmbedBuilder builder = new WebhookEmbedBuilder().setColor(colour).setFooter(new EmbedFooter(state, null)).setTimestamp(disconnectTime != null ? disconnectTime : Instant.now()).addField(new EmbedField(false, "Shard", (shardInfo.getShardId() + 1) + "/" + shardInfo.getShardTotal())).setAuthor(new EmbedAuthor(jda.getSelfUser().getAsTag(), jda.getSelfUser().getEffectiveAvatarUrl(), null));
if (closeCode != null) {
builder.addField(new EmbedField(false, "Reason", closeCode.getMeaning() + " [" + closeCode.getCode() + "]"));
}
return builder.build();
}
use of club.minnced.discord.webhook.send.WebhookEmbed.EmbedField in project Sx4 by sx4-discord-bot.
the class ModLog method getWebhookEmbed.
public WebhookEmbed getWebhookEmbed(User moderator, User target) {
WebhookEmbedBuilder embed = new WebhookEmbedBuilder();
embed.setTitle(new EmbedTitle(this.action.toString(), null));
embed.addField(new EmbedField(false, "Target", (target == null || target.getClass() == UserById.class ? "Anonymous#0000" : target.getAsTag()) + " (" + this.getTargetId() + ")"));
embed.addField(new EmbedField(false, "Moderator", (moderator == null || moderator.getClass() == UserById.class ? "Anonymous#0000" : moderator.getAsTag()) + " (" + this.getModeratorId() + ")"));
embed.addField(new EmbedField(false, "Reason", this.reason == null ? "None Given" : this.reason.getParsed()));
embed.setTimestamp(Instant.ofEpochSecond(this.getTimestamp()));
embed.setFooter(new EmbedFooter("ID: " + this.getHex(), null));
return embed.build();
}
use of club.minnced.discord.webhook.send.WebhookEmbed.EmbedField in project Sx4 by sx4-discord-bot.
the class LoggerHandler method onRoleUpdateName.
public void onRoleUpdateName(RoleUpdateNameEvent event) {
Guild guild = event.getGuild();
Role role = event.getRole();
LoggerEvent loggerEvent = LoggerEvent.ROLE_NAME_UPDATE;
LoggerContext loggerContext = new LoggerContext().setRole(role);
WebhookEmbedBuilder embed = new WebhookEmbedBuilder();
embed.setDescription(String.format("The role %s has been renamed", role.getAsMention()));
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));
embed.addField(new EmbedField(false, "Before", String.format("`%s`", event.getOldName())));
embed.addField(new EmbedField(false, "After", String.format("`%s`", event.getNewName())));
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.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_NAME) != null).map(AuditLogEntry::getUser).findFirst().orElse(null);
if (moderator != null) {
loggerContext.setModerator(moderator);
embed.setDescription(String.format("The role %s has been renamed by **%s**", role.getAsMention(), moderator.getAsTag()));
}
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
});
} else {
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
}
});
}
Aggregations