Java Code Examples for net.dv8tion.jda.api.EmbedBuilder#setTitle()
The following examples show how to use
net.dv8tion.jda.api.EmbedBuilder#setTitle() .
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: 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 2
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 3
Source File: GroovyCommand.java From JuniperBot with GNU General Public License v3.0 | 6 votes |
@Override public boolean doCommand(GuildMessageReceivedEvent message, BotContext context, String query) { if (!enabled || !discordService.isSuperUser(message.getAuthor()) || StringUtils.isEmpty(query)) { return false; } message.getChannel().sendTyping().queue(); String script = CommonUtils.unwrapCode(query); try { Object result = getShell(message).evaluate(script); if (result != null) { messageService.sendMessageSilent(message.getChannel()::sendMessage, "```groovy\n" + String.valueOf(result) + "```"); } } catch (Exception e) { String errorText = String.format("\n`%s`\n\nStack trace:```javascript\n%s", e.getMessage(), ExceptionUtils.getStackTrace(e)); EmbedBuilder builder = messageService.getBaseEmbed(); builder.setTitle(e.getClass().getName()); builder.setColor(Color.RED); builder.setDescription(CommonUtils.trimTo(errorText, 2045) + "```"); messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build()); return fail(message); } return ok(message); }
Example 4
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 5
Source File: AudioMessageManager.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
private EmbedBuilder getBasicMessage(TrackRequest request) { AudioTrackInfo info = request.getTrack().getInfo(); EmbedBuilder builder = messageService.getBaseEmbed(); builder.setTitle(getTitle(info), getUrl(info)); String artworkUri = DiscordUtils.getUrl(TrackData.getArtwork(request.getTrack())); builder.setAuthor(getArtist(info), getUrl(info), artworkUri); builder.setThumbnail(artworkUri); builder.setDescription(messageService.getMessage("discord.command.audio.queue.add")); return builder; }
Example 6
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 7
Source File: InviteCommand.java From JuniperBot with GNU General Public License v3.0 | 5 votes |
private MessageEmbed createInfoMessage(InviteInfo inviteInfo, BotContext context) { EmbedBuilder builder = messageService.getBaseEmbed(false); if (inviteInfo.getGuild() != null) { InviteInfo.Guild guildInfo = inviteInfo.getGuild(); String iconUrl = AvatarType.ICON.getUrl(guildInfo.getId(), guildInfo.getIcon()); String inviteUrl = "https://discord.gg/" + (StringUtils.isNotEmpty(guildInfo.getVanityUrlCode()) ? guildInfo.getVanityUrlCode() : inviteInfo.getCode()); builder.setTitle(String.format("%s (ID: %s)", guildInfo.getName(), guildInfo.getId()), inviteUrl); builder.setDescription(guildInfo.getDescription()); builder.setThumbnail(iconUrl); Guild guild = discordService.getGuildById(Long.valueOf(guildInfo.getId())); if (guild != 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)); } else { if (guildInfo.getVerificationLevel() != null) { builder.addField(getVerificationLevel(Guild.VerificationLevel.fromKey(guildInfo.getVerificationLevel()))); } } } if (inviteInfo.getChannel() != null) { InviteInfo.Channel channel = inviteInfo.getChannel(); String info = String.format("`#%s` (ID: %s)", channel.getName(), channel.getId()); builder.addField(messageService.getMessage("discord.command.invite.channel"), info, true); } if (inviteInfo.getInviter() != null) { InviteInfo.Inviter inviter = inviteInfo.getInviter(); String avatarUrl = StringUtils.isNotEmpty(inviter.getAvatar()) ? AvatarType.AVATAR.getUrl(inviter.getId(), inviter.getAvatar()) : null; builder.setFooter(String.format("%s#%s (ID: %s)", inviter.getUsername(), inviter.getDiscriminator(), inviter.getId()), avatarUrl); } return builder.build(); }
Example 8
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 9
Source File: AbstractStateHandler.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
protected EmbedBuilder getBaseEmbed() { EmbedBuilder embed = messageService.getBaseEmbed(); embed.setTitle(messageService.getMessage("discord.command.group.mafia")); return embed; }
Example 10
Source File: UserInfoCommand.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
@Override public boolean doCommand(MemberReference reference, GuildMessageReceivedEvent event, BotContext context, String query) { DateTimeFormatter formatter = DateTimeFormat.mediumDateTime() .withLocale(contextService.getLocale()) .withZone(context.getTimeZone()); LocalMember localMember = reference.getLocalMember(); LocalUser localUser = reference.getLocalUser(); EmbedBuilder builder = messageService.getBaseEmbed(); builder.setTitle(messageService.getMessage("discord.command.user.title", reference.getEffectiveName())); builder.setThumbnail(reference.getEffectiveAvatarUrl()); builder.setFooter(messageService.getMessage("discord.command.info.identifier", reference.getId()), null); StringBuilder commonBuilder = new StringBuilder(); getName(commonBuilder, reference); if (reference.getMember() != null) { Member member = reference.getMember(); getOnlineStatus(commonBuilder, member); if (CollectionUtils.isNotEmpty(member.getActivities())) { getActivities(commonBuilder, member); } if (member.getOnlineStatus() == OnlineStatus.OFFLINE || member.getOnlineStatus() == OnlineStatus.INVISIBLE) { if (localUser != null && localUser.getLastOnline() != null) { getLastOnlineAt(commonBuilder, localUser, formatter); } } getJoinedAt(commonBuilder, member, formatter); getCreatedAt(commonBuilder, member.getUser(), formatter); } builder.addField(messageService.getMessage("discord.command.user.common"), commonBuilder.toString(), false); Guild guild = event.getGuild(); if (localMember != null) { RankingConfig config = rankingConfigService.get(event.getGuild()); if (config != null && config.isEnabled()) { RankingInfo info = rankingService.getRankingInfo(event.getGuild().getIdLong(), reference.getId()); rankCommand.addFields(builder, config, info, guild); } } MemberBio memberBio = bioRepository.findByGuildIdAndUserId(guild.getIdLong(), reference.getId()); String bio = memberBio != null ? memberBio.getBio() : null; if (StringUtils.isEmpty(bio) && Objects.equals(event.getAuthor(), reference.getUser()) && !commandsService.isRestricted(BioCommand.KEY, event.getChannel(), event.getMember())) { String bioCommand = messageService.getMessageByLocale("discord.command.bio.key", context.getCommandLocale()); bio = messageService.getMessage("discord.command.user.bio.none", context.getConfig().getPrefix(), bioCommand); } if (StringUtils.isNotEmpty(bio)) { builder.setDescription(CommonUtils.trimTo(bio, MessageEmbed.TEXT_MAX_LENGTH)); } messageService.sendMessageSilent(event.getChannel()::sendMessage, builder.build()); return true; }
Example 11
Source File: RemindCommand.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
@Override public boolean doCommand(GuildMessageReceivedEvent message, BotContext context, String content) { try { DateTime date = null; String reminder = null; Matcher m = PATTERN.matcher(content); if (m.find()) { date = getFormatter(context).parseDateTime(String.format("%s %s", m.group(1), m.group(2))); reminder = m.group(3); if (DateTime.now().isAfter(date)) { messageService.onError(message.getChannel(), "discord.command.remind.error.future"); return fail(message); } } String keyWord = messageService.getMessage("discord.command.remind.keyWord"); m = Pattern.compile(String.format(RELATIVE_PATTERN_FORMAT, keyWord)).matcher(content); if (m.find()) { Long millis = TimeSequenceParser.parseFull(m.group(1)); reminder = m.group(2); if (millis != null && StringUtils.isNotEmpty(reminder)) { date = DateTime.now().plus(millis); } } if (date != null && reminder != null) { createReminder(message.getChannel(), message.getMember(), reminder, date.toDate()); return ok(message, "discord.command.remind.done"); } } catch (IllegalArgumentException e) { // fall down } String prefix = context.getConfig() != null ? context.getConfig().getPrefix() : commonProperties.getDiscord().getDefaultPrefix(); String remindCommand = messageService.getMessageByLocale("discord.command.remind.key", context.getCommandLocale()); DateTime current = DateTime.now(); current = current.plusMinutes(1); EmbedBuilder builder = messageService.getBaseEmbed(); builder.setTitle(messageService.getMessage("discord.command.remind.help.title")); builder.addField( messageService.getMessage("discord.command.remind.help.field1.title", CommonUtils.getUTCOffset(context.getTimeZone())), messageService.getMessage("discord.command.remind.help.field1.value", prefix, remindCommand, getFormatter(context).print(current)), false); builder.addField( messageService.getMessage("discord.command.remind.help.field2.title"), messageService.getMessage("discord.command.remind.help.field2.value", prefix, remindCommand), false); messageService.sendMessageSilent(message.getChannel()::sendMessage, builder.build()); return false; }
Example 12
Source File: WarnsCommand.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
@Override public boolean doCommand(MemberReference reference, GuildMessageReceivedEvent event, BotContext context, String query) { LocalMember member = reference.getLocalMember(); List<MemberWarning> warningList = moderationService.getWarnings(member); if (warningList.isEmpty()) { messageService.onEmbedMessage(event.getChannel(), "discord.command.mod.warns.empty"); return false; } if (warningList.size() > 20) { warningList = warningList.subList(0, 20); } EmbedBuilder builder = messageService.getBaseEmbed(); builder.setTitle(messageService.getMessage("discord.command.mod.warns.message.title", member.getEffectiveName())); DateTimeFormatter formatter = DateTimeFormat .shortDateTime() .withZone(context.getTimeZone()) .withLocale(contextService.getLocale()); int i = 1; int length = builder.length(); for (MemberWarning warning : warningList) { String title = String.format("%2s. %s %s (%s)", i++, formatter.print(new DateTime(warning.getDate())), CommonUtils.getUTCOffset(context.getTimeZone()), warning.getModerator().getEffectiveName()); StringBuilder detailsBuilder = new StringBuilder(); if (StringUtils.isNotEmpty(warning.getReason())) { detailsBuilder.append(messageService.getMessage("discord.command.mod.warns.reason", warning.getReason())); } if (warning.getEndDate() != null) { if (detailsBuilder.length() > 0) { detailsBuilder.append("\n"); } detailsBuilder.append(messageService.getMessage("discord.command.mod.warns.until", formatter.print(new DateTime(warning.getEndDate())), CommonUtils.getUTCOffset(context.getTimeZone()))); } if ((length += title.length() + detailsBuilder.length()) > MessageEmbed.EMBED_MAX_LENGTH_BOT) { break; } builder.addField(title, detailsBuilder.toString(), false); } messageService.sendMessageSilent(event.getChannel()::sendMessage, builder.build()); return true; }
Example 13
Source File: MessageTemplateServiceImpl.java From JuniperBot with GNU General Public License v3.0 | 4 votes |
public Message compile(@NonNull MessageTemplateCompiler compiler) { try { MessageTemplatePlaceholderResolver resolver = getPropertyResolver(compiler); String content = processContent(getContent(compiler), resolver, compiler, Message.MAX_CONTENT_LENGTH, false); MessageBuilder messageBuilder = new MessageBuilder(); messageBuilder.setContent(content); if (compiler.getTemplate() != null) { messageBuilder.setTTS(compiler.getTemplate().isTts()); } if (compiler.getTemplate() == null || compiler.getTemplate().getType() == MessageTemplateType.TEXT) { if (StringUtils.isBlank(content)) { return null; } return messageBuilder.build(); } MessageTemplate template = compiler.getTemplate(); EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.setDescription(processContent(getEmbedContent(compiler), resolver, compiler, MessageEmbed.TEXT_MAX_LENGTH, false)); embedBuilder.setThumbnail(processUrl(template.getThumbnailUrl(), resolver, compiler)); embedBuilder.setImage(processUrl(template.getImageUrl(), resolver, compiler)); if (StringUtils.isNotEmpty(template.getColor())) { embedBuilder.setColor(Color.decode(template.getColor())); } else { embedBuilder.setColor(contextService.getDefaultColor()); } if (template.getTimestamp() != null) { embedBuilder.setTimestamp(template.getTimestamp().toInstant()); } embedBuilder.setAuthor( processContent(template.getAuthor(), resolver, compiler, MessageEmbed.TITLE_MAX_LENGTH, false), processUrl(template.getAuthorUrl(), resolver, compiler), processUrl(template.getAuthorIconUrl(), resolver, compiler)); embedBuilder.setTitle( processContent(template.getTitle(), resolver, compiler, MessageEmbed.TITLE_MAX_LENGTH, false), processUrl(template.getTitleUrl(), resolver, compiler)); embedBuilder.setFooter( processContent(template.getFooter(), resolver, compiler, MessageEmbed.TEXT_MAX_LENGTH, false), processUrl(template.getFooterIconUrl(), resolver, compiler)); int length = embedBuilder.length(); if (CollectionUtils.isNotEmpty(template.getFields())) { for (MessageTemplateField templateField : template.getFields()) { String name = processContent(templateField.getName(), resolver, compiler, MessageEmbed.TITLE_MAX_LENGTH, false); if (StringUtils.isEmpty(name)) { name = ""; } String value = processContent(templateField.getValue(), resolver, compiler, MessageEmbed.VALUE_MAX_LENGTH, false); if (StringUtils.isEmpty(value)) { value = ""; } if ((length += name.length() + value.length()) > MessageEmbed.EMBED_MAX_LENGTH_BOT) { break; } embedBuilder.addField(name, value, templateField.isInline()); } } if (messageBuilder.isEmpty() && embedBuilder.isEmpty()) { return null; } messageBuilder.setEmbed(embedBuilder.build()); return messageBuilder.build(); } catch (IllegalArgumentException e) { log.error("Cannot compile message", e); } return null; }