Search in sources :

Example 1 with WebhookMessageBuilder

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

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

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

the class WebhookUtil method sendMsg.

public void sendMsg(String avatar, String name, String message, WebhookEmbed embed) {
    WebhookMessage msg = new WebhookMessageBuilder().setAvatarUrl(avatar).setUsername(name).setContent(message).addEmbeds(embed).build();
    client.send(msg);
}
Also used : WebhookMessage(club.minnced.discord.webhook.send.WebhookMessage) WebhookMessageBuilder(club.minnced.discord.webhook.send.WebhookMessageBuilder)

Example 4 with WebhookMessageBuilder

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

the class PatreonEndpoint method postPatreon.

@POST
@Path("patreon")
public Response postPatreon(final String body, @HeaderParam("X-Patreon-Signature") final String signature, @HeaderParam("X-Patreon-Event") final String event) {
    String hash;
    try {
        hash = HmacUtility.getSignatureHex(this.bot.getConfig().getPatreonWebhookSecret(), body, HmacUtility.HMAC_MD5);
    } catch (InvalidKeyException | NoSuchAlgorithmException e) {
        return Response.status(500).build();
    }
    if (!hash.equals(signature)) {
        return Response.status(401).build();
    }
    Document document = Document.parse(body);
    WebhookMessage message = new WebhookMessageBuilder().setContent("Patreon payload received").addFile("patreon.json", document.toJson(MongoDatabase.PRETTY_JSON).getBytes(StandardCharsets.UTF_8)).build();
    this.webhook.send(message);
    int totalAmount = document.getEmbedded(List.of("data", "attributes", "lifetime_support_cents"), 0);
    if (totalAmount == 0) {
        return Response.status(204).build();
    }
    Document user = document.getList("included", Document.class).stream().filter(included -> included.getString("type").equals("user")).findFirst().orElse(null);
    if (user != null) {
        String discordId = user.getEmbedded(List.of("attributes", "social_connections", "discord", "user_id"), String.class);
        if (discordId != null) {
            this.bot.getPatreonManager().onPatreonEvent(new PatreonEvent(Long.parseLong(discordId), totalAmount));
        }
    }
    return Response.status(204).build();
}
Also used : WebhookMessage(club.minnced.discord.webhook.send.WebhookMessage) WebhookMessageBuilder(club.minnced.discord.webhook.send.WebhookMessageBuilder) PatreonEvent(com.sx4.bot.events.patreon.PatreonEvent) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) Document(org.bson.Document) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 5 with WebhookMessageBuilder

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

the class LeaverCommand method preview.

@Command(value = "preview", description = "Preview your leaver message")
@CommandId(195)
@Examples({ "leaver preview" })
public void preview(Sx4CommandEvent event) {
    Document data = event.getMongo().getGuildById(event.getGuild().getIdLong(), Projections.include("leaver.message", "leaver.enabled"));
    Document leaver = data.get("leaver", MongoDatabase.EMPTY_DOCUMENT);
    if (!leaver.get("enabled", false)) {
        event.replyFailure("Leaver is not enabled").queue();
        return;
    }
    WebhookMessageBuilder builder;
    try {
        builder = LeaverUtility.getLeaverMessage(leaver.get("message", LeaverManager.DEFAULT_MESSAGE), event.getMember());
    } catch (IllegalArgumentException e) {
        event.replyFailure(e.getMessage()).queue();
        return;
    }
    MessageUtility.fromWebhookMessage(event.getTextChannel(), builder.build()).queue();
}
Also used : WebhookMessageBuilder(club.minnced.discord.webhook.send.WebhookMessageBuilder) Document(org.bson.Document) ReturnDocument(com.mongodb.client.model.ReturnDocument) Command(com.jockie.bot.core.command.Command) Sx4Command(com.sx4.bot.core.Sx4Command)

Aggregations

WebhookMessageBuilder (club.minnced.discord.webhook.send.WebhookMessageBuilder)22 WebhookEmbed (club.minnced.discord.webhook.send.WebhookEmbed)9 WebhookMessage (club.minnced.discord.webhook.send.WebhookMessage)9 WebhookEmbedBuilder (club.minnced.discord.webhook.send.WebhookEmbedBuilder)7 Document (org.bson.Document)7 WebhookClient (com.sx4.bot.entities.webhook.WebhookClient)5 User (net.dv8tion.jda.api.entities.User)5 Guild (net.dv8tion.jda.api.entities.Guild)4 TextChannel (net.dv8tion.jda.api.entities.TextChannel)4 HttpException (club.minnced.discord.webhook.exception.HttpException)3 ReadonlyMessage (com.sx4.bot.entities.webhook.ReadonlyMessage)3 Permission (net.dv8tion.jda.api.Permission)3 OkHttpClient (okhttp3.OkHttpClient)3 Updates (com.mongodb.client.model.Updates)2 Sx4 (com.sx4.bot.core.Sx4)2 MongoDatabase (com.sx4.bot.database.mongo.MongoDatabase)2 BotPermissionException (com.sx4.bot.exceptions.mod.BotPermissionException)2 BigInteger (java.math.BigInteger)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2