@arcscord/discord-ui-core 0.2.0-beta.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,551 @@
1
+ import { ButtonStyle, CDNRoutes, ChannelType, ComponentType, ImageFormat, MessageFlags, MessageType, RouteBases, SeparatorSpacingSize, StickerFormatType, UserFlags } from "discord-api-types/v10";
2
+ import { t as decodeWaveform } from "./media-DKcZ5Id4.mjs";
3
+ import { t as linkUrl } from "./urls-BdQaTx9e.mjs";
4
+ // src/discord-api/entities.ts
5
+ function hexColor(color) {
6
+ return `#${color.toString(16).padStart(6, "0")}`;
7
+ }
8
+ function avatarFormat(hash) {
9
+ return hash.startsWith("a_") ? ImageFormat.GIF : ImageFormat.WebP;
10
+ }
11
+ function guildAvatarUrl(guildId, userId, hash) {
12
+ return RouteBases.cdn + CDNRoutes.guildMemberAvatar(guildId, userId, hash, avatarFormat(hash));
13
+ }
14
+ function userAvatarUrl(user) {
15
+ if (user.avatar) return RouteBases.cdn + CDNRoutes.userAvatar(user.id, user.avatar, avatarFormat(user.avatar));
16
+ const index = user.discriminator && user.discriminator !== "0" ? Number(user.discriminator) % 5 : Number((BigInt(user.id) >> 22n) % 6n);
17
+ return `${RouteBases.cdn}/embed/avatars/${index}.png`;
18
+ }
19
+ function discordUserIdentity(user) {
20
+ const flags = user.public_flags ?? user.flags ?? 0;
21
+ return {
22
+ id: user.id,
23
+ displayName: user.global_name || user.username,
24
+ avatarUrl: userAvatarUrl(user),
25
+ bot: user.bot ?? false,
26
+ verified: Boolean(flags & UserFlags.VerifiedBot)
27
+ };
28
+ }
29
+ /** Server tag the user chose to display, with its badge from Discord's CDN. */
30
+ function discordUserTag(user) {
31
+ const guild = user.primary_guild;
32
+ if (!guild?.identity_enabled || !guild.tag) return void 0;
33
+ return {
34
+ text: guild.tag,
35
+ ...guild.identity_guild_id && guild.badge ? { badgeUrl: `${RouteBases.cdn}/guild-tag-badges/${guild.identity_guild_id}/${guild.badge}.png` } : {}
36
+ };
37
+ }
38
+ /** Convert a Discord user to identity data for authors, avatars and entity menus. */
39
+ function fromDiscordUser(user) {
40
+ return {
41
+ ...discordUserIdentity(user),
42
+ username: user.username
43
+ };
44
+ }
45
+ /** Convert a role's name and primary display color. */
46
+ function fromDiscordRole(role) {
47
+ const color = role.colors?.primary_color ?? role.color;
48
+ return {
49
+ id: role.id,
50
+ name: role.name,
51
+ ...color ? { color: hexColor(color) } : {}
52
+ };
53
+ }
54
+ const supportedChannelTypes = /* @__PURE__ */ new Set([
55
+ 0,
56
+ 1,
57
+ 2,
58
+ 3,
59
+ 4,
60
+ 5,
61
+ 10,
62
+ 11,
63
+ 12,
64
+ 13,
65
+ 14,
66
+ 15,
67
+ 16
68
+ ]);
69
+ function isDisplayChannelType(type) {
70
+ return supportedChannelTypes.has(type);
71
+ }
72
+ /** Convert a named channel identity. Unnamed or unsupported channels return undefined. */
73
+ function fromDiscordChannel(channel) {
74
+ if (channel.name && isDisplayChannelType(channel.type)) return {
75
+ id: channel.id,
76
+ name: channel.name,
77
+ channelType: channel.type
78
+ };
79
+ }
80
+ function emojiView(emoji) {
81
+ if (emoji.id) {
82
+ const format = emoji.animated ? ImageFormat.GIF : ImageFormat.WebP;
83
+ return {
84
+ name: emoji.name || "emoji",
85
+ image: RouteBases.cdn + CDNRoutes.emoji(emoji.id, format)
86
+ };
87
+ }
88
+ return emoji.name ? { name: emoji.name } : void 0;
89
+ }
90
+ // src/discord-api/media.ts
91
+ const attachmentPrefix = "attachment://";
92
+ function resolveMedia(source, attachments) {
93
+ const filename = source.url.startsWith(attachmentPrefix) ? source.url.slice(13) : void 0;
94
+ const attachment = source.attachment_id && attachments.find((item) => item.id === source.attachment_id) || filename && attachments.find((item) => item.filename === filename || item.title === filename) || void 0;
95
+ return {
96
+ url: linkUrl(attachment?.url) ?? linkUrl(source.url) ?? linkUrl(source.proxy_url) ?? linkUrl(attachment?.proxy_url),
97
+ attachment,
98
+ filename
99
+ };
100
+ }
101
+ function attachmentKind(source) {
102
+ const mime = source.content_type?.split(";", 1)[0]?.trim().toLowerCase();
103
+ if (mime) return mime.startsWith("image/") ? "image" : mime.startsWith("video/") ? "video" : mime.startsWith("audio/") ? "audio" : "file";
104
+ const name = source.filename ?? source.url?.split(/[?#]/u, 1)[0] ?? "";
105
+ if (/\.(?:avif|gif|jpe?g|png|webp|svg|bmp|ico)$/iu.test(name)) return "image";
106
+ if (/\.(?:mp4|m4v|webm|mov|ogv)$/iu.test(name)) return "video";
107
+ if (/\.(?:mp3|m4a|aac|ogg|oga|opus|wav|flac|weba)$/iu.test(name)) return "audio";
108
+ return "file";
109
+ }
110
+ function mediaView(id, source, attachments, alt, spoiler) {
111
+ const { url, attachment, filename } = resolveMedia(source, attachments);
112
+ const contentType = source.content_type ?? attachment?.content_type;
113
+ const kind = attachmentKind({
114
+ content_type: contentType ?? null,
115
+ filename: attachment?.filename ?? filename ?? source.url.split(/[?#]/u, 1)[0] ?? ""
116
+ });
117
+ if (!url || contentType && !contentType.toLowerCase().startsWith("image/") || kind === "video" || kind === "audio") return void 0;
118
+ const width = source.width ?? attachment?.width;
119
+ const height = source.height ?? attachment?.height;
120
+ return {
121
+ id,
122
+ url,
123
+ alt: alt ?? attachment?.description ?? attachment?.filename ?? filename ?? "",
124
+ ...width != null ? { width } : {},
125
+ ...height != null ? { height } : {},
126
+ ...spoiler || attachment?.filename.startsWith("SPOILER_") || filename?.startsWith("SPOILER_") ? { spoiler: true } : {}
127
+ };
128
+ }
129
+ function fileView(id, url, name, size, spoiler) {
130
+ return {
131
+ id,
132
+ kind: "file",
133
+ name,
134
+ url,
135
+ ...size !== void 0 ? { size: `${size} B` } : {},
136
+ ...spoiler || name.startsWith("SPOILER_") ? { spoiler: true } : {}
137
+ };
138
+ }
139
+ function galleryMediaView(id, source, attachments, alt, spoiler) {
140
+ const { attachment, url, filename } = resolveMedia(source, attachments);
141
+ const kind = attachmentKind({
142
+ ...source,
143
+ content_type: source.content_type ?? attachment?.content_type ?? null,
144
+ filename: attachment?.filename ?? filename ?? source.url.split(/[?#]/u, 1)[0] ?? ""
145
+ });
146
+ if (kind === "audio") return void 0;
147
+ if (kind !== "video") return mediaView(id, source, attachments, alt, spoiler);
148
+ if (!url) return void 0;
149
+ const width = source.width ?? attachment?.width;
150
+ const height = source.height ?? attachment?.height;
151
+ const video = {
152
+ kind: "video",
153
+ id,
154
+ url,
155
+ alt: alt ?? attachment?.description ?? attachment?.filename ?? ""
156
+ };
157
+ if (width != null) video.width = width;
158
+ if (height != null) video.height = height;
159
+ if (spoiler || attachment?.filename.startsWith("SPOILER_") || filename?.startsWith("SPOILER_")) video.spoiler = true;
160
+ const duration = source.duration_secs ?? attachment?.duration_secs;
161
+ if (duration !== void 0 && Number.isFinite(duration) && duration >= 0) video.durationSeconds = duration;
162
+ return video;
163
+ }
164
+ function audioView(attachment, voice) {
165
+ const url = linkUrl(attachment.url) ?? linkUrl(attachment.proxy_url);
166
+ if (!url) return void 0;
167
+ const audio = {
168
+ ...fileView(attachment.id, url, attachment.filename, attachment.size),
169
+ kind: "audio"
170
+ };
171
+ if (voice) audio.voice = true;
172
+ if (attachment.duration_secs !== void 0 && Number.isFinite(attachment.duration_secs) && attachment.duration_secs >= 0) audio.durationSeconds = attachment.duration_secs;
173
+ const waveform = voice && decodeWaveform(attachment.waveform);
174
+ if (waveform) audio.waveform = waveform;
175
+ return audio;
176
+ }
177
+ // src/discord-api/components.ts
178
+ function componentId(component, path) {
179
+ return component.id ? String(component.id) : `component:${path}`;
180
+ }
181
+ const buttonStyles = {
182
+ [ButtonStyle.Primary]: "primary",
183
+ [ButtonStyle.Secondary]: "secondary",
184
+ [ButtonStyle.Success]: "success",
185
+ [ButtonStyle.Danger]: "danger"
186
+ };
187
+ function convertButton(button, path) {
188
+ const disabled = button.disabled === void 0 ? {} : { disabled: button.disabled };
189
+ if (button.style === ButtonStyle.Premium) return {
190
+ id: componentId(button, path),
191
+ kind: "premium-button",
192
+ skuId: button.sku_id,
193
+ label: "Premium",
194
+ ...disabled
195
+ };
196
+ const emoji = button.emoji && emojiView(button.emoji);
197
+ const presentation = {
198
+ label: button.label ?? "",
199
+ ...emoji ? { emoji } : {},
200
+ ...disabled
201
+ };
202
+ if (button.style === ButtonStyle.Link) return {
203
+ id: componentId(button, path),
204
+ kind: "link-button",
205
+ url: button.url,
206
+ ...presentation
207
+ };
208
+ const style = buttonStyles[button.style];
209
+ return style ? {
210
+ id: button.custom_id,
211
+ kind: "button",
212
+ style,
213
+ ...presentation
214
+ } : void 0;
215
+ }
216
+ function convertSelect(select, options) {
217
+ const base = {
218
+ id: select.custom_id,
219
+ ...select.placeholder !== void 0 ? { placeholder: select.placeholder } : {},
220
+ ...select.min_values !== void 0 ? { minValues: select.min_values } : {},
221
+ ...select.max_values !== void 0 ? { maxValues: select.max_values } : {},
222
+ ...select.disabled !== void 0 ? { disabled: select.disabled } : {}
223
+ };
224
+ if (select.type === ComponentType.StringSelect) return {
225
+ ...base,
226
+ kind: "string-select",
227
+ options: select.options.map(({ label, value, description, emoji, default: selected }) => {
228
+ const displayEmoji = emoji && emojiView(emoji);
229
+ return {
230
+ label,
231
+ value,
232
+ ...description !== void 0 ? { description } : {},
233
+ ...selected !== void 0 ? { default: selected } : {},
234
+ ...displayEmoji ? { emoji: displayEmoji } : {}
235
+ };
236
+ })
237
+ };
238
+ const choices = options.selectEntities && Object.hasOwn(options.selectEntities, select.custom_id) ? options.selectEntities[select.custom_id] : void 0;
239
+ switch (select.type) {
240
+ case ComponentType.UserSelect: return {
241
+ ...base,
242
+ kind: "user-select",
243
+ entities: (choices?.users ?? []).map((user) => ({
244
+ ...user,
245
+ entityType: "user"
246
+ })),
247
+ ...defaultsFor(select.default_values)
248
+ };
249
+ case ComponentType.RoleSelect: return {
250
+ ...base,
251
+ kind: "role-select",
252
+ entities: (choices?.roles ?? []).map((role) => ({
253
+ ...role,
254
+ entityType: "role"
255
+ })),
256
+ ...defaultsFor(select.default_values)
257
+ };
258
+ case ComponentType.MentionableSelect: return {
259
+ ...base,
260
+ kind: "mentionable-select",
261
+ entities: [...(choices?.users ?? []).map((user) => ({
262
+ ...user,
263
+ entityType: "user"
264
+ })), ...(choices?.roles ?? []).map((role) => ({
265
+ ...role,
266
+ entityType: "role"
267
+ }))],
268
+ ...defaultsFor(select.default_values)
269
+ };
270
+ case ComponentType.ChannelSelect: return {
271
+ ...base,
272
+ kind: "channel-select",
273
+ entities: (choices?.channels ?? []).map((channel) => ({
274
+ ...channel,
275
+ entityType: "channel"
276
+ })),
277
+ ...select.channel_types !== void 0 ? { channelTypes: select.channel_types.filter(isDisplayChannelType) } : {},
278
+ ...defaultsFor(select.default_values)
279
+ };
280
+ default: return;
281
+ }
282
+ }
283
+ function defaultsFor(values) {
284
+ return values === void 0 ? {} : { defaultValues: values.map(({ id, type }) => ({
285
+ id,
286
+ type
287
+ })) };
288
+ }
289
+ function convertActionRow(row, path, options) {
290
+ const id = componentId(row, path);
291
+ const buttons = [];
292
+ for (const [index, child] of row.components.entries()) if (child.type === ComponentType.Button) {
293
+ const button = convertButton(child, `${path}.${index}`);
294
+ if (button) buttons.push(button);
295
+ } else {
296
+ const select = convertSelect(child, options);
297
+ if (select) return {
298
+ id,
299
+ kind: "action-row",
300
+ select
301
+ };
302
+ }
303
+ return buttons.length ? {
304
+ id,
305
+ kind: "action-row",
306
+ buttons
307
+ } : void 0;
308
+ }
309
+ function convertChild(component, path, options) {
310
+ const id = componentId(component, path);
311
+ const attachments = options.attachments ?? [];
312
+ switch (component.type) {
313
+ case ComponentType.ActionRow: return convertActionRow(component, path, options);
314
+ case ComponentType.TextDisplay: return {
315
+ id,
316
+ kind: "text-display",
317
+ content: component.content
318
+ };
319
+ case ComponentType.Separator: return {
320
+ id,
321
+ kind: "separator",
322
+ divider: component.divider ?? true,
323
+ spacing: component.spacing === SeparatorSpacingSize.Large ? "large" : "small"
324
+ };
325
+ case ComponentType.Section: {
326
+ const source = component.accessory;
327
+ const accessoryId = componentId(source, `${path}.accessory`);
328
+ const thumbnail = source.type === ComponentType.Thumbnail ? mediaView(accessoryId, source.media, attachments, source.description, source.spoiler) : void 0;
329
+ const accessory = thumbnail ? {
330
+ id: accessoryId,
331
+ kind: "thumbnail",
332
+ media: thumbnail
333
+ } : source.type === ComponentType.Button ? convertButton(source, `${path}.accessory`) : void 0;
334
+ const components = component.components.flatMap((text, index) => text.type === ComponentType.TextDisplay ? [{
335
+ id: componentId(text, `${path}.${index}`),
336
+ kind: "text-display",
337
+ content: text.content
338
+ }] : []);
339
+ return accessory && components.length ? {
340
+ id,
341
+ kind: "section",
342
+ components,
343
+ accessory
344
+ } : void 0;
345
+ }
346
+ case ComponentType.MediaGallery: {
347
+ const items = component.items.map((item, index) => galleryMediaView(`${id}:item:${index}`, item.media, attachments, item.description, item.spoiler)).filter((item) => item !== void 0);
348
+ return items.length ? {
349
+ id,
350
+ kind: "media-gallery",
351
+ items
352
+ } : void 0;
353
+ }
354
+ case ComponentType.File: {
355
+ const { url, attachment, filename } = resolveMedia(component.file, attachments);
356
+ return url ? fileView(id, url, component.name ?? attachment?.filename ?? filename ?? "File", component.size ?? attachment?.size, component.spoiler || attachment?.filename.startsWith("SPOILER_") || filename?.startsWith("SPOILER_")) : void 0;
357
+ }
358
+ default: return;
359
+ }
360
+ }
361
+ /** Convert a message's component array in order, omitting unsupported nodes. */
362
+ function fromDiscordMessageComponents(components, options = {}) {
363
+ return components.map((component, index) => {
364
+ const path = String(index);
365
+ if (component.type !== ComponentType.Container) return convertChild(component, path, options);
366
+ return {
367
+ id: componentId(component, path),
368
+ kind: "container",
369
+ components: component.components.map((child, childIndex) => convertChild(child, `${path}.${childIndex}`, options)).filter((child) => child !== void 0),
370
+ ...component.spoiler !== void 0 ? { spoiler: component.spoiler } : {},
371
+ ...component.accent_color != null ? { accentColor: hexColor(component.accent_color) } : {}
372
+ };
373
+ }).filter((component) => component !== void 0);
374
+ }
375
+ // src/discord-api.ts
376
+ function userAuthor(user) {
377
+ const tag = discordUserTag(user);
378
+ return {
379
+ ...discordUserIdentity(user),
380
+ ...tag ? { tag } : {}
381
+ };
382
+ }
383
+ function messageAuthor(message) {
384
+ const author = userAuthor(message.author);
385
+ const memberAvatar = message.member?.avatar;
386
+ return {
387
+ ...author,
388
+ displayName: message.member?.nick || author.displayName,
389
+ avatarUrl: message.guild_id && memberAvatar ? guildAvatarUrl(message.guild_id, author.id, memberAvatar) : author.avatarUrl
390
+ };
391
+ }
392
+ function messageReply(message) {
393
+ if (message.type === MessageType.Reply) {
394
+ if (message.referenced_message) return {
395
+ messageId: message.referenced_message.id,
396
+ author: messageAuthor(message.referenced_message),
397
+ content: message.referenced_message.content
398
+ };
399
+ if (message.referenced_message === null && message.message_reference?.message_id) return {
400
+ messageId: message.message_reference.message_id,
401
+ unavailable: true
402
+ };
403
+ }
404
+ if (message.type === MessageType.ChatInputCommand && message.interaction?.name) return {
405
+ kind: "interaction",
406
+ author: userAuthor(message.interaction.user),
407
+ commandName: message.interaction.name
408
+ };
409
+ }
410
+ function threadSummary(thread) {
411
+ if (thread?.type === ChannelType.AnnouncementThread || thread?.type === ChannelType.PublicThread || thread?.type === ChannelType.PrivateThread) {
412
+ if (thread.name && thread.message_count !== void 0) return {
413
+ id: thread.id,
414
+ name: thread.name,
415
+ messageCount: thread.message_count
416
+ };
417
+ }
418
+ }
419
+ function embedIcon(iconUrl, proxyUrl, attachments) {
420
+ return iconUrl === void 0 ? linkUrl(proxyUrl) : resolveMedia({
421
+ url: iconUrl,
422
+ ...proxyUrl ? { proxy_url: proxyUrl } : {}
423
+ }, attachments).url;
424
+ }
425
+ function convertEmbed(embed, id, attachments) {
426
+ const { author, footer, title, url, description, color, timestamp } = embed;
427
+ const thumbnail = embed.thumbnail && mediaView(`${id}:thumbnail`, embed.thumbnail, attachments);
428
+ const image = embed.image && mediaView(`${id}:image`, embed.image, attachments);
429
+ const view = { id };
430
+ if (title !== void 0) view.title = title;
431
+ if (url !== void 0) view.url = url;
432
+ if (description !== void 0) view.description = description;
433
+ if (color !== void 0) view.color = hexColor(color);
434
+ if (timestamp !== void 0) view.timestamp = timestamp;
435
+ if (thumbnail) view.thumbnail = thumbnail;
436
+ if (image) view.image = image;
437
+ if (author) {
438
+ const iconUrl = embedIcon(author.icon_url, author.proxy_icon_url, attachments);
439
+ view.author = { name: author.name };
440
+ if (author.url !== void 0) view.author.url = author.url;
441
+ if (iconUrl) view.author.iconUrl = iconUrl;
442
+ }
443
+ if (footer) {
444
+ const iconUrl = embedIcon(footer.icon_url, footer.proxy_icon_url, attachments);
445
+ view.footer = { text: footer.text };
446
+ if (iconUrl) view.footer.iconUrl = iconUrl;
447
+ }
448
+ if (embed.fields) view.fields = embed.fields.map((field, index) => ({
449
+ ...field,
450
+ id: `${id}:field:${index}`
451
+ }));
452
+ return view;
453
+ }
454
+ function attachmentUrlKey(url) {
455
+ return /^https:\/\/(?:cdn\.discordapp\.com|media\.discordapp\.net)(\/(?:ephemeral-)?attachments\/\d+\/\d+)\//u.exec(url)?.[1] ?? url;
456
+ }
457
+ /** Convert a complete REST message or Gateway MESSAGE_CREATE payload to a display snapshot. */
458
+ function fromDiscordMessage(message, options = {}) {
459
+ const flags = message.flags ?? 0;
460
+ const reply = messageReply(message);
461
+ const thread = threadSummary(message.thread);
462
+ const reactions = message.reactions?.flatMap((reaction) => {
463
+ const emoji = emojiView(reaction.emoji);
464
+ return emoji ? [{
465
+ id: reaction.emoji.id ?? emoji.name,
466
+ emoji,
467
+ count: reaction.count,
468
+ me: reaction.me || reaction.me_burst === true
469
+ }] : [];
470
+ });
471
+ const metadata = {
472
+ id: message.id,
473
+ author: messageAuthor(message),
474
+ timestamp: message.timestamp,
475
+ edited: message.edited_timestamp != null,
476
+ ephemeral: Boolean(flags & MessageFlags.Ephemeral)
477
+ };
478
+ if (reactions) metadata.reactions = reactions;
479
+ if (reply) metadata.reply = reply;
480
+ if (thread) metadata.thread = thread;
481
+ if (flags & MessageFlags.IsComponentsV2) return {
482
+ ...metadata,
483
+ body: {
484
+ kind: "components-v2",
485
+ components: fromDiscordMessageComponents(message.components ?? [], {
486
+ ...options,
487
+ attachments: message.attachments
488
+ })
489
+ }
490
+ };
491
+ const embeds = flags & MessageFlags.SuppressEmbeds ? [] : message.embeds.map((embed, index) => convertEmbed(embed, `embed:${index}`, message.attachments));
492
+ const embeddedMedia = new Set(embeds.flatMap((embed) => [
493
+ embed.image?.url,
494
+ embed.thumbnail?.url,
495
+ embed.author?.iconUrl,
496
+ embed.footer?.iconUrl
497
+ ].filter((url) => url !== void 0).map(attachmentUrlKey)));
498
+ const media = [];
499
+ const files = [];
500
+ for (const attachment of message.attachments) {
501
+ if (embeddedMedia.has(attachmentUrlKey(attachment.url)) || embeddedMedia.has(attachmentUrlKey(attachment.proxy_url))) continue;
502
+ const kind = attachmentKind(attachment);
503
+ if (kind === "image" || kind === "video") {
504
+ const image = galleryMediaView(attachment.id, attachment, [attachment], attachment.description ?? attachment.filename, attachment.filename.startsWith("SPOILER_"));
505
+ if (image) media.push(image);
506
+ } else if (kind === "audio") {
507
+ const audio = audioView(attachment, Boolean(flags & MessageFlags.IsVoiceMessage));
508
+ if (audio) files.push(audio);
509
+ } else {
510
+ const url = linkUrl(attachment.url) ?? linkUrl(attachment.proxy_url);
511
+ if (url) files.push(fileView(attachment.id, url, attachment.filename, attachment.size));
512
+ }
513
+ }
514
+ const components = message.components?.flatMap((component, index) => {
515
+ const row = component.type === ComponentType.ActionRow && convertActionRow(component, String(index), options);
516
+ return row ? [row] : [];
517
+ });
518
+ const view = {
519
+ ...metadata,
520
+ body: {
521
+ kind: "markdown",
522
+ content: message.content
523
+ }
524
+ };
525
+ const stickers = message.sticker_items?.flatMap((sticker) => {
526
+ const format = {
527
+ [StickerFormatType.PNG]: "png",
528
+ [StickerFormatType.APNG]: "apng",
529
+ [StickerFormatType.GIF]: "gif",
530
+ [StickerFormatType.Lottie]: "lottie"
531
+ }[sticker.format_type];
532
+ if (!format) return [];
533
+ const extension = format === "apng" ? "png" : format === "lottie" ? "json" : format;
534
+ const origin = format === "gif" ? "https://media.discordapp.net" : "https://cdn.discordapp.com";
535
+ return [{
536
+ id: sticker.id,
537
+ name: sticker.name,
538
+ format,
539
+ url: `${origin}/stickers/${encodeURIComponent(sticker.id)}.${extension}`
540
+ }];
541
+ });
542
+ if (stickers?.length) view.stickers = stickers;
543
+ if (media.length) view.media = media;
544
+ if (files.length) view.attachments = files;
545
+ if (embeds.length) view.embeds = embeds;
546
+ if (components?.length) view.components = components;
547
+ return view;
548
+ }
549
+ export { fromDiscordChannel, fromDiscordMessage, fromDiscordMessageComponents, fromDiscordRole, fromDiscordUser };
550
+
551
+ //# sourceMappingURL=discord-api.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"discord-api.mjs","names":[],"sources":["../src/discord-api/entities.ts","../src/discord-api/media.ts","../src/discord-api/components.ts","../src/discord-api.ts"],"sourcesContent":["import type { APIPartialChannel, APIRole, APIUser } from \"discord-api-types/v10\";\nimport type { ChannelEntityView, ChannelType, RoleView, UserView } from \"../model/entities\";\nimport type { AuthorTag } from \"../model/message\";\nimport { CDNRoutes, ImageFormat, RouteBases, UserFlags } from \"discord-api-types/v10\";\n\nexport function hexColor(color: number): string {\n return `#${color.toString(16).padStart(6, \"0\")}`;\n}\n\nfunction avatarFormat(hash: string): ImageFormat.GIF | ImageFormat.WebP {\n return hash.startsWith(\"a_\")\n ? ImageFormat.GIF\n : ImageFormat.WebP;\n}\n\nexport function guildAvatarUrl(guildId: string, userId: string, hash: string): string {\n return RouteBases.cdn + CDNRoutes.guildMemberAvatar(guildId, userId, hash, avatarFormat(hash));\n}\n\nfunction userAvatarUrl(user: APIUser): string {\n if (user.avatar)\n return RouteBases.cdn + CDNRoutes.userAvatar(user.id, user.avatar, avatarFormat(user.avatar));\n\n const index = user.discriminator && user.discriminator !== \"0\"\n ? Number(user.discriminator) % 5\n : Number((BigInt(user.id) >> 22n) % 6n);\n return `${RouteBases.cdn}/embed/avatars/${index}.png`;\n}\n\nexport function discordUserIdentity(user: APIUser): Required<Pick<UserView, \"id\" | \"displayName\" | \"avatarUrl\" | \"bot\" | \"verified\">> {\n const flags = user.public_flags ?? user.flags ?? 0;\n return {\n id: user.id,\n displayName: user.global_name || user.username,\n avatarUrl: userAvatarUrl(user),\n bot: user.bot ?? false,\n verified: Boolean(flags & UserFlags.VerifiedBot),\n };\n}\n\n/** Server tag the user chose to display, with its badge from Discord's CDN. */\nexport function discordUserTag(user: APIUser): AuthorTag | undefined {\n const guild = user.primary_guild;\n if (!guild?.identity_enabled || !guild.tag)\n return undefined;\n return {\n text: guild.tag,\n ...(guild.identity_guild_id && guild.badge\n ? { badgeUrl: `${RouteBases.cdn}/guild-tag-badges/${guild.identity_guild_id}/${guild.badge}.png` }\n : {}),\n };\n}\n\n/** Convert a Discord user to identity data for authors, avatars and entity menus. */\nexport function fromDiscordUser(user: APIUser): UserView {\n return {\n ...discordUserIdentity(user),\n username: user.username,\n };\n}\n\n/** Convert a role's name and primary display color. */\nexport function fromDiscordRole(role: Pick<APIRole, \"id\" | \"name\" | \"color\"> & Partial<Pick<APIRole, \"colors\">>): RoleView {\n const color = role.colors?.primary_color ?? role.color;\n return {\n id: role.id,\n name: role.name,\n ...(color\n ? {\n color: hexColor(color),\n }\n : {}),\n };\n}\n\nconst supportedChannelTypes = new Set<number>([\n 0,\n 1,\n 2,\n 3,\n 4,\n 5,\n 10,\n 11,\n 12,\n 13,\n 14,\n 15,\n 16,\n] satisfies ChannelType[]);\n\nexport function isDisplayChannelType(type: number): type is ChannelType {\n return supportedChannelTypes.has(type);\n}\n\n/** Convert a named channel identity. Unnamed or unsupported channels return undefined. */\nexport function fromDiscordChannel(channel: APIPartialChannel): ChannelEntityView | undefined {\n if (channel.name && isDisplayChannelType(channel.type))\n return { id: channel.id, name: channel.name, channelType: channel.type };\n return undefined;\n}\n\nexport function emojiView(emoji: { name?: string | null; id?: string | null; animated?: boolean }): { name: string; image?: string } | undefined {\n if (emoji.id) {\n const format = emoji.animated ? ImageFormat.GIF : ImageFormat.WebP;\n return { name: emoji.name || \"emoji\", image: RouteBases.cdn + CDNRoutes.emoji(emoji.id, format) };\n }\n return emoji.name\n ? { name: emoji.name }\n : undefined;\n}\n","import type { APIAttachment } from \"discord-api-types/v10\";\nimport type { FileView } from \"../model/components\";\nimport type { AudioView, MediaView, MessageMediaView, VideoView } from \"../model/content\";\nimport { decodeWaveform } from \"../utils/media\";\nimport { linkUrl } from \"../utils/urls\";\n\ntype DiscordMedia = {\n url: string;\n proxy_url?: string;\n attachment_id?: string;\n content_type?: string | null;\n width?: number | null;\n height?: number | null;\n duration_secs?: number;\n};\n\nconst attachmentPrefix = \"attachment://\";\n\nexport function resolveMedia(source: DiscordMedia, attachments: readonly APIAttachment[]): { url: string | undefined; attachment: APIAttachment | undefined; filename: string | undefined } {\n const filename = source.url.startsWith(attachmentPrefix)\n ? source.url.slice(attachmentPrefix.length)\n : undefined;\n const attachment = (source.attachment_id && attachments.find(item => item.id === source.attachment_id))\n || (filename && attachments.find(item => item.filename === filename || item.title === filename))\n || undefined;\n const url = linkUrl(attachment?.url) ?? linkUrl(source.url) ?? linkUrl(source.proxy_url) ?? linkUrl(attachment?.proxy_url);\n return { url, attachment, filename };\n}\n\nexport function attachmentKind(source: { content_type?: string | null; filename?: string; url?: string }): \"image\" | \"video\" | \"audio\" | \"file\" {\n const mime = source.content_type?.split(\";\", 1)[0]?.trim().toLowerCase();\n if (mime) {\n return mime.startsWith(\"image/\")\n ? \"image\"\n : mime.startsWith(\"video/\")\n ? \"video\"\n : mime.startsWith(\"audio/\")\n ? \"audio\"\n : \"file\";\n }\n const name = source.filename ?? source.url?.split(/[?#]/u, 1)[0] ?? \"\";\n if (/\\.(?:avif|gif|jpe?g|png|webp|svg|bmp|ico)$/iu.test(name))\n return \"image\";\n if (/\\.(?:mp4|m4v|webm|mov|ogv)$/iu.test(name))\n return \"video\";\n if (/\\.(?:mp3|m4a|aac|ogg|oga|opus|wav|flac|weba)$/iu.test(name))\n return \"audio\";\n return \"file\";\n}\n\nexport function mediaView(id: string, source: DiscordMedia, attachments: readonly APIAttachment[], alt?: string | null, spoiler?: boolean): MediaView | undefined {\n const { url, attachment, filename } = resolveMedia(source, attachments);\n const contentType = source.content_type ?? attachment?.content_type;\n const kind = attachmentKind({ content_type: contentType ?? null, filename: attachment?.filename ?? filename ?? source.url.split(/[?#]/u, 1)[0] ?? \"\" });\n if (!url || (contentType && !contentType.toLowerCase().startsWith(\"image/\")) || kind === \"video\" || kind === \"audio\")\n return undefined;\n const width = source.width ?? attachment?.width;\n const height = source.height ?? attachment?.height;\n return {\n id,\n url,\n alt: alt ?? attachment?.description ?? attachment?.filename ?? filename ?? \"\",\n ...(width != null\n ? { width }\n : {}),\n ...(height != null\n ? { height }\n : {}),\n ...((spoiler || attachment?.filename.startsWith(\"SPOILER_\") || filename?.startsWith(\"SPOILER_\"))\n ? { spoiler: true }\n : {}),\n };\n}\n\nexport function fileView(id: string, url: string, name: string, size: number | undefined, spoiler?: boolean): FileView {\n return {\n id,\n kind: \"file\",\n name,\n url,\n ...(size !== undefined\n ? { size: `${size} B` }\n : {}),\n ...(spoiler || name.startsWith(\"SPOILER_\")\n ? { spoiler: true }\n : {}),\n };\n}\n\nexport function galleryMediaView(id: string, source: DiscordMedia, attachments: readonly APIAttachment[], alt?: string | null, spoiler?: boolean): MessageMediaView | undefined {\n const { attachment, url, filename } = resolveMedia(source, attachments);\n const kind = attachmentKind({ ...source, content_type: source.content_type ?? attachment?.content_type ?? null, filename: attachment?.filename ?? filename ?? source.url.split(/[?#]/u, 1)[0] ?? \"\" });\n if (kind === \"audio\")\n return undefined;\n if (kind !== \"video\")\n return mediaView(id, source, attachments, alt, spoiler);\n if (!url)\n return undefined;\n const width = source.width ?? attachment?.width;\n const height = source.height ?? attachment?.height;\n const video: VideoView = {\n kind: \"video\",\n id,\n url,\n alt: alt ?? attachment?.description ?? attachment?.filename ?? \"\",\n };\n if (width != null)\n video.width = width;\n if (height != null)\n video.height = height;\n if (spoiler || attachment?.filename.startsWith(\"SPOILER_\") || filename?.startsWith(\"SPOILER_\"))\n video.spoiler = true;\n const duration = source.duration_secs ?? attachment?.duration_secs;\n if (duration !== undefined && Number.isFinite(duration) && duration >= 0)\n video.durationSeconds = duration;\n return video;\n}\n\nexport function audioView(attachment: APIAttachment, voice: boolean): AudioView | undefined {\n const url = linkUrl(attachment.url) ?? linkUrl(attachment.proxy_url);\n if (!url)\n return undefined;\n const audio: AudioView = {\n ...fileView(attachment.id, url, attachment.filename, attachment.size),\n kind: \"audio\",\n };\n if (voice)\n audio.voice = true;\n if (attachment.duration_secs !== undefined && Number.isFinite(attachment.duration_secs) && attachment.duration_secs >= 0)\n audio.durationSeconds = attachment.duration_secs;\n const waveform = voice && decodeWaveform(attachment.waveform);\n if (waveform)\n audio.waveform = waveform;\n return audio;\n}\n","import type { APIActionRowComponent, APIAttachment, APIButtonComponent, APIComponentInContainer, APIComponentInMessageActionRow, APIMessageTopLevelComponent } from \"discord-api-types/v10\";\nimport type { ActionRowView, ButtonView, ContainerChild, MessageButtonView, MessageComponent, SelectDefaultValue, SelectMenuView } from \"../model/components\";\nimport type { ChannelEntityView, RoleView, UserView } from \"../model/entities\";\nimport { ButtonStyle, ComponentType, SeparatorSpacingSize } from \"discord-api-types/v10\";\nimport { emojiView, hexColor, isDisplayChannelType } from \"./entities\";\nimport { fileView, galleryMediaView, mediaView, resolveMedia } from \"./media\";\n\nexport type DiscordMessageConversionOptions = {\n /** Available choices for each entity select, keyed by its Discord custom_id. */\n selectEntities?: Readonly<Record<string, {\n users?: readonly UserView[];\n roles?: readonly RoleView[];\n channels?: readonly ChannelEntityView[];\n } | undefined>>;\n};\n\nexport type DiscordComponentConversionOptions = DiscordMessageConversionOptions & {\n /** Attachments supplied by the containing message for attachment:// references. */\n attachments?: readonly APIAttachment[];\n};\n\nfunction componentId(component: { id?: number }, path: string): string {\n return component.id\n ? String(component.id)\n : `component:${path}`;\n}\n\nconst buttonStyles = {\n [ButtonStyle.Primary]: \"primary\",\n [ButtonStyle.Secondary]: \"secondary\",\n [ButtonStyle.Success]: \"success\",\n [ButtonStyle.Danger]: \"danger\",\n} satisfies Record<number, ButtonView[\"style\"]>;\n\nfunction convertButton(button: APIButtonComponent, path: string): MessageButtonView | undefined {\n const disabled = button.disabled === undefined\n ? {}\n : { disabled: button.disabled };\n if (button.style === ButtonStyle.Premium) {\n return {\n id: componentId(button, path),\n kind: \"premium-button\",\n skuId: button.sku_id,\n label: \"Premium\",\n ...disabled,\n };\n }\n\n const emoji = button.emoji && emojiView(button.emoji);\n const presentation = {\n label: button.label ?? \"\",\n ...(emoji\n ? { emoji }\n : {}),\n ...disabled,\n };\n if (button.style === ButtonStyle.Link) {\n return {\n id: componentId(button, path),\n kind: \"link-button\",\n url: button.url,\n ...presentation,\n };\n }\n\n const style = buttonStyles[button.style];\n return style\n ? {\n id: button.custom_id,\n kind: \"button\",\n style,\n ...presentation,\n }\n : undefined;\n}\n\nfunction convertSelect(select: Exclude<APIComponentInMessageActionRow, APIButtonComponent>, options: DiscordMessageConversionOptions): SelectMenuView | undefined {\n const base = {\n id: select.custom_id,\n ...(select.placeholder !== undefined\n ? { placeholder: select.placeholder }\n : {}),\n ...(select.min_values !== undefined\n ? { minValues: select.min_values }\n : {}),\n ...(select.max_values !== undefined\n ? { maxValues: select.max_values }\n : {}),\n ...(select.disabled !== undefined\n ? { disabled: select.disabled }\n : {}),\n };\n if (select.type === ComponentType.StringSelect) {\n return {\n ...base,\n kind: \"string-select\",\n options: select.options.map(({ label, value, description, emoji, default: selected }) => {\n const displayEmoji = emoji && emojiView(emoji);\n return {\n label,\n value,\n ...(description !== undefined\n ? { description }\n : {}),\n ...(selected !== undefined\n ? { default: selected }\n : {}),\n ...(displayEmoji\n ? { emoji: displayEmoji }\n : {}),\n };\n }),\n };\n }\n\n const choices = options.selectEntities && Object.hasOwn(options.selectEntities, select.custom_id)\n ? options.selectEntities[select.custom_id]\n : undefined;\n switch (select.type) {\n case ComponentType.UserSelect:\n return {\n ...base,\n kind: \"user-select\",\n entities: (choices?.users ?? []).map(user => ({ ...user, entityType: \"user\" })),\n ...defaultsFor(select.default_values),\n };\n case ComponentType.RoleSelect:\n return {\n ...base,\n kind: \"role-select\",\n entities: (choices?.roles ?? []).map(role => ({ ...role, entityType: \"role\" })),\n ...defaultsFor(select.default_values),\n };\n case ComponentType.MentionableSelect:\n return {\n ...base,\n kind: \"mentionable-select\",\n entities: [\n ...(choices?.users ?? []).map(user => ({ ...user, entityType: \"user\" as const })),\n ...(choices?.roles ?? []).map(role => ({ ...role, entityType: \"role\" as const })),\n ],\n ...defaultsFor(select.default_values),\n };\n case ComponentType.ChannelSelect:\n return {\n ...base,\n kind: \"channel-select\",\n entities: (choices?.channels ?? []).map(channel => ({ ...channel, entityType: \"channel\" })),\n ...(select.channel_types !== undefined\n ? {\n channelTypes: select.channel_types.filter(isDisplayChannelType),\n }\n : {}),\n ...defaultsFor(select.default_values),\n };\n default:\n return undefined;\n }\n}\n\nfunction defaultsFor<Type extends \"user\" | \"role\" | \"channel\">(values: readonly SelectDefaultValue<Type>[] | undefined): { defaultValues?: SelectDefaultValue<Type>[] } {\n return values === undefined\n ? {}\n : {\n defaultValues: values.map(({ id, type }) => ({ id, type })),\n };\n}\n\nexport function convertActionRow(row: APIActionRowComponent<APIComponentInMessageActionRow>, path: string, options: DiscordMessageConversionOptions): ActionRowView | undefined {\n const id = componentId(row, path);\n const buttons: MessageButtonView[] = [];\n for (const [index, child] of row.components.entries()) {\n if (child.type === ComponentType.Button) {\n const button = convertButton(child, `${path}.${index}`);\n if (button)\n buttons.push(button);\n }\n else {\n const select = convertSelect(child, options);\n if (select)\n return { id, kind: \"action-row\", select };\n }\n }\n return buttons.length\n ? { id, kind: \"action-row\", buttons }\n : undefined;\n}\n\nfunction convertChild(component: APIComponentInContainer, path: string, options: DiscordComponentConversionOptions): ContainerChild | undefined {\n const id = componentId(component, path);\n const attachments = options.attachments ?? [];\n switch (component.type) {\n case ComponentType.ActionRow:\n return convertActionRow(component, path, options);\n case ComponentType.TextDisplay:\n return { id, kind: \"text-display\", content: component.content };\n case ComponentType.Separator:\n return {\n id,\n kind: \"separator\",\n divider: component.divider ?? true,\n spacing: component.spacing === SeparatorSpacingSize.Large\n ? \"large\"\n : \"small\",\n };\n case ComponentType.Section: {\n const source = component.accessory;\n const accessoryId = componentId(source, `${path}.accessory`);\n const thumbnail = source.type === ComponentType.Thumbnail\n ? mediaView(accessoryId, source.media, attachments, source.description, source.spoiler)\n : undefined;\n const accessory = thumbnail\n ? { id: accessoryId, kind: \"thumbnail\" as const, media: thumbnail }\n : source.type === ComponentType.Button\n ? convertButton(source, `${path}.accessory`)\n : undefined;\n const components = component.components.flatMap((text, index) => text.type === ComponentType.TextDisplay\n ? [\n {\n id: componentId(text, `${path}.${index}`),\n kind: \"text-display\" as const,\n content: text.content,\n },\n ]\n : []);\n return accessory && components.length\n ? {\n id,\n kind: \"section\",\n components,\n accessory,\n }\n : undefined;\n }\n case ComponentType.MediaGallery: {\n const items = component.items\n .map((item, index) => galleryMediaView(`${id}:item:${index}`, item.media, attachments, item.description, item.spoiler))\n .filter(item => item !== undefined);\n return items.length\n ? { id, kind: \"media-gallery\", items }\n : undefined;\n }\n case ComponentType.File: {\n const { url, attachment, filename } = resolveMedia(component.file, attachments);\n return url\n ? fileView(id, url, component.name ?? attachment?.filename ?? filename ?? \"File\", component.size ?? attachment?.size, component.spoiler || attachment?.filename.startsWith(\"SPOILER_\") || filename?.startsWith(\"SPOILER_\"))\n : undefined;\n }\n default:\n return undefined;\n }\n}\n\n/** Convert a message's component array in order, omitting unsupported nodes. */\nexport function fromDiscordMessageComponents(components: readonly APIMessageTopLevelComponent[], options: DiscordComponentConversionOptions = {}): MessageComponent[] {\n return components.map((component, index): MessageComponent | undefined => {\n const path = String(index);\n if (component.type !== ComponentType.Container)\n return convertChild(component, path, options);\n\n return {\n id: componentId(component, path),\n kind: \"container\",\n components: component.components.map((child, childIndex) => convertChild(child, `${path}.${childIndex}`, options)).filter(child => child !== undefined),\n ...(component.spoiler !== undefined\n ? { spoiler: component.spoiler }\n : {}),\n ...(component.accent_color != null\n ? {\n accentColor: hexColor(component.accent_color),\n }\n : {}),\n };\n }).filter(component => component !== undefined);\n}\n","import type { APIAttachment, APIEmbed, APIMessage, APIUser, GatewayMessageCreateDispatchData } from \"discord-api-types/v10\";\nimport type { DiscordMessageConversionOptions } from \"./discord-api/components\";\nimport type { FileView } from \"./model/components\";\nimport type { AudioView, EmbedView, MessageMediaView, StickerView } from \"./model/content\";\nimport type { MessageAuthor, MessageMetadata, MessageView, ReplyView } from \"./model/message\";\nimport type { ThreadSummaryView } from \"./model/thread\";\nimport { ChannelType, ComponentType, MessageFlags, MessageType, StickerFormatType } from \"discord-api-types/v10\";\nimport { convertActionRow, fromDiscordMessageComponents } from \"./discord-api/components\";\nimport { discordUserIdentity, discordUserTag, emojiView, guildAvatarUrl, hexColor } from \"./discord-api/entities\";\nimport { attachmentKind, audioView, fileView, galleryMediaView, mediaView, resolveMedia } from \"./discord-api/media\";\nimport { linkUrl } from \"./utils/urls\";\n\nexport { fromDiscordMessageComponents } from \"./discord-api/components\";\nexport type { DiscordComponentConversionOptions, DiscordMessageConversionOptions } from \"./discord-api/components\";\nexport { fromDiscordChannel, fromDiscordRole, fromDiscordUser } from \"./discord-api/entities\";\n\ntype DiscordMessageInput = APIMessage & Pick<GatewayMessageCreateDispatchData, \"guild_id\" | \"member\">;\n\nfunction userAuthor(user: APIUser): ReturnType<typeof discordUserIdentity> & Pick<MessageAuthor, \"tag\"> {\n const tag = discordUserTag(user);\n return {\n ...discordUserIdentity(user),\n ...(tag\n ? { tag }\n : {}),\n };\n}\n\nfunction messageAuthor(message: DiscordMessageInput): MessageAuthor {\n const author = userAuthor(message.author);\n const memberAvatar = message.member?.avatar;\n return {\n ...author,\n displayName: message.member?.nick || author.displayName,\n avatarUrl: message.guild_id && memberAvatar\n ? guildAvatarUrl(message.guild_id, author.id, memberAvatar)\n : author.avatarUrl,\n };\n}\n\nfunction messageReply(message: APIMessage): ReplyView | undefined {\n if (message.type === MessageType.Reply) {\n if (message.referenced_message) {\n return {\n messageId: message.referenced_message.id,\n author: messageAuthor(message.referenced_message),\n content: message.referenced_message.content,\n };\n }\n if (message.referenced_message === null && message.message_reference?.message_id)\n return { messageId: message.message_reference.message_id, unavailable: true };\n }\n if (message.type === MessageType.ChatInputCommand && message.interaction?.name) {\n return {\n kind: \"interaction\",\n author: userAuthor(message.interaction.user),\n commandName: message.interaction.name,\n };\n }\n return undefined;\n}\n\nfunction threadSummary(thread: APIMessage[\"thread\"]): ThreadSummaryView | undefined {\n if (thread?.type === ChannelType.AnnouncementThread || thread?.type === ChannelType.PublicThread || thread?.type === ChannelType.PrivateThread) {\n if (thread.name && thread.message_count !== undefined)\n return { id: thread.id, name: thread.name, messageCount: thread.message_count };\n }\n return undefined;\n}\n\nfunction embedIcon(iconUrl: string | undefined, proxyUrl: string | undefined, attachments: readonly APIAttachment[]): string | undefined {\n return iconUrl === undefined\n ? linkUrl(proxyUrl)\n : resolveMedia({\n url: iconUrl,\n ...(proxyUrl\n ? { proxy_url: proxyUrl }\n : {}),\n }, attachments).url;\n}\n\nfunction convertEmbed(embed: APIEmbed, id: string, attachments: readonly APIAttachment[]): EmbedView {\n const { author, footer, title, url, description, color, timestamp } = embed;\n const thumbnail = embed.thumbnail && mediaView(`${id}:thumbnail`, embed.thumbnail, attachments);\n const image = embed.image && mediaView(`${id}:image`, embed.image, attachments);\n const view: EmbedView = { id };\n if (title !== undefined)\n view.title = title;\n if (url !== undefined)\n view.url = url;\n if (description !== undefined)\n view.description = description;\n if (color !== undefined)\n view.color = hexColor(color);\n if (timestamp !== undefined)\n view.timestamp = timestamp;\n if (thumbnail)\n view.thumbnail = thumbnail;\n if (image)\n view.image = image;\n if (author) {\n const iconUrl = embedIcon(author.icon_url, author.proxy_icon_url, attachments);\n view.author = { name: author.name };\n if (author.url !== undefined)\n view.author.url = author.url;\n if (iconUrl)\n view.author.iconUrl = iconUrl;\n }\n if (footer) {\n const iconUrl = embedIcon(footer.icon_url, footer.proxy_icon_url, attachments);\n view.footer = { text: footer.text };\n if (iconUrl)\n view.footer.iconUrl = iconUrl;\n }\n if (embed.fields)\n view.fields = embed.fields.map((field, index) => ({ ...field, id: `${id}:field:${index}` }));\n return view;\n}\n\nfunction attachmentUrlKey(url: string): string {\n // Discord's direct and resized URLs can have different hosts and query strings.\n return /^https:\\/\\/(?:cdn\\.discordapp\\.com|media\\.discordapp\\.net)(\\/(?:ephemeral-)?attachments\\/\\d+\\/\\d+)\\//u.exec(url)?.[1] ?? url;\n}\n\n/** Convert a complete REST message or Gateway MESSAGE_CREATE payload to a display snapshot. */\nexport function fromDiscordMessage(message: DiscordMessageInput, options: DiscordMessageConversionOptions = {}): MessageView {\n const flags = message.flags ?? 0;\n const reply = messageReply(message);\n const thread = threadSummary(message.thread);\n const reactions = message.reactions?.flatMap((reaction) => {\n const emoji = emojiView(reaction.emoji);\n return emoji\n ? [\n {\n id: reaction.emoji.id ?? emoji.name,\n emoji,\n count: reaction.count,\n me: reaction.me || reaction.me_burst === true,\n },\n ]\n : [];\n });\n const metadata: MessageMetadata & { thread?: ThreadSummaryView } = {\n id: message.id,\n author: messageAuthor(message),\n timestamp: message.timestamp,\n edited: message.edited_timestamp != null,\n ephemeral: Boolean(flags & MessageFlags.Ephemeral),\n };\n if (reactions)\n metadata.reactions = reactions;\n if (reply)\n metadata.reply = reply;\n if (thread)\n metadata.thread = thread;\n\n if (flags & MessageFlags.IsComponentsV2) {\n return {\n ...metadata,\n body: {\n kind: \"components-v2\",\n components: fromDiscordMessageComponents(message.components ?? [], { ...options, attachments: message.attachments }),\n },\n };\n }\n\n const embeds = flags & MessageFlags.SuppressEmbeds\n ? []\n : message.embeds.map((embed, index) => convertEmbed(embed, `embed:${index}`, message.attachments));\n const embeddedMedia = new Set(embeds.flatMap(embed => [\n embed.image?.url,\n embed.thumbnail?.url,\n embed.author?.iconUrl,\n embed.footer?.iconUrl,\n ]\n .filter(url => url !== undefined)\n .map(attachmentUrlKey)));\n const media: MessageMediaView[] = [];\n const files: (FileView | AudioView)[] = [];\n for (const attachment of message.attachments) {\n if (embeddedMedia.has(attachmentUrlKey(attachment.url)) || embeddedMedia.has(attachmentUrlKey(attachment.proxy_url)))\n continue;\n const kind = attachmentKind(attachment);\n if (kind === \"image\" || kind === \"video\") {\n const image = galleryMediaView(attachment.id, attachment, [attachment], attachment.description ?? attachment.filename, attachment.filename.startsWith(\"SPOILER_\"));\n if (image)\n media.push(image);\n }\n else if (kind === \"audio\") {\n const audio = audioView(attachment, Boolean(flags & MessageFlags.IsVoiceMessage));\n if (audio)\n files.push(audio);\n }\n else {\n const url = linkUrl(attachment.url) ?? linkUrl(attachment.proxy_url);\n if (url)\n files.push(fileView(attachment.id, url, attachment.filename, attachment.size));\n }\n }\n const components = message.components?.flatMap((component, index) => {\n const row = component.type === ComponentType.ActionRow && convertActionRow(component, String(index), options);\n return row\n ? [row]\n : [];\n });\n const view: MessageView = {\n ...metadata,\n body: { kind: \"markdown\", content: message.content },\n };\n const stickers = message.sticker_items?.flatMap((sticker): StickerView[] => {\n const formats = {\n [StickerFormatType.PNG]: \"png\",\n [StickerFormatType.APNG]: \"apng\",\n [StickerFormatType.GIF]: \"gif\",\n [StickerFormatType.Lottie]: \"lottie\",\n } as const;\n const format = formats[sticker.format_type];\n if (!format)\n return [];\n const extension = format === \"apng\"\n ? \"png\"\n : format === \"lottie\"\n ? \"json\"\n : format;\n const origin = format === \"gif\"\n ? \"https://media.discordapp.net\"\n : \"https://cdn.discordapp.com\";\n return [\n {\n id: sticker.id,\n name: sticker.name,\n format,\n url: `${origin}/stickers/${encodeURIComponent(sticker.id)}.${extension}`,\n },\n ];\n });\n if (stickers?.length)\n view.stickers = stickers;\n if (media.length)\n view.media = media;\n if (files.length)\n view.attachments = files;\n if (embeds.length)\n view.embeds = embeds;\n if (components?.length)\n view.components = components;\n return view;\n}\n"],"mappings":";;;;AA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