net.dv8tion.jda.api.MessageBuilder Java Examples
The following examples show how to use
net.dv8tion.jda.api.MessageBuilder.
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: CustomCommandCommand.java From SkyBot with GNU Affero General Public License v3.0 | 6 votes |
private void listCustomCommands(String arg, GuildMessageReceivedEvent event, CommandManager manager, CommandContext ctx) { if (arg.equalsIgnoreCase("list")) { final GuildSettings s = ctx.getGuildSettings(); final StringBuilder sb = new StringBuilder(); manager.getCustomCommands().stream() .filter(c -> c.getGuildId() == event.getGuild().getIdLong()) .forEach(cmd -> sb.append(s.getCustomPrefix()) .append(cmd.getName()) .append("\n") ); sendMsg(event, new MessageBuilder().append("Custom Commands for this server").append('\n') .appendCodeBlock(sb.toString(), "ldif").build()); } else { sendMsg(event, "Insufficient arguments use `" + ctx.getPrefix() + "help customcommand`"); } }
Example #2
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 #3
Source File: CustomCommandHandler.java From MantaroBot with GNU General Public License v3.0 | 6 votes |
public void handle(boolean preview) { if (!processResponse()) return; if (specialHandling()) return; if (response.startsWith("v3:")) { CCv3.process(prefixUsed, ctx, new Parser(response.substring(3)).parse(), preview); return; } MessageBuilder builder = new MessageBuilder().setContent(filtered1.matcher(response).replaceAll("-filtered regex-")); if (preview) { builder.append("\n\n") .append(EmoteReference.WARNING) .append("**This is a preview of how a CC with this content would look like, ALL MENTIONS ARE DISABLED ON THIS MODE.**\n") .append("`Command preview requested by: ") .append(ctx.getAuthor().getAsTag()) .append("`"); } builder.denyMentions(Message.MentionType.ROLE, Message.MentionType.USER, Message.MentionType.EVERYONE, Message.MentionType.HERE); ctx.send(builder.build()); }
Example #4
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 #5
Source File: MemberMuteAuditForwardProvider.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; } Boolean global = action.getAttribute(GLOBAL_ATTR, Boolean.class); embedBuilder.setDescription(messageService.getMessage(Boolean.TRUE.equals(global) ? "audit.member.mute.message.global" : "audit.member.mute.message", getReferenceContent(action.getTargetUser(), false))); addModeratorField(action, embedBuilder); addChannelField(action, embedBuilder); addReasonField(action, embedBuilder); addExpirationField(action, embedBuilder); Integer duration = action.getAttribute(DURATION_ATTR, Integer.class); if (duration != null) { embedBuilder.addField(messageService.getMessage("audit.member.mute.duration.title"), String.valueOf(duration), true); } embedBuilder.setFooter(messageService.getMessage("audit.member.id", action.getTargetUser().getId()), null); }
Example #6
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 #7
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 #8
Source File: DiscordUtil.java From DiscordSRV with GNU General Public License v3.0 | 6 votes |
/** * Send the given message to the given channel, blocking the thread's execution until it's successfully sent then returning it * @param channel The channel to send the message to * @param message The message to send to the channel * @return The sent message */ public static Message sendMessageBlocking(TextChannel channel, String message) { if (message == null || StringUtils.isBlank(message)) { DiscordSRV.debug("Tried sending a null or blank message"); return null; } if (channel == null) { DiscordSRV.debug("Tried sending a message to a null channel"); return null; } message = translateEmotes(message, channel.getGuild()); return sendMessageBlocking(channel, new MessageBuilder().append(message).build()); }
Example #9
Source File: MessageDeleteAuditForwardProvider.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.delete.message", String.valueOf(action.getGuildId()), action.getChannel().getId(), messageId)); embedBuilder.addField(messageService.getMessage("audit.message.deletedContent.title"), getMessageValue(action, OLD_CONTENT), false); addAuthorField(action, embedBuilder); addChannelField(action, embedBuilder); embedBuilder.setFooter(messageService.getMessage("audit.message.id", messageId), null); }
Example #10
Source File: InfoCommand.java From Yui with Apache License 2.0 | 6 votes |
@Override public void onCommand(MessageReceivedEvent e, String[] args) { MessageBuilder builder = new MessageBuilder(); builder.append("__Yui Information__\n") .append(" **Version**: " + YuiInfo.VERSION.toString().replace("_", "\\_") + "\n") .append(" **ID**: " + e.getJDA().getSelfUser().getId() + "\n") .append("__Creator__\n") .append(" **Name**: DV8FromTheWorld\n") .append(" **ID**: 107562988810027008\n") .append(" **Github**: <http://code.dv8tion.net>\n") .append("__Development__\n") .append(" **Language**: Java 8\n") .append(" **Library**: JDA - v" + JDAInfo.VERSION + "\n") .append(" **Source**: <https://github.com/DV8FromTheWorld/Yui>"); sendMessage(e, builder.build()); }
Example #11
Source File: DiscordUtil.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
/** * Send the given message to the given channel * @param channel The channel to send the message to * @param message The message to send to the channel */ public static void queueMessage(TextChannel channel, String message) { if (channel == null) { DiscordSRV.debug("Tried sending a message to a null channel"); return; } message = translateEmotes(message, channel.getGuild()); queueMessage(channel, new MessageBuilder().append(message).build()); }
Example #12
Source File: ReceivedMessage.java From JDA with Apache License 2.0 | 5 votes |
@Nonnull @Override public MessageAction editMessageFormat(@Nonnull String format, @Nonnull Object... args) { Checks.notBlank(format, "Format String"); return editMessage(new MessageBuilder().appendFormat(format, args).build()); }
Example #13
Source File: DeathMessagePostProcessEvent.java From DiscordSRV with GNU General Public License v3.0 | 5 votes |
@Deprecated public DeathMessagePostProcessEvent(String channel, String processedMessage, Player player, String deathMessage, boolean cancelled) { super(player); this.channel = channel; this.discordMessage = new MessageBuilder().setContent(processedMessage).build(); this.deathMessage = deathMessage; setCancelled(cancelled); }
Example #14
Source File: PermissionsCommand.java From Yui with Apache License 2.0 | 5 votes |
@Override public void onCommand(MessageReceivedEvent e, String[] args) { if (!Permissions.getPermissions().isOp(e.getAuthor())) { sendMessage(e, Permissions.OP_REQUIRED_MESSAGE); return; } if (args[0].contains(".perms") || args[0].contains(".permissions")) { args = ArrayUtils.subarray(args, 1, args.length); //We cut off the .perms or .permissions to make the array behave as .op would } else { args[0] = args[0].replace(".", ""); //Cut off the leading . } if (args.length < 1) //If the command sent was just '.perms', and we removed that above, then we have an array of length 0 currently. { sendMessage(e, "**Improper syntax, no permissions group provided!**"); return; } switch (args[0]) { //Only 1 case for now. Later we will have more user permissions types...probably. case "op": processOp(e, args); break; default: sendMessage(e, new MessageBuilder() .append("**Improper syntax, unrecognized permission group:** ") .append(args[0]) .append("\n**Provided Command:** ") .append(e.getMessage().getContentDisplay()) .build()); return; } }
Example #15
Source File: PermissionsCommand.java From Yui with Apache License 2.0 | 5 votes |
/** * This processes the addOp commands of the format: .perms op add/ .permission op add/ .op add * * @param args * The array of arguments that represent the .perms/.permissions removed command. * @param e * The original UserChatEvent, used to sendMessages. */ private void processAddOp(MessageReceivedEvent e, String[] args) { if (args.length < 3 || e.getMessage().getMentionedUsers().isEmpty()) { sendMessage(e, "Please provide a user!"); return; } for (User user : e.getMessage().getMentionedUsers()) { try { if (Permissions.getPermissions().addOp(user.getId())) { sendMessage(e, "Successfully added " + user.getName() + " to the OPs list!"); return; } else { sendMessage(e, user.getName() + " is already an OP!"); return; } } catch (Exception e1) { sendMessage(e, new MessageBuilder() .append("Encountered an error when attempting to add OP.\n") .append("User: ").append(user.getName()) .append("Error: ").append(e1.getClass().getName()).append("\n") .append("Reason: ").append(e1.getMessage()) .build()); } } }
Example #16
Source File: UpdateCommand.java From Yui with Apache License 2.0 | 5 votes |
@Override public void onCommand(MessageReceivedEvent e, String[] args) { if (!Permissions.getPermissions().isOp(e.getAuthor().getId())) { sendMessage(e, Permissions.OP_REQUIRED_MESSAGE); return; } if (YuiInfo.hasNewBuild()) { sendMessage(e, new MessageBuilder() .append("Updating to the latest version.\n") .append(YuiInfo.VERSION.toString()) .append(" -> ") .append(YuiInfo.getLatestBuildVersion().toString()) .build()); System.exit(Yui.UPDATE_TO_LATEST_BUILD_EXITCODE); } else { sendMessage(e, new MessageBuilder() .append("Yui is currently up-to-date compared to the latest build.\n") .append("Current version: ", MessageBuilder.Formatting.BOLD) .append(YuiInfo.VERSION.toString()) .build()); } }
Example #17
Source File: ImageCmd.java From MantaroBot with GNU General Public License v3.0 | 5 votes |
@Override protected void call(Context ctx, String content) { String random; String id = ""; if (images.size() == 1) { if (type != null) { Pair<String, String> result = weebapi.getRandomImageByType(type, false, null); images = Collections.singletonList(result.getKey()); id = result.getValue(); } random = images.get(0); //Guaranteed random selection :^). } else { random = images.get(rand.nextInt(images.size())); } String extension = random.substring(random.lastIndexOf(".")); MessageBuilder builder = new MessageBuilder(); builder.append(EmoteReference.TALKING); if (!noMentions) { List<User> users = ctx.getMentionedUsers(); var names = users.stream().distinct().map(user -> { var member = ctx.getGuild().getMember(user); if (member == null) { return "unknown"; } return member.getEffectiveName(); }).collect(Collectors.joining(", ")); if (!names.isEmpty()) builder.append("**").append(names).append("**, "); } builder.append(ctx.getLanguageContext().get(toSend)); ctx.getChannel().sendMessage(builder.build()).addFile(CACHE.getInput(random), imageName + "-" + id + "." + extension).queue(); }
Example #18
Source File: HelpCommand.java From Yui with Apache License 2.0 | 5 votes |
@Override public void onCommand(MessageReceivedEvent e, String[] args) { if(!e.isFromType(ChannelType.PRIVATE)) { e.getTextChannel().sendMessage(new MessageBuilder() .append(e.getAuthor()) .append(": Help information was sent as a private message.") .build()).queue(); } sendPrivate(e.getAuthor().openPrivateChannel().complete(), args); }
Example #19
Source File: CCv3.java From MantaroBot with GNU General Public License v3.0 | 5 votes |
public static void process(String prefix, Context ctx, Node ast, boolean preview) { InterpreterContext context = new InterpreterContext(new DynamicModifiers() .mapEvent(prefix, "event", ctx.getEvent()), DEFAULT_OPERATIONS, ctx); String result = ast.accept(new InterpreterVisitor(), context); EmbedJSON embed = context.get("embed"); if (embed == null && result.isEmpty()) { ctx.send("Command response is empty."); return; } MessageBuilder builder = new MessageBuilder().setContent(FILTER.matcher(result).replaceAll("-filtered regex-")); if (preview) { builder.append("\n\n") .append(EmoteReference.WARNING) .append("**This is a preview of how a CC with this content would look like, ALL MENTIONS ARE DISABLED ON THIS MODE.**\n") .append("`Command preview requested by: ") .append(ctx.getAuthor().getAsTag()) .append("`"); } builder.setEmbed(embed == null ? null : embed.gen(ctx.getMember())) .denyMentions(Message.MentionType.ROLE, Message.MentionType.USER, Message.MentionType.EVERYONE, Message.MentionType.HERE); ctx.send(builder.build()); }
Example #20
Source File: ImageCmds.java From MantaroBot with GNU General Public License v3.0 | 5 votes |
@Subscribe public void cat(CommandRegistry cr) { cr.register("cat", new SimpleCommand(CommandCategory.IMAGE) { @Override protected void call(Context ctx, String content, String[] args) { try { Pair<String, String> result = weebAPIRequester.getRandomImageByType("animal_cat", false, null); String url = result.getKey(); ctx.getChannel().sendMessage( new MessageBuilder().append(EmoteReference.TALKING).append( catResponses[random.nextInt(catResponses.length)].replace("%mention%", ctx.getAuthor().getName())) .build() ).addFile(CACHE.getFile(url), "cat-" + result.getValue() + ".png") .queue(); } catch (Exception e) { ctx.sendLocalized("commands.imageboard.cat.error", EmoteReference.ERROR); } } @Override public HelpContent help() { return new HelpContent.Builder() .setDescription("Sends a random cat image. Really cute stuff, you know?") .build(); } }); }
Example #21
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 #22
Source File: TestTagCommand.java From SkyBot with GNU Affero General Public License v3.0 | 5 votes |
@Override public void execute(@Nonnull CommandContext ctx) { if (ctx.getArgs().isEmpty()) { this.sendUsageInstructions(ctx); return; } final GuildMessageReceivedEvent event = ctx.getEvent(); final String input = ctx.getArgsRaw(); if (input.length() > 1000) { sendMsg(event, "Please limit your input to 1000 characters."); return; } final String output = CommandUtils.parseJagTag(ctx, input); final String message = new MessageBuilder() .append("**Input:**") .appendCodeBlock(input, "pascal") .append('\n') .append("**Output:**\n") .append(output) .getStringBuilder().toString(); sendEmbed(event, EmbedUtils.embedMessage(message)); }
Example #23
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 #24
Source File: MemberLeaveAuditForwardProvider.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) { return; } String message = messageService.getMessage("audit.member.leave.message", getReferenceContent(action.getUser(), false)); embedBuilder.setDescription(message); embedBuilder.setFooter(messageService.getMessage("audit.member.id", action.getUser().getId()), null); }
Example #25
Source File: WolframAlphaCommand.java From SkyBot with GNU Affero General Public License v3.0 | 5 votes |
@Override public void execute(@Nonnull CommandContext ctx) { if (!isUserOrGuildPatron(ctx.getEvent())) { return; } final WAEngine engine = getWolframEngine(ctx.getConfig().apis.wolframalpha); if (engine == null) { MessageUtils.sendMsg(ctx, ":x: Wolfram|Alpha function unavailable!"); return; } final AtomicReference<Message> message = new AtomicReference<>(); MessageUtils.sendMsg(ctx, "Calculating.....", message::set); final String queryString = ctx.getArgsRaw(); final WAQuery query = engine.createQuery(queryString); final WAQueryResult result; try { result = engine.performQuery(query); } catch (WAException e) { editMsg(message, ctx.getChannel(), new MessageBuilder() .append(":x: Error: ") .append(e.getClass().getSimpleName()) .append(": ") .append(e.getMessage()) .build()); e.printStackTrace(); return; } editMsg(message, ctx.getChannel(), new MessageBuilder().append("Result:") .setEmbed( generateEmbed(ctx.getEvent(), result, ctx.getConfig().apis.googl, ctx.getVariables().getJackson()) ).build()); }
Example #26
Source File: TagCommand.java From SkyBot with GNU Affero General Public License v3.0 | 5 votes |
private void sendTagRaw(CommandContext ctx, String tagName) { if (!this.tagStore.containsKey(tagName)) { sendMsg(ctx, "That tag does not exist"); return; } final Message message = new MessageBuilder() .appendCodeBlock(this.tagStore.get(tagName).content, "").build(); sendMsg(ctx, message); }
Example #27
Source File: CommandManager.java From SkyBot with GNU Affero General Public License v3.0 | 5 votes |
private void runCustomCommand(ICommand cmd, String invoke, List<String> args, GuildMessageReceivedEvent event) { final CustomCommand cc = (CustomCommand) cmd; if (cc.getGuildId() != event.getGuild().getIdLong()) { return; } try { MDC.put("command.custom.message", cc.getMessage()); final Parser parser = CommandUtils.getParser(new CommandContext(invoke, args, event, variables)); final String message = parser.parse(cc.getMessage()); final MessageBuilder messageBuilder = new MessageBuilder(); final DataObject object = parser.get("embed"); if (!message.isEmpty()) { messageBuilder.setContent("\u200B" + message); } if (object != null) { final JDAImpl jda = (JDAImpl) event.getJDA(); final MessageEmbed embed = jda.getEntityBuilder().createMessageEmbed(object); messageBuilder.setEmbed(embed); } if (!messageBuilder.isEmpty()) { sendMsg(event, messageBuilder.build()); } parser.clear(); } catch (Exception e) { sendMsg(event, "Error with parsing custom command: " + e.getMessage()); Sentry.capture(e); } }
Example #28
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 #29
Source File: VoiceJoinAuditForwardProvider.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.join.message")); embedBuilder.setFooter(messageService.getMessage("audit.member.id", action.getUser().getId()), null); } }
Example #30
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); } }