@zoodogood/utils 1.0.4-change.334 → 1.0.5-change.421
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/lib/discordjs/mod.d.ts +47 -30
- package/lib/discordjs/mod.js +56 -19
- package/package.json +1 -1
package/lib/discordjs/mod.d.ts
CHANGED
|
@@ -1,37 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Create a message object for Discord.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} params = Parameters for creating the message.
|
|
5
|
+
* @param {string} [params.content] - The message content.
|
|
6
|
+
* @param {string} [params.title] - The title of the embed.
|
|
7
|
+
* @param {string} [params.url] - The URL of the embed.
|
|
8
|
+
* @param {Object} [params.author] - The author of the embed.
|
|
9
|
+
* @param {string} [params.thumbnail] - The thumbnail URL of the embed.
|
|
10
|
+
* @param {string} [params.description] - The description of the embed.
|
|
11
|
+
* @param {string} [params.color] - The color of the embed.
|
|
12
|
+
* @param {Object[]} [params.fields] - The fields of the embed.
|
|
13
|
+
* @param {string} [params.image] - The image URL of the embed.
|
|
14
|
+
* @param {string} [params.video] - The video URL of the embed.
|
|
15
|
+
* @param {Object} [params.footer] - The footer of the embed.
|
|
16
|
+
* @param {string} [params.timestamp] - The timestamp of the embed.
|
|
17
|
+
* @param {boolean} [params.ephemeral] - Whether the message should be ephemeral.
|
|
18
|
+
* @param {boolean} [params.fetchReply] - Whether to fetch the message reply.
|
|
19
|
+
* @param {Object[] | Object} [params.components] - The message components.
|
|
20
|
+
* @param {Object[] | Object[]} [params.files] - The message files.
|
|
21
|
+
* @param {string} [params.reference] - The message reference.
|
|
22
|
+
* @returns {Object} - The message object.
|
|
23
|
+
*/
|
|
24
|
+
export function CreateMessage({ content, title, url, author, thumbnail, description, color, fields, image, video, footer, timestamp, ephemeral, fetchReply, components, files, reference, }: {
|
|
25
|
+
content?: string | undefined;
|
|
26
|
+
title?: string | undefined;
|
|
27
|
+
url?: string | undefined;
|
|
28
|
+
author?: Object | undefined;
|
|
29
|
+
thumbnail?: string | undefined;
|
|
30
|
+
description?: string | undefined;
|
|
31
|
+
color?: string | undefined;
|
|
32
|
+
fields?: Object[] | undefined;
|
|
33
|
+
image?: string | undefined;
|
|
34
|
+
video?: string | undefined;
|
|
35
|
+
footer?: Object | undefined;
|
|
36
|
+
timestamp?: string | undefined;
|
|
37
|
+
ephemeral?: boolean | undefined;
|
|
38
|
+
fetchReply?: boolean | undefined;
|
|
39
|
+
components?: Object | Object[] | undefined;
|
|
40
|
+
files?: Object[] | undefined;
|
|
41
|
+
reference?: string | undefined;
|
|
42
|
+
}): Object;
|
|
30
43
|
export function CreateModal({ title, customId, components }: {
|
|
31
44
|
title: any;
|
|
32
45
|
customId: any;
|
|
33
46
|
components: any;
|
|
34
47
|
}): import("discord.js").APIModalInteractionResponseCallbackData;
|
|
35
48
|
export function SimplifyComponents(data: any): any;
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param {*} embed
|
|
52
|
+
* @returns {boolean}
|
|
53
|
+
*/
|
|
36
54
|
export function isEmptyEmbed(embed: any): boolean;
|
|
37
|
-
import { EmbedBuilder } from 'discord.js';
|
package/lib/discordjs/mod.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import { EmbedBuilder, ModalBuilder, resolveColor, ActionRow } from
|
|
2
|
-
import { ComponentType } from
|
|
1
|
+
import { EmbedBuilder, ModalBuilder, resolveColor, ActionRow, } from "discord.js";
|
|
2
|
+
import { ComponentType } from "discord-api-types/v10";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {*} embed
|
|
6
|
+
* @returns {boolean}
|
|
7
|
+
*/
|
|
3
8
|
function isEmptyEmbed(embed) {
|
|
4
9
|
const DEFAULT_PROPERTIES = {
|
|
5
10
|
title: undefined,
|
|
@@ -10,24 +15,54 @@ function isEmptyEmbed(embed) {
|
|
|
10
15
|
image: undefined,
|
|
11
16
|
footer: undefined,
|
|
12
17
|
timestamp: undefined,
|
|
13
|
-
video: undefined
|
|
18
|
+
video: undefined,
|
|
14
19
|
};
|
|
15
20
|
// in isEmptyEmbed context is a good compare
|
|
16
21
|
const isEqualDefault = (key) => String(embed[key]) === String(DEFAULT_PROPERTIES[key]);
|
|
17
|
-
const isEveryPropertyDefault = Object.keys(DEFAULT_PROPERTIES)
|
|
18
|
-
.every(isEqualDefault);
|
|
22
|
+
const isEveryPropertyDefault = Object.keys(DEFAULT_PROPERTIES).every(isEqualDefault);
|
|
19
23
|
return isEveryPropertyDefault;
|
|
20
24
|
}
|
|
21
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Create a message object for Discord.
|
|
27
|
+
*
|
|
28
|
+
* @param {Object} params = Parameters for creating the message.
|
|
29
|
+
* @param {string} [params.content] - The message content.
|
|
30
|
+
* @param {string} [params.title] - The title of the embed.
|
|
31
|
+
* @param {string} [params.url] - The URL of the embed.
|
|
32
|
+
* @param {Object} [params.author] - The author of the embed.
|
|
33
|
+
* @param {string} [params.thumbnail] - The thumbnail URL of the embed.
|
|
34
|
+
* @param {string} [params.description] - The description of the embed.
|
|
35
|
+
* @param {string} [params.color] - The color of the embed.
|
|
36
|
+
* @param {Object[]} [params.fields] - The fields of the embed.
|
|
37
|
+
* @param {string} [params.image] - The image URL of the embed.
|
|
38
|
+
* @param {string} [params.video] - The video URL of the embed.
|
|
39
|
+
* @param {Object} [params.footer] - The footer of the embed.
|
|
40
|
+
* @param {string} [params.timestamp] - The timestamp of the embed.
|
|
41
|
+
* @param {boolean} [params.ephemeral] - Whether the message should be ephemeral.
|
|
42
|
+
* @param {boolean} [params.fetchReply] - Whether to fetch the message reply.
|
|
43
|
+
* @param {Object[] | Object} [params.components] - The message components.
|
|
44
|
+
* @param {Object[] | Object[]} [params.files] - The message files.
|
|
45
|
+
* @param {string} [params.reference] - The message reference.
|
|
46
|
+
* @returns {Object} - The message object.
|
|
47
|
+
*/
|
|
48
|
+
function CreateMessage({ content, title, url, author, thumbnail, description, color, fields, image, video, footer, timestamp, ephemeral, fetchReply, components, files, reference, }) {
|
|
22
49
|
const message = {};
|
|
23
50
|
thumbnail && (thumbnail = { url: thumbnail });
|
|
24
51
|
image && (image = { url: image });
|
|
25
52
|
video && (video = { url: video });
|
|
26
53
|
color = resolveColor(color !== null && color !== void 0 ? color : "Random");
|
|
27
54
|
const embed = new EmbedBuilder({
|
|
28
|
-
title,
|
|
29
|
-
|
|
30
|
-
|
|
55
|
+
title,
|
|
56
|
+
url,
|
|
57
|
+
author,
|
|
58
|
+
thumbnail,
|
|
59
|
+
description,
|
|
60
|
+
color,
|
|
61
|
+
fields,
|
|
62
|
+
image,
|
|
63
|
+
video,
|
|
64
|
+
footer,
|
|
65
|
+
timestamp,
|
|
31
66
|
});
|
|
32
67
|
if (!isEmptyEmbed(embed.data)) {
|
|
33
68
|
message.embeds = [embed];
|
|
@@ -37,7 +72,7 @@ function CreateMessage({ content, title, url, author, thumbnail, description, co
|
|
|
37
72
|
}
|
|
38
73
|
if (reference)
|
|
39
74
|
message.reply = {
|
|
40
|
-
messageReference: reference
|
|
75
|
+
messageReference: reference,
|
|
41
76
|
};
|
|
42
77
|
message.components = components ? SimplifyComponents(components) : null;
|
|
43
78
|
message.content = content;
|
|
@@ -52,27 +87,29 @@ function CreateModal({ title, customId, components }) {
|
|
|
52
87
|
function SimplifyComponents(data) {
|
|
53
88
|
if (data instanceof Array && data.length === 0)
|
|
54
89
|
return [];
|
|
55
|
-
const isComponent = (component) => "type" in component;
|
|
56
|
-
const isActionRow = (component) => component instanceof Array && isComponent(component.at(0)) ||
|
|
57
|
-
|
|
90
|
+
const isComponent = (component) => "type" in component && component.type !== ComponentType.ActionRow;
|
|
91
|
+
const isActionRow = (component) => (component instanceof Array && isComponent(component.at(0))) ||
|
|
92
|
+
component instanceof ActionRow;
|
|
93
|
+
const isComponents = (component) => component instanceof Array && isActionRow(component.at(0));
|
|
58
94
|
const argumentType = [
|
|
59
95
|
isComponent(data),
|
|
60
96
|
isActionRow(data),
|
|
61
|
-
isComponents(data)
|
|
97
|
+
isComponents(data),
|
|
62
98
|
].findIndex(Boolean);
|
|
63
99
|
if (argumentType === -1)
|
|
64
100
|
throw new TypeError("expected component");
|
|
65
|
-
const
|
|
101
|
+
const wrapToArray = (component) => [component];
|
|
66
102
|
const arrayToActionRow = (componentsArray) => {
|
|
67
|
-
|
|
103
|
+
const isActionRow = "type" in componentsArray &&
|
|
104
|
+
componentsArray.type === ComponentType.ActionRow;
|
|
105
|
+
if (isActionRow)
|
|
68
106
|
return componentsArray;
|
|
69
107
|
return { type: ComponentType.ActionRow, components: componentsArray };
|
|
70
108
|
};
|
|
71
|
-
const actionRowInArray = (actionRow) => [actionRow];
|
|
72
109
|
if (argumentType <= 0)
|
|
73
|
-
data =
|
|
110
|
+
data = wrapToArray(data);
|
|
74
111
|
if (argumentType <= 1)
|
|
75
|
-
data =
|
|
112
|
+
data = wrapToArray(data);
|
|
76
113
|
data = data.map(arrayToActionRow);
|
|
77
114
|
return data;
|
|
78
115
|
}
|