Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/main/java/club/minnced/discord/webhook/MessageFlags.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@
*/
@SuppressWarnings("PointlessBitwiseExpression")
public class MessageFlags {
public static final int CROSSPOSTED = 1 << 0;
public static final int IS_CROSSPOSTED = 1 << 1;
public static final int SUPPRESS_EMBEDS = 1 << 2;
public static final int SOURCE_MESSAGE_DELETED = 1 << 3;
public static final int URGENT = 1 << 4;
public static final int HAS_THREAD = 1 << 5;
public static final int EPHEMERAL = 1 << 6;
public static final int LOADING = 1 << 7;
}
public static final int CROSSPOSTED = 1 << 0;
public static final int IS_CROSSPOSTED = 1 << 1;
public static final int SUPPRESS_EMBEDS = 1 << 2;
public static final int SOURCE_MESSAGE_DELETED = 1 << 3;
public static final int URGENT = 1 << 4;
public static final int HAS_THREAD = 1 << 5;
public static final int EPHEMERAL = 1 << 6;
public static final int LOADING = 1 << 7;
public static final int FAILED_TO_MENTION_SOME_ROLES_IN_THREAD = 1 << 8;
public static final int SUPPRESS_NOTIFICATIONS = 1 << 12;
public static final int IS_VOICE_MESSAGE = 1 << 13;
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ 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
@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.
Expand All @@ -176,6 +187,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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,23 @@ public WebhookMessageBuilder setEphemeral(boolean ephemeral) {
return this;
}

/**
* Whether the message should be silent
*
* @param silent
* True if the message should be silent, false otherwise
*
* @return This builder for chaining convenience
*/
@NotNull
public WebhookMessageBuilder setSilent(boolean suppressNotifications) {
if (suppressNotifications)
flags |= MessageFlags.SUPPRESS_NOTIFICATIONS;
else
flags &= ~MessageFlags.SUPPRESS_NOTIFICATIONS;
return this;
}

/**
* Adds the provided file as an attachment to this message.
* <br>A single message can have up to {@value WebhookMessage#MAX_FILES} attachments.
Expand Down