@discordeno/utils 19.0.0-next.a7d645e → 19.0.0-next.a8f9e5e
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.
- package/dist/builders/embeds.d.ts +146 -0
- package/dist/builders/embeds.d.ts.map +1 -0
- package/dist/builders/embeds.js +295 -0
- package/dist/builders/embeds.js.map +1 -0
- package/dist/builders.d.ts +4 -0
- package/dist/builders.d.ts.map +1 -0
- package/dist/builders.js +5 -0
- package/dist/builders.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/typeguards.d.ts +2 -1
- package/dist/typeguards.d.ts.map +1 -1
- package/dist/typeguards.js +3 -0
- package/dist/typeguards.js.map +1 -1
- package/package.json +2 -2
- package/dist/interactions.d.ts +0 -3
- package/dist/interactions.d.ts.map +0 -1
- package/dist/interactions.js +0 -41
- package/dist/interactions.js.map +0 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { DiscordEmbed, DiscordEmbedAuthor, DiscordEmbedField, DiscordEmbedFooter, DiscordEmbedImage, DiscordEmbedThumbnail, DiscordEmbedVideo } from '@discordeno/types';
|
|
2
|
+
/**
|
|
3
|
+
* A builder to help create Discord embeds.
|
|
4
|
+
*
|
|
5
|
+
* @export
|
|
6
|
+
* @class EmbedsBuilder
|
|
7
|
+
* @typedef {EmbedsBuilder}
|
|
8
|
+
* @extends {Array<DiscordEmbed>}
|
|
9
|
+
* @example
|
|
10
|
+
* const embeds = new EmbedBuilder()
|
|
11
|
+
* .setTitle('My Embed')
|
|
12
|
+
* .setDescription('This is my new embed')
|
|
13
|
+
* .newEmbed()
|
|
14
|
+
* .setTitle('My Second Embed')
|
|
15
|
+
*/
|
|
16
|
+
export declare class EmbedsBuilder extends Array<DiscordEmbed> {
|
|
17
|
+
#private;
|
|
18
|
+
/**
|
|
19
|
+
* Adds a new field to the embed fields array.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} name - Field name
|
|
22
|
+
* @param {string} value - Field value
|
|
23
|
+
* @param {?boolean} [inline=false] - Field should be inline or not.
|
|
24
|
+
* @returns {EmbedsBuilder}
|
|
25
|
+
*/
|
|
26
|
+
addField(name: string, value: string, inline?: boolean): EmbedsBuilder;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a blank embed.
|
|
29
|
+
*
|
|
30
|
+
* @returns {EmbedsBuilder}
|
|
31
|
+
*/
|
|
32
|
+
newEmbed(): EmbedsBuilder;
|
|
33
|
+
/**
|
|
34
|
+
* Set the current embed author.
|
|
35
|
+
*
|
|
36
|
+
* @param {string} name - Name of the author
|
|
37
|
+
* @param {?Omit<DiscordEmbedAuthor, 'name'>} [options] - Extra author options
|
|
38
|
+
* @returns {EmbedsBuilder}
|
|
39
|
+
*/
|
|
40
|
+
setAuthor(name: string, options?: Omit<DiscordEmbedAuthor, 'name'>): EmbedsBuilder;
|
|
41
|
+
/**
|
|
42
|
+
* Set the color on the side of the current embed.
|
|
43
|
+
*
|
|
44
|
+
* @param {(number | string)} color - The color, in base16 or hex color code
|
|
45
|
+
* @returns {EmbedsBuilder}
|
|
46
|
+
*/
|
|
47
|
+
setColor(color: number | string): EmbedsBuilder;
|
|
48
|
+
/**
|
|
49
|
+
* Set the current embed to a different index.
|
|
50
|
+
*
|
|
51
|
+
* WARNING: Only use this method if you know what you're doing. Make sure to set it back to the latest when you're done.
|
|
52
|
+
*
|
|
53
|
+
* @param {?number} [index] - The index of the embed in the EmbedsBuilder array
|
|
54
|
+
* @returns {EmbedsBuilder}
|
|
55
|
+
*/
|
|
56
|
+
setCurrentEmbed(index?: number): EmbedsBuilder;
|
|
57
|
+
/**
|
|
58
|
+
* Set the description of the current embed.
|
|
59
|
+
*
|
|
60
|
+
* @param {string} description - Description
|
|
61
|
+
* @returns {EmbedsBuilder}
|
|
62
|
+
*/
|
|
63
|
+
setDescription(description: string): EmbedsBuilder;
|
|
64
|
+
/**
|
|
65
|
+
* Overwrite all fields on the current embed.
|
|
66
|
+
*
|
|
67
|
+
* @param {DiscordEmbedField[]} fields
|
|
68
|
+
* @returns {EmbedsBuilder}
|
|
69
|
+
*/
|
|
70
|
+
setFields(fields: DiscordEmbedField[]): EmbedsBuilder;
|
|
71
|
+
/**
|
|
72
|
+
* Set the footer in the current embed.
|
|
73
|
+
*
|
|
74
|
+
* @param {string} text - The text to display in the footer
|
|
75
|
+
* @param {?Omit<DiscordEmbedFooter, 'text'>} [options]
|
|
76
|
+
* @returns {EmbedsBuilder}
|
|
77
|
+
*/
|
|
78
|
+
setFooter(text: string, options?: Omit<DiscordEmbedFooter, 'text'>): EmbedsBuilder;
|
|
79
|
+
/**
|
|
80
|
+
* Set the image in the current embed.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} url - URL of the image
|
|
83
|
+
* @param {?Omit<DiscordEmbedImage, 'url'>} [options]
|
|
84
|
+
* @returns {EmbedsBuilder}
|
|
85
|
+
*/
|
|
86
|
+
setImage(url: string, options?: Omit<DiscordEmbedImage, 'url'>): EmbedsBuilder;
|
|
87
|
+
/**
|
|
88
|
+
* Set the provider of the current embed.
|
|
89
|
+
*
|
|
90
|
+
* @param {string} name
|
|
91
|
+
* @param {?string} [url]
|
|
92
|
+
* @returns {EmbedsBuilder}
|
|
93
|
+
*/
|
|
94
|
+
setProvider(name: string, url?: string): EmbedsBuilder;
|
|
95
|
+
/**
|
|
96
|
+
* Set the color of the current embed to a random value.
|
|
97
|
+
*
|
|
98
|
+
* @returns {EmbedsBuilder}
|
|
99
|
+
*/
|
|
100
|
+
setRandomColor(): EmbedsBuilder;
|
|
101
|
+
/**
|
|
102
|
+
* Set the title of the current embed.
|
|
103
|
+
*
|
|
104
|
+
* @param {string} title
|
|
105
|
+
* @param {?string} [url]
|
|
106
|
+
* @returns {EmbedsBuilder}
|
|
107
|
+
*/
|
|
108
|
+
setTitle(title: string, url?: string): EmbedsBuilder;
|
|
109
|
+
/**
|
|
110
|
+
* Set the timestamp of the current embed.
|
|
111
|
+
*
|
|
112
|
+
* @param {?(string | number | Date)} [timestamp]
|
|
113
|
+
* @returns {EmbedsBuilder}
|
|
114
|
+
*/
|
|
115
|
+
setTimestamp(timestamp?: string | number | Date): EmbedsBuilder;
|
|
116
|
+
/**
|
|
117
|
+
* Set the thumbnail of the current embed.
|
|
118
|
+
*
|
|
119
|
+
* @param {string} url - URL of the image
|
|
120
|
+
* @param {?Omit<DiscordEmbedThumbnail, 'url'>} [options]
|
|
121
|
+
* @returns {EmbedsBuilder}
|
|
122
|
+
*/
|
|
123
|
+
setThumbnail(url: string, options?: Omit<DiscordEmbedThumbnail, 'url'>): EmbedsBuilder;
|
|
124
|
+
/**
|
|
125
|
+
* Set the URL of the current embed title.
|
|
126
|
+
*
|
|
127
|
+
* @param {string} url
|
|
128
|
+
* @returns {EmbedsBuilder}
|
|
129
|
+
*/
|
|
130
|
+
setUrl(url: string): EmbedsBuilder;
|
|
131
|
+
/**
|
|
132
|
+
* Set the video of the current embed.
|
|
133
|
+
*
|
|
134
|
+
* @param {string} url
|
|
135
|
+
* @param {?Omit<DiscordEmbedVideo, 'url'>} [options]
|
|
136
|
+
* @returns {EmbedsBuilder}
|
|
137
|
+
*/
|
|
138
|
+
setVideo(url: string, options?: Omit<DiscordEmbedVideo, 'url'>): EmbedsBuilder;
|
|
139
|
+
/**
|
|
140
|
+
* Validate all embeds available against current known Discord limits to help prevent bad requests.
|
|
141
|
+
*
|
|
142
|
+
* @returns {EmbedsBuilder}
|
|
143
|
+
*/
|
|
144
|
+
validate(): EmbedsBuilder;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=embeds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embeds.d.ts","sourceRoot":"","sources":["../../src/builders/embeds.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,qB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SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,aAAa;IAM/D;;;;;;OAMG;IACH,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,EAAE,KAAK,CAAC,GAAG,aAAa;IAUtF;;;;;OAKG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa;IAMlC;;;;;;OAMG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,KAAK,CAAC,GAAG,aAAa;IAU9E;;;;OAIG;IACH,QAAQ,IAAI,aAAa;CA4F1B"}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A builder to help create Discord embeds.
|
|
3
|
+
*
|
|
4
|
+
* @export
|
|
5
|
+
* @class EmbedsBuilder
|
|
6
|
+
* @typedef {EmbedsBuilder}
|
|
7
|
+
* @extends {Array<DiscordEmbed>}
|
|
8
|
+
* @example
|
|
9
|
+
* const embeds = new EmbedBuilder()
|
|
10
|
+
* .setTitle('My Embed')
|
|
11
|
+
* .setDescription('This is my new embed')
|
|
12
|
+
* .newEmbed()
|
|
13
|
+
* .setTitle('My Second Embed')
|
|
14
|
+
*/ export class EmbedsBuilder extends Array {
|
|
15
|
+
#currentEmbedIndex;
|
|
16
|
+
/**
|
|
17
|
+
* Adds a new field to the embed fields array.
|
|
18
|
+
*
|
|
19
|
+
* @param {string} name - Field name
|
|
20
|
+
* @param {string} value - Field value
|
|
21
|
+
* @param {?boolean} [inline=false] - Field should be inline or not.
|
|
22
|
+
* @returns {EmbedsBuilder}
|
|
23
|
+
*/ addField(name, value, inline) {
|
|
24
|
+
if (this.#currentEmbed.fields === undefined) {
|
|
25
|
+
this.#currentEmbed.fields = [];
|
|
26
|
+
}
|
|
27
|
+
this.#currentEmbed.fields.push({
|
|
28
|
+
name,
|
|
29
|
+
value,
|
|
30
|
+
inline
|
|
31
|
+
});
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Creates a blank embed.
|
|
36
|
+
*
|
|
37
|
+
* @returns {EmbedsBuilder}
|
|
38
|
+
*/ newEmbed() {
|
|
39
|
+
if (this.length >= 10) {
|
|
40
|
+
throw new Error('Maximum embed count exceeded. You can not have more than 10 embeds.');
|
|
41
|
+
}
|
|
42
|
+
this.push({});
|
|
43
|
+
this.setCurrentEmbed();
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Set the current embed author.
|
|
48
|
+
*
|
|
49
|
+
* @param {string} name - Name of the author
|
|
50
|
+
* @param {?Omit<DiscordEmbedAuthor, 'name'>} [options] - Extra author options
|
|
51
|
+
* @returns {EmbedsBuilder}
|
|
52
|
+
*/ setAuthor(name, options) {
|
|
53
|
+
this.#currentEmbed.author = {
|
|
54
|
+
...this.#currentEmbed.author,
|
|
55
|
+
...options,
|
|
56
|
+
name
|
|
57
|
+
};
|
|
58
|
+
return this;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Set the color on the side of the current embed.
|
|
62
|
+
*
|
|
63
|
+
* @param {(number | string)} color - The color, in base16 or hex color code
|
|
64
|
+
* @returns {EmbedsBuilder}
|
|
65
|
+
*/ setColor(color) {
|
|
66
|
+
if (typeof color === 'string') {
|
|
67
|
+
const convertedValue = parseInt(color.replace('#', ''), 16);
|
|
68
|
+
color = Number.isNaN(convertedValue) ? 0 : convertedValue;
|
|
69
|
+
}
|
|
70
|
+
this.#currentEmbed.color = color;
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Set the current embed to a different index.
|
|
75
|
+
*
|
|
76
|
+
* WARNING: Only use this method if you know what you're doing. Make sure to set it back to the latest when you're done.
|
|
77
|
+
*
|
|
78
|
+
* @param {?number} [index] - The index of the embed in the EmbedsBuilder array
|
|
79
|
+
* @returns {EmbedsBuilder}
|
|
80
|
+
*/ setCurrentEmbed(index) {
|
|
81
|
+
if (index === undefined) {
|
|
82
|
+
this.#currentEmbedIndex = this.length - 1;
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
if (index >= this.length || index < 0) {
|
|
86
|
+
throw new Error('Can not set the current embed to a index out of bounds.');
|
|
87
|
+
}
|
|
88
|
+
this.#currentEmbedIndex = index;
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Set the description of the current embed.
|
|
93
|
+
*
|
|
94
|
+
* @param {string} description - Description
|
|
95
|
+
* @returns {EmbedsBuilder}
|
|
96
|
+
*/ setDescription(description) {
|
|
97
|
+
this.#currentEmbed.description = description;
|
|
98
|
+
return this;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Overwrite all fields on the current embed.
|
|
102
|
+
*
|
|
103
|
+
* @param {DiscordEmbedField[]} fields
|
|
104
|
+
* @returns {EmbedsBuilder}
|
|
105
|
+
*/ setFields(fields) {
|
|
106
|
+
this.#currentEmbed.fields = fields;
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Set the footer in the current embed.
|
|
111
|
+
*
|
|
112
|
+
* @param {string} text - The text to display in the footer
|
|
113
|
+
* @param {?Omit<DiscordEmbedFooter, 'text'>} [options]
|
|
114
|
+
* @returns {EmbedsBuilder}
|
|
115
|
+
*/ setFooter(text, options) {
|
|
116
|
+
this.#currentEmbed.footer = {
|
|
117
|
+
...this.#currentEmbed.footer,
|
|
118
|
+
...options,
|
|
119
|
+
text
|
|
120
|
+
};
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Set the image in the current embed.
|
|
125
|
+
*
|
|
126
|
+
* @param {string} url - URL of the image
|
|
127
|
+
* @param {?Omit<DiscordEmbedImage, 'url'>} [options]
|
|
128
|
+
* @returns {EmbedsBuilder}
|
|
129
|
+
*/ setImage(url, options) {
|
|
130
|
+
this.#currentEmbed.image = {
|
|
131
|
+
...this.#currentEmbed.image,
|
|
132
|
+
...options,
|
|
133
|
+
url
|
|
134
|
+
};
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Set the provider of the current embed.
|
|
139
|
+
*
|
|
140
|
+
* @param {string} name
|
|
141
|
+
* @param {?string} [url]
|
|
142
|
+
* @returns {EmbedsBuilder}
|
|
143
|
+
*/ setProvider(name, url) {
|
|
144
|
+
this.#currentEmbed.provider = {
|
|
145
|
+
name,
|
|
146
|
+
url
|
|
147
|
+
};
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Set the color of the current embed to a random value.
|
|
152
|
+
*
|
|
153
|
+
* @returns {EmbedsBuilder}
|
|
154
|
+
*/ setRandomColor() {
|
|
155
|
+
return this.setColor(Math.floor(Math.random() * (0xffffff + 1)));
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Set the title of the current embed.
|
|
159
|
+
*
|
|
160
|
+
* @param {string} title
|
|
161
|
+
* @param {?string} [url]
|
|
162
|
+
* @returns {EmbedsBuilder}
|
|
163
|
+
*/ setTitle(title, url) {
|
|
164
|
+
this.#currentEmbed.title = title;
|
|
165
|
+
if (url) {
|
|
166
|
+
this.setUrl(url);
|
|
167
|
+
}
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Set the timestamp of the current embed.
|
|
172
|
+
*
|
|
173
|
+
* @param {?(string | number | Date)} [timestamp]
|
|
174
|
+
* @returns {EmbedsBuilder}
|
|
175
|
+
*/ setTimestamp(timestamp) {
|
|
176
|
+
this.#currentEmbed.timestamp = new Date(timestamp).toISOString();
|
|
177
|
+
return this;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Set the thumbnail of the current embed.
|
|
181
|
+
*
|
|
182
|
+
* @param {string} url - URL of the image
|
|
183
|
+
* @param {?Omit<DiscordEmbedThumbnail, 'url'>} [options]
|
|
184
|
+
* @returns {EmbedsBuilder}
|
|
185
|
+
*/ setThumbnail(url, options) {
|
|
186
|
+
this.#currentEmbed.thumbnail = {
|
|
187
|
+
...this.#currentEmbed.thumbnail,
|
|
188
|
+
...options,
|
|
189
|
+
url
|
|
190
|
+
};
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Set the URL of the current embed title.
|
|
195
|
+
*
|
|
196
|
+
* @param {string} url
|
|
197
|
+
* @returns {EmbedsBuilder}
|
|
198
|
+
*/ setUrl(url) {
|
|
199
|
+
this.#currentEmbed.url = url;
|
|
200
|
+
return this;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Set the video of the current embed.
|
|
204
|
+
*
|
|
205
|
+
* @param {string} url
|
|
206
|
+
* @param {?Omit<DiscordEmbedVideo, 'url'>} [options]
|
|
207
|
+
* @returns {EmbedsBuilder}
|
|
208
|
+
*/ setVideo(url, options) {
|
|
209
|
+
this.#currentEmbed.video = {
|
|
210
|
+
...this.#currentEmbed.video,
|
|
211
|
+
...options,
|
|
212
|
+
url
|
|
213
|
+
};
|
|
214
|
+
return this;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Validate all embeds available against current known Discord limits to help prevent bad requests.
|
|
218
|
+
*
|
|
219
|
+
* @returns {EmbedsBuilder}
|
|
220
|
+
*/ validate() {
|
|
221
|
+
let totalCharacters = 0;
|
|
222
|
+
if (this.length > 10) {
|
|
223
|
+
throw new Error('You can not have more than 10 embeds on a single message.');
|
|
224
|
+
}
|
|
225
|
+
this.forEach(({ author , description , fields , footer , title }, index)=>{
|
|
226
|
+
if (title) {
|
|
227
|
+
const trimmedTitle = title.trim();
|
|
228
|
+
if (trimmedTitle.length > 256) {
|
|
229
|
+
throw new Error(`Title of embed ${index} can not be longer than 256 characters.`);
|
|
230
|
+
}
|
|
231
|
+
totalCharacters += trimmedTitle.length;
|
|
232
|
+
}
|
|
233
|
+
if (description) {
|
|
234
|
+
const trimmedDescription = description.trim();
|
|
235
|
+
if (trimmedDescription.length > 4096) {
|
|
236
|
+
throw new Error(`Description of embed ${index} can not be longer than 4096 characters.`);
|
|
237
|
+
}
|
|
238
|
+
totalCharacters += trimmedDescription.length;
|
|
239
|
+
}
|
|
240
|
+
if (fields) {
|
|
241
|
+
if (fields.length > 25) {
|
|
242
|
+
throw new Error(`embed ${index} can not have more than 25 fields.`);
|
|
243
|
+
}
|
|
244
|
+
fields.forEach(({ name , value }, fieldIndex)=>{
|
|
245
|
+
const trimmedName = name.trim();
|
|
246
|
+
const trimmedValue = value.trim();
|
|
247
|
+
if (trimmedName.length > 256) {
|
|
248
|
+
throw new Error(`Name of field ${fieldIndex} on embed ${index} can not be longer than 256 characters.`);
|
|
249
|
+
}
|
|
250
|
+
if (trimmedValue.length > 4096) {
|
|
251
|
+
throw new Error(`Value of field ${fieldIndex} on embed ${index} can not be longer than 1024 characters.`);
|
|
252
|
+
}
|
|
253
|
+
totalCharacters += trimmedName.length;
|
|
254
|
+
totalCharacters += trimmedValue.length;
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
if (footer) {
|
|
258
|
+
const trimmedFooterText = footer.text.trim();
|
|
259
|
+
if (trimmedFooterText.length > 2048) {
|
|
260
|
+
throw new Error(`Footer text of embed ${index} can not be longer than 2048 characters.`);
|
|
261
|
+
}
|
|
262
|
+
totalCharacters += trimmedFooterText.length;
|
|
263
|
+
}
|
|
264
|
+
if (author) {
|
|
265
|
+
const trimmedAuthorName = author.name.trim();
|
|
266
|
+
if (trimmedAuthorName.length > 256) {
|
|
267
|
+
throw new Error(`Author name of embed ${index} can not be longer than 256 characters.`);
|
|
268
|
+
}
|
|
269
|
+
totalCharacters += trimmedAuthorName.length;
|
|
270
|
+
}
|
|
271
|
+
});
|
|
272
|
+
if (totalCharacters > 6000) {
|
|
273
|
+
throw new Error('Total character length of all embeds can not exceed 6000 characters.');
|
|
274
|
+
}
|
|
275
|
+
return this;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Returns the current embed.
|
|
279
|
+
*
|
|
280
|
+
* @readonly
|
|
281
|
+
* @type {DiscordEmbed}
|
|
282
|
+
*/ get #currentEmbed() {
|
|
283
|
+
if (this.length === 0) {
|
|
284
|
+
this.newEmbed();
|
|
285
|
+
this.setCurrentEmbed();
|
|
286
|
+
}
|
|
287
|
+
return this[this.#currentEmbedIndex];
|
|
288
|
+
}
|
|
289
|
+
constructor(...args){
|
|
290
|
+
super(...args);
|
|
291
|
+
this.#currentEmbedIndex = 0;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
//# sourceMappingURL=embeds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/builders/embeds.ts"],"sourcesContent":["import type {\n DiscordEmbed,\n DiscordEmbedAuthor,\n DiscordEmbedField,\n DiscordEmbedFooter,\n DiscordEmbedImage,\n DiscordEmbedThumbnail,\n DiscordEmbedVideo,\n} from '@discordeno/types'\n\n/**\n * A builder to help create Discord embeds.\n *\n * @export\n * @class EmbedsBuilder\n * @typedef {EmbedsBuilder}\n * @extends {Array<DiscordEmbed>}\n * @example\n * const embeds = new EmbedBuilder()\n * .setTitle('My Embed')\n * .setDescription('This is my new embed')\n * .newEmbed()\n * .setTitle('My Second Embed')\n */\nexport class EmbedsBuilder extends Array<DiscordEmbed> {\n #currentEmbedIndex: number = 0\n\n /**\n * Adds a new field to the embed fields array.\n *\n * @param {string} name - Field name\n * @param {string} value - Field value\n * @param {?boolean} [inline=false] - Field should be inline or not.\n * @returns {EmbedsBuilder}\n */\n addField(name: string, value: string, inline?: boolean): EmbedsBuilder {\n if (this.#currentEmbed.fields === undefined) {\n this.#currentEmbed.fields = []\n }\n\n this.#currentEmbed.fields.push({\n name,\n value,\n inline,\n })\n\n return this\n }\n\n /**\n * Creates a blank embed.\n *\n * @returns {EmbedsBuilder}\n */\n newEmbed(): EmbedsBuilder {\n if (this.length >= 10) {\n throw new Error('Maximum embed count exceeded. You can not have more than 10 embeds.')\n }\n\n this.push({})\n this.setCurrentEmbed()\n\n return this\n }\n\n /**\n * Set the current embed author.\n *\n * @param {string} name - Name of the author\n * @param {?Omit<DiscordEmbedAuthor, 'name'>} [options] - Extra author options\n * @returns {EmbedsBuilder}\n */\n setAuthor(name: string, options?: Omit<DiscordEmbedAuthor, 'name'>): EmbedsBuilder {\n this.#currentEmbed.author = {\n ...this.#currentEmbed.author,\n ...options,\n name,\n }\n\n return this\n }\n\n /**\n * Set the color on the side of the current embed.\n *\n * @param {(number | string)} color - The color, in base16 or hex color code\n * @returns {EmbedsBuilder}\n */\n setColor(color: number | string): EmbedsBuilder {\n if (typeof color === 'string') {\n const convertedValue = parseInt(color.replace('#', ''), 16)\n color = Number.isNaN(convertedValue) ? 0 : convertedValue\n }\n\n this.#currentEmbed.color = color\n\n return this\n }\n\n /**\n * Set the current embed to a different index.\n *\n * WARNING: Only use this method if you know what you're doing. Make sure to set it back to the latest when you're done.\n *\n * @param {?number} [index] - The index of the embed in the EmbedsBuilder array\n * @returns {EmbedsBuilder}\n */\n setCurrentEmbed(index?: number): EmbedsBuilder {\n if (index === undefined) {\n this.#currentEmbedIndex = this.length - 1\n\n return this\n }\n\n if (index >= this.length || index < 0) {\n throw new Error('Can not set the current embed to a index out of bounds.')\n }\n\n this.#currentEmbedIndex = index\n\n return this\n }\n\n /**\n * Set the description of the current embed.\n *\n * @param {string} description - Description\n * @returns {EmbedsBuilder}\n */\n setDescription(description: string): EmbedsBuilder {\n this.#currentEmbed.description = description\n\n return this\n }\n\n /**\n * Overwrite all fields on the current embed.\n *\n * @param {DiscordEmbedField[]} fields\n * @returns {EmbedsBuilder}\n */\n setFields(fields: DiscordEmbedField[]): EmbedsBuilder {\n this.#currentEmbed.fields = fields\n\n return this\n }\n\n /**\n * Set the footer in the current embed.\n *\n * @param {string} text - The text to display in the footer\n * @param {?Omit<DiscordEmbedFooter, 'text'>} [options]\n * @returns {EmbedsBuilder}\n */\n setFooter(text: string, options?: Omit<DiscordEmbedFooter, 'text'>): EmbedsBuilder {\n this.#currentEmbed.footer = {\n ...this.#currentEmbed.footer,\n ...options,\n text,\n }\n\n return this\n }\n\n /**\n * Set the image in the current embed.\n *\n * @param {string} url - URL of the image\n * @param {?Omit<DiscordEmbedImage, 'url'>} [options]\n * @returns {EmbedsBuilder}\n */\n setImage(url: string, options?: Omit<DiscordEmbedImage, 'url'>): EmbedsBuilder {\n this.#currentEmbed.image = {\n ...this.#currentEmbed.image,\n ...options,\n url,\n }\n\n return this\n }\n\n /**\n * Set the provider of the current embed.\n *\n * @param {string} name\n * @param {?string} [url]\n * @returns {EmbedsBuilder}\n */\n setProvider(name: string, url?: string): EmbedsBuilder {\n this.#currentEmbed.provider = {\n name,\n url,\n }\n\n return this\n }\n\n /**\n * Set the color of the current embed to a random value.\n *\n * @returns {EmbedsBuilder}\n */\n setRandomColor(): EmbedsBuilder {\n return this.setColor(Math.floor(Math.random() * (0xffffff + 1)))\n }\n\n /**\n * Set the title of the current embed.\n *\n * @param {string} title\n * @param {?string} [url]\n * @returns {EmbedsBuilder}\n */\n setTitle(title: string, url?: string): EmbedsBuilder {\n this.#currentEmbed.title = title\n\n if (url) {\n this.setUrl(url)\n }\n\n return this\n }\n\n /**\n * Set the timestamp of the current embed.\n *\n * @param {?(string | number | Date)} [timestamp]\n * @returns {EmbedsBuilder}\n */\n setTimestamp(timestamp?: string | number | Date): EmbedsBuilder {\n this.#currentEmbed.timestamp = new Date(timestamp!).toISOString()\n\n return this\n }\n\n /**\n * Set the thumbnail of the current embed.\n *\n * @param {string} url - URL of the image\n * @param {?Omit<DiscordEmbedThumbnail, 'url'>} [options]\n * @returns {EmbedsBuilder}\n */\n setThumbnail(url: string, options?: Omit<DiscordEmbedThumbnail, 'url'>): EmbedsBuilder {\n this.#currentEmbed.thumbnail = {\n ...this.#currentEmbed.thumbnail,\n ...options,\n url,\n }\n\n return this\n }\n\n /**\n * Set the URL of the current embed title.\n *\n * @param {string} url\n * @returns {EmbedsBuilder}\n */\n setUrl(url: string): EmbedsBuilder {\n this.#currentEmbed.url = url\n\n return this\n }\n\n /**\n * Set the video of the current embed.\n *\n * @param {string} url\n * @param {?Omit<DiscordEmbedVideo, 'url'>} [options]\n * @returns {EmbedsBuilder}\n */\n setVideo(url: string, options?: Omit<DiscordEmbedVideo, 'url'>): EmbedsBuilder {\n this.#currentEmbed.video = {\n ...this.#currentEmbed.video,\n ...options,\n url,\n }\n\n return this\n }\n\n /**\n * Validate all embeds available against current known Discord limits to help prevent bad requests.\n *\n * @returns {EmbedsBuilder}\n */\n validate(): EmbedsBuilder {\n let totalCharacters = 0\n\n if (this.length > 10) {\n throw new Error('You can not have more than 10 embeds on a single message.')\n }\n\n this.forEach(({ author, description, fields, footer, title }, index) => {\n if (title) {\n const trimmedTitle = title.trim()\n\n if (trimmedTitle.length > 256) {\n throw new Error(`Title of embed ${index} can not be longer than 256 characters.`)\n }\n\n totalCharacters += trimmedTitle.length\n }\n\n if (description) {\n const trimmedDescription = description.trim()\n\n if (trimmedDescription.length > 4096) {\n throw new Error(`Description of embed ${index} can not be longer than 4096 characters.`)\n }\n\n totalCharacters += trimmedDescription.length\n }\n\n if (fields) {\n if (fields.length > 25) {\n throw new Error(`embed ${index} can not have more than 25 fields.`)\n }\n\n fields.forEach(({ name, value }, fieldIndex) => {\n const trimmedName = name.trim()\n const trimmedValue = value.trim()\n\n if (trimmedName.length > 256) {\n throw new Error(`Name of field ${fieldIndex} on embed ${index} can not be longer than 256 characters.`)\n }\n\n if (trimmedValue.length > 4096) {\n throw new Error(`Value of field ${fieldIndex} on embed ${index} can not be longer than 1024 characters.`)\n }\n\n totalCharacters += trimmedName.length\n totalCharacters += trimmedValue.length\n })\n }\n\n if (footer) {\n const trimmedFooterText = footer.text.trim()\n\n if (trimmedFooterText.length > 2048) {\n throw new Error(`Footer text of embed ${index} can not be longer than 2048 characters.`)\n }\n\n totalCharacters += trimmedFooterText.length\n }\n\n if (author) {\n const trimmedAuthorName = author.name.trim()\n\n if (trimmedAuthorName.length > 256) {\n throw new Error(`Author name of embed ${index} can not be longer than 256 characters.`)\n }\n\n totalCharacters += trimmedAuthorName.length\n }\n })\n\n if (totalCharacters > 6000) {\n throw new Error('Total character length of all embeds can not exceed 6000 characters.')\n }\n\n return this\n }\n\n /**\n * Returns the current embed.\n *\n * @readonly\n * @type {DiscordEmbed}\n */\n get #currentEmbed(): DiscordEmbed {\n if (this.length === 0) {\n this.newEmbed()\n this.setCurrentEmbed()\n }\n\n return this[this.#currentEmbedIndex]\n }\n}\n"],"names":["EmbedsBuilder","Array","currentEmbedIndex","addField","name","value","inline","currentEmbed","fields","undefined","push","newEmbed","length","Error","setCurrentEmbed","setAuthor","options","author","setColor","color","convertedValue","parseInt","replace","Number","isNaN","index","setDescription","description","setFields","setFooter","text","footer","setImage","url","image","setProvider","provider","setRandomColor","Math","floor","random","setTitle","title","setUrl","setTimestamp","timestamp","Date","toISOString","setThumbnail","thumbnail","setVideo","video","validate","totalCharacters","forEach","trimmedTitle","trim","trimmedDescription","fieldIndex","trimmedName","trimmedValue","trimmedFooterText","trimmedAuthorName"],"mappings":"AAUA;;;;;;;;;;;;;CAaC,GACD,OAAO,MAAMA,sBAAsBC;IACjC,CAACC,iBAAiB,CAAY;IAE9B;;;;;;;GAOC,GACDC,SAASC,IAAY,EAAEC,KAAa,EAAEC,MAAgB,EAAiB;QACrE,IAAI,IAAI,CAAC,CAACC,YAAY,CAACC,MAAM,KAAKC,WAAW;YAC3C,IAAI,CAAC,CAACF,YAAY,CAACC,MAAM,GAAG,EAAE;QAChC,CAAC;QAED,IAAI,CAAC,CAACD,YAAY,CAACC,MAAM,CAACE,IAAI,CAAC;YAC7BN;YACAC;YACAC;QACF;QAEA,OAAO,IAAI;IACb;IAEA;;;;GAIC,GACDK,WAA0B;QACxB,IAAI,IAAI,CAACC,MAAM,IAAI,IAAI;YACrB,MAAM,IAAIC,MAAM,uEAAsE;QACxF,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ACb,IAAI,CAACG,eAAe;QACtB,CAAC;QAED,OAAO,IAAI,CAAC,IAAI,CAAC,CAACZ,iBAAiB,CAAC;IACtC;;;aAhWA,CAACA,iBAAiB,GAAW;;AAiW/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builders.d.ts","sourceRoot":"","sources":["../src/builders.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAEpD,cAAc,sBAAsB,CAAA;AAEpC,eAAO,MAAM,YAAY,QAAO,aAAoC,CAAA"}
|
package/dist/builders.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/builders.ts"],"sourcesContent":["import { EmbedsBuilder } from './builders/embeds.js'\n\nexport * from './builders/embeds.js'\n\nexport const createEmbeds = (): EmbedsBuilder => new EmbedsBuilder()\n"],"names":["EmbedsBuilder","createEmbeds"],"mappings":"AAAA,SAASA,aAAa,QAAQ,uBAAsB;AAEpD,cAAc,uBAAsB;AAEpC,OAAO,MAAMC,eAAe,IAAqB,IAAID,gBAAe"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,YAAY,CAAA"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './Collection.js'\nexport * from './base64.js'\nexport * from './bucket.js'\nexport * from './casing.js'\nexport * from './colors.js'\nexport * from './hash.js'\nexport * from './images.js'\nexport * from './logger.js'\nexport * from './oauth2.js'\nexport * from './permissions.js'\nexport * from './reactions.js'\nexport * from './token.js'\nexport * from './typeguards.js'\nexport * from './urlToBase64.js'\nexport * from './utils.js'\n"],"names":[],"mappings":"AAAA,cAAc,kBAAiB;AAC/B,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,YAAW;AACzB,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,mBAAkB;AAChC,cAAc,iBAAgB;AAC9B,cAAc,aAAY;AAC1B,cAAc,kBAAiB;AAC/B,cAAc,mBAAkB;AAChC,cAAc,aAAY"}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './Collection.js'\nexport * from './base64.js'\nexport * from './bucket.js'\nexport * from './builders.js'\nexport * from './casing.js'\nexport * from './colors.js'\nexport * from './hash.js'\nexport * from './images.js'\nexport * from './logger.js'\nexport * from './oauth2.js'\nexport * from './permissions.js'\nexport * from './reactions.js'\nexport * from './token.js'\nexport * from './typeguards.js'\nexport * from './urlToBase64.js'\nexport * from './utils.js'\n"],"names":[],"mappings":"AAAA,cAAc,kBAAiB;AAC/B,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,gBAAe;AAC7B,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,YAAW;AACzB,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,cAAa;AAC3B,cAAc,mBAAkB;AAChC,cAAc,iBAAgB;AAC9B,cAAc,aAAY;AAC1B,cAAc,kBAAiB;AAC/B,cAAc,mBAAkB;AAChC,cAAc,aAAY"}
|
package/dist/typeguards.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { GetMessagesAfter, GetMessagesAround, GetMessagesBefore, GetMessagesLimit, GetMessagesOptions } from '@discordeno/types';
|
|
1
|
+
import type { DiscordInviteCreate, DiscordInviteMetadata, GetMessagesAfter, GetMessagesAround, GetMessagesBefore, GetMessagesLimit, GetMessagesOptions } from '@discordeno/types';
|
|
2
2
|
export declare function isGetMessagesAfter(options: GetMessagesOptions): options is GetMessagesAfter;
|
|
3
3
|
export declare function isGetMessagesBefore(options: GetMessagesOptions): options is GetMessagesBefore;
|
|
4
4
|
export declare function isGetMessagesAround(options: GetMessagesOptions): options is GetMessagesAround;
|
|
5
5
|
export declare function isGetMessagesLimit(options: GetMessagesOptions): options is GetMessagesLimit;
|
|
6
|
+
export declare function isInviteWithMetadata(options: DiscordInviteCreate | DiscordInviteMetadata): options is DiscordInviteMetadata;
|
|
6
7
|
//# sourceMappingURL=typeguards.d.ts.map
|
package/dist/typeguards.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeguards.d.ts","sourceRoot":"","sources":["../src/typeguards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"typeguards.d.ts","sourceRoot":"","sources":["../src/typeguards.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,qBAAqB,EACrB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EACnB,MAAM,mBAAmB,CAAA;AAG1B,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,IAAI,gBAAgB,CAE3F;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,IAAI,iBAAiB,CAE7F;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,IAAI,iBAAiB,CAE7F;AAED,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,IAAI,gBAAgB,CAE3F;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,qBAAqB,GAAG,OAAO,IAAI,qBAAqB,CAE3H"}
|
package/dist/typeguards.js
CHANGED
|
@@ -11,5 +11,8 @@ export function isGetMessagesAround(options) {
|
|
|
11
11
|
export function isGetMessagesLimit(options) {
|
|
12
12
|
return hasProperty(options, 'limit');
|
|
13
13
|
}
|
|
14
|
+
export function isInviteWithMetadata(options) {
|
|
15
|
+
return !hasProperty(options, 'channel_id');
|
|
16
|
+
}
|
|
14
17
|
|
|
15
18
|
//# sourceMappingURL=typeguards.js.map
|
package/dist/typeguards.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/typeguards.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../src/typeguards.ts"],"sourcesContent":["import type {\n DiscordInviteCreate,\n DiscordInviteMetadata,\n GetMessagesAfter,\n GetMessagesAround,\n GetMessagesBefore,\n GetMessagesLimit,\n GetMessagesOptions,\n} from '@discordeno/types'\nimport { hasProperty } from './utils.js'\n\nexport function isGetMessagesAfter(options: GetMessagesOptions): options is GetMessagesAfter {\n return hasProperty(options, 'after')\n}\n\nexport function isGetMessagesBefore(options: GetMessagesOptions): options is GetMessagesBefore {\n return hasProperty(options, 'before')\n}\n\nexport function isGetMessagesAround(options: GetMessagesOptions): options is GetMessagesAround {\n return hasProperty(options, 'around')\n}\n\nexport function isGetMessagesLimit(options: GetMessagesOptions): options is GetMessagesLimit {\n return hasProperty(options, 'limit')\n}\n\nexport function isInviteWithMetadata(options: DiscordInviteCreate | DiscordInviteMetadata): options is DiscordInviteMetadata {\n return !hasProperty(options, 'channel_id')\n}\n"],"names":["hasProperty","isGetMessagesAfter","options","isGetMessagesBefore","isGetMessagesAround","isGetMessagesLimit","isInviteWithMetadata"],"mappings":"AASA,SAASA,WAAW,QAAQ,aAAY;AAExC,OAAO,SAASC,mBAAmBC,OAA2B,EAA+B;IAC3F,OAAOF,YAAYE,SAAS;AAC9B,CAAC;AAED,OAAO,SAASC,oBAAoBD,OAA2B,EAAgC;IAC7F,OAAOF,YAAYE,SAAS;AAC9B,CAAC;AAED,OAAO,SAASE,oBAAoBF,OAA2B,EAAgC;IAC7F,OAAOF,YAAYE,SAAS;AAC9B,CAAC;AAED,OAAO,SAASG,mBAAmBH,OAA2B,EAA+B;IAC3F,OAAOF,YAAYE,SAAS;AAC9B,CAAC;AAED,OAAO,SAASI,qBAAqBJ,OAAoD,EAAoC;IAC3H,OAAO,CAACF,YAAYE,SAAS;AAC/B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@discordeno/utils",
|
|
3
|
-
"version": "19.0.0-next.
|
|
3
|
+
"version": "19.0.0-next.a8f9e5e",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test:test-type": "tsc --project tsconfig.test.json"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@discordeno/types": "19.0.0-next.
|
|
26
|
+
"@discordeno/types": "19.0.0-next.a8f9e5e",
|
|
27
27
|
"tweetnacl": "^1.0.3"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
package/dist/interactions.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"interactions.d.ts","sourceRoot":"","sources":["../src/interactions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;AAE1F,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,WAAW,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAwCvJ"}
|
package/dist/interactions.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ApplicationCommandOptionTypes } from '@discordeno/types';
|
|
2
|
-
export function commandOptionsParser(interaction, options) {
|
|
3
|
-
if (!interaction.data) return {};
|
|
4
|
-
if (!options) options = interaction.data.options ?? [];
|
|
5
|
-
const args = {};
|
|
6
|
-
for (const option of options){
|
|
7
|
-
switch(option.type){
|
|
8
|
-
case ApplicationCommandOptionTypes.SubCommandGroup:
|
|
9
|
-
case ApplicationCommandOptionTypes.SubCommand:
|
|
10
|
-
args[option.name] = commandOptionsParser(interaction, option.options);
|
|
11
|
-
break;
|
|
12
|
-
case ApplicationCommandOptionTypes.Channel:
|
|
13
|
-
args[option.name] = interaction.data.resolved?.channels?.[option.value];
|
|
14
|
-
break;
|
|
15
|
-
case ApplicationCommandOptionTypes.Role:
|
|
16
|
-
args[option.name] = interaction.data.resolved?.roles?.[option.value];
|
|
17
|
-
break;
|
|
18
|
-
case ApplicationCommandOptionTypes.User:
|
|
19
|
-
args[option.name] = {
|
|
20
|
-
user: interaction.data.resolved?.users?.[option.value],
|
|
21
|
-
member: interaction.data.resolved?.members?.[option.value]
|
|
22
|
-
};
|
|
23
|
-
break;
|
|
24
|
-
case ApplicationCommandOptionTypes.Attachment:
|
|
25
|
-
args[option.name] = interaction.data.resolved?.attachments?.[option.value];
|
|
26
|
-
break;
|
|
27
|
-
case ApplicationCommandOptionTypes.Mentionable:
|
|
28
|
-
// Mentionable are roles or users
|
|
29
|
-
args[option.name] = interaction.data.resolved?.roles?.[option.value] ?? {
|
|
30
|
-
user: interaction.data.resolved?.users?.[option.value],
|
|
31
|
-
member: interaction.data.resolved?.members?.[option.value]
|
|
32
|
-
};
|
|
33
|
-
break;
|
|
34
|
-
default:
|
|
35
|
-
args[option.name] = option.value;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return args;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
//# sourceMappingURL=interactions.js.map
|
package/dist/interactions.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/interactions.ts"],"sourcesContent":["import { ApplicationCommandOptionTypes, type DiscordInteraction } from '@discordeno/types'\n\nexport function commandOptionsParser(interaction: DiscordInteraction, options?: NonNullable<DiscordInteraction['data']>['options']): Record<string, any> {\n if (!interaction.data) return {}\n if (!options) options = interaction.data.options ?? []\n\n const args: Record<string, any> = {}\n\n for (const option of options) {\n switch (option.type) {\n case ApplicationCommandOptionTypes.SubCommandGroup:\n case ApplicationCommandOptionTypes.SubCommand:\n args[option.name] = commandOptionsParser(interaction, option.options)\n break\n case ApplicationCommandOptionTypes.Channel:\n args[option.name] = interaction.data.resolved?.channels?.[option.value as string]\n break\n case ApplicationCommandOptionTypes.Role:\n args[option.name] = interaction.data.resolved?.roles?.[option.value as string]\n break\n case ApplicationCommandOptionTypes.User:\n args[option.name] = {\n user: interaction.data.resolved?.users?.[option.value as string],\n member: interaction.data.resolved?.members?.[option.value as string],\n }\n break\n case ApplicationCommandOptionTypes.Attachment:\n args[option.name] = interaction.data.resolved?.attachments?.[option.value as string]\n break;\n case ApplicationCommandOptionTypes.Mentionable:\n // Mentionable are roles or users\n args[option.name] = interaction.data.resolved?.roles?.[option.value as string] ?? {\n user: interaction.data.resolved?.users?.[option.value as string],\n member: interaction.data.resolved?.members?.[option.value as string],\n }\n break\n default:\n args[option.name] = option.value\n }\n }\n\n return args\n}\n"],"names":["ApplicationCommandOptionTypes","commandOptionsParser","interaction","options","data","args","option","type","SubCommandGroup","SubCommand","name","Channel","resolved","channels","value","Role","roles","User","user","users","member","members","Attachment","attachments","Mentionable"],"mappings":"AAAA,SAASA,6BAA6B,QAAiC,oBAAmB;AAE1F,OAAO,SAASC,qBAAqBC,WAA+B,EAAEC,OAA4D,EAAuB;IACvJ,IAAI,CAACD,YAAYE,IAAI,EAAE,OAAO,CAAC;IAC/B,IAAI,CAACD,SAASA,UAAUD,YAAYE,IAAI,CAACD,OAAO,IAAI,EAAE;IAEtD,MAAME,OAA4B,CAAC;IAEnC,KAAK,MAAMC,UAAUH,QAAS;QAC5B,OAAQG,OAAOC,IAAI;YACjB,KAAKP,8BAA8BQ,eAAe;YAClD,KAAKR,8BAA8BS,UAAU;gBAC3CJ,IAAI,CAACC,OAAOI,IAAI,CAAC,GAAGT,qBAAqBC,aAAaI,OAAOH,OAAO;gBACpE,KAAK;YACP,KAAKH,8BAA8BW,OAAO;gBACxCN,IAAI,CAACC,OAAOI,IAAI,CAAC,GAAGR,YAAYE,IAAI,CAACQ,QAAQ,EAAEC,UAAU,CAACP,OAAOQ,KAAK,CAAW;gBACjF,KAAK;YACP,KAAKd,8BAA8Be,IAAI;gBACrCV,IAAI,CAACC,OAAOI,IAAI,CAAC,GAAGR,YAAYE,IAAI,CAACQ,QAAQ,EAAEI,OAAO,CAACV,OAAOQ,KAAK,CAAW;gBAC9E,KAAK;YACP,KAAKd,8BAA8BiB,IAAI;gBACrCZ,IAAI,CAACC,OAAOI,IAAI,CAAC,GAAG;oBAClBQ,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