Skip to content
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
7 changes: 4 additions & 3 deletions src/main/java/net/dv8tion/jda/api/EmbedBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ public MessageEmbed build() {
null,
footer,
image,
new ArrayList<>(fields));
new ArrayList<>(fields),
0);
}

/**
Expand Down Expand Up @@ -560,7 +561,7 @@ public EmbedBuilder setThumbnail(@Nullable String url) {
this.thumbnail = null;
} else {
urlCheck(url);
this.thumbnail = new MessageEmbed.Thumbnail(url, null, 0, 0);
this.thumbnail = new MessageEmbed.Thumbnail(url, null, 0, 0, null, null, null, 0);
}
return this;
}
Expand Down Expand Up @@ -605,7 +606,7 @@ public EmbedBuilder setImage(@Nullable String url) {
this.image = null;
} else {
urlCheck(url);
this.image = new MessageEmbed.ImageInfo(url, null, 0, 0);
this.image = new MessageEmbed.ImageInfo(url, null, 0, 0, null, null, null, 0);
}
return this;
}
Expand Down
101 changes: 101 additions & 0 deletions src/main/java/net/dv8tion/jda/api/components/ResolvedMedia.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,16 @@

package net.dv8tion.jda.api.components;

import net.dv8tion.jda.api.entities.Placeholder;
import net.dv8tion.jda.api.utils.AttachmentProxy;
import net.dv8tion.jda.internal.utils.Checks;
import org.jetbrains.annotations.Unmodifiable;

import java.util.Arrays;
import java.util.Collection;
import java.util.EnumSet;
import java.util.Set;
import java.util.stream.Collectors;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -109,4 +118,96 @@ default Long getAttachmentIdLong() {
*/
@Nullable
String getContentType();

/**
* The placeholder, if this is an image or video, or {@code null}.
*
* @return The placeholder or {@code null}
*
* @see Placeholder
*/
@Nullable
Placeholder getPlaceholder();

/**
* Returns the raw media flags of this media.
*
* @return The raw media flags
*
* @see #getFlags()
*/
long getFlagsRaw();

/**
* Returns an unmodifiable set of all {@link ResolvedMediaFlag ResolvedMediaFlags} present for this media.
*
* @return Unmodifiable set of present {@link ResolvedMediaFlag ResolvedMediaFlags}
*
* @see ResolvedMediaFlag
*/
@Nonnull
@Unmodifiable
Set<ResolvedMediaFlag> getFlags();

/**
* Known media flags.
*/
enum ResolvedMediaFlag {
/**
* This image is animated.
*/
IS_ANIMATED(0);

private final int value;

ResolvedMediaFlag(int offset) {
this.value = 1 << offset;
}

/**
* Returns the value of the flag as represented in the bitfield. It is always a power of 2. (single bit)
*
* @return Non-zero bit value of the field
*/
public int getValue() {
return value;
}

/**
* Given a bitfield, this function extracts all enum values according to their bit values and returns
* a set containing all matching media flags.
*
* @param bitfield
* Non-negative integer representing a bitfield of media flags
*
* @return Set of media flags found in the bitfield
*/
@Nonnull
public static EnumSet<ResolvedMediaFlag> fromBitField(int bitfield) {
return Arrays.stream(ResolvedMediaFlag.values())
.filter(e -> (e.value & bitfield) > 0)
.collect(Collectors.toCollection(() -> EnumSet.noneOf(ResolvedMediaFlag.class)));
}

/**
* Converts a collection of media flags back to the integer representing the bitfield.
* This is the reverse operation of {@link #fromBitField(int)}.
*
* @param flags
* A non-null collection of media flags
*
* @throws IllegalArgumentException
* If the provided collection is {@code null}
*
* @return Integer value of the bitfield representing the given media flags
*/
public static int toBitField(@Nonnull Collection<ResolvedMediaFlag> flags) {
Checks.notNull(flags, "Flags");
int rawFlags = 0;
for (ResolvedMediaFlag flag : flags) {
rawFlags |= flag.value;
}
return rawFlags;
}
}
}
15 changes: 15 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -2725,6 +2725,7 @@ class Attachment implements ISnowflake, AttachedFile {
private final boolean ephemeral;
private final String waveform;
private final double duration;
private final Placeholder placeholder;

private final JDAImpl jda;

Expand All @@ -2741,6 +2742,7 @@ public Attachment(
boolean ephemeral,
String waveform,
double duration,
Placeholder placeholder,
JDAImpl jda) {
this.id = id;
this.url = url;
Expand All @@ -2754,6 +2756,7 @@ public Attachment(
this.ephemeral = ephemeral;
this.waveform = waveform;
this.duration = duration;
this.placeholder = placeholder;
this.jda = jda;
}

Expand Down Expand Up @@ -2955,6 +2958,18 @@ public boolean isSpoiler() {
return getFileName().startsWith("SPOILER_");
}

/**
* The placeholder, if this is an image or video, or {@code null}.
*
* @return The placeholder or {@code null}
*
* @see Placeholder
*/
@Nullable
public Placeholder getPlaceholder() {
return placeholder;
}

@Override
public void close() {}

Expand Down
Loading