Search in sources :

Example 1 with WebhookEmbedBuilder

use of club.minnced.discord.webhook.send.WebhookEmbedBuilder in project MCAntiMalware by OpticFusion1.

the class DiscordNotifSender method sendNotification.

@Override
public void sendNotification(Path path, CheckResult result) {
    WebhookMessageBuilder packet = new WebhookMessageBuilder();
    packet.setUsername("AntiMalwareScanner");
    String pluginName = "";
    String resourceID = "";
    String version = "N/A";
    try {
        String fileName = path.getParent().getParent().getFileName().toString();
        String[] args = fileName.split("\\.");
        pluginName = args[0];
        resourceID = args[1];
        try {
            version = path.getFileName().toString().split("-")[1].split("\\.")[0];
        } catch (Exception e) {
        }
    } catch (NullPointerException e) {
        String fileName = path.getFileName().toString();
        String[] args = fileName.split("\\(");
        if (args.length == 1) {
            if (args[0].startsWith("(")) {
                pluginName = resourceID = args[0].replaceAll("[^\\d]", "");
            } else {
                pluginName = resourceID = args[0];
            }
        } else {
            pluginName = args[0];
            resourceID = args[1].replaceAll("[^\\d]", "");
        }
    }
    WebhookEmbedBuilder embed = new WebhookEmbedBuilder();
    embed.setTitle(new WebhookEmbed.EmbedTitle("[DETECTED] " + pluginName, "https://spigotmc.org/resources/" + resourceID + "/"));
    embed.setDescription("Plugin " + pluginName + " (" + resourceID + ") of Version " + version + String.format(" might be infected with %s.%s.%s.%s Class path: %s ; Line/SourceFile %d/%s", result.getPlatform(), result.getType(), result.getFamily(), result.getVariant(), result.getClassNodePath(), result.getLine(), result.getSourceFilePath()));
    embed.setColor(16711680);
    packet.addEmbeds(embed.build());
    CLIENT.send(packet.build());
}
Also used : WebhookEmbed(club.minnced.discord.webhook.send.WebhookEmbed) WebhookMessageBuilder(club.minnced.discord.webhook.send.WebhookMessageBuilder) WebhookEmbedBuilder(club.minnced.discord.webhook.send.WebhookEmbedBuilder)

Example 2 with WebhookEmbedBuilder

use of club.minnced.discord.webhook.send.WebhookEmbedBuilder 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 3 with WebhookEmbedBuilder

use of club.minnced.discord.webhook.send.WebhookEmbedBuilder 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 4 with WebhookEmbedBuilder

use of club.minnced.discord.webhook.send.WebhookEmbedBuilder in project PurrBot by purrbot-site.

the class GuildListener method sendWebhook.

private void sendWebhook(Member owner, Guild guild, Action action) {
    String mention = owner == null ? "Unknown" : owner.getAsMention();
    String name = owner == null ? "Unknown" : owner.getUser().getName();
    String id = owner == null ? "?" : owner.getId();
    String title = null;
    WebhookEmbedBuilder embed = new WebhookEmbedBuilder().setThumbnailUrl(guild.getIconUrl()).addField(new WebhookEmbed.EmbedField(true, "Name", guild.getName())).addField(new WebhookEmbed.EmbedField(true, "Shard [Current / Total]", guild.getJDA().getShardInfo().getShardString())).addField(new WebhookEmbed.EmbedField(false, "Owner", String.format("%s | %s (`%s`)", mention, MarkdownSanitizer.escape(name), id))).addField(new WebhookEmbed.EmbedField(false, "Members", String.format("```yaml\n" + "Total: %d\n" + "```", guild.getMemberCount()))).setFooter(new WebhookEmbed.EmbedFooter(String.format("Guild #%s", bot.getMessageUtil().formatNumber(bot.getShardManager().getGuildCache().size())), null)).setTimestamp(ZonedDateTime.now());
    switch(action) {
        case JOIN:
            title = "Join";
            embed.setColor(0x00FF00).setTitle(new WebhookEmbed.EmbedTitle(Emotes.PLUS.getEmote(), null));
            break;
        case LEAVE:
            title = "Leave";
            embed.setColor(0xFF0000).setTitle(new WebhookEmbed.EmbedTitle(Emotes.MINUS.getEmote(), null));
            break;
        case AUTO_LEAVE:
            title = "Leave [Auto]";
            embed.setColor(0xFF0000).setTitle(new WebhookEmbed.EmbedTitle(Emotes.MINUS.getEmote(), null));
            break;
    }
    webhookUtil.sendMsg(guild.getSelfMember().getUser().getEffectiveAvatarUrl(), title, action == Action.JOIN ? ".leave " + guild.getId() : null, embed.build());
}
Also used : WebhookEmbed(club.minnced.discord.webhook.send.WebhookEmbed) WebhookEmbedBuilder(club.minnced.discord.webhook.send.WebhookEmbedBuilder)

Example 5 with WebhookEmbedBuilder

use of club.minnced.discord.webhook.send.WebhookEmbedBuilder in project PurrBot by purrbot-site.

the class ReadyListener method onReady.

@Override
public void onReady(@NotNull ReadyEvent event) {
    ShardManager shardManager = bot.getShardManager();
    JDA jda = event.getJDA();
    shards++;
    logger.info("Shard {} ({} Guilds) ready!", jda.getShardInfo().getShardId(), jda.getGuildCache().size());
    WebhookEmbed embed = new WebhookEmbedBuilder().setColor(0x00FF00).setTitle(new WebhookEmbed.EmbedTitle(Emotes.STATUS_READY.getEmote(), null)).addField(new WebhookEmbed.EmbedField(true, "Guilds:", String.valueOf(jda.getGuilds().size()))).addField(new WebhookEmbed.EmbedField(true, "Shard:", String.valueOf(jda.getShardInfo().getShardId()))).setFooter(new WebhookEmbed.EmbedFooter("Ready at", null)).setTimestamp(ZonedDateTime.now()).build();
    webhookUtil.sendMsg(jda.getSelfUser().getEffectiveAvatarUrl(), "Shard ready!", embed);
    if (shards == jda.getShardInfo().getShardTotal()) {
        shardManager.setPresence(OnlineStatus.ONLINE, Activity.of(Activity.ActivityType.WATCHING, bot.getMessageUtil().getBotGame(shardManager.getGuildCache().size())));
        bot.startUpdater();
        WebhookEmbed finished = new WebhookEmbedBuilder().setColor(0x00FF00).setTitle(new WebhookEmbed.EmbedTitle(String.format("\\%s ready!", jda.getSelfUser().getName()), null)).setDescription(String.format("\\%s is online and ready to bring you fun and nekos. <:catUwU:703924268022497340>", jda.getSelfUser().getName())).build();
        webhookUtil.sendMsg(jda.getSelfUser().getEffectiveAvatarUrl(), "Ready!", finished);
        logger.info("Loaded Bot {} vBOT_VERSION with {} shard(s) and {} guilds!", jda.getSelfUser().getAsTag(), shardManager.getShardCache().size(), bot.getMessageUtil().formatNumber(shardManager.getGuildCache().size()));
    }
}
Also used : WebhookEmbed(club.minnced.discord.webhook.send.WebhookEmbed) JDA(net.dv8tion.jda.api.JDA) WebhookEmbedBuilder(club.minnced.discord.webhook.send.WebhookEmbedBuilder) ShardManager(net.dv8tion.jda.api.sharding.ShardManager)

Aggregations

WebhookEmbedBuilder (club.minnced.discord.webhook.send.WebhookEmbedBuilder)49 WebhookEmbed (club.minnced.discord.webhook.send.WebhookEmbed)43 EmbedFooter (club.minnced.discord.webhook.send.WebhookEmbed.EmbedFooter)34 EmbedAuthor (club.minnced.discord.webhook.send.WebhookEmbed.EmbedAuthor)33 Document (org.bson.Document)32 EmbedField (club.minnced.discord.webhook.send.WebhookEmbed.EmbedField)30 LoggerContext (com.sx4.bot.entities.management.LoggerContext)30 LoggerEvent (com.sx4.bot.entities.management.LoggerEvent)29 Sx4 (com.sx4.bot.core.Sx4)28 GuildMessage (com.sx4.bot.entities.cache.GuildMessage)28 Instant (java.time.Instant)28 Permission (net.dv8tion.jda.api.Permission)28 GenericEvent (net.dv8tion.jda.api.events.GenericEvent)28 MongoDatabase (com.sx4.bot.database.mongo.MongoDatabase)27 Operators (com.sx4.bot.database.mongo.model.Operators)27 ExceptionUtility (com.sx4.bot.utility.ExceptionUtility)27 StringUtility (com.sx4.bot.utility.StringUtility)27 Duration (java.time.Duration)27 ZoneOffset (java.time.ZoneOffset)27 ZonedDateTime (java.time.ZonedDateTime)27