Skip to content
Merged
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
42 changes: 39 additions & 3 deletions lib/types/channels.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1206,10 +1206,7 @@ export interface MessagePollResults {
}

export interface RawTextDisplayComponent extends Omit<TextDisplayComponent, "id"> {}
export interface RawThumbnailComponent extends Omit<ThumbnailComponent, "id"> {}
export interface RawMediaGalleryComponent extends Omit<MediaGalleryComponent, "id"> {}
export interface RawSeparatorComponent extends Omit<SeparatorComponent, "id"> {}
export interface RawFileComponent extends Omit<FileComponent, "id"> {}

export interface RawSectionComponent extends BaseComponent {
accessory: RawThumbnailComponent | RawButtonComponent;
Expand Down Expand Up @@ -1438,8 +1435,22 @@ export interface TextInput extends BaseComponent {
value?: string;
}

export interface RawUnfurledMediaItem {
attachment_id?: string;
content_type?: string;
height?: number;
proxy_url?: string;
url: string;
width?: number;
}

export interface UnfurledMediaItem {
attachmentID?: string;
contentType?: string;
height?: number;
proxyURL?: string;
url: string;
width?: number;
}

export interface SectionComponent extends BaseComponent {
Expand All @@ -1460,6 +1471,19 @@ export interface ThumbnailComponent extends BaseComponent {
type: ComponentTypes.THUMBNAIL;
}

export interface RawThumbnailComponent extends Omit<BaseComponent, "id"> {
description?: string;
media: RawUnfurledMediaItem;
spoiler?: boolean;
type: ComponentTypes.THUMBNAIL;
}

export interface RawMediaGalleryItem {
description?: string;
media: RawUnfurledMediaItem;
spoiler?: boolean;
}

export interface MediaGalleryItem {
description?: string;
media: UnfurledMediaItem;
Expand All @@ -1471,6 +1495,11 @@ export interface MediaGalleryComponent extends BaseComponent {
type: ComponentTypes.MEDIA_GALLERY;
}

export interface RawMediaGalleryComponent extends Omit<BaseComponent, "id"> {
items: Array<RawMediaGalleryItem>;
type: ComponentTypes.MEDIA_GALLERY;
}

export interface SeparatorComponent extends BaseComponent {
divider?: boolean;
spacing?: SeparatorSpacingSize;
Expand All @@ -1484,6 +1513,13 @@ export interface FileComponent extends BaseComponent {
type: ComponentTypes.FILE;
}

export interface RawFileComponent extends Omit<BaseComponent, "id"> {
// The RawUnfurledMediaItem ONLY supports attachment://<filename> references
file: RawUnfurledMediaItem;
spoiler?: boolean;
type: ComponentTypes.FILE;
}

export interface ContainerComponent extends BaseComponent {
accentColor?: number;
components: Array<MessageActionRow | TextDisplayComponent | SectionComponent | MediaGalleryComponent | SeparatorComponent | FileComponent>;
Expand Down
114 changes: 106 additions & 8 deletions lib/util/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,59 @@ export default class Util {
}
}

case ComponentTypes.TEXT_DISPLAY:
case ComponentTypes.THUMBNAIL:
case ComponentTypes.MEDIA_GALLERY:
case ComponentTypes.FILE:
case ComponentTypes.TEXT_DISPLAY: {
return component as never;
}

case ComponentTypes.THUMBNAIL: {
return {
description: component.description,
media: {
attachmentID: component.media.attachment_id,
contentType: component.media.content_type,
height: component.media.height,
proxyURL: component.media.proxy_url,
url: component.media.url,
width: component.media.width
},
spoiler: component.spoiler,
type: component.type
} as never;
}

case ComponentTypes.MEDIA_GALLERY: {
return {
items: component.items.map(i => ({
description: i.description,
media: {
attachmentID: i.media.attachment_id,
contentType: i.media.content_type,
height: i.media.height,
proxyURL: i.media.proxy_url,
url: i.media.url,
width: i.media.width
},
spoiler: i.spoiler
})),
type: component.type
} as never;
}

case ComponentTypes.FILE: {
return {
file: {
attachmentID: component.file.attachment_id,
contentType: component.file.content_type,
height: component.file.height,
proxyURL: component.file.proxy_url,
url: component.file.url,
width: component.file.width
},
spoiler: component.spoiler,
type: component.type
} as never;
}

case ComponentTypes.SEPARATOR: {
return component as never;
}
Expand Down Expand Up @@ -356,10 +405,59 @@ export default class Util {
}
}

case ComponentTypes.TEXT_DISPLAY:
case ComponentTypes.THUMBNAIL:
case ComponentTypes.MEDIA_GALLERY:
case ComponentTypes.FILE:
case ComponentTypes.TEXT_DISPLAY: {
return component as never;
}

case ComponentTypes.THUMBNAIL: {
return {
description: component.description,
media: {
attachment_id: component.media.attachmentID,
content_type: component.media.contentType,
height: component.media.height,
proxy_url: component.media.proxyURL,
url: component.media.url,
width: component.media.width
},
spoiler: component.spoiler,
type: component.type
} as never;
}

case ComponentTypes.MEDIA_GALLERY: {
return {
items: component.items.map(i => ({
description: i.description,
media: {
attachment_id: i.media.attachmentID,
content_type: i.media.contentType,
height: i.media.height,
proxy_url: i.media.proxyURL,
url: i.media.url,
width: i.media.width
},
spoiler: i.spoiler
})),
type: component.type
} as never;
}

case ComponentTypes.FILE: {
return {
file: {
attachment_id: component.file.attachmentID,
content_type: component.file.contentType,
height: component.file.height,
proxy_url: component.file.proxyURL,
url: component.file.url,
width: component.file.width
},
spoiler: component.spoiler,
type: component.type
} as never;
}

case ComponentTypes.SEPARATOR: {
return component as never;
}
Expand Down