net.dv8tion.jda.api.EmbedBuilder Java Examples
The following examples show how to use
net.dv8tion.jda.api.EmbedBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HelpCommand.java From SkyBot with GNU Affero General Public License v3.0 | 6 votes |
private void sendCommandHelpMessage(GuildMessageReceivedEvent event, Command cmd, String prefix, String invoke) { final Class<? extends Command> commandClass = cmd.getClass(); final String clsPath = commandClass.getName().replace('.', '/'); final boolean isKotlin = isKotlin(commandClass); final String extension = isKotlin ? ".kt" : ".java"; final String type = isKotlin ? "kotlin" : "java"; final String url = String.format("https://github.com/DuncteBot/SkyBot/blob/master/src/main/%s/%s%s", type, clsPath, extension); final EmbedBuilder builder = EmbedUtils .defaultEmbed() .setTitle("Command help for " + cmd.getName() + " (<required argument> [optional argument])", url) .setDescription(cmd.help(invoke, prefix) + "\nUsage: " + cmd.getUsageInstructions(prefix, invoke)); if (cmd.flags.length > 0) { builder.addField("Flags", parseFlags(cmd.flags), false); } sendEmbed(event, builder); }
Example #2
Source File: CommandStatsManager.java From MantaroBot with GNU General Public License v3.0 | 6 votes |
public static EmbedBuilder fillEmbed(Bucket bucket, EmbedBuilder builder) { long total = TRACKERS.total(bucket); if (total == 0) { builder.addField("Nothing Here.", "Just dust.", false); return builder; } TRACKERS.highest(bucket, 12) .forEach(tracker -> { long percent = bucket.amount(tracker) * 100 / total; builder.addField(tracker.getKey(), String.format("%s %d%% (%d)", bar(percent, 15), percent, bucket.amount(tracker)), false); }); return builder; }
Example #3
Source File: LeaderboardCmd.java From MantaroBot with GNU General Public License v3.0 | 6 votes |
private EmbedBuilder generateLeaderboardEmbed(Context ctx, String description, String leaderboardKey, List<Map<String, Object>> lb, Function<Map<?, ?>, Pair<User, String>> mapFunction, String format, boolean isSeasonal) { I18nContext languageContext = ctx.getLanguageContext(); return new EmbedBuilder() .setAuthor(isSeasonal ? String.format(languageContext.get("commands.leaderboard.header_seasonal"), config.getCurrentSeason().getDisplay()) : languageContext.get("commands.leaderboard.header"), null, ctx.getSelfUser().getEffectiveAvatarUrl() ).setDescription(description) .addField(languageContext.get(leaderboardKey), lb.stream() .map(mapFunction) .filter(p -> Objects.nonNull(p.getKey())) .map(p -> { //This is... an interesting place to do it lol if(p.getKey().getIdLong() == ctx.getAuthor().getIdLong()) { var player = MantaroData.db().getPlayer(ctx.getAuthor()); if(player.getData().addBadgeIfAbsent(Badge.CHAMPION)) player.saveAsync(); } return String.format( format, EmoteReference.BLUE_SMALL_MARKER, p.getKey().getName(), p.getKey().getDiscriminator(), StringUtils.isNumeric(p.getValue()) ? Long.parseLong(p.getValue()) : p.getValue() ); }).collect(Collectors.joining("\n")), false) .setFooter(String.format(languageContext.get("general.requested_by"), ctx.getAuthor().getName()), null) .setThumbnail(ctx.getAuthor().getEffectiveAvatarUrl()); }
Example #4
Source File: ServerInfoCommand.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@Override public boolean doCommand(GuildMessageReceivedEvent message, BotContext context, String query) { Guild guild = message.getGuild(); EmbedBuilder builder = messageService.getBaseEmbed(); builder.setTitle(messageService.getMessage("discord.command.server.title", guild.getName())); builder.setThumbnail(guild.getIconUrl()); builder.setFooter(messageService.getMessage("discord.command.info.identifier", guild.getId()), null); builder.addField(getMemberListField(guild)); builder.addField(getChannelListField(guild)); builder.addField(getShard(guild)); builder.addField(getVerificationLevel(guild.getVerificationLevel())); builder.addField(getRegion(guild)); builder.addField(getOwner(guild)); builder.addField(getCreatedAt(guild, context)); messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build()); return true; }
Example #5
Source File: MessageEditAuditForwardProvider.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@Override protected void build(AuditAction action, MessageBuilder messageBuilder, EmbedBuilder embedBuilder) { String messageId = action.getAttribute(MESSAGE_ID, String.class); if (action.getChannel() == null || action.getUser() == null || messageId == null) { return; } embedBuilder.setDescription(messageService.getMessage("audit.message.edit.message", String.valueOf(action.getGuildId()), action.getChannel().getId(), messageId)); addOldContentField(action, embedBuilder); embedBuilder.addField(messageService.getMessage("audit.message.newContent.title"), getMessageValue(action, NEW_CONTENT), false); addAuthorField(action, embedBuilder); addChannelField(action, embedBuilder); embedBuilder.setFooter(messageService.getMessage("audit.message.id", messageId), null); }
Example #6
Source File: WikiFurService.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
private MessageEmbed renderArticle(Article article, boolean redirected) { if (article == null || StringUtils.isEmpty(article.getRevisionId())) { return null; } EngProcessedPage processedPage = processedPage(article); String redirect = lookupRedirect(processedPage); if (redirect != null) { if (redirected) { return null; } return renderArticle(getArticle(redirect), true); } EmbedBuilder embedBuilder = messageService.getBaseEmbed(); embedBuilder.setTitle(article.getTitle(), WIKI_URL + UriUtils.encode(article.getTitle(), "UTF-8")); TextConverter converter = new TextConverter(config, embedBuilder); return (MessageEmbed) converter.go(processedPage.getPage()); }
Example #7
Source File: TrackScheduler.java From SkyBot with GNU Affero General Public License v3.0 | 6 votes |
@Override public void onTrackStart(AudioPlayer player, AudioTrack track) { final TrackUserData data = track.getUserData(TrackUserData.class); // If the track was a skipped track or we announce tracks if (data.getWasFromSkip() || this.guildMusicManager.isAnnounceTracks()) { // Reset the was from skip status data.setWasFromSkip(false); final EmbedBuilder message = AudioTrackKt.toEmbed( track, this.guildMusicManager, getInstance().getShardManager(), false ); sendEmbed(this.guildMusicManager.getLatestChannel(), message); } }
Example #8
Source File: DiscordUtils.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
public static String getUrl(String url) { if (StringUtils.isEmpty(url) || url.length() > MessageEmbed.URL_MAX_LENGTH) { return null; } if (EmbedBuilder.URL_PATTERN.matcher(url).matches()) { return url; } try { String result = java.net.URLDecoder.decode(url, StandardCharsets.UTF_8); if (EmbedBuilder.URL_PATTERN.matcher(result).matches()) { return result; } } catch (Exception e) { // nah I don't care } return null; }
Example #9
Source File: MemberWarnAuditForwardProvider.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@Override protected void build(AuditAction action, MessageBuilder messageBuilder, EmbedBuilder embedBuilder) { if (action.getTargetUser() == null) { return; } String message = messageService.getMessage("audit.member.warn.message", getReferenceContent(action.getTargetUser(), false)); embedBuilder.setDescription(message); addModeratorField(action, embedBuilder); Number count = action.getAttribute(COUNT_ATTR, Number.class); if (count != null) { embedBuilder.addField(messageService.getMessage("audit.member.warn.count.title"), messageService.getMessage("audit.member.warn.count.content", count), true); } addReasonField(action, embedBuilder); addExpirationField(action, embedBuilder); embedBuilder.setFooter(messageService.getMessage("audit.member.id", action.getTargetUser().getId()), null); }
Example #10
Source File: StatsManager.java From MantaroBot with GNU General Public License v3.0 | 6 votes |
public EmbedBuilder fillEmbed(Map<T, AtomicInteger> values, EmbedBuilder builder) { int total = values.values().stream().mapToInt(AtomicInteger::get).sum(); if (total == 0) { builder.addField("Nothing Here.", "Just dust.", false); return builder; } values.entrySet().stream() .filter(entry -> entry.getValue().get() > 0) .sorted(Comparator.comparingInt(entry -> total - entry.getValue().get())) .limit(12) .forEachOrdered(entry -> { int percent = entry.getValue().get() * 100 / total; builder.addField(String.valueOf(entry.getKey()), String.format("%s %d%% (%d)", bar(percent, 15), percent, entry.getValue().get()), false); }); return builder; }
Example #11
Source File: VoiceMoveAuditForwardProvider.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@Override protected void build(AuditAction action, MessageBuilder messageBuilder, EmbedBuilder embedBuilder) { if (action.getChannel() == null || action.getUser() == null) { return; } embedBuilder.setDescription(messageService.getMessage("audit.message.voice.move.message", getReferenceContent(action.getUser(), false))); addChannelField(action, embedBuilder); NamedReference oldChannel = action.getAttribute(OLD_CHANNEL, NamedReference.class); if (oldChannel != null) { embedBuilder.addField(messageService.getMessage("audit.message.voice.move.old.title"), getReferenceContent(oldChannel, true), true); } embedBuilder.setFooter(messageService.getMessage("audit.member.id", action.getUser().getId()), null); }
Example #12
Source File: EmergencyServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@Override public void error(String message, Throwable throwable) { Long emergencyChannelId = workerProperties.getSupport().getEmergencyChannelId(); if (emergencyChannelId == null || !discordService.isConnected(workerProperties.getSupport().getGuildId())) { return; } TextChannel channel = discordService.getShardManager().getTextChannelById(emergencyChannelId); if (channel == null) { return; } String errorText = String.format("`%s`\n\nStack trace:```javascript\n%s", throwable.getMessage(), ExceptionUtils.getStackTrace(throwable)); EmbedBuilder builder = messageService.getBaseEmbed(); builder.setTitle(message); builder.setColor(Color.RED); builder.setDescription(CommonUtils.trimTo(errorText, 2045) + "```"); MessageBuilder messageBuilder = new MessageBuilder(); messageBuilder.setContent("@here"); messageBuilder.setEmbed(builder.build()); messageService.sendMessageSilent(channel::sendMessage, messageBuilder.build()); }
Example #13
Source File: AvatarCommand.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@Override public boolean doCommand(MemberReference reference, GuildMessageReceivedEvent event, BotContext context, String query) { String avatarUrl = reference.getEffectiveAvatarUrl(); if (StringUtils.isEmpty(avatarUrl)) { messageService.onEmbedMessage(event.getChannel(), "discord.command.avatar.none"); return false; } String name = reference.getEffectiveName(); EmbedBuilder builder = messageService.getBaseEmbed(); if (StringUtils.isNotEmpty(name)) { builder.setDescription(messageService.getMessage("discord.command.avatar.text", name)); } builder.setImage(avatarUrl + "?size=512"); messageService.sendMessageSilent(event.getChannel()::sendMessage, builder.build()); return true; }
Example #14
Source File: MemberBanAuditForwardProvider.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override protected void build(AuditAction action, MessageBuilder messageBuilder, EmbedBuilder embedBuilder) { if (action.getTargetUser() == null) { return; } embedBuilder.setDescription(messageService.getMessage("audit.member.ban.message", getReferenceContent(action.getTargetUser(), false))); addModeratorField(action, embedBuilder); addReasonField(action, embedBuilder); addExpirationField(action, embedBuilder); embedBuilder.setFooter(messageService.getMessage("audit.member.id", action.getTargetUser().getId()), null); }
Example #15
Source File: ProfileCmd.java From MantaroBot with GNU General Public License v3.0 | 5 votes |
private void applyBadge(MessageChannel channel, Badge badge, User author, EmbedBuilder builder) { if (badge == null) { channel.sendMessage(builder.build()).queue(); return; } Message message = new MessageBuilder().setEmbed(builder.setThumbnail("attachment://avatar.png").build()).build(); byte[] bytes; try { String url = author.getEffectiveAvatarUrl(); if (url.endsWith(".gif")) { url = url.substring(0, url.length() - 3) + "png"; } Response res = httpClient.newCall(new Request.Builder() .url(url) .addHeader("User-Agent", MantaroInfo.USER_AGENT) .build() ).execute(); ResponseBody body = res.body(); if (body == null) throw new IOException("body is null"); bytes = body.bytes(); res.close(); } catch (IOException e) { throw new AssertionError("io error", e); } channel.sendMessage(message).addFile(badge.apply(bytes), "avatar.png").queue(); }
Example #16
Source File: MessagesClearAuditForwardProvider.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override protected void build(AuditAction action, MessageBuilder messageBuilder, EmbedBuilder embedBuilder) { Integer messageCount = action.getAttribute(MESSAGE_COUNT, Integer.class); if (action.getChannel() == null || action.getUser() == null || messageCount == null) { return; } String pluralMessages = messageService.getCountPlural(messageCount, "discord.plurals.message"); embedBuilder.setDescription(messageService.getMessage("audit.message.delete.messages", messageCount, pluralMessages)); addModeratorField(action, embedBuilder); addChannelField(action, embedBuilder); }
Example #17
Source File: ModerationAuditForwardProvider.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
protected void addReasonField(AuditAction action, EmbedBuilder embedBuilder) { String reason = action.getAttribute(REASON_ATTR, String.class); if (StringUtils.isNotEmpty(reason)) { embedBuilder.addField(messageService.getMessage("audit.reason"), CommonUtils.trimTo(reason, MessageEmbed.TEXT_MAX_LENGTH), true); } }
Example #18
Source File: VoiceLeaveAuditForwardProvider.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override protected void build(AuditAction action, MessageBuilder messageBuilder, EmbedBuilder embedBuilder) { if (action.getChannel() != null && action.getUser() != null) { embedBuilder.setDescription(getUserMessage(action, "audit.message.voice.leave.message")); embedBuilder.setFooter(messageService.getMessage("audit.member.id", action.getUser().getId()), null); } }
Example #19
Source File: MemberUnMuteAuditForwardProvider.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override protected void build(AuditAction action, MessageBuilder messageBuilder, EmbedBuilder embedBuilder) { if (action.getTargetUser() == null) { return; } embedBuilder.setDescription(messageService.getMessage("audit.member.unmute.message", getReferenceContent(action.getTargetUser(), false))); addModeratorField(action, embedBuilder); addChannelField(action, embedBuilder); embedBuilder.setFooter(messageService.getMessage("audit.member.id", action.getTargetUser().getId()), null); }
Example #20
Source File: MemberUnBanAuditForwardProvider.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override protected void build(AuditAction action, MessageBuilder messageBuilder, EmbedBuilder embedBuilder) { if (action.getTargetUser() == null) { return; } embedBuilder.setDescription(messageService.getMessage("audit.member.unban.message", getReferenceContent(action.getTargetUser(), false))); embedBuilder.setFooter(messageService.getMessage("audit.member.id", action.getTargetUser().getId()), null); }
Example #21
Source File: MemberKickAuditForwardProvider.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override protected void build(AuditAction action, MessageBuilder messageBuilder, EmbedBuilder embedBuilder) { if (action.getTargetUser() == null) { return; } String message = messageService.getMessage("audit.member.kick.message", getReferenceContent(action.getTargetUser(), false)); embedBuilder.setDescription(message); addModeratorField(action, embedBuilder); addReasonField(action, embedBuilder); embedBuilder.setFooter(messageService.getMessage("audit.member.id", action.getTargetUser().getId()), null); }
Example #22
Source File: NicknameChangeAuditForwardProvider.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override protected void build(AuditAction action, MessageBuilder messageBuilder, EmbedBuilder embedBuilder) { if (action.getUser() != null) { embedBuilder.setDescription(messageService.getMessage("audit.message.nickname.change.message", getReferenceContent(action.getUser(), false))); embedBuilder.addField(messageService.getMessage("audit.message.nickname.old.title"), action.getAttribute(OLD_NAME, String.class), true); embedBuilder.addField(messageService.getMessage("audit.message.nickname.new.title"), action.getAttribute(NEW_NAME, String.class), true); embedBuilder.setFooter(messageService.getMessage("audit.member.id", action.getUser().getId()), null); } }
Example #23
Source File: MessageEmbed.java From JDA with Apache License 2.0 | 5 votes |
public Field(String name, String value, boolean inline, boolean checked) { if (checked) { if (name == null || value == null) throw new IllegalArgumentException("Both Name and Value must be set!"); else if (name.length() > TITLE_MAX_LENGTH) throw new IllegalArgumentException("Name cannot be longer than " + TITLE_MAX_LENGTH + " characters."); else if (value.length() > VALUE_MAX_LENGTH) throw new IllegalArgumentException("Value cannot be longer than " + VALUE_MAX_LENGTH + " characters."); name = name.trim(); value = value.trim(); if (name.isEmpty()) this.name = EmbedBuilder.ZERO_WIDTH_SPACE; else this.name = name; if (value.isEmpty()) this.value = EmbedBuilder.ZERO_WIDTH_SPACE; else this.value = value; this.inline = inline; } else { this.name = name; this.value = value; this.inline = inline; } }
Example #24
Source File: EmbedJSON.java From MantaroBot with GNU General Public License v3.0 | 5 votes |
public MessageEmbed gen(Member member) { EmbedBuilder embedBuilder = new EmbedBuilder(); if (title != null) embedBuilder.setTitle(title, titleUrl); if (description != null) embedBuilder.setDescription(description); if (author != null) embedBuilder.setAuthor(author, authorUrl, authorImg); if (footer != null) embedBuilder.setFooter(footer, footerImg); if (image != null) embedBuilder.setImage(image); if (thumbnail != null) embedBuilder.setThumbnail(thumbnail); if (color != null) { Color col = null; try { col = (Color) Color.class.getField(color).get(null); } catch (Exception ignored) { String colorLower = color.toLowerCase(); if (colorLower.equals("member")) { if (member != null) col = member.getColor(); } else if (colorLower.matches("#?(0x)?[0123456789abcdef]{1,6}")) { try { col = Color.decode(colorLower.startsWith("0x") ? colorLower : "0x" + colorLower); } catch (Exception ignored2) { } } } if (col != null) embedBuilder.setColor(col); } fields.forEach(f -> { if (f == null) { embedBuilder.addBlankField(false); } else if (f.value == null) { embedBuilder.addBlankField(f.inline); } else { embedBuilder.addField(f.name == null ? "" : f.name, f.value, f.inline); } }); return embedBuilder.build(); }
Example #25
Source File: StatsCommand.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
@Override public boolean doCommand(GuildMessageReceivedEvent message, BotContext context, String content) { EmbedBuilder builder = messageService.getBaseEmbed(true); builder.setTitle(messageService.getMessage("discord.command.stats.title")); builder.setThumbnail(commonProperties.getBranding().getAvatarSmallUrl()); Map<String, Metric> metricMap = metricRegistry.getMetrics(); builder.addField(getCommonStats(metricMap)); builder.addField(getCommandStats(metricMap)); builder.addField(getPlatformStats(metricMap)); messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build()); return true; }
Example #26
Source File: HelpCommand.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
private EmbedBuilder getBaseEmbed(String group) { EmbedBuilder embedBuilder = messageService.getBaseEmbed(true) .setThumbnail(commonProperties.getBranding().getAvatarSmallUrl()); if (COMMON_GROUP.equals(group)) { embedBuilder.setDescription(messageService.getMessage("discord.command.help.title")); } else { embedBuilder.setDescription(messageService.getMessage("discord.command.help.group.title", messageService.getMessage(group))); } return embedBuilder; }
Example #27
Source File: HelpCommand.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
private void send(GuildMessageReceivedEvent message, MessageChannel channel, EmbedBuilder embedBuilder, boolean direct) { channel.sendMessage(embedBuilder.build()).queue(); if (direct && message.getAuthor() != null) { contextService.withContext(message.getGuild(), () -> { messageService.onMessage(message.getChannel(), "discord.command.help.sent", message.getAuthor().getAsMention()); }); } }
Example #28
Source File: ChangeLogCommand.java From SkyBot with GNU Affero General Public License v3.0 | 5 votes |
private void fetchLatetstGitHubCommits(GuildMessageReceivedEvent event) { WebUtils.ins.getJSONObject("https://api.github.com/repos/DuncteBot/SkyBot/releases/latest").async(json -> { final String body = json.get("body").asText(); final String version = json.get("tag_name").asText(); final EmbedBuilder eb = EmbedUtils.defaultEmbed() .setTitle("Changelog for DuncteBot v" + version, json.get("html_url").asText()); for (final String item : body.split("\n")) { final String hash = item.substring(0, 7); final String text = item.substring(8); eb.appendDescription(String.format("[%s](http://g.entered.space/%s)%n", text, hash)); } // fallback if with url is too long if (eb.getDescriptionBuilder().length() > MessageEmbed.TEXT_MAX_LENGTH) { eb.setDescription(body); } final MessageEmbed embed = eb.setFooter("Released on", null) .setTimestamp(Instant.ofEpochMilli(parseTimeStamp(json.get("published_at").asText()))) .build(); embedJson = embed.toData() .put("type", "rich") .toString(); sendEmbed(event, embed); }); }
Example #29
Source File: DogCommand.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
private void sendImage(GuildMessageReceivedEvent event, DogImage image) { EmbedBuilder builder = messageService.getBaseEmbed(); builder.setImage(image.getUrl()); if (CollectionUtils.isNotEmpty(image.getBreeds())) { DogBreed breed = image.getBreeds().get(0); if (StringUtils.isNotEmpty(breed.getName())) { builder.addField(messageService.getMessage("discord.command.dog.breed.title"), breed.getName(), true); } if (StringUtils.isNotEmpty(breed.getBreedGroup())) { builder.addField(messageService.getMessage("discord.command.dog.breedGroup.title"), breed.getBreedGroup(), true); } if (StringUtils.isNotEmpty(breed.getBredFor())) { builder.addField(messageService.getMessage("discord.command.dog.bredFor.title"), breed.getBredFor(), true); } if (StringUtils.isNotEmpty(breed.getTemperament())) { builder.addField(messageService.getMessage("discord.command.dog.temperament.title"), breed.getTemperament(), true); } String weight = getMeasure(breed.getWeight()); if (StringUtils.isNotEmpty(weight)) { builder.addField(messageService.getMessage("discord.command.dog.weight.title"), weight, true); } String height = getMeasure(breed.getHeight()); if (StringUtils.isNotEmpty(height)) { builder.addField(messageService.getMessage("discord.command.dog.height.title"), height, true); } } messageService.sendMessageSilent(event.getChannel()::sendMessage, builder.build()); }
Example #30
Source File: InvestigateCmd.java From MantaroBot with GNU General Public License v3.0 | 5 votes |
private static void investigateUser(GuildMessageReceivedEvent event, User user, boolean file) { if (user == null) { event.getChannel().sendMessage("Unknown user").queue(); return; } EmbedBuilder eb = new EmbedBuilder() .setTitle("Please pick a guild") .setColor(Color.PINK); DiscordUtils.selectList(event, user.getMutualGuilds(), Guild::toString, s -> eb.setDescription(s).build(), g -> investigateGuild(event, g, file)); }