Search in sources :

Example 1 with EmbedAuthor

use of club.minnced.discord.webhook.send.WebhookEmbed.EmbedAuthor in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class DiscordMessageContent method toWebhookMessageBuilder.

public WebhookMessageBuilder toWebhookMessageBuilder() {
    WebhookEmbedBuilder embed = new WebhookEmbedBuilder().setAuthor(new EmbedAuthor(authorName, authorIconUrl, null)).setColor(color).setThumbnailUrl(thumbnail);
    if (description.size() > 0) {
        embed.setDescription(description.get(0));
    }
    if (imageUrl.size() > 0) {
        embed.setImageUrl(imageUrl.get(0));
    }
    if (imageUrl.size() == 1 || description.size() == 1) {
        if (footer != null) {
            embed.setFooter(new EmbedFooter(footer, footerImageUrl));
        }
    }
    WebhookMessageBuilder webhookMessage = new WebhookMessageBuilder().addEmbeds(embed.build());
    for (int i = 1; i < imageUrl.size() || i < description.size(); i++) {
        WebhookEmbedBuilder otherEmbed = new WebhookEmbedBuilder().setColor(color);
        if (i < imageUrl.size()) {
            otherEmbed.setImageUrl(imageUrl.get(i));
        }
        if (i < description.size()) {
            otherEmbed.setDescription(description.get(i));
        }
        if (!(i + 1 < imageUrl.size() || i + 1 < description.size())) {
            if (footer != null) {
                otherEmbed.setFooter(new EmbedFooter(footer, footerImageUrl));
            }
        }
        if (!otherEmbed.isEmpty()) {
            webhookMessage.addEmbeds(otherEmbed.build());
        }
    }
    for (Entry<String, byte[]> entry : attachments.entrySet()) {
        webhookMessage.addFile(entry.getKey(), entry.getValue());
    }
    return webhookMessage;
}
Also used : EmbedFooter(club.minnced.discord.webhook.send.WebhookEmbed.EmbedFooter) WebhookMessageBuilder(club.minnced.discord.webhook.send.WebhookMessageBuilder) EmbedAuthor(club.minnced.discord.webhook.send.WebhookEmbed.EmbedAuthor) WebhookEmbedBuilder(club.minnced.discord.webhook.send.WebhookEmbedBuilder)

Example 2 with EmbedAuthor

use of club.minnced.discord.webhook.send.WebhookEmbed.EmbedAuthor in project InteractiveChat-DiscordSRV-Addon by LOOHP.

the class DiscordMessageContent method toWebhookEmbeds.

public List<WebhookEmbed> toWebhookEmbeds() {
    List<WebhookEmbed> list = new ArrayList<>();
    WebhookEmbedBuilder embed = new WebhookEmbedBuilder().setAuthor(new EmbedAuthor(authorName, authorIconUrl, null)).setColor(color).setThumbnailUrl(thumbnail);
    if (description.size() > 0) {
        embed.setDescription(description.get(0));
    }
    if (imageUrl.size() > 0) {
        embed.setImageUrl(imageUrl.get(0));
    }
    if (imageUrl.size() == 1 || description.size() == 1) {
        if (footer != null) {
            embed.setFooter(new EmbedFooter(footer, footerImageUrl));
        }
    }
    list.add(embed.build());
    for (int i = 1; i < imageUrl.size() || i < description.size(); i++) {
        WebhookEmbedBuilder otherEmbed = new WebhookEmbedBuilder().setColor(color);
        if (i < imageUrl.size()) {
            otherEmbed.setImageUrl(imageUrl.get(i));
        }
        if (i < description.size()) {
            otherEmbed.setDescription(description.get(i));
        }
        if (!(i + 1 < imageUrl.size() || i + 1 < description.size())) {
            if (footer != null) {
                otherEmbed.setFooter(new EmbedFooter(footer, footerImageUrl));
            }
        }
        if (!otherEmbed.isEmpty()) {
            list.add(otherEmbed.build());
        }
    }
    return list;
}
Also used : EmbedFooter(club.minnced.discord.webhook.send.WebhookEmbed.EmbedFooter) WebhookEmbed(club.minnced.discord.webhook.send.WebhookEmbed) EmbedAuthor(club.minnced.discord.webhook.send.WebhookEmbed.EmbedAuthor) ArrayList(java.util.ArrayList) WebhookEmbedBuilder(club.minnced.discord.webhook.send.WebhookEmbedBuilder)

Example 3 with EmbedAuthor

use of club.minnced.discord.webhook.send.WebhookEmbed.EmbedAuthor in project Sx4 by sx4-discord-bot.

the class LoggerHandler method onGuildVoiceJoin.

public void onGuildVoiceJoin(GuildVoiceJoinEvent event) {
    Guild guild = event.getGuild();
    Member member = event.getMember();
    User user = member.getUser();
    VoiceChannel channel = event.getChannelJoined();
    LoggerEvent loggerEvent = LoggerEvent.MEMBER_VOICE_JOIN;
    LoggerContext loggerContext = new LoggerContext().setUser(user).setChannel(channel);
    WebhookEmbedBuilder embed = new WebhookEmbedBuilder().setDescription(String.format("`%s` just joined the voice channel %s", member.getEffectiveName(), channel.getAsMention())).setColor(this.bot.getConfig().getGreen()).setTimestamp(Instant.now()).setFooter(new EmbedFooter(String.format("User ID: %s", member.getId()), null)).setAuthor(new EmbedAuthor(user.getAsTag(), user.getEffectiveAvatarUrl(), 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);
        this.queue(guild, data.getList("loggers", Document.class), loggerEvent, loggerContext, embed.build());
    });
}
Also used : EmbedFooter(club.minnced.discord.webhook.send.WebhookEmbed.EmbedFooter) EmbedAuthor(club.minnced.discord.webhook.send.WebhookEmbed.EmbedAuthor) WebhookEmbedBuilder(club.minnced.discord.webhook.send.WebhookEmbedBuilder) LoggerEvent(com.sx4.bot.entities.management.LoggerEvent) Document(org.bson.Document) LoggerContext(com.sx4.bot.entities.management.LoggerContext)

Example 4 with EmbedAuthor

use of club.minnced.discord.webhook.send.WebhookEmbed.EmbedAuthor 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);
    }
}
Also used : EmbedField(club.minnced.discord.webhook.send.WebhookEmbed.EmbedField) Document(org.bson.Document) LoggerContext(com.sx4.bot.entities.management.LoggerContext) EmbedFooter(club.minnced.discord.webhook.send.WebhookEmbed.EmbedFooter) WebhookEmbed(club.minnced.discord.webhook.send.WebhookEmbed) GuildMessage(com.sx4.bot.entities.cache.GuildMessage) EmbedAuthor(club.minnced.discord.webhook.send.WebhookEmbed.EmbedAuthor) WebhookEmbedBuilder(club.minnced.discord.webhook.send.WebhookEmbedBuilder)

Example 5 with EmbedAuthor

use of club.minnced.discord.webhook.send.WebhookEmbed.EmbedAuthor 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());
        }
    });
}
Also used : MessageBulkDeleteEvent(net.dv8tion.jda.api.events.message.MessageBulkDeleteEvent) Document(org.bson.Document) PermissionOverrideCreateEvent(net.dv8tion.jda.api.events.guild.override.PermissionOverrideCreateEvent) RoleCreateEvent(net.dv8tion.jda.api.events.role.RoleCreateEvent) StoreChannelDeleteEvent(net.dv8tion.jda.api.events.channel.store.StoreChannelDeleteEvent) Permission(net.dv8tion.jda.api.Permission) ZonedDateTime(java.time.ZonedDateTime) Aggregates(com.mongodb.client.model.Aggregates) EmoteUpdateRolesEvent(net.dv8tion.jda.api.events.emote.update.EmoteUpdateRolesEvent) AuditLogChange(net.dv8tion.jda.api.audit.AuditLogChange) CategoryCreateEvent(net.dv8tion.jda.api.events.channel.category.CategoryCreateEvent) LoggerManager(com.sx4.bot.managers.LoggerManager) ColourUtility(com.sx4.bot.utility.ColourUtility) TextChannelDeleteEvent(net.dv8tion.jda.api.events.channel.text.TextChannelDeleteEvent) EmoteAddedEvent(net.dv8tion.jda.api.events.emote.EmoteAddedEvent) TextChannelUpdateNameEvent(net.dv8tion.jda.api.events.channel.text.update.TextChannelUpdateNameEvent) TextChannelCreateEvent(net.dv8tion.jda.api.events.channel.text.TextChannelCreateEvent) Duration(java.time.Duration) GenericEvent(net.dv8tion.jda.api.events.GenericEvent) ZoneOffset(java.time.ZoneOffset) LoggerContext(com.sx4.bot.entities.management.LoggerContext) LoggerEvent(com.sx4.bot.entities.management.LoggerEvent) AuditLogKey(net.dv8tion.jda.api.audit.AuditLogKey) PermissionOverrideDeleteEvent(net.dv8tion.jda.api.events.guild.override.PermissionOverrideDeleteEvent) EmbedFooter(club.minnced.discord.webhook.send.WebhookEmbed.EmbedFooter) GuildMessageUpdateEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent) java.util.concurrent(java.util.concurrent) EmoteUpdateNameEvent(net.dv8tion.jda.api.events.emote.update.EmoteUpdateNameEvent) CategoryDeleteEvent(net.dv8tion.jda.api.events.channel.category.CategoryDeleteEvent) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) GuildBanEvent(net.dv8tion.jda.api.events.guild.GuildBanEvent) GuildMemberRemoveEvent(net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent) EventListener(net.dv8tion.jda.api.hooks.EventListener) CategoryUpdateNameEvent(net.dv8tion.jda.api.events.channel.category.update.CategoryUpdateNameEvent) GuildMemberUpdateNicknameEvent(net.dv8tion.jda.api.events.guild.member.update.GuildMemberUpdateNicknameEvent) NotNull(org.jetbrains.annotations.NotNull) RoleUpdateColorEvent(net.dv8tion.jda.api.events.role.update.RoleUpdateColorEvent) ActionType(net.dv8tion.jda.api.audit.ActionType) net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) VoiceChannelUpdateNameEvent(net.dv8tion.jda.api.events.channel.voice.update.VoiceChannelUpdateNameEvent) java.util(java.util) JDA(net.dv8tion.jda.api.JDA) EmbedAuthor(club.minnced.discord.webhook.send.WebhookEmbed.EmbedAuthor) GuildMemberRoleRemoveEvent(net.dv8tion.jda.api.events.guild.member.GuildMemberRoleRemoveEvent) RoleUpdatePermissionsEvent(net.dv8tion.jda.api.events.role.update.RoleUpdatePermissionsEvent) VoiceChannelDeleteEvent(net.dv8tion.jda.api.events.channel.voice.VoiceChannelDeleteEvent) Projections(com.mongodb.client.model.Projections) MongoDatabase(com.sx4.bot.database.mongo.MongoDatabase) TLongIntHashMap(gnu.trove.map.hash.TLongIntHashMap) EmbedField(club.minnced.discord.webhook.send.WebhookEmbed.EmbedField) AuditLogEntry(net.dv8tion.jda.api.audit.AuditLogEntry) Filters(com.mongodb.client.model.Filters) GuildMessageDeleteEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageDeleteEvent) Bson(org.bson.conversions.Bson) Pair(net.dv8tion.jda.internal.utils.tuple.Pair) WebhookEmbedBuilder(club.minnced.discord.webhook.send.WebhookEmbedBuilder) Sx4(com.sx4.bot.core.Sx4) GuildMemberRoleAddEvent(net.dv8tion.jda.api.events.guild.member.GuildMemberRoleAddEvent) WebhookEmbed(club.minnced.discord.webhook.send.WebhookEmbed) EmoteRemovedEvent(net.dv8tion.jda.api.events.emote.EmoteRemovedEvent) Operators(com.sx4.bot.database.mongo.model.Operators) Accumulators(com.mongodb.client.model.Accumulators) TLongIntMap(gnu.trove.map.TLongIntMap) VoiceChannelCreateEvent(net.dv8tion.jda.api.events.channel.voice.VoiceChannelCreateEvent) LoggerUtility(com.sx4.bot.utility.LoggerUtility) RoleUpdateNameEvent(net.dv8tion.jda.api.events.role.update.RoleUpdateNameEvent) StoreChannelUpdateNameEvent(net.dv8tion.jda.api.events.channel.store.update.StoreChannelUpdateNameEvent) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) OkHttpClient(okhttp3.OkHttpClient) PermissionOverrideUpdateEvent(net.dv8tion.jda.api.events.guild.override.PermissionOverrideUpdateEvent) net.dv8tion.jda.api.events.guild.voice(net.dv8tion.jda.api.events.guild.voice) StoreChannelCreateEvent(net.dv8tion.jda.api.events.channel.store.StoreChannelCreateEvent) GuildMessage(com.sx4.bot.entities.cache.GuildMessage) GuildUnbanEvent(net.dv8tion.jda.api.events.guild.GuildUnbanEvent) TLongObjectMap(gnu.trove.map.TLongObjectMap) RoleDeleteEvent(net.dv8tion.jda.api.events.role.RoleDeleteEvent) ExceptionUtility(com.sx4.bot.utility.ExceptionUtility) StringUtility(com.sx4.bot.utility.StringUtility) GuildMemberJoinEvent(net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent) EmbedFooter(club.minnced.discord.webhook.send.WebhookEmbed.EmbedFooter) EmbedAuthor(club.minnced.discord.webhook.send.WebhookEmbed.EmbedAuthor) WebhookEmbedBuilder(club.minnced.discord.webhook.send.WebhookEmbedBuilder) LoggerEvent(com.sx4.bot.entities.management.LoggerEvent) Document(org.bson.Document) LoggerContext(com.sx4.bot.entities.management.LoggerContext)

Aggregations

EmbedAuthor (club.minnced.discord.webhook.send.WebhookEmbed.EmbedAuthor)33 EmbedFooter (club.minnced.discord.webhook.send.WebhookEmbed.EmbedFooter)33 WebhookEmbedBuilder (club.minnced.discord.webhook.send.WebhookEmbedBuilder)33 LoggerContext (com.sx4.bot.entities.management.LoggerContext)30 Document (org.bson.Document)30 EmbedField (club.minnced.discord.webhook.send.WebhookEmbed.EmbedField)29 LoggerEvent (com.sx4.bot.entities.management.LoggerEvent)29 WebhookEmbed (club.minnced.discord.webhook.send.WebhookEmbed)28 GuildMessage (com.sx4.bot.entities.cache.GuildMessage)28 Accumulators (com.mongodb.client.model.Accumulators)26 Aggregates (com.mongodb.client.model.Aggregates)26 Filters (com.mongodb.client.model.Filters)26 Projections (com.mongodb.client.model.Projections)26 Sx4 (com.sx4.bot.core.Sx4)26 MongoDatabase (com.sx4.bot.database.mongo.MongoDatabase)26 Operators (com.sx4.bot.database.mongo.model.Operators)26 LoggerManager (com.sx4.bot.managers.LoggerManager)26 ColourUtility (com.sx4.bot.utility.ColourUtility)26 ExceptionUtility (com.sx4.bot.utility.ExceptionUtility)26 LoggerUtility (com.sx4.bot.utility.LoggerUtility)26