The files are provided in pairs of {@literal Name->Data} similar + *
+ * The files are provided in pairs of {@literal Name->Data} similar
* to the first 2 arguments.
- *
- * The files are provided in pairs of {@literal Name->Data} similar
+ * The files are provided in pairs of {@literal Name->Data} similar
* to the first 2 arguments.
- * The files are provided in pairs of {@literal Name->Data} similar
+ *
+ * The files are provided in pairs of {@literal Name->Data} similar
* to the first 2 arguments.
- *
- * The files are provided in pairs of {@literal Name->Data} similar
+ * The files are provided in pairs of {@literal Name->Data} similar
* to the first 2 arguments.
- *
The allowed data types are {@code byte[] | InputStream | File}
+ *
+ * The allowed data types are {@code byte[] | InputStream | File}
*
* @param name1
- * The alternative name of the first attachment
+ * The alternative name of the first attachment
* @param data1
- * The first attachment, must be of type {@code byte[] | InputStream | File}
+ * The first attachment, must be of type
+ * {@code byte[] | InputStream | File}
* @param attachments
- * Optional additional attachments to add, pairs of {@literal String->Data}
+ * Optional additional attachments to add, pairs of
+ * {@literal String->Data}
*
* @return A WebhookMessage for the attachments
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If no attachments are provided or more than {@value #MAX_FILES}
- * or the additional arguments are not an even count or an invalid format
+ * If no attachments are provided or
+ * more than {@value #MAX_FILES}
+ * or the additional arguments are
+ * not an even count or an invalid
+ * format
*/
- @NotNull // forcing first pair as we expect at least one entry (Effective Java 3rd. Edition - Item 53)
+ @NotNull // forcing first pair as we expect at least one entry (Effective Java 3rd.
+ // Edition - Item 53)
public static WebhookMessage files(@NotNull String name1, @NotNull Object data1, @NotNull Object... attachments) {
Objects.requireNonNull(name1, "Name");
Objects.requireNonNull(data1, "Data");
@@ -305,14 +352,17 @@ public static WebhookMessage files(@NotNull String name1, @NotNull Object data1,
throw new IllegalArgumentException("Must provide even number of varargs arguments");
int fileAmount = 1 + attachments.length / 2;
if (fileAmount > WebhookMessage.MAX_FILES)
- throw new IllegalArgumentException("Cannot add more than " + WebhookMessage.MAX_FILES + " files to a message");
+ throw new IllegalArgumentException(
+ "Cannot add more than " + WebhookMessage.MAX_FILES + " files to a message");
MessageAttachment[] files = new MessageAttachment[fileAmount];
files[0] = convertAttachment(name1, data1);
for (int i = 0, j = 1; i < attachments.length; j++, i += 2) {
Object name = attachments[i];
Object data = attachments[i + 1];
if (!(name instanceof String))
- throw new IllegalArgumentException("Provided arguments must be pairs for (String, Data). Expected String and found " + (name == null ? null : name.getClass().getName()));
+ throw new IllegalArgumentException(
+ "Provided arguments must be pairs for (String, Data). Expected String and found "
+ + (name == null ? null : name.getClass().getName()));
files[j] = convertAttachment((String) name, data);
}
return new WebhookMessage(null, null, null, null, false, files, AllowedMentions.all(), 0, null);
@@ -329,7 +379,8 @@ public boolean isFile() {
/**
* Provides a {@link okhttp3.RequestBody} of this message.
- *
This is used internally for executing webhooks through HTTP requests.
+ *
+ * This is used internally for executing webhooks through HTTP requests.
*
* @return The request body
*/
@@ -383,10 +434,11 @@ else if (data instanceof InputStream)
else if (data instanceof byte[])
a = new MessageAttachment(name, (byte[]) data);
else
- throw new IllegalArgumentException("Provided arguments must be pairs for (String, Data). Unexpected data type " + data.getClass().getName());
+ throw new IllegalArgumentException(
+ "Provided arguments must be pairs for (String, Data). Unexpected data type "
+ + data.getClass().getName());
return a;
- }
- catch (IOException ex) {
+ } catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
}
diff --git a/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java b/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java
index b3d7cdd..18e6b71 100644
--- a/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java
+++ b/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java
@@ -114,19 +114,19 @@ public WebhookMessageBuilder resetEmbeds() {
/**
* The mention whitelist.
- *
See {@link AllowedMentions} for more details.
+ *
+ * See {@link AllowedMentions} for more details.
*
- * @param mentions
- * The mention whitelist
+ * @param mentions
+ * The mention whitelist
*
* @throws NullPointerException
- * If provided null
+ * If provided null
*
* @return This builder for chaining convenience
*/
@NotNull
- public WebhookMessageBuilder setAllowedMentions(@NotNull AllowedMentions mentions)
- {
+ public WebhookMessageBuilder setAllowedMentions(@NotNull AllowedMentions mentions) {
this.allowedMentions = Objects.requireNonNull(mentions);
return this;
}
@@ -135,14 +135,16 @@ public WebhookMessageBuilder setAllowedMentions(@NotNull AllowedMentions mention
* Adds the provided embeds to the builder
*
* @param embeds
- * The embeds to add
+ * The embeds to add
*
* @return This builder for chaining convenience
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalStateException
- * If more than {@value WebhookMessage#MAX_EMBEDS} are added
+ * If more than
+ * {@value WebhookMessage#MAX_EMBEDS}
+ * are added
*/
@NotNull
public WebhookMessageBuilder addEmbeds(@NotNull WebhookEmbed... embeds) {
@@ -159,15 +161,17 @@ public WebhookMessageBuilder addEmbeds(@NotNull WebhookEmbed... embeds) {
/**
* Adds the provided embeds to the builder
*
- * @param embeds
- * The embeds to add
+ * @param embeds
+ * The embeds to add
*
* @return This builder for chaining convenience
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalStateException
- * If more than {@value WebhookMessage#MAX_EMBEDS} are added
+ * If more than
+ * {@value WebhookMessage#MAX_EMBEDS}
+ * are added
*/
@NotNull
public WebhookMessageBuilder addEmbeds(@NotNull Collection extends WebhookEmbed> embeds) {
@@ -184,13 +188,14 @@ public WebhookMessageBuilder addEmbeds(@NotNull Collection extends WebhookEmbe
/**
* Configures the content for this builder
*
- * @param content
- * The (nullable) content to use
+ * @param content
+ * The (nullable) content to use
*
* @return This builder for chaining convenience
*
* @throws java.lang.IllegalArgumentException
- * If the content is larger than 2000 characters
+ * If the content is larger than 2000
+ * characters
*/
@NotNull
public WebhookMessageBuilder setContent(@Nullable String content) {
@@ -206,15 +211,16 @@ public WebhookMessageBuilder setContent(@Nullable String content) {
* Appends the provided content to the already
* present content in this message.
*
- * @param content
- * The content to append
+ * @param content
+ * The content to append
*
* @return This builder for chaining convenience
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If the content exceeds 2000 characters
+ * If the content exceeds 2000
+ * characters
*/
@NotNull
public WebhookMessageBuilder append(@NotNull String content) {
@@ -227,12 +233,13 @@ public WebhookMessageBuilder append(@NotNull String content) {
/**
* The username to use for this message.
- *
Each message by a webhook can have a different user appearance.
+ *
+ * Each message by a webhook can have a different user appearance.
* If this is not set it will default the user appearance in the settings of
* the webhook.
*
- * @param username
- * The (nullable) username to use
+ * @param username
+ * The (nullable) username to use
*
* @return This builder for chaining convenience
*/
@@ -244,12 +251,13 @@ public WebhookMessageBuilder setUsername(@Nullable String username) {
/**
* The avatar url to use for this message.
- *
Each message by a webhook can have a different user appearance.
+ *
+ * Each message by a webhook can have a different user appearance.
* If this is not set it will default the user appearance in the settings of
* the webhook.
*
- * @param avatarUrl
- * The (nullable) avatar url to use
+ * @param avatarUrl
+ * The (nullable) avatar url to use
*
* @return This builder for chaining convenience
*/
@@ -262,8 +270,8 @@ public WebhookMessageBuilder setAvatarUrl(@Nullable String avatarUrl) {
/**
* Whether this message should use Text-to-Speech (TTS)
*
- * @param tts
- * True, if this message should use tts
+ * @param tts
+ * True, if this message should use tts
*
* @return This builder for chaining convenience
*/
@@ -274,10 +282,11 @@ public WebhookMessageBuilder setTTS(boolean tts) {
}
/**
- * Whether the message should be ephemeral (only works for interaction webhooks).
+ * Whether the message should be ephemeral (only works for interaction
+ * webhooks).
*
- * @param ephemeral
- * True if the message should be ephemeral, false otherwise
+ * @param ephemeral
+ * True if the message should be ephemeral, false otherwise
*
* @return This builder for chaining convenience
*/
@@ -290,17 +299,36 @@ public WebhookMessageBuilder setEphemeral(boolean ephemeral) {
return this;
}
+ /**
+ * Whether the message should be silent
+ *
+ * @param silent
+ * True if the message should be sent silently, false otherwise
+ *
+ * @return This builder for chaining convenience
+ */
+ @NotNull
+ public WebhookMessageBuilder setSilent(boolean silent) {
+ if (silent)
+ flags |= MessageFlags.SUPPRESS_NOTIFICATIONS;
+ else
+ flags &= ~MessageFlags.SUPPRESS_NOTIFICATIONS;
+ return this;
+ }
+
/**
* Adds the provided file as an attachment to this message.
- *
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
+ *
+ * A single message can have up to {@value WebhookMessage#MAX_FILES}
+ * attachments.
*
* @param file
- * The file to attach
+ * The file to attach
*
* @return This builder for chaining convenience
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*/
@NotNull
public WebhookMessageBuilder addFile(@NotNull File file) {
@@ -310,15 +338,17 @@ public WebhookMessageBuilder addFile(@NotNull File file) {
/**
* Adds the provided file as an attachment to this message.
- *
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
+ *
+ * A single message can have up to {@value WebhookMessage#MAX_FILES}
+ * attachments.
*
- * @param name
- * The alternative name that should be used instead
- * @param file
- * The file to attach
+ * @param name
+ * The alternative name that should be used instead
+ * @param file
+ * The file to attach
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*
* @return This builder for chaining convenience
*/
@@ -326,31 +356,34 @@ public WebhookMessageBuilder addFile(@NotNull File file) {
public WebhookMessageBuilder addFile(@NotNull String name, @NotNull File file) {
Objects.requireNonNull(file, "File");
Objects.requireNonNull(name, "Name");
- if (!file.exists() || !file.canRead()) throw new IllegalArgumentException("File must exist and be readable");
+ if (!file.exists() || !file.canRead())
+ throw new IllegalArgumentException("File must exist and be readable");
if (fileIndex >= WebhookMessage.MAX_FILES)
- throw new IllegalStateException("Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
+ throw new IllegalStateException(
+ "Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
try {
MessageAttachment attachment = new MessageAttachment(name, file);
files[fileIndex++] = attachment;
return this;
- }
- catch (IOException ex) {
+ } catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
}
/**
* Adds the provided data as a file attachment to this message.
- *
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
+ *
+ * A single message can have up to {@value WebhookMessage#MAX_FILES}
+ * attachments.
*
- * @param name
- * The alternative name that should be used
- * @param data
- * The data to attach as a file
+ * @param name
+ * The alternative name that should be used
+ * @param data
+ * The data to attach as a file
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*
* @return This builder for chaining convenience
*/
@@ -359,7 +392,8 @@ public WebhookMessageBuilder addFile(@NotNull String name, @NotNull byte[] data)
Objects.requireNonNull(data, "Data");
Objects.requireNonNull(name, "Name");
if (fileIndex >= WebhookMessage.MAX_FILES)
- throw new IllegalStateException("Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
+ throw new IllegalStateException(
+ "Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
MessageAttachment attachment = new MessageAttachment(name, data);
files[fileIndex++] = attachment;
@@ -368,15 +402,17 @@ public WebhookMessageBuilder addFile(@NotNull String name, @NotNull byte[] data)
/**
* Adds the provided data as a file attachment to this message.
- *
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
+ *
+ * A single message can have up to {@value WebhookMessage#MAX_FILES}
+ * attachments.
*
- * @param name
- * The alternative name that should be used
- * @param data
- * The data to attach as a file
+ * @param name
+ * The alternative name that should be used
+ * @param data
+ * The data to attach as a file
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*
* @return This builder for chaining convenience
*/
@@ -385,24 +421,25 @@ public WebhookMessageBuilder addFile(@NotNull String name, @NotNull InputStream
Objects.requireNonNull(data, "InputStream");
Objects.requireNonNull(name, "Name");
if (fileIndex >= WebhookMessage.MAX_FILES)
- throw new IllegalStateException("Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
+ throw new IllegalStateException(
+ "Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
try {
MessageAttachment attachment = new MessageAttachment(name, data);
files[fileIndex++] = attachment;
return this;
- }
- catch (IOException ex) {
+ } catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
}
/**
* Sets the provided name as the name for a newly created thread.
- *
This is only valid for forum/media channels.
+ *
+ * This is only valid for forum/media channels.
*
- * @param name
- * The name that should be used
+ * @param name
+ * The name that should be used
*
* @return This builder for chaining convenience
*/
@@ -416,7 +453,8 @@ public WebhookMessageBuilder setThreadName(@Nullable String name) {
* Constructs the {@link club.minnced.discord.webhook.send.WebhookMessage}
* from the current configurations.
*
- * @return The resulting {@link club.minnced.discord.webhook.send.WebhookMessage}
+ * @return The resulting
+ * {@link club.minnced.discord.webhook.send.WebhookMessage}
*/
@NotNull
public WebhookMessage build() {
@@ -426,7 +464,6 @@ public WebhookMessage build() {
fileIndex == 0 ? null : Arrays.copyOf(files, fileIndex), allowedMentions, flags, threadName);
}
-
/////////////////////////////////
/// Third-party compatibility ///
/////////////////////////////////
@@ -434,11 +471,11 @@ public WebhookMessage build() {
/**
* Converts a JDA {@link Message} into a compatible WebhookMessageBuilder.
*
- * @param message
- * The message
+ * @param message
+ * The message
*
* @throws NullPointerException
- * If null is provided
+ * If null is provided
*
* @return WebhookMessageBuilder with the converted data
*/
@@ -450,11 +487,11 @@ public static WebhookMessageBuilder fromJDA(@NotNull net.dv8tion.jda.api.entitie
/**
* Converts a JDA {@link Message} into a compatible WebhookMessageBuilder.
*
- * @param message
- * The message
+ * @param message
+ * The message
*
* @throws NullPointerException
- * If null is provided
+ * If null is provided
*
* @return WebhookMessageBuilder with the converted data
*/
@@ -469,26 +506,25 @@ public static WebhookMessageBuilder fromJDA(@NotNull MessageCreateData message)
Set
- * A {@link club.minnced.discord.webhook.receive.ReadonlyMessage} can be sent
- * by first converting it to a WebhookMessage with
- * {@link #from(club.minnced.discord.webhook.receive.ReadonlyMessage)}.
+ *
A {@link club.minnced.discord.webhook.receive.ReadonlyMessage} can be sent
+ * by first converting it to a WebhookMessage with {@link #from(club.minnced.discord.webhook.receive.ReadonlyMessage)}.
*/
public class WebhookMessage {
/**
@@ -55,9 +53,9 @@ public class WebhookMessage {
protected final String threadName;
protected WebhookMessage(final String username, final String avatarUrl, final String content,
- final List
- * This instance remains unchanged and a new instance is returned.
+ * Returns a new WebhookMessage instance with the ephemeral flag turned on/off (true/false).
+ *
This instance remains unchanged and a new instance is returned.
*
- * @param ephemeral
- * Whether to make this message ephemeral
+ * @param ephemeral
+ * Whether to make this message ephemeral
*
* @return New WebhookMessage instance
*/
@@ -155,43 +151,19 @@ public WebhookMessage asEphemeral(boolean ephemeral) {
flags |= MessageFlags.EPHEMERAL;
else
flags &= ~MessageFlags.EPHEMERAL;
- return new WebhookMessage(username, avatarUrl, content, embeds, isTTS, attachments, allowedMentions, flags,
- threadName);
- }
-
- /**
- * Returns a new WebhookMessage instance with the silent flag turned on/off
- * (true/false).
- *
- * This instance remains unchanged and a new instance is returned.
- *
- * @param silent
- * Whether to make this message silent
- *
- * @return New WebhookMessage instance
- */
- @NotNull
- public WebhookMessage asSilent(boolean silent) {
- int flags = this.flags;
- if (silent)
- flags |= MessageFlags.SUPPRESS_NOTIFICATIONS;
- else
- flags &= ~MessageFlags.SUPPRESS_NOTIFICATIONS;
- return new WebhookMessage(username, avatarUrl, content, embeds, isTTS, attachments, allowedMentions, flags,
- threadName);
+ return new WebhookMessage(username, avatarUrl, content, embeds, isTTS, attachments, allowedMentions, flags, threadName);
}
/**
* Converts a {@link club.minnced.discord.webhook.receive.ReadonlyMessage} to a
* WebhookMessage.
- *
- * This does not convert attachments.
+ *
This does not convert attachments.
*
- * @param message
- * The message to convert
+ * @param message
+ * The message to convert
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*
* @return A WebhookMessage copy
*/
@@ -204,7 +176,6 @@ public static WebhookMessage from(@NotNull ReadonlyMessage message) {
builder.setContent(message.getContent());
builder.setTTS(message.isTTS());
builder.setEphemeral((message.getFlags() & MessageFlags.EPHEMERAL) != 0);
- builder.setSilent((message.getFlags() & MessageFlags.SUPPRESS_NOTIFICATIONS) != 0);
builder.addEmbeds(message.getEmbeds());
return builder.build();
}
@@ -214,21 +185,18 @@ public static WebhookMessage from(@NotNull ReadonlyMessage message) {
* the provided embeds. A message can hold up to {@value #MAX_EMBEDS} embeds.
*
* @param first
- * The first embed
+ * The first embed
* @param embeds
- * Optional additional embeds for the message
+ * Optional additional embeds for the message
*
* @return A WebhookMessage for the embeds
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If more than
- * {@value WebhookMessage#MAX_EMBEDS}
- * are provided
+ * If more than {@value WebhookMessage#MAX_EMBEDS} are provided
*/
- @NotNull // forcing first embed as we expect at least one entry (Effective Java 3rd.
- // Edition - Item 53)
+ @NotNull // forcing first embed as we expect at least one entry (Effective Java 3rd. Edition - Item 53)
public static WebhookMessage embeds(@NotNull WebhookEmbed first, @NotNull WebhookEmbed... embeds) {
Objects.requireNonNull(embeds, "Embeds");
if (embeds.length >= WebhookMessage.MAX_EMBEDS)
@@ -246,15 +214,13 @@ public static WebhookMessage embeds(@NotNull WebhookEmbed first, @NotNull Webhoo
* Creates a WebhookMessage from
* the provided embeds. A message can hold up to {@value #MAX_EMBEDS} embeds.
*
- * @param embeds
- * Embeds for the message
+ * @param embeds
+ * Embeds for the message
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If more than
- * {@value WebhookMessage#MAX_EMBEDS}
- * are provided
+ * If more than {@value WebhookMessage#MAX_EMBEDS} are provided
*
* @return A WebhookMessage for the embeds
*/
@@ -266,25 +232,22 @@ public static WebhookMessage embeds(@NotNull Collection
- * A message can hold up to {@value #MAX_FILES} attachments
+ *
A message can hold up to {@value #MAX_FILES} attachments
* and a total of 8MiB of data.
*
- * @param attachments
- * The attachments to add, keys are the alternative names
- * for each attachment
+ * @param attachments
+ * The attachments to add, keys are the alternative names
+ * for each attachment
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If no attachments are provided or
- * more than {@value #MAX_FILES}
+ * If no attachments are provided or more than {@value #MAX_FILES}
*
* @return A WebhookMessage for the attachments
*/
@@ -296,8 +259,7 @@ public static WebhookMessage files(@NotNull Map
- * A message can hold up to {@value #MAX_FILES} attachments
+ *
A message can hold up to {@value #MAX_FILES} attachments
* and a total of 8MiB of data.
*
- *
- * The allowed data types are {@code byte[] | InputStream | File}
+ *
The allowed data types are {@code byte[] | InputStream | File}
*
* @param name1
- * The alternative name of the first attachment
+ * The alternative name of the first attachment
* @param data1
- * The first attachment, must be of type
- * {@code byte[] | InputStream | File}
+ * The first attachment, must be of type {@code byte[] | InputStream | File}
* @param attachments
- * Optional additional attachments to add, pairs of
- * {@literal String->Data}
+ * Optional additional attachments to add, pairs of {@literal String->Data}
*
* @return A WebhookMessage for the attachments
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If no attachments are provided or
- * more than {@value #MAX_FILES}
- * or the additional arguments are
- * not an even count or an invalid
- * format
+ * If no attachments are provided or more than {@value #MAX_FILES}
+ * or the additional arguments are not an even count or an invalid format
*/
- @NotNull // forcing first pair as we expect at least one entry (Effective Java 3rd.
- // Edition - Item 53)
+ @NotNull // forcing first pair as we expect at least one entry (Effective Java 3rd. Edition - Item 53)
public static WebhookMessage files(@NotNull String name1, @NotNull Object data1, @NotNull Object... attachments) {
Objects.requireNonNull(name1, "Name");
Objects.requireNonNull(data1, "Data");
@@ -352,17 +305,14 @@ public static WebhookMessage files(@NotNull String name1, @NotNull Object data1,
throw new IllegalArgumentException("Must provide even number of varargs arguments");
int fileAmount = 1 + attachments.length / 2;
if (fileAmount > WebhookMessage.MAX_FILES)
- throw new IllegalArgumentException(
- "Cannot add more than " + WebhookMessage.MAX_FILES + " files to a message");
+ throw new IllegalArgumentException("Cannot add more than " + WebhookMessage.MAX_FILES + " files to a message");
MessageAttachment[] files = new MessageAttachment[fileAmount];
files[0] = convertAttachment(name1, data1);
for (int i = 0, j = 1; i < attachments.length; j++, i += 2) {
Object name = attachments[i];
Object data = attachments[i + 1];
if (!(name instanceof String))
- throw new IllegalArgumentException(
- "Provided arguments must be pairs for (String, Data). Expected String and found "
- + (name == null ? null : name.getClass().getName()));
+ throw new IllegalArgumentException("Provided arguments must be pairs for (String, Data). Expected String and found " + (name == null ? null : name.getClass().getName()));
files[j] = convertAttachment((String) name, data);
}
return new WebhookMessage(null, null, null, null, false, files, AllowedMentions.all(), 0, null);
@@ -379,8 +329,7 @@ public boolean isFile() {
/**
* Provides a {@link okhttp3.RequestBody} of this message.
- *
- * This is used internally for executing webhooks through HTTP requests.
+ *
This is used internally for executing webhooks through HTTP requests.
*
* @return The request body
*/
@@ -434,11 +383,10 @@ else if (data instanceof InputStream)
else if (data instanceof byte[])
a = new MessageAttachment(name, (byte[]) data);
else
- throw new IllegalArgumentException(
- "Provided arguments must be pairs for (String, Data). Unexpected data type "
- + data.getClass().getName());
+ throw new IllegalArgumentException("Provided arguments must be pairs for (String, Data). Unexpected data type " + data.getClass().getName());
return a;
- } catch (IOException ex) {
+ }
+ catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
}
diff --git a/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java b/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java
index 18e6b71..b3d7cdd 100644
--- a/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java
+++ b/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java
@@ -114,19 +114,19 @@ public WebhookMessageBuilder resetEmbeds() {
/**
* The mention whitelist.
- *
- * See {@link AllowedMentions} for more details.
+ *
See {@link AllowedMentions} for more details.
*
- * @param mentions
- * The mention whitelist
+ * @param mentions
+ * The mention whitelist
*
* @throws NullPointerException
- * If provided null
+ * If provided null
*
* @return This builder for chaining convenience
*/
@NotNull
- public WebhookMessageBuilder setAllowedMentions(@NotNull AllowedMentions mentions) {
+ public WebhookMessageBuilder setAllowedMentions(@NotNull AllowedMentions mentions)
+ {
this.allowedMentions = Objects.requireNonNull(mentions);
return this;
}
@@ -135,16 +135,14 @@ public WebhookMessageBuilder setAllowedMentions(@NotNull AllowedMentions mention
* Adds the provided embeds to the builder
*
* @param embeds
- * The embeds to add
+ * The embeds to add
*
* @return This builder for chaining convenience
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalStateException
- * If more than
- * {@value WebhookMessage#MAX_EMBEDS}
- * are added
+ * If more than {@value WebhookMessage#MAX_EMBEDS} are added
*/
@NotNull
public WebhookMessageBuilder addEmbeds(@NotNull WebhookEmbed... embeds) {
@@ -161,17 +159,15 @@ public WebhookMessageBuilder addEmbeds(@NotNull WebhookEmbed... embeds) {
/**
* Adds the provided embeds to the builder
*
- * @param embeds
- * The embeds to add
+ * @param embeds
+ * The embeds to add
*
* @return This builder for chaining convenience
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalStateException
- * If more than
- * {@value WebhookMessage#MAX_EMBEDS}
- * are added
+ * If more than {@value WebhookMessage#MAX_EMBEDS} are added
*/
@NotNull
public WebhookMessageBuilder addEmbeds(@NotNull Collection extends WebhookEmbed> embeds) {
@@ -188,14 +184,13 @@ public WebhookMessageBuilder addEmbeds(@NotNull Collection extends WebhookEmbe
/**
* Configures the content for this builder
*
- * @param content
- * The (nullable) content to use
+ * @param content
+ * The (nullable) content to use
*
* @return This builder for chaining convenience
*
* @throws java.lang.IllegalArgumentException
- * If the content is larger than 2000
- * characters
+ * If the content is larger than 2000 characters
*/
@NotNull
public WebhookMessageBuilder setContent(@Nullable String content) {
@@ -211,16 +206,15 @@ public WebhookMessageBuilder setContent(@Nullable String content) {
* Appends the provided content to the already
* present content in this message.
*
- * @param content
- * The content to append
+ * @param content
+ * The content to append
*
* @return This builder for chaining convenience
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If the content exceeds 2000
- * characters
+ * If the content exceeds 2000 characters
*/
@NotNull
public WebhookMessageBuilder append(@NotNull String content) {
@@ -233,13 +227,12 @@ public WebhookMessageBuilder append(@NotNull String content) {
/**
* The username to use for this message.
- *
- * Each message by a webhook can have a different user appearance.
+ *
Each message by a webhook can have a different user appearance.
* If this is not set it will default the user appearance in the settings of
* the webhook.
*
- * @param username
- * The (nullable) username to use
+ * @param username
+ * The (nullable) username to use
*
* @return This builder for chaining convenience
*/
@@ -251,13 +244,12 @@ public WebhookMessageBuilder setUsername(@Nullable String username) {
/**
* The avatar url to use for this message.
- *
- * Each message by a webhook can have a different user appearance.
+ *
Each message by a webhook can have a different user appearance.
* If this is not set it will default the user appearance in the settings of
* the webhook.
*
- * @param avatarUrl
- * The (nullable) avatar url to use
+ * @param avatarUrl
+ * The (nullable) avatar url to use
*
* @return This builder for chaining convenience
*/
@@ -270,8 +262,8 @@ public WebhookMessageBuilder setAvatarUrl(@Nullable String avatarUrl) {
/**
* Whether this message should use Text-to-Speech (TTS)
*
- * @param tts
- * True, if this message should use tts
+ * @param tts
+ * True, if this message should use tts
*
* @return This builder for chaining convenience
*/
@@ -282,11 +274,10 @@ public WebhookMessageBuilder setTTS(boolean tts) {
}
/**
- * Whether the message should be ephemeral (only works for interaction
- * webhooks).
+ * Whether the message should be ephemeral (only works for interaction webhooks).
*
- * @param ephemeral
- * True if the message should be ephemeral, false otherwise
+ * @param ephemeral
+ * True if the message should be ephemeral, false otherwise
*
* @return This builder for chaining convenience
*/
@@ -299,36 +290,17 @@ public WebhookMessageBuilder setEphemeral(boolean ephemeral) {
return this;
}
- /**
- * Whether the message should be silent
- *
- * @param silent
- * True if the message should be sent silently, false otherwise
- *
- * @return This builder for chaining convenience
- */
- @NotNull
- public WebhookMessageBuilder setSilent(boolean silent) {
- if (silent)
- flags |= MessageFlags.SUPPRESS_NOTIFICATIONS;
- else
- flags &= ~MessageFlags.SUPPRESS_NOTIFICATIONS;
- return this;
- }
-
/**
* Adds the provided file as an attachment to this message.
- *
- * A single message can have up to {@value WebhookMessage#MAX_FILES}
- * attachments.
+ *
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
*
* @param file
- * The file to attach
+ * The file to attach
*
* @return This builder for chaining convenience
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*/
@NotNull
public WebhookMessageBuilder addFile(@NotNull File file) {
@@ -338,17 +310,15 @@ public WebhookMessageBuilder addFile(@NotNull File file) {
/**
* Adds the provided file as an attachment to this message.
- *
- * A single message can have up to {@value WebhookMessage#MAX_FILES}
- * attachments.
+ *
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
*
- * @param name
- * The alternative name that should be used instead
- * @param file
- * The file to attach
+ * @param name
+ * The alternative name that should be used instead
+ * @param file
+ * The file to attach
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*
* @return This builder for chaining convenience
*/
@@ -356,34 +326,31 @@ public WebhookMessageBuilder addFile(@NotNull File file) {
public WebhookMessageBuilder addFile(@NotNull String name, @NotNull File file) {
Objects.requireNonNull(file, "File");
Objects.requireNonNull(name, "Name");
- if (!file.exists() || !file.canRead())
- throw new IllegalArgumentException("File must exist and be readable");
+ if (!file.exists() || !file.canRead()) throw new IllegalArgumentException("File must exist and be readable");
if (fileIndex >= WebhookMessage.MAX_FILES)
- throw new IllegalStateException(
- "Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
+ throw new IllegalStateException("Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
try {
MessageAttachment attachment = new MessageAttachment(name, file);
files[fileIndex++] = attachment;
return this;
- } catch (IOException ex) {
+ }
+ catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
}
/**
* Adds the provided data as a file attachment to this message.
- *
- * A single message can have up to {@value WebhookMessage#MAX_FILES}
- * attachments.
+ *
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
*
- * @param name
- * The alternative name that should be used
- * @param data
- * The data to attach as a file
+ * @param name
+ * The alternative name that should be used
+ * @param data
+ * The data to attach as a file
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*
* @return This builder for chaining convenience
*/
@@ -392,8 +359,7 @@ public WebhookMessageBuilder addFile(@NotNull String name, @NotNull byte[] data)
Objects.requireNonNull(data, "Data");
Objects.requireNonNull(name, "Name");
if (fileIndex >= WebhookMessage.MAX_FILES)
- throw new IllegalStateException(
- "Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
+ throw new IllegalStateException("Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
MessageAttachment attachment = new MessageAttachment(name, data);
files[fileIndex++] = attachment;
@@ -402,17 +368,15 @@ public WebhookMessageBuilder addFile(@NotNull String name, @NotNull byte[] data)
/**
* Adds the provided data as a file attachment to this message.
- *
- * A single message can have up to {@value WebhookMessage#MAX_FILES}
- * attachments.
+ *
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
*
- * @param name
- * The alternative name that should be used
- * @param data
- * The data to attach as a file
+ * @param name
+ * The alternative name that should be used
+ * @param data
+ * The data to attach as a file
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*
* @return This builder for chaining convenience
*/
@@ -421,25 +385,24 @@ public WebhookMessageBuilder addFile(@NotNull String name, @NotNull InputStream
Objects.requireNonNull(data, "InputStream");
Objects.requireNonNull(name, "Name");
if (fileIndex >= WebhookMessage.MAX_FILES)
- throw new IllegalStateException(
- "Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
+ throw new IllegalStateException("Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
try {
MessageAttachment attachment = new MessageAttachment(name, data);
files[fileIndex++] = attachment;
return this;
- } catch (IOException ex) {
+ }
+ catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
}
/**
* Sets the provided name as the name for a newly created thread.
- *
- * This is only valid for forum/media channels.
+ *
This is only valid for forum/media channels.
*
- * @param name
- * The name that should be used
+ * @param name
+ * The name that should be used
*
* @return This builder for chaining convenience
*/
@@ -453,8 +416,7 @@ public WebhookMessageBuilder setThreadName(@Nullable String name) {
* Constructs the {@link club.minnced.discord.webhook.send.WebhookMessage}
* from the current configurations.
*
- * @return The resulting
- * {@link club.minnced.discord.webhook.send.WebhookMessage}
+ * @return The resulting {@link club.minnced.discord.webhook.send.WebhookMessage}
*/
@NotNull
public WebhookMessage build() {
@@ -464,6 +426,7 @@ public WebhookMessage build() {
fileIndex == 0 ? null : Arrays.copyOf(files, fileIndex), allowedMentions, flags, threadName);
}
+
/////////////////////////////////
/// Third-party compatibility ///
/////////////////////////////////
@@ -471,11 +434,11 @@ public WebhookMessage build() {
/**
* Converts a JDA {@link Message} into a compatible WebhookMessageBuilder.
*
- * @param message
- * The message
+ * @param message
+ * The message
*
* @throws NullPointerException
- * If null is provided
+ * If null is provided
*
* @return WebhookMessageBuilder with the converted data
*/
@@ -487,11 +450,11 @@ public static WebhookMessageBuilder fromJDA(@NotNull net.dv8tion.jda.api.entitie
/**
* Converts a JDA {@link Message} into a compatible WebhookMessageBuilder.
*
- * @param message
- * The message
+ * @param message
+ * The message
*
* @throws NullPointerException
- * If null is provided
+ * If null is provided
*
* @return WebhookMessageBuilder with the converted data
*/
@@ -506,25 +469,26 @@ public static WebhookMessageBuilder fromJDA(@NotNull MessageCreateData message)
Set
A {@link club.minnced.discord.webhook.receive.ReadonlyMessage} can be sent
- * by first converting it to a WebhookMessage with {@link #from(club.minnced.discord.webhook.receive.ReadonlyMessage)}.
+ *
+ * A {@link club.minnced.discord.webhook.receive.ReadonlyMessage} can be sent
+ * by first converting it to a WebhookMessage with
+ * {@link #from(club.minnced.discord.webhook.receive.ReadonlyMessage)}.
*/
public class WebhookMessage {
/**
@@ -53,9 +55,9 @@ public class WebhookMessage {
protected final String threadName;
protected WebhookMessage(final String username, final String avatarUrl, final String content,
- final List
This instance remains unchanged and a new instance is returned.
+ * Returns a new WebhookMessage instance with the ephemeral flag turned on/off
+ * (true/false).
+ *
+ * This instance remains unchanged and a new instance is returned.
*
- * @param ephemeral
- * Whether to make this message ephemeral
+ * @param ephemeral
+ * Whether to make this message ephemeral
*
* @return New WebhookMessage instance
*/
@@ -151,19 +155,43 @@ public WebhookMessage asEphemeral(boolean ephemeral) {
flags |= MessageFlags.EPHEMERAL;
else
flags &= ~MessageFlags.EPHEMERAL;
- return new WebhookMessage(username, avatarUrl, content, embeds, isTTS, attachments, allowedMentions, flags, threadName);
+ return new WebhookMessage(username, avatarUrl, content, embeds, isTTS, attachments, allowedMentions, flags,
+ threadName);
+ }
+
+ /**
+ * Returns a new WebhookMessage instance with the silent flag turned on/off
+ * (true/false).
+ *
+ * This instance remains unchanged and a new instance is returned.
+ *
+ * @param silent
+ * Whether to make this message silent
+ *
+ * @return New WebhookMessage instance
+ */
+ @NotNull
+ public WebhookMessage asSilent(boolean silent) {
+ int flags = this.flags;
+ if (silent)
+ flags |= MessageFlags.SUPPRESS_NOTIFICATIONS;
+ else
+ flags &= ~MessageFlags.SUPPRESS_NOTIFICATIONS;
+ return new WebhookMessage(username, avatarUrl, content, embeds, isTTS, attachments, allowedMentions, flags,
+ threadName);
}
/**
* Converts a {@link club.minnced.discord.webhook.receive.ReadonlyMessage} to a
* WebhookMessage.
- *
This does not convert attachments.
+ *
+ * This does not convert attachments.
*
- * @param message
- * The message to convert
+ * @param message
+ * The message to convert
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*
* @return A WebhookMessage copy
*/
@@ -176,6 +204,7 @@ public static WebhookMessage from(@NotNull ReadonlyMessage message) {
builder.setContent(message.getContent());
builder.setTTS(message.isTTS());
builder.setEphemeral((message.getFlags() & MessageFlags.EPHEMERAL) != 0);
+ builder.setSilent((message.getFlags() & MessageFlags.SUPPRESS_NOTIFICATIONS) != 0);
builder.addEmbeds(message.getEmbeds());
return builder.build();
}
@@ -185,18 +214,21 @@ public static WebhookMessage from(@NotNull ReadonlyMessage message) {
* the provided embeds. A message can hold up to {@value #MAX_EMBEDS} embeds.
*
* @param first
- * The first embed
+ * The first embed
* @param embeds
- * Optional additional embeds for the message
+ * Optional additional embeds for the message
*
* @return A WebhookMessage for the embeds
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If more than {@value WebhookMessage#MAX_EMBEDS} are provided
+ * If more than
+ * {@value WebhookMessage#MAX_EMBEDS}
+ * are provided
*/
- @NotNull // forcing first embed as we expect at least one entry (Effective Java 3rd. Edition - Item 53)
+ @NotNull // forcing first embed as we expect at least one entry (Effective Java 3rd.
+ // Edition - Item 53)
public static WebhookMessage embeds(@NotNull WebhookEmbed first, @NotNull WebhookEmbed... embeds) {
Objects.requireNonNull(embeds, "Embeds");
if (embeds.length >= WebhookMessage.MAX_EMBEDS)
@@ -214,13 +246,15 @@ public static WebhookMessage embeds(@NotNull WebhookEmbed first, @NotNull Webhoo
* Creates a WebhookMessage from
* the provided embeds. A message can hold up to {@value #MAX_EMBEDS} embeds.
*
- * @param embeds
- * Embeds for the message
+ * @param embeds
+ * Embeds for the message
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If more than {@value WebhookMessage#MAX_EMBEDS} are provided
+ * If more than
+ * {@value WebhookMessage#MAX_EMBEDS}
+ * are provided
*
* @return A WebhookMessage for the embeds
*/
@@ -232,22 +266,25 @@ public static WebhookMessage embeds(@NotNull Collection
A message can hold up to {@value #MAX_FILES} attachments
+ *
+ * A message can hold up to {@value #MAX_FILES} attachments
* and a total of 8MiB of data.
*
- * @param attachments
- * The attachments to add, keys are the alternative names
- * for each attachment
+ * @param attachments
+ * The attachments to add, keys are the alternative names
+ * for each attachment
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If no attachments are provided or more than {@value #MAX_FILES}
+ * If no attachments are provided or
+ * more than {@value #MAX_FILES}
*
* @return A WebhookMessage for the attachments
*/
@@ -259,7 +296,8 @@ public static WebhookMessage files(@NotNull Map
A message can hold up to {@value #MAX_FILES} attachments
+ *
+ * A message can hold up to {@value #MAX_FILES} attachments
* and a total of 8MiB of data.
*
- *
The allowed data types are {@code byte[] | InputStream | File}
+ *
+ * The allowed data types are {@code byte[] | InputStream | File}
*
* @param name1
- * The alternative name of the first attachment
+ * The alternative name of the first attachment
* @param data1
- * The first attachment, must be of type {@code byte[] | InputStream | File}
+ * The first attachment, must be of type
+ * {@code byte[] | InputStream | File}
* @param attachments
- * Optional additional attachments to add, pairs of {@literal String->Data}
+ * Optional additional attachments to add, pairs of
+ * {@literal String->Data}
*
* @return A WebhookMessage for the attachments
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If no attachments are provided or more than {@value #MAX_FILES}
- * or the additional arguments are not an even count or an invalid format
+ * If no attachments are provided or
+ * more than {@value #MAX_FILES}
+ * or the additional arguments are
+ * not an even count or an invalid
+ * format
*/
- @NotNull // forcing first pair as we expect at least one entry (Effective Java 3rd. Edition - Item 53)
+ @NotNull // forcing first pair as we expect at least one entry (Effective Java 3rd.
+ // Edition - Item 53)
public static WebhookMessage files(@NotNull String name1, @NotNull Object data1, @NotNull Object... attachments) {
Objects.requireNonNull(name1, "Name");
Objects.requireNonNull(data1, "Data");
@@ -305,14 +352,17 @@ public static WebhookMessage files(@NotNull String name1, @NotNull Object data1,
throw new IllegalArgumentException("Must provide even number of varargs arguments");
int fileAmount = 1 + attachments.length / 2;
if (fileAmount > WebhookMessage.MAX_FILES)
- throw new IllegalArgumentException("Cannot add more than " + WebhookMessage.MAX_FILES + " files to a message");
+ throw new IllegalArgumentException(
+ "Cannot add more than " + WebhookMessage.MAX_FILES + " files to a message");
MessageAttachment[] files = new MessageAttachment[fileAmount];
files[0] = convertAttachment(name1, data1);
for (int i = 0, j = 1; i < attachments.length; j++, i += 2) {
Object name = attachments[i];
Object data = attachments[i + 1];
if (!(name instanceof String))
- throw new IllegalArgumentException("Provided arguments must be pairs for (String, Data). Expected String and found " + (name == null ? null : name.getClass().getName()));
+ throw new IllegalArgumentException(
+ "Provided arguments must be pairs for (String, Data). Expected String and found "
+ + (name == null ? null : name.getClass().getName()));
files[j] = convertAttachment((String) name, data);
}
return new WebhookMessage(null, null, null, null, false, files, AllowedMentions.all(), 0, null);
@@ -329,7 +379,8 @@ public boolean isFile() {
/**
* Provides a {@link okhttp3.RequestBody} of this message.
- *
This is used internally for executing webhooks through HTTP requests.
+ *
+ * This is used internally for executing webhooks through HTTP requests.
*
* @return The request body
*/
@@ -383,10 +434,11 @@ else if (data instanceof InputStream)
else if (data instanceof byte[])
a = new MessageAttachment(name, (byte[]) data);
else
- throw new IllegalArgumentException("Provided arguments must be pairs for (String, Data). Unexpected data type " + data.getClass().getName());
+ throw new IllegalArgumentException(
+ "Provided arguments must be pairs for (String, Data). Unexpected data type "
+ + data.getClass().getName());
return a;
- }
- catch (IOException ex) {
+ } catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
}
diff --git a/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java b/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java
index b3d7cdd..18e6b71 100644
--- a/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java
+++ b/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java
@@ -114,19 +114,19 @@ public WebhookMessageBuilder resetEmbeds() {
/**
* The mention whitelist.
- *
See {@link AllowedMentions} for more details.
+ *
+ * See {@link AllowedMentions} for more details.
*
- * @param mentions
- * The mention whitelist
+ * @param mentions
+ * The mention whitelist
*
* @throws NullPointerException
- * If provided null
+ * If provided null
*
* @return This builder for chaining convenience
*/
@NotNull
- public WebhookMessageBuilder setAllowedMentions(@NotNull AllowedMentions mentions)
- {
+ public WebhookMessageBuilder setAllowedMentions(@NotNull AllowedMentions mentions) {
this.allowedMentions = Objects.requireNonNull(mentions);
return this;
}
@@ -135,14 +135,16 @@ public WebhookMessageBuilder setAllowedMentions(@NotNull AllowedMentions mention
* Adds the provided embeds to the builder
*
* @param embeds
- * The embeds to add
+ * The embeds to add
*
* @return This builder for chaining convenience
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalStateException
- * If more than {@value WebhookMessage#MAX_EMBEDS} are added
+ * If more than
+ * {@value WebhookMessage#MAX_EMBEDS}
+ * are added
*/
@NotNull
public WebhookMessageBuilder addEmbeds(@NotNull WebhookEmbed... embeds) {
@@ -159,15 +161,17 @@ public WebhookMessageBuilder addEmbeds(@NotNull WebhookEmbed... embeds) {
/**
* Adds the provided embeds to the builder
*
- * @param embeds
- * The embeds to add
+ * @param embeds
+ * The embeds to add
*
* @return This builder for chaining convenience
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalStateException
- * If more than {@value WebhookMessage#MAX_EMBEDS} are added
+ * If more than
+ * {@value WebhookMessage#MAX_EMBEDS}
+ * are added
*/
@NotNull
public WebhookMessageBuilder addEmbeds(@NotNull Collection extends WebhookEmbed> embeds) {
@@ -184,13 +188,14 @@ public WebhookMessageBuilder addEmbeds(@NotNull Collection extends WebhookEmbe
/**
* Configures the content for this builder
*
- * @param content
- * The (nullable) content to use
+ * @param content
+ * The (nullable) content to use
*
* @return This builder for chaining convenience
*
* @throws java.lang.IllegalArgumentException
- * If the content is larger than 2000 characters
+ * If the content is larger than 2000
+ * characters
*/
@NotNull
public WebhookMessageBuilder setContent(@Nullable String content) {
@@ -206,15 +211,16 @@ public WebhookMessageBuilder setContent(@Nullable String content) {
* Appends the provided content to the already
* present content in this message.
*
- * @param content
- * The content to append
+ * @param content
+ * The content to append
*
* @return This builder for chaining convenience
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If the content exceeds 2000 characters
+ * If the content exceeds 2000
+ * characters
*/
@NotNull
public WebhookMessageBuilder append(@NotNull String content) {
@@ -227,12 +233,13 @@ public WebhookMessageBuilder append(@NotNull String content) {
/**
* The username to use for this message.
- *
Each message by a webhook can have a different user appearance.
+ *
+ * Each message by a webhook can have a different user appearance.
* If this is not set it will default the user appearance in the settings of
* the webhook.
*
- * @param username
- * The (nullable) username to use
+ * @param username
+ * The (nullable) username to use
*
* @return This builder for chaining convenience
*/
@@ -244,12 +251,13 @@ public WebhookMessageBuilder setUsername(@Nullable String username) {
/**
* The avatar url to use for this message.
- *
Each message by a webhook can have a different user appearance.
+ *
+ * Each message by a webhook can have a different user appearance.
* If this is not set it will default the user appearance in the settings of
* the webhook.
*
- * @param avatarUrl
- * The (nullable) avatar url to use
+ * @param avatarUrl
+ * The (nullable) avatar url to use
*
* @return This builder for chaining convenience
*/
@@ -262,8 +270,8 @@ public WebhookMessageBuilder setAvatarUrl(@Nullable String avatarUrl) {
/**
* Whether this message should use Text-to-Speech (TTS)
*
- * @param tts
- * True, if this message should use tts
+ * @param tts
+ * True, if this message should use tts
*
* @return This builder for chaining convenience
*/
@@ -274,10 +282,11 @@ public WebhookMessageBuilder setTTS(boolean tts) {
}
/**
- * Whether the message should be ephemeral (only works for interaction webhooks).
+ * Whether the message should be ephemeral (only works for interaction
+ * webhooks).
*
- * @param ephemeral
- * True if the message should be ephemeral, false otherwise
+ * @param ephemeral
+ * True if the message should be ephemeral, false otherwise
*
* @return This builder for chaining convenience
*/
@@ -290,17 +299,36 @@ public WebhookMessageBuilder setEphemeral(boolean ephemeral) {
return this;
}
+ /**
+ * Whether the message should be silent
+ *
+ * @param silent
+ * True if the message should be sent silently, false otherwise
+ *
+ * @return This builder for chaining convenience
+ */
+ @NotNull
+ public WebhookMessageBuilder setSilent(boolean silent) {
+ if (silent)
+ flags |= MessageFlags.SUPPRESS_NOTIFICATIONS;
+ else
+ flags &= ~MessageFlags.SUPPRESS_NOTIFICATIONS;
+ return this;
+ }
+
/**
* Adds the provided file as an attachment to this message.
- *
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
+ *
+ * A single message can have up to {@value WebhookMessage#MAX_FILES}
+ * attachments.
*
* @param file
- * The file to attach
+ * The file to attach
*
* @return This builder for chaining convenience
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*/
@NotNull
public WebhookMessageBuilder addFile(@NotNull File file) {
@@ -310,15 +338,17 @@ public WebhookMessageBuilder addFile(@NotNull File file) {
/**
* Adds the provided file as an attachment to this message.
- *
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
+ *
+ * A single message can have up to {@value WebhookMessage#MAX_FILES}
+ * attachments.
*
- * @param name
- * The alternative name that should be used instead
- * @param file
- * The file to attach
+ * @param name
+ * The alternative name that should be used instead
+ * @param file
+ * The file to attach
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*
* @return This builder for chaining convenience
*/
@@ -326,31 +356,34 @@ public WebhookMessageBuilder addFile(@NotNull File file) {
public WebhookMessageBuilder addFile(@NotNull String name, @NotNull File file) {
Objects.requireNonNull(file, "File");
Objects.requireNonNull(name, "Name");
- if (!file.exists() || !file.canRead()) throw new IllegalArgumentException("File must exist and be readable");
+ if (!file.exists() || !file.canRead())
+ throw new IllegalArgumentException("File must exist and be readable");
if (fileIndex >= WebhookMessage.MAX_FILES)
- throw new IllegalStateException("Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
+ throw new IllegalStateException(
+ "Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
try {
MessageAttachment attachment = new MessageAttachment(name, file);
files[fileIndex++] = attachment;
return this;
- }
- catch (IOException ex) {
+ } catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
}
/**
* Adds the provided data as a file attachment to this message.
- *
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
+ *
+ * A single message can have up to {@value WebhookMessage#MAX_FILES}
+ * attachments.
*
- * @param name
- * The alternative name that should be used
- * @param data
- * The data to attach as a file
+ * @param name
+ * The alternative name that should be used
+ * @param data
+ * The data to attach as a file
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*
* @return This builder for chaining convenience
*/
@@ -359,7 +392,8 @@ public WebhookMessageBuilder addFile(@NotNull String name, @NotNull byte[] data)
Objects.requireNonNull(data, "Data");
Objects.requireNonNull(name, "Name");
if (fileIndex >= WebhookMessage.MAX_FILES)
- throw new IllegalStateException("Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
+ throw new IllegalStateException(
+ "Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
MessageAttachment attachment = new MessageAttachment(name, data);
files[fileIndex++] = attachment;
@@ -368,15 +402,17 @@ public WebhookMessageBuilder addFile(@NotNull String name, @NotNull byte[] data)
/**
* Adds the provided data as a file attachment to this message.
- *
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
+ *
+ * A single message can have up to {@value WebhookMessage#MAX_FILES}
+ * attachments.
*
- * @param name
- * The alternative name that should be used
- * @param data
- * The data to attach as a file
+ * @param name
+ * The alternative name that should be used
+ * @param data
+ * The data to attach as a file
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*
* @return This builder for chaining convenience
*/
@@ -385,24 +421,25 @@ public WebhookMessageBuilder addFile(@NotNull String name, @NotNull InputStream
Objects.requireNonNull(data, "InputStream");
Objects.requireNonNull(name, "Name");
if (fileIndex >= WebhookMessage.MAX_FILES)
- throw new IllegalStateException("Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
+ throw new IllegalStateException(
+ "Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
try {
MessageAttachment attachment = new MessageAttachment(name, data);
files[fileIndex++] = attachment;
return this;
- }
- catch (IOException ex) {
+ } catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
}
/**
* Sets the provided name as the name for a newly created thread.
- *
This is only valid for forum/media channels.
+ *
+ * This is only valid for forum/media channels.
*
- * @param name
- * The name that should be used
+ * @param name
+ * The name that should be used
*
* @return This builder for chaining convenience
*/
@@ -416,7 +453,8 @@ public WebhookMessageBuilder setThreadName(@Nullable String name) {
* Constructs the {@link club.minnced.discord.webhook.send.WebhookMessage}
* from the current configurations.
*
- * @return The resulting {@link club.minnced.discord.webhook.send.WebhookMessage}
+ * @return The resulting
+ * {@link club.minnced.discord.webhook.send.WebhookMessage}
*/
@NotNull
public WebhookMessage build() {
@@ -426,7 +464,6 @@ public WebhookMessage build() {
fileIndex == 0 ? null : Arrays.copyOf(files, fileIndex), allowedMentions, flags, threadName);
}
-
/////////////////////////////////
/// Third-party compatibility ///
/////////////////////////////////
@@ -434,11 +471,11 @@ public WebhookMessage build() {
/**
* Converts a JDA {@link Message} into a compatible WebhookMessageBuilder.
*
- * @param message
- * The message
+ * @param message
+ * The message
*
* @throws NullPointerException
- * If null is provided
+ * If null is provided
*
* @return WebhookMessageBuilder with the converted data
*/
@@ -450,11 +487,11 @@ public static WebhookMessageBuilder fromJDA(@NotNull net.dv8tion.jda.api.entitie
/**
* Converts a JDA {@link Message} into a compatible WebhookMessageBuilder.
*
- * @param message
- * The message
+ * @param message
+ * The message
*
* @throws NullPointerException
- * If null is provided
+ * If null is provided
*
* @return WebhookMessageBuilder with the converted data
*/
@@ -469,26 +506,25 @@ public static WebhookMessageBuilder fromJDA(@NotNull MessageCreateData message)
Set
- * A {@link club.minnced.discord.webhook.receive.ReadonlyMessage} can be sent
- * by first converting it to a WebhookMessage with
- * {@link #from(club.minnced.discord.webhook.receive.ReadonlyMessage)}.
+ *
A {@link club.minnced.discord.webhook.receive.ReadonlyMessage} can be sent
+ * by first converting it to a WebhookMessage with {@link #from(club.minnced.discord.webhook.receive.ReadonlyMessage)}.
*/
public class WebhookMessage {
/**
@@ -55,9 +53,9 @@ public class WebhookMessage {
protected final String threadName;
protected WebhookMessage(final String username, final String avatarUrl, final String content,
- final List
- * This instance remains unchanged and a new instance is returned.
+ * Returns a new WebhookMessage instance with the ephemeral flag turned on/off (true/false).
+ *
This instance remains unchanged and a new instance is returned.
*
- * @param ephemeral
- * Whether to make this message ephemeral
+ * @param ephemeral
+ * Whether to make this message ephemeral
*
* @return New WebhookMessage instance
*/
@@ -155,43 +151,19 @@ public WebhookMessage asEphemeral(boolean ephemeral) {
flags |= MessageFlags.EPHEMERAL;
else
flags &= ~MessageFlags.EPHEMERAL;
- return new WebhookMessage(username, avatarUrl, content, embeds, isTTS, attachments, allowedMentions, flags,
- threadName);
- }
-
- /**
- * Returns a new WebhookMessage instance with the silent flag turned on/off
- * (true/false).
- *
- * This instance remains unchanged and a new instance is returned.
- *
- * @param silent
- * Whether to make this message silent
- *
- * @return New WebhookMessage instance
- */
- @NotNull
- public WebhookMessage asSilent(boolean silent) {
- int flags = this.flags;
- if (silent)
- flags |= MessageFlags.SUPPRESS_NOTIFICATIONS;
- else
- flags &= ~MessageFlags.SUPPRESS_NOTIFICATIONS;
- return new WebhookMessage(username, avatarUrl, content, embeds, isTTS, attachments, allowedMentions, flags,
- threadName);
+ return new WebhookMessage(username, avatarUrl, content, embeds, isTTS, attachments, allowedMentions, flags, threadName);
}
/**
* Converts a {@link club.minnced.discord.webhook.receive.ReadonlyMessage} to a
* WebhookMessage.
- *
- * This does not convert attachments.
+ *
This does not convert attachments.
*
- * @param message
- * The message to convert
+ * @param message
+ * The message to convert
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*
* @return A WebhookMessage copy
*/
@@ -204,7 +176,6 @@ public static WebhookMessage from(@NotNull ReadonlyMessage message) {
builder.setContent(message.getContent());
builder.setTTS(message.isTTS());
builder.setEphemeral((message.getFlags() & MessageFlags.EPHEMERAL) != 0);
- builder.setSilent((message.getFlags() & MessageFlags.SUPPRESS_NOTIFICATIONS) != 0);
builder.addEmbeds(message.getEmbeds());
return builder.build();
}
@@ -214,21 +185,18 @@ public static WebhookMessage from(@NotNull ReadonlyMessage message) {
* the provided embeds. A message can hold up to {@value #MAX_EMBEDS} embeds.
*
* @param first
- * The first embed
+ * The first embed
* @param embeds
- * Optional additional embeds for the message
+ * Optional additional embeds for the message
*
* @return A WebhookMessage for the embeds
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If more than
- * {@value WebhookMessage#MAX_EMBEDS}
- * are provided
+ * If more than {@value WebhookMessage#MAX_EMBEDS} are provided
*/
- @NotNull // forcing first embed as we expect at least one entry (Effective Java 3rd.
- // Edition - Item 53)
+ @NotNull // forcing first embed as we expect at least one entry (Effective Java 3rd. Edition - Item 53)
public static WebhookMessage embeds(@NotNull WebhookEmbed first, @NotNull WebhookEmbed... embeds) {
Objects.requireNonNull(embeds, "Embeds");
if (embeds.length >= WebhookMessage.MAX_EMBEDS)
@@ -246,15 +214,13 @@ public static WebhookMessage embeds(@NotNull WebhookEmbed first, @NotNull Webhoo
* Creates a WebhookMessage from
* the provided embeds. A message can hold up to {@value #MAX_EMBEDS} embeds.
*
- * @param embeds
- * Embeds for the message
+ * @param embeds
+ * Embeds for the message
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If more than
- * {@value WebhookMessage#MAX_EMBEDS}
- * are provided
+ * If more than {@value WebhookMessage#MAX_EMBEDS} are provided
*
* @return A WebhookMessage for the embeds
*/
@@ -266,25 +232,22 @@ public static WebhookMessage embeds(@NotNull Collection
- * A message can hold up to {@value #MAX_FILES} attachments
+ *
A message can hold up to {@value #MAX_FILES} attachments
* and a total of 8MiB of data.
*
- * @param attachments
- * The attachments to add, keys are the alternative names
- * for each attachment
+ * @param attachments
+ * The attachments to add, keys are the alternative names
+ * for each attachment
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If no attachments are provided or
- * more than {@value #MAX_FILES}
+ * If no attachments are provided or more than {@value #MAX_FILES}
*
* @return A WebhookMessage for the attachments
*/
@@ -296,8 +259,7 @@ public static WebhookMessage files(@NotNull Map
- * A message can hold up to {@value #MAX_FILES} attachments
+ *
A message can hold up to {@value #MAX_FILES} attachments
* and a total of 8MiB of data.
*
- *
- * The allowed data types are {@code byte[] | InputStream | File}
+ *
The allowed data types are {@code byte[] | InputStream | File}
*
* @param name1
- * The alternative name of the first attachment
+ * The alternative name of the first attachment
* @param data1
- * The first attachment, must be of type
- * {@code byte[] | InputStream | File}
+ * The first attachment, must be of type {@code byte[] | InputStream | File}
* @param attachments
- * Optional additional attachments to add, pairs of
- * {@literal String->Data}
+ * Optional additional attachments to add, pairs of {@literal String->Data}
*
* @return A WebhookMessage for the attachments
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If no attachments are provided or
- * more than {@value #MAX_FILES}
- * or the additional arguments are
- * not an even count or an invalid
- * format
+ * If no attachments are provided or more than {@value #MAX_FILES}
+ * or the additional arguments are not an even count or an invalid format
*/
- @NotNull // forcing first pair as we expect at least one entry (Effective Java 3rd.
- // Edition - Item 53)
+ @NotNull // forcing first pair as we expect at least one entry (Effective Java 3rd. Edition - Item 53)
public static WebhookMessage files(@NotNull String name1, @NotNull Object data1, @NotNull Object... attachments) {
Objects.requireNonNull(name1, "Name");
Objects.requireNonNull(data1, "Data");
@@ -352,17 +305,14 @@ public static WebhookMessage files(@NotNull String name1, @NotNull Object data1,
throw new IllegalArgumentException("Must provide even number of varargs arguments");
int fileAmount = 1 + attachments.length / 2;
if (fileAmount > WebhookMessage.MAX_FILES)
- throw new IllegalArgumentException(
- "Cannot add more than " + WebhookMessage.MAX_FILES + " files to a message");
+ throw new IllegalArgumentException("Cannot add more than " + WebhookMessage.MAX_FILES + " files to a message");
MessageAttachment[] files = new MessageAttachment[fileAmount];
files[0] = convertAttachment(name1, data1);
for (int i = 0, j = 1; i < attachments.length; j++, i += 2) {
Object name = attachments[i];
Object data = attachments[i + 1];
if (!(name instanceof String))
- throw new IllegalArgumentException(
- "Provided arguments must be pairs for (String, Data). Expected String and found "
- + (name == null ? null : name.getClass().getName()));
+ throw new IllegalArgumentException("Provided arguments must be pairs for (String, Data). Expected String and found " + (name == null ? null : name.getClass().getName()));
files[j] = convertAttachment((String) name, data);
}
return new WebhookMessage(null, null, null, null, false, files, AllowedMentions.all(), 0, null);
@@ -379,8 +329,7 @@ public boolean isFile() {
/**
* Provides a {@link okhttp3.RequestBody} of this message.
- *
- * This is used internally for executing webhooks through HTTP requests.
+ *
This is used internally for executing webhooks through HTTP requests.
*
* @return The request body
*/
@@ -434,11 +383,10 @@ else if (data instanceof InputStream)
else if (data instanceof byte[])
a = new MessageAttachment(name, (byte[]) data);
else
- throw new IllegalArgumentException(
- "Provided arguments must be pairs for (String, Data). Unexpected data type "
- + data.getClass().getName());
+ throw new IllegalArgumentException("Provided arguments must be pairs for (String, Data). Unexpected data type " + data.getClass().getName());
return a;
- } catch (IOException ex) {
+ }
+ catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
}
diff --git a/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java b/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java
index 18e6b71..b3d7cdd 100644
--- a/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java
+++ b/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java
@@ -114,19 +114,19 @@ public WebhookMessageBuilder resetEmbeds() {
/**
* The mention whitelist.
- *
- * See {@link AllowedMentions} for more details.
+ *
See {@link AllowedMentions} for more details.
*
- * @param mentions
- * The mention whitelist
+ * @param mentions
+ * The mention whitelist
*
* @throws NullPointerException
- * If provided null
+ * If provided null
*
* @return This builder for chaining convenience
*/
@NotNull
- public WebhookMessageBuilder setAllowedMentions(@NotNull AllowedMentions mentions) {
+ public WebhookMessageBuilder setAllowedMentions(@NotNull AllowedMentions mentions)
+ {
this.allowedMentions = Objects.requireNonNull(mentions);
return this;
}
@@ -135,16 +135,14 @@ public WebhookMessageBuilder setAllowedMentions(@NotNull AllowedMentions mention
* Adds the provided embeds to the builder
*
* @param embeds
- * The embeds to add
+ * The embeds to add
*
* @return This builder for chaining convenience
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalStateException
- * If more than
- * {@value WebhookMessage#MAX_EMBEDS}
- * are added
+ * If more than {@value WebhookMessage#MAX_EMBEDS} are added
*/
@NotNull
public WebhookMessageBuilder addEmbeds(@NotNull WebhookEmbed... embeds) {
@@ -161,17 +159,15 @@ public WebhookMessageBuilder addEmbeds(@NotNull WebhookEmbed... embeds) {
/**
* Adds the provided embeds to the builder
*
- * @param embeds
- * The embeds to add
+ * @param embeds
+ * The embeds to add
*
* @return This builder for chaining convenience
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalStateException
- * If more than
- * {@value WebhookMessage#MAX_EMBEDS}
- * are added
+ * If more than {@value WebhookMessage#MAX_EMBEDS} are added
*/
@NotNull
public WebhookMessageBuilder addEmbeds(@NotNull Collection extends WebhookEmbed> embeds) {
@@ -188,14 +184,13 @@ public WebhookMessageBuilder addEmbeds(@NotNull Collection extends WebhookEmbe
/**
* Configures the content for this builder
*
- * @param content
- * The (nullable) content to use
+ * @param content
+ * The (nullable) content to use
*
* @return This builder for chaining convenience
*
* @throws java.lang.IllegalArgumentException
- * If the content is larger than 2000
- * characters
+ * If the content is larger than 2000 characters
*/
@NotNull
public WebhookMessageBuilder setContent(@Nullable String content) {
@@ -211,16 +206,15 @@ public WebhookMessageBuilder setContent(@Nullable String content) {
* Appends the provided content to the already
* present content in this message.
*
- * @param content
- * The content to append
+ * @param content
+ * The content to append
*
* @return This builder for chaining convenience
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
* @throws java.lang.IllegalArgumentException
- * If the content exceeds 2000
- * characters
+ * If the content exceeds 2000 characters
*/
@NotNull
public WebhookMessageBuilder append(@NotNull String content) {
@@ -233,13 +227,12 @@ public WebhookMessageBuilder append(@NotNull String content) {
/**
* The username to use for this message.
- *
- * Each message by a webhook can have a different user appearance.
+ *
Each message by a webhook can have a different user appearance.
* If this is not set it will default the user appearance in the settings of
* the webhook.
*
- * @param username
- * The (nullable) username to use
+ * @param username
+ * The (nullable) username to use
*
* @return This builder for chaining convenience
*/
@@ -251,13 +244,12 @@ public WebhookMessageBuilder setUsername(@Nullable String username) {
/**
* The avatar url to use for this message.
- *
- * Each message by a webhook can have a different user appearance.
+ *
Each message by a webhook can have a different user appearance.
* If this is not set it will default the user appearance in the settings of
* the webhook.
*
- * @param avatarUrl
- * The (nullable) avatar url to use
+ * @param avatarUrl
+ * The (nullable) avatar url to use
*
* @return This builder for chaining convenience
*/
@@ -270,8 +262,8 @@ public WebhookMessageBuilder setAvatarUrl(@Nullable String avatarUrl) {
/**
* Whether this message should use Text-to-Speech (TTS)
*
- * @param tts
- * True, if this message should use tts
+ * @param tts
+ * True, if this message should use tts
*
* @return This builder for chaining convenience
*/
@@ -282,11 +274,10 @@ public WebhookMessageBuilder setTTS(boolean tts) {
}
/**
- * Whether the message should be ephemeral (only works for interaction
- * webhooks).
+ * Whether the message should be ephemeral (only works for interaction webhooks).
*
- * @param ephemeral
- * True if the message should be ephemeral, false otherwise
+ * @param ephemeral
+ * True if the message should be ephemeral, false otherwise
*
* @return This builder for chaining convenience
*/
@@ -299,36 +290,17 @@ public WebhookMessageBuilder setEphemeral(boolean ephemeral) {
return this;
}
- /**
- * Whether the message should be silent
- *
- * @param silent
- * True if the message should be sent silently, false otherwise
- *
- * @return This builder for chaining convenience
- */
- @NotNull
- public WebhookMessageBuilder setSilent(boolean silent) {
- if (silent)
- flags |= MessageFlags.SUPPRESS_NOTIFICATIONS;
- else
- flags &= ~MessageFlags.SUPPRESS_NOTIFICATIONS;
- return this;
- }
-
/**
* Adds the provided file as an attachment to this message.
- *
- * A single message can have up to {@value WebhookMessage#MAX_FILES}
- * attachments.
+ *
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
*
* @param file
- * The file to attach
+ * The file to attach
*
* @return This builder for chaining convenience
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*/
@NotNull
public WebhookMessageBuilder addFile(@NotNull File file) {
@@ -338,17 +310,15 @@ public WebhookMessageBuilder addFile(@NotNull File file) {
/**
* Adds the provided file as an attachment to this message.
- *
- * A single message can have up to {@value WebhookMessage#MAX_FILES}
- * attachments.
+ *
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
*
- * @param name
- * The alternative name that should be used instead
- * @param file
- * The file to attach
+ * @param name
+ * The alternative name that should be used instead
+ * @param file
+ * The file to attach
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*
* @return This builder for chaining convenience
*/
@@ -356,34 +326,31 @@ public WebhookMessageBuilder addFile(@NotNull File file) {
public WebhookMessageBuilder addFile(@NotNull String name, @NotNull File file) {
Objects.requireNonNull(file, "File");
Objects.requireNonNull(name, "Name");
- if (!file.exists() || !file.canRead())
- throw new IllegalArgumentException("File must exist and be readable");
+ if (!file.exists() || !file.canRead()) throw new IllegalArgumentException("File must exist and be readable");
if (fileIndex >= WebhookMessage.MAX_FILES)
- throw new IllegalStateException(
- "Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
+ throw new IllegalStateException("Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
try {
MessageAttachment attachment = new MessageAttachment(name, file);
files[fileIndex++] = attachment;
return this;
- } catch (IOException ex) {
+ }
+ catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
}
/**
* Adds the provided data as a file attachment to this message.
- *
- * A single message can have up to {@value WebhookMessage#MAX_FILES}
- * attachments.
+ *
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
*
- * @param name
- * The alternative name that should be used
- * @param data
- * The data to attach as a file
+ * @param name
+ * The alternative name that should be used
+ * @param data
+ * The data to attach as a file
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*
* @return This builder for chaining convenience
*/
@@ -392,8 +359,7 @@ public WebhookMessageBuilder addFile(@NotNull String name, @NotNull byte[] data)
Objects.requireNonNull(data, "Data");
Objects.requireNonNull(name, "Name");
if (fileIndex >= WebhookMessage.MAX_FILES)
- throw new IllegalStateException(
- "Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
+ throw new IllegalStateException("Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
MessageAttachment attachment = new MessageAttachment(name, data);
files[fileIndex++] = attachment;
@@ -402,17 +368,15 @@ public WebhookMessageBuilder addFile(@NotNull String name, @NotNull byte[] data)
/**
* Adds the provided data as a file attachment to this message.
- *
- * A single message can have up to {@value WebhookMessage#MAX_FILES}
- * attachments.
+ *
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
*
- * @param name
- * The alternative name that should be used
- * @param data
- * The data to attach as a file
+ * @param name
+ * The alternative name that should be used
+ * @param data
+ * The data to attach as a file
*
* @throws java.lang.NullPointerException
- * If provided with null
+ * If provided with null
*
* @return This builder for chaining convenience
*/
@@ -421,25 +385,24 @@ public WebhookMessageBuilder addFile(@NotNull String name, @NotNull InputStream
Objects.requireNonNull(data, "InputStream");
Objects.requireNonNull(name, "Name");
if (fileIndex >= WebhookMessage.MAX_FILES)
- throw new IllegalStateException(
- "Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
+ throw new IllegalStateException("Cannot add more than " + WebhookMessage.MAX_FILES + " attachments to a message");
try {
MessageAttachment attachment = new MessageAttachment(name, data);
files[fileIndex++] = attachment;
return this;
- } catch (IOException ex) {
+ }
+ catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
}
/**
* Sets the provided name as the name for a newly created thread.
- *
- * This is only valid for forum/media channels.
+ *
This is only valid for forum/media channels.
*
- * @param name
- * The name that should be used
+ * @param name
+ * The name that should be used
*
* @return This builder for chaining convenience
*/
@@ -453,8 +416,7 @@ public WebhookMessageBuilder setThreadName(@Nullable String name) {
* Constructs the {@link club.minnced.discord.webhook.send.WebhookMessage}
* from the current configurations.
*
- * @return The resulting
- * {@link club.minnced.discord.webhook.send.WebhookMessage}
+ * @return The resulting {@link club.minnced.discord.webhook.send.WebhookMessage}
*/
@NotNull
public WebhookMessage build() {
@@ -464,6 +426,7 @@ public WebhookMessage build() {
fileIndex == 0 ? null : Arrays.copyOf(files, fileIndex), allowedMentions, flags, threadName);
}
+
/////////////////////////////////
/// Third-party compatibility ///
/////////////////////////////////
@@ -471,11 +434,11 @@ public WebhookMessage build() {
/**
* Converts a JDA {@link Message} into a compatible WebhookMessageBuilder.
*
- * @param message
- * The message
+ * @param message
+ * The message
*
* @throws NullPointerException
- * If null is provided
+ * If null is provided
*
* @return WebhookMessageBuilder with the converted data
*/
@@ -487,11 +450,11 @@ public static WebhookMessageBuilder fromJDA(@NotNull net.dv8tion.jda.api.entitie
/**
* Converts a JDA {@link Message} into a compatible WebhookMessageBuilder.
*
- * @param message
- * The message
+ * @param message
+ * The message
*
* @throws NullPointerException
- * If null is provided
+ * If null is provided
*
* @return WebhookMessageBuilder with the converted data
*/
@@ -506,25 +469,26 @@ public static WebhookMessageBuilder fromJDA(@NotNull MessageCreateData message)
Set
A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
From 72aaa74f4fa40b896498f8b955b64ce808e7f7bf Mon Sep 17 00:00:00 2001
From: William Beemer <37132465+MrBubbles06@users.noreply.github.com>
Date: Mon, 26 Feb 2024 10:29:43 -0800
Subject: [PATCH 6/6] Added documentation for asSilent(), and fixed formatting
issues.
---
.../minnced/discord/webhook/send/WebhookMessage.java | 10 +++++++++-
.../discord/webhook/send/WebhookMessageBuilder.java | 6 +++---
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/main/java/club/minnced/discord/webhook/send/WebhookMessage.java b/src/main/java/club/minnced/discord/webhook/send/WebhookMessage.java
index 8d08d8e..033b975 100644
--- a/src/main/java/club/minnced/discord/webhook/send/WebhookMessage.java
+++ b/src/main/java/club/minnced/discord/webhook/send/WebhookMessage.java
@@ -154,7 +154,15 @@ public WebhookMessage asEphemeral(boolean ephemeral) {
return new WebhookMessage(username, avatarUrl, content, embeds, isTTS, attachments, allowedMentions, flags, threadName);
}
- //copy the above function but change it to be for the silent flag
+ /**
+ * Returns a new WebhookMessage instance with the silent flag turned on/off (true/false).
+ *
This instance remains unchanged and a new instance is returned.
+ *
+ * @param silent
+ * Whether to make this message silent
+ *
+ * @return New WebhookMessage instance
+ */
@NotNull
public WebhookMessage asSilent(boolean silent) {
int flags = this.flags;
diff --git a/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java b/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java
index e2ea3a5..e7d6ef8 100644
--- a/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java
+++ b/src/main/java/club/minnced/discord/webhook/send/WebhookMessageBuilder.java
@@ -294,13 +294,13 @@ public WebhookMessageBuilder setEphemeral(boolean ephemeral) {
* Whether the message should be silent
*
* @param silent
- * True if the message should be silent, false otherwise
+ * True if the message should be silent, false otherwise
*
* @return This builder for chaining convenience
*/
@NotNull
- public WebhookMessageBuilder setSilent(boolean suppressNotifications) {
- if (suppressNotifications)
+ public WebhookMessageBuilder setSilent(boolean silent) {
+ if (silent)
flags |= MessageFlags.SUPPRESS_NOTIFICATIONS;
else
flags &= ~MessageFlags.SUPPRESS_NOTIFICATIONS;