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());
}
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;
}
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);
}
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();
}
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();
}
Aggregations