Skip to content

Commit

Permalink
Add embed flags & missing attachment properties
Browse files Browse the repository at this point in the history
  • Loading branch information
DonovanDMC committed Feb 17, 2025
1 parent 16e80b5 commit c3a8425
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
10 changes: 10 additions & 0 deletions lib/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,7 @@ export enum AttachmentFlags {
IS_REMIX = 1 << 2,
IS_SPOILER = 1 << 3,
CONTAINS_EXPLICIT_MEDIA = 1 << 4,
IS_ANIMATED = 1 << 5,
}

export enum SKUTypes {
Expand Down Expand Up @@ -1528,6 +1529,15 @@ export const ApplicationEventWebhookEventTypes = [
] as const;
export type ApplicationEventWebhookEventType = typeof ApplicationEventWebhookEventTypes[number];

export enum EmbedFlags {
CONTAINS_EXPLICIT_MEDIA = 1 << 4,
IS_CONTENT_INVENTORY_ENTRY = 1 << 5,
}

export enum EmbedMediaFlags {
IS_ANIMATED = 1 << 5,
}

// entries are intentionally not aligned
/** The error codes that can be received. See [Discord's Documentation](https://discord.com/developers/docs/topics/opcodes-and-status-codes#json). */
export enum JSONErrorCodes {
Expand Down
11 changes: 11 additions & 0 deletions lib/structures/Attachment.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
/** @module Attachment */
import Base from "./Base";
import type User from "./User";
import Application from "./Application";
import type Client from "../Client";
import type { RawAttachment } from "../types/channels";
import type { JSONAttachment } from "../types/json";

/** Represents a file attachment. */
export default class Attachment extends Base {
/** For Clips, the application in the stream, if recognized. */
application?: Application;
/** For Clips, when the clip was created. */
clipCreatedAt?: Date;
/** For Clips, array of users who were in the stream. */
clipParticipants?: Array<User>;
/** The mime type of this attachment. */
contentType?: string;
/** The description of this attachment. */
Expand Down Expand Up @@ -34,6 +42,9 @@ export default class Attachment extends Base {
width?: number;
constructor(data: RawAttachment, client: Client) {
super(data.id, client);
this.application = data.application ? new Application(data.application, client) : undefined;
this.clipCreatedAt = data.clip_created_at ? new Date(data.clip_created_at) : undefined;
this.clipParticipants = data.clip_participants ? data.clip_participants.map(user => client.users.update(user)) : undefined;
this.contentType = data.content_type;
this.description = data.description;
this.durationSecs = data.duration_secs;
Expand Down
42 changes: 29 additions & 13 deletions lib/types/channels.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @module Types/Channels */
import type { NullablePartialEmoji, PartialEmoji, RawInviteGuild, RawMember } from "./guilds";
import type { RawApplication, RawPartialApplication } from "./applications";
import type { RESTApplication, RawApplication, RawPartialApplication } from "./applications";
import type { RawUser, RawUserWithMember } from "./users";
import type { File } from "./request-handler";
import type { RawScheduledEvent } from "./scheduled-events";
Expand Down Expand Up @@ -307,7 +307,7 @@ export interface CreateMessageOptions {
enforceNonce?: boolean;
/** The files to send. */
files?: Array<File>;
/** The [flags](https://discord.com/developers/docs/resources/channel#message-object-message-flags) to send with the message. */
/** The {@link Constants.MessageFlags | Message Flags} to send with the message. */
flags?: number;
/** Reply to a message. */
messageReference?: MessageReference;
Expand Down Expand Up @@ -355,6 +355,8 @@ export interface EmbedBase extends EmbedOptionsBase {
export interface RawEmbed extends EmbedBase {
author?: RawEmbedAuthor;
fields?: Array<EmbedField>;
/** The {@link Constants.EmbedFlags | Embed Flags} for the embed. */
flags?: number;
footer?: RawEmbedFooter;
image?: RawEmbedImage;
provider?: EmbedProvider;
Expand All @@ -365,6 +367,8 @@ export interface RawEmbed extends EmbedBase {
export interface Embed extends EmbedBase {
author?: EmbedAuthor;
fields?: Array<EmbedField>;
/** The {@link Constants.EmbedFlags | Embed Flags} for the embed. */
flags?: number;
footer?: EmbedFooter;
image?: EmbedImage;
provider?: EmbedProvider;
Expand All @@ -384,36 +388,41 @@ export interface RawEmbedAuthor extends EmbedAuthorBase {
proxy_icon_url?: string;
}

export interface EmbedAuthorOptions extends EmbedAuthorBase {
export interface EmbedAuthor extends EmbedAuthorOptions {
iconURL?: string;
proxyIconURL?: string;
}

export interface RawEmbedAuthorOptions extends EmbedAuthorBase {
icon_url?: string;
}

export interface EmbedAuthor extends EmbedAuthorOptions {
export interface EmbedAuthorOptions extends EmbedAuthorBase {
iconURL?: string;
proxyIconURL?: string;
}

export interface EmbedFooterBase {
text: string;
}

export interface EmbedFooterOptions extends EmbedFooterBase {
iconURL?: string;
}

export interface RawEmbedFooterOptions extends EmbedFooterBase {
icon_url?: string;
}

export interface EmbedFooterOptions extends EmbedFooterBase {
iconURL?: string;
}

export interface RawEmbedFooter extends EmbedFooterBase {
/** The {@link Constants.EmbedMediaFlags | Embed Media Flags} for the media. */
flags?: number;
icon_url?: string;
proxy_icon_url?: string;
}

export interface EmbedFooter extends EmbedFooterOptions {
/** The {@link Constants.EmbedMediaFlags | Embed Media Flags} for the media. */
flags?: number;
iconURL?: string;
proxyIconURL?: string;
}
Expand All @@ -424,17 +433,21 @@ export interface EmbedImageBase {
}

export interface RawEmbedImage extends EmbedImageBase, EmbedImageOptions {
/** The {@link Constants.EmbedMediaFlags | Embed Media Flags} for the media. */
flags?: number;
proxy_url?: string;
}

export interface EmbedImageOptions {
url: string;
}

export interface EmbedImage extends EmbedImageBase, EmbedImageOptions {
/** The {@link Constants.EmbedMediaFlags | Embed Media Flags} for the media. */
flags?: number;
proxyURL?: string;
}

export interface EmbedImageOptions {
url: string;
}

export interface EmbedField {
inline?: boolean;
name: string;
Expand Down Expand Up @@ -653,6 +666,9 @@ export interface TextInput {
}

export interface RawAttachment {
application?: RESTApplication;
clip_created_at?: string;
clip_participants?: Array<RawUser>;
content_type?: string;
description?: string;
duration_secs?: number;
Expand Down
9 changes: 6 additions & 3 deletions lib/util/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,17 +422,20 @@ export default class Util {
name: field.name,
value: field.value
})),
flags: embed.flags,
footer: embed.footer === undefined ? undefined : {
text: embed.footer.text,
flags: embed.footer.flags,
iconURL: embed.footer.icon_url,
proxyIconURL: embed.footer.proxy_icon_url
proxyIconURL: embed.footer.proxy_icon_url,
text: embed.footer.text
},
timestamp: embed.timestamp,
title: embed.title,
image: embed.image === undefined ? undefined : {
url: embed.image.url,
flags: embed.image.flags,
height: embed.image.height,
proxyURL: embed.image.proxy_url,
url: embed.image.url,
width: embed.image.width
},
provider: embed.provider === undefined ? undefined : {
Expand Down

0 comments on commit c3a8425

Please sign in to comment.