public MessageBuilder(Message message) { if (message != null) { isTTS = message.isTTS(); builder.append(message.getContentRaw()); List<MessageEmbed> embeds = message.getEmbeds(); if (embeds != null && !embeds.isEmpty()) embed = embeds.get(0); } }
/** * Creates a new WebhookMessageBuilder and applies * the information of the provided {@link net.dv8tion.jda.core.entities.Message Message} * as preset values. * <br>This will not copy any attachments! * * @param message * The {@link net.dv8tion.jda.core.entities.Message Message} used * to set initial values of the builder */ public WebhookMessageBuilder(Message message) { if (message != null) { embeds.addAll(message.getEmbeds()); setContent(message.getContentRaw()); isTTS = message.isTTS(); } }
@Override public MessageAction editMessageById(String id, Message newContent) { Checks.notNull(newContent, "Message"); //checkVerification(); no verification needed to edit a message checkPermission(Permission.MESSAGE_READ); checkPermission(Permission.MESSAGE_WRITE); if (newContent.getContentRaw().isEmpty() && !newContent.getEmbeds().isEmpty()) checkPermission(Permission.MESSAGE_EMBED_LINKS); //Call MessageChannel's default return TextChannel.super.editMessageById(id, newContent); }
@Override public MessageAction sendMessage(Message msg) { Checks.notNull(msg, "Message"); checkVerification(); checkPermission(Permission.MESSAGE_READ); checkPermission(Permission.MESSAGE_WRITE); if (msg.getContentRaw().isEmpty() && !msg.getEmbeds().isEmpty()) checkPermission(Permission.MESSAGE_EMBED_LINKS); //Call MessageChannel's default return TextChannel.super.sendMessage(msg); }
/** * Applies the sendable information of the provided {@link net.dv8tion.jda.core.entities.Message Message} * to this MessageAction settings. * <br>This will override all existing settings <b>if</b> new settings are available. * * <p><b>This does not copy files!</b> * * @param message * The nullable Message to apply settings from * * @throws java.lang.IllegalArgumentException * If the message contains an {@link net.dv8tion.jda.core.entities.MessageEmbed MessageEmbed} * that exceeds the sendable character limit, * see {@link net.dv8tion.jda.core.entities.MessageEmbed#isSendable(net.dv8tion.jda.core.AccountType) MessageEmbed.isSendable(AccountType)} * * @return Updated MessageAction for chaining convenience */ @CheckReturnValue public MessageAction apply(final Message message) { if (message == null || message.getType() != MessageType.DEFAULT) return this; final List<MessageEmbed> embeds = message.getEmbeds(); if (embeds != null && !embeds.isEmpty()) embed(embeds.get(0)); files.clear(); return content(message.getContentRaw()).tts(message.isTTS()); }
/** * Creates a new WebhookMessage instance with the provided {@link net.dv8tion.jda.core.entities.Message Message} * as layout for copying. * <br><b>This does not copy the attachments of the provided message!</b> * * @param message * The message to copy * * @throws java.lang.IllegalArgumentException * If the provided message is {@code null} * * @return The resulting WebhookMessage instance */ public static WebhookMessage from(Message message) { Checks.notNull(message, "Message"); final String content = message.getContentRaw(); final List<MessageEmbed> embeds = message.getEmbeds(); final boolean isTTS = message.isTTS(); return new WebhookMessage(null, null, content, embeds, isTTS, null); }
@Override public String getRawMessage() { return message.getContentRaw(); }
public static boolean hasYouTubeLink(Message message) { return YOUTUBE_LINK_REGEX.matcher(message.getContentRaw()).find(); }
public static boolean hasInvite(Message message) { return INVITE_REGEX.matcher(message.getContentRaw()).find(); }
public static boolean hasLink(Message message) { return LINK_REGEX.matcher(message.getContentRaw()).find(); }
public String getContentRaw() { String[] parts = message.getContentRaw().split(" "); return (aliasArguments == null ? "" : aliasArguments) + String.join(" ", Arrays.copyOfRange(parts, isMentionableCommand() ? 2 : 1, parts.length) ); }
public static void editMessage(EmbedBuilder embed, Message message) { editMessage(message.getContentRaw(), embed, message); }
/** * Get the command matching the message raw contents first argument, both * the command prefix and the command trigger must match for the command * to be returned, if the guild/server that the command was executed * in has a custom prefix set the custom prefix will be used to * match the command instead. * <p> * If a commands priority is set to {@link CommandPriority#IGNORED} * the command will be omitted from the search. * * @param message The JDA message object for the current message. * @return Possibly-null, The command matching the given command with the highest priority. */ public static CommandContainer getCommand(Message message) { return getCommand(message, message.getContentRaw().split(" ")[0].toLowerCase()); }
private boolean isMentionableAction(MessageReceivedEvent event) { if (!event.getMessage().isMentioned(avaire.getSelfUser())) { return false; } String[] args = event.getMessage().getContentRaw().split(" "); return args.length >= 2 && userRegEX.matcher(args[0]).matches() && event.getMessage().getMentionedUsers().get(0).getId().equals(avaire.getSelfUser().getId()); }
@Override public void onMessageReceived(MessageReceivedEvent event) { String[] command = event.getMessage().getContentRaw().split(" ", 2); Guild guild = event.getGuild(); if (guild != null) { if ("~play".equals(command[0]) && command.length == 2) { loadAndPlay(event.getTextChannel(), command[1]); } else if ("~skip".equals(command[0])) { skipTrack(event.getTextChannel()); } } super.onMessageReceived(event); }
public void handlePrivateMessage(PrivateChannel channel, User author, Message message) { if (security.isBanned(author)) { return; } if (CommandHandler.isCommand(null, message.getContentRaw(), mentionMe, mentionMeAlias)) { CommandHandler.process(this, channel, author, message); } else { channel.sendTyping().queue(); this.out.sendAsyncMessage(channel, this.chatBotHandler.chat(0L, message.getContentRaw(), channel), null); } }
@Override public void onCommand(User sender, GuildWrapper guild, TextChannel channel, Message msg, String[] args, Member member) { if (PerGuildPermissions.isAdmin(sender)) { if (args.length == 0) { channel.sendMessage("Specify a version or PR to post about!").queue(); return; } if (args[0].startsWith("pr:")) { channel.sendMessage(new MessageBuilder().setEmbed(GitHubUtils.getEmbedForPR(args[0].substring(3)) .build()).build()).queue(); } else { String message = msg.getContentRaw(); message = message.substring(message.indexOf(" ") + 1); channel.sendMessage(message).queue(); } } }
/** * Message fields: * - Message ID * - Author ID * - Channel ID * - Guild ID * - Raw Content * - Timestamp (Epoch seconds) * * @param message The message to serialise * @return The serialised message */ public static String getRedisMessageJson(Message message) { return FlareBot.GSON.toJson(new RedisMessage( message.getId(), message.getAuthor().getId(), message.getChannel().getId(), message.getGuild().getId(), message.getContentRaw(), message.getCreationTime().toInstant().toEpochMilli() )); }
public boolean autoReplied(Message message) { if (message.getChannel() instanceof PrivateChannel) { return false; } if (!(message.getChannel() instanceof TextChannel)) { return false; } TextChannel channel = (TextChannel) message.getChannel(); long guildId = channel.getGuild().getIdLong(); int internalGuildId = CGuild.getCachedId(guildId); Long now = System.currentTimeMillis(); for (int index = 0; index < replies.length; index++) { if (replies[index].guildId == 0 || replies[index].guildId == internalGuildId) { Long lastUse = getCooldown(guildId, index); if (lastUse + replies[index].cooldown < now) { Matcher matcher = replies[index].pattern.matcher(message.getContentRaw()); if (matcher.find()) { saveCooldown(guildId, index, now); bot.out.sendAsyncMessage(channel, message.getAuthor().getAsMention() + ", " + replies[index].reply, null); return true; } } } } return false; }
private void auditLog(Config config, Context context) { String content = String.format("[%s] tried invoking: `%s`", context.getEvent().getAuthor().getAsMention(), context.getEvent().getMessage().getContentRaw()); WebhookMessage message = new WebhookMessageBuilder() .addEmbeds(new EmbedBuilder() .setColor(Color.RED) .setDescription(content) .setTimestamp(new Date().toInstant()) .build()) .setUsername("admin log") .build(); WebhookClient client = new WebhookClientBuilder(config.auditWebhook) .build(); client.send(message); }