discord-message-transcript 1.3.1-dev.1.45 → 1.3.1-dev.1.47
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { TopLevelComponent } from "discord.js";
|
|
2
|
-
import { JsonTopLevelComponent,
|
|
2
|
+
import { JsonTopLevelComponent, TranscriptOptionsBase, JsonComponentInContainer } from "discord-message-transcript-base";
|
|
3
3
|
export declare function componentsToJson(components: TopLevelComponent[], options: TranscriptOptionsBase): Promise<JsonTopLevelComponent[]>;
|
|
4
4
|
export declare function isJsonComponentInContainer(component: JsonTopLevelComponent): component is JsonComponentInContainer;
|
|
@@ -3,137 +3,151 @@ import { mapButtonStyle, mapSelectorType, mapSeparatorSpacing } from "./mappers.
|
|
|
3
3
|
import { JsonComponentType } from "discord-message-transcript-base";
|
|
4
4
|
import { isValidHexColor } from "discord-message-transcript-base";
|
|
5
5
|
export async function componentsToJson(components, options) {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
accessory: accessoryJson,
|
|
116
|
-
components: sectionComponents,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
case ComponentType.Separator: {
|
|
120
|
-
return {
|
|
121
|
-
type: JsonComponentType.Separator,
|
|
122
|
-
spacing: mapSeparatorSpacing(component.spacing),
|
|
123
|
-
divider: component.divider,
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
case ComponentType.TextDisplay: {
|
|
127
|
-
return {
|
|
128
|
-
type: JsonComponentType.TextDisplay,
|
|
129
|
-
content: component.content,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
default:
|
|
133
|
-
return null;
|
|
6
|
+
const filtered = components.filter(c => options.includeV2Components || c.type === ComponentType.ActionRow);
|
|
7
|
+
const processed = await Promise.all(filtered.map(c => convertComponent(c, options)));
|
|
8
|
+
return processed.filter(c => c != null);
|
|
9
|
+
}
|
|
10
|
+
async function convertComponent(component, options) {
|
|
11
|
+
switch (component.type) {
|
|
12
|
+
case ComponentType.ActionRow:
|
|
13
|
+
return convertActionRow(component, options);
|
|
14
|
+
case ComponentType.Container:
|
|
15
|
+
return convertContainer(component, options);
|
|
16
|
+
case ComponentType.File:
|
|
17
|
+
return convertFile(component);
|
|
18
|
+
case ComponentType.MediaGallery:
|
|
19
|
+
return convertMediaGallery(component);
|
|
20
|
+
case ComponentType.Section:
|
|
21
|
+
return convertSection(component);
|
|
22
|
+
case ComponentType.Separator:
|
|
23
|
+
return convertSeparator(component);
|
|
24
|
+
case ComponentType.TextDisplay:
|
|
25
|
+
return convertTextDisplay(component);
|
|
26
|
+
default:
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
async function convertActionRow(component, options) {
|
|
31
|
+
const rowComponents = await Promise.all(component.components
|
|
32
|
+
.filter(c => (c.type === ComponentType.Button ? options.includeButtons : options.includeComponents))
|
|
33
|
+
.map(c => convertActionRowChild(c)));
|
|
34
|
+
if (rowComponents.length === 0)
|
|
35
|
+
return null;
|
|
36
|
+
return { type: JsonComponentType.ActionRow, components: rowComponents };
|
|
37
|
+
}
|
|
38
|
+
async function convertActionRowChild(component) {
|
|
39
|
+
switch (component.type) {
|
|
40
|
+
case ComponentType.Button: {
|
|
41
|
+
return {
|
|
42
|
+
type: JsonComponentType.Button,
|
|
43
|
+
style: mapButtonStyle(component.style),
|
|
44
|
+
label: component.label,
|
|
45
|
+
emoji: component.emoji?.name ?? null,
|
|
46
|
+
url: component.url,
|
|
47
|
+
disabled: component.disabled,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
case ComponentType.StringSelect: {
|
|
51
|
+
return {
|
|
52
|
+
type: JsonComponentType.StringSelect,
|
|
53
|
+
placeholder: component.placeholder,
|
|
54
|
+
disabled: component.disabled,
|
|
55
|
+
options: component.options.map(option => ({
|
|
56
|
+
label: option.label,
|
|
57
|
+
description: option.description ?? null,
|
|
58
|
+
emoji: option.emoji ? { id: option.emoji.id ?? null, name: option.emoji.name ?? null, animated: option.emoji.animated ?? false } : null,
|
|
59
|
+
})),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
default: {
|
|
63
|
+
return {
|
|
64
|
+
type: mapSelectorType(component.type),
|
|
65
|
+
placeholder: component.placeholder,
|
|
66
|
+
disabled: component.disabled,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async function convertContainer(component, options) {
|
|
72
|
+
const newOptions = { ...options, includeComponents: true, includeButtons: true };
|
|
73
|
+
const componentsJson = await componentsToJson(component.components, newOptions);
|
|
74
|
+
return {
|
|
75
|
+
type: JsonComponentType.Container,
|
|
76
|
+
components: componentsJson.filter(isJsonComponentInContainer), // Input components that are container-safe must always produce container-safe output.
|
|
77
|
+
hexAccentColor: isValidHexColor(component.hexAccentColor, false),
|
|
78
|
+
spoiler: component.spoiler,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function convertFile(component) {
|
|
82
|
+
return {
|
|
83
|
+
type: JsonComponentType.File,
|
|
84
|
+
fileName: component.data.name ?? null,
|
|
85
|
+
size: component.data.size ?? 0,
|
|
86
|
+
url: component.file.url,
|
|
87
|
+
spoiler: component.spoiler,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async function convertMediaGallery(component) {
|
|
91
|
+
const mediaItems = await Promise.all(component.items.map(item => {
|
|
92
|
+
return {
|
|
93
|
+
media: { url: item.media.url },
|
|
94
|
+
spoiler: item.spoiler,
|
|
95
|
+
};
|
|
96
|
+
}));
|
|
97
|
+
return {
|
|
98
|
+
type: JsonComponentType.MediaGallery,
|
|
99
|
+
items: mediaItems,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function convertSection(component) {
|
|
103
|
+
let accessoryJson = null;
|
|
104
|
+
switch (component.accessory.type) {
|
|
105
|
+
case ComponentType.Button: {
|
|
106
|
+
accessoryJson = {
|
|
107
|
+
type: JsonComponentType.Button,
|
|
108
|
+
style: mapButtonStyle(component.accessory.style),
|
|
109
|
+
label: component.accessory.label,
|
|
110
|
+
emoji: component.accessory.emoji?.name ? component.accessory.emoji.name : null,
|
|
111
|
+
url: component.accessory.url,
|
|
112
|
+
disabled: component.accessory.disabled,
|
|
113
|
+
};
|
|
114
|
+
break;
|
|
134
115
|
}
|
|
116
|
+
case ComponentType.Thumbnail: {
|
|
117
|
+
accessoryJson = {
|
|
118
|
+
type: JsonComponentType.Thumbnail,
|
|
119
|
+
media: {
|
|
120
|
+
url: component.accessory.media.url,
|
|
121
|
+
},
|
|
122
|
+
spoiler: component.accessory.spoiler,
|
|
123
|
+
};
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
default:
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
const sectionComponents = component.components.map(c => ({
|
|
130
|
+
type: JsonComponentType.TextDisplay,
|
|
131
|
+
content: c.content,
|
|
135
132
|
}));
|
|
136
|
-
return
|
|
133
|
+
return {
|
|
134
|
+
type: JsonComponentType.Section,
|
|
135
|
+
accessory: accessoryJson,
|
|
136
|
+
components: sectionComponents,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function convertSeparator(component) {
|
|
140
|
+
return {
|
|
141
|
+
type: JsonComponentType.Separator,
|
|
142
|
+
spacing: mapSeparatorSpacing(component.spacing),
|
|
143
|
+
divider: component.divider,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
function convertTextDisplay(component) {
|
|
147
|
+
return {
|
|
148
|
+
type: JsonComponentType.TextDisplay,
|
|
149
|
+
content: component.content,
|
|
150
|
+
};
|
|
137
151
|
}
|
|
138
152
|
export function isJsonComponentInContainer(component) {
|
|
139
153
|
return (component.type == JsonComponentType.ActionRow ||
|
package/dist/core/urlResolver.js
CHANGED
|
@@ -57,7 +57,7 @@ export async function messagesUrlResolver(messages, options, cdnOptions, urlCach
|
|
|
57
57
|
}));
|
|
58
58
|
async function componentsFunction(components) {
|
|
59
59
|
return Promise.all(components.map(async (component) => {
|
|
60
|
-
if (component.type == JsonComponentType.Section) {
|
|
60
|
+
if (component.type == JsonComponentType.Section && component.accessory) {
|
|
61
61
|
if (component.accessory.type == JsonComponentType.Thumbnail) {
|
|
62
62
|
return {
|
|
63
63
|
...component,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "discord-message-transcript",
|
|
3
|
-
"version": "1.3.1-dev.1.
|
|
3
|
+
"version": "1.3.1-dev.1.47",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"homepage": "https://github.com/HenriqueMairesse/discord-message-transcript#readme",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"discord-message-transcript-base": "1.3.1-dev.1.
|
|
48
|
+
"discord-message-transcript-base": "1.3.1-dev.1.47"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"discord.js": ">=14.19.0 <15"
|