use of club.minnced.discord.webhook.send.WebhookEmbedBuilder in project Sx4 by sx4-discord-bot.
the class LoggerHandler method onEmoteAdded.
public void onEmoteAdded(EmoteAddedEvent event) {
Guild guild = event.getGuild();
Emote emote = event.getEmote();
LoggerEvent loggerEvent = LoggerEvent.EMOTE_CREATE;
LoggerContext loggerContext = new LoggerContext().setEmote(emote);
WebhookEmbedBuilder embed = new WebhookEmbedBuilder();
embed.setDescription(String.format("The emote %s has been created", emote.getAsMention()));
embed.setColor(this.bot.getConfig().getGreen());
embed.setTimestamp(Instant.now());
embed.setAuthor(new EmbedAuthor(guild.getName(), guild.getIconUrl(), null));
embed.setFooter(new EmbedFooter(String.format("Emote ID: %s", emote.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 (!emote.isManaged() && guild.getSelfMember().hasPermission(Permission.VIEW_AUDIT_LOGS)) {
this.retrieveAuditLogsDelayed(guild, ActionType.EMOTE_CREATE).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() == emote.getIdLong()).map(AuditLogEntry::getUser).findFirst().orElse(null);
if (moderator != null) {
loggerContext.setModerator(moderator);
embed.setDescription(String.format("The emote %s has been created by **%s**", emote.getAsMention(), moderator.getAsTag()));
}
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
});
} else {
this.queue(guild, loggers, loggerEvent, loggerContext, embed.build());
}
});
}
use of club.minnced.discord.webhook.send.WebhookEmbedBuilder 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.WebhookEmbedBuilder 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.WebhookEmbedBuilder in project Vinny by kikkia.
the class R4cCommand method buildWebhookMessage.
private WebhookMessage buildWebhookMessage(CommandEvent commandEvent, String imageUrl, String title, JSONObject thread, String body) {
WebhookMessageBuilder builder = new WebhookMessageBuilder();
WebhookEmbedBuilder embedBuilder = new WebhookEmbedBuilder();
embedBuilder.setImageUrl(imageUrl);
embedBuilder.setTitle(new WebhookEmbed.EmbedTitle("/" + commandEvent.getArgs() + "/", "http://boards.4channel.org/" + commandEvent.getArgs() + "/thread/" + thread.getInt("no")));
embedBuilder.setDescription(body);
embedBuilder.addField(new WebhookEmbed.EmbedField(true, "Replies", thread.getInt("replies") + ""));
embedBuilder.addField(new WebhookEmbed.EmbedField(true, "Images", thread.getInt("images") + ""));
builder.addEmbeds(embedBuilder.build());
return builder.build();
}
use of club.minnced.discord.webhook.send.WebhookEmbedBuilder in project Vinny by kikkia.
the class RedditHelper method buildWebhookEmbedMessageForSubmission.
private static WebhookMessage buildWebhookEmbedMessageForSubmission(CommandEvent event, Submission submission) {
WebhookEmbedBuilder builder = new WebhookEmbedBuilder();
// TODO: Populate author url
builder.setAuthor(new WebhookEmbed.EmbedAuthor(submission.getAuthor(), null, null));
builder.addField(new WebhookEmbed.EmbedField(true, "Score", submission.getScore() + ""));
builder.addField(new WebhookEmbed.EmbedField(true, "Comments", submission.getCommentCount() + ""));
builder.setFooter(new WebhookEmbed.EmbedFooter(submission.getUrl(), REDDIT_SNOO_ICON_URL));
// If the title is more than 256 characters then trim it
String title = submission.getTitle();
title = title.length() <= 256 ? title : title.substring(0, 252) + "...";
builder.setTitle(new WebhookEmbed.EmbedTitle(title, submission.getUrl()));
builder.setDescription("r/" + submission.getSubreddit());
// If there is a thumbnail and it does match a url to an image
if (submission.hasThumbnail() && submission.getThumbnail().matches("^[a-zA-Z0-9\\-\\.]+\\.(com|org|net|mil|edu|COM|ORG|NET|MIL|EDU)$")) {
builder.setImageUrl(submission.getThumbnail());
}
WebhookEmbed embed = builder.build();
WebhookMessageBuilder mBuilder = new WebhookMessageBuilder();
mBuilder.addEmbeds(embed);
mBuilder.setUsername(event.getSelfMember().getEffectiveName());
mBuilder.setAvatarUrl(event.getSelfUser().getAvatarUrl());
return mBuilder.build();
}
Aggregations