Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a setSilent method similar to the setEphmeral method #92

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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,25 @@ public WebhookMessage asEphemeral(boolean 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).
* <br>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) {
mrbubbles06 marked this conversation as resolved.
Show resolved Hide resolved
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 +195,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 silent) {
if (silent)
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