gralonium 0.3.0 → 0.4.1
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/classes/Client.d.ts +9 -3
- package/lib/classes/Client.js +2 -2
- package/lib/classes/Context.d.ts +42 -1
- package/lib/classes/Context.js +276 -13
- package/lib/classes/Cooldowns.d.ts +2 -0
- package/lib/classes/Cooldowns.js +28 -0
- package/lib/classes/HelpCommand.d.ts +55 -13
- package/lib/classes/HelpCommand.js +319 -1
- package/lib/classes/Loader.d.ts +10 -1
- package/lib/classes/Loader.js +143 -58
- package/lib/classes/Plugins.js +3 -2
- package/lib/classes/Utils.d.ts +1 -1
- package/lib/classes/Utils.js +103 -24
- package/lib/classes/builders/CommandBuilder.d.ts +24 -0
- package/lib/classes/builders/CommandBuilder.js +66 -2
- package/lib/classes/builders/ComponentsV2Builder.d.ts +288 -113
- package/lib/classes/builders/ComponentsV2Builder.js +1071 -180
- package/lib/classes/builders/GroupBuilder.d.ts +20 -0
- package/lib/classes/builders/GroupBuilder.js +37 -1
- package/lib/classes/builders/InteractionBuilder.d.ts +86 -25
- package/lib/classes/builders/InteractionBuilder.js +212 -1
- package/lib/classes/builders/ParamsBuilder.d.ts +118 -76
- package/lib/classes/builders/ParamsBuilder.js +167 -1
- package/lib/classes/builders/components/StyleMapper.d.ts +14 -2
- package/lib/classes/builders/components/StyleMapper.js +35 -9
- package/lib/classes/builders/components/helpers.d.ts +68 -4
- package/lib/classes/builders/components/helpers.js +366 -7
- package/lib/classes/builders/components/templates.d.ts +151 -9
- package/lib/classes/builders/components/templates.js +376 -17
- package/lib/classes/builders/components/text.d.ts +24 -0
- package/lib/classes/builders/components/text.js +91 -0
- package/lib/classes/experiments/Confirmator.d.ts +44 -26
- package/lib/classes/experiments/Confirmator.js +37 -21
- package/lib/classes/experiments/Paginator.d.ts +48 -29
- package/lib/classes/experiments/Paginator.js +48 -19
- package/lib/classes/views/V2Paginator.d.ts +91 -0
- package/lib/classes/views/V2Paginator.js +268 -0
- package/lib/classes/views/V2View.d.ts +113 -0
- package/lib/classes/views/V2View.js +438 -0
- package/lib/experiments.d.ts +2 -0
- package/lib/experiments.js +9 -1
- package/lib/main.d.ts +3 -0
- package/lib/main.js +3 -0
- package/package.json +3 -1
|
@@ -1 +1,167 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ParamsBuilder = void 0;
|
|
4
|
+
|
|
5
|
+
const discord_js_1 = require("discord.js");
|
|
6
|
+
const CommandBuilder_js_1 = require("./CommandBuilder.js");
|
|
7
|
+
|
|
8
|
+
const INTERNAL_RUNTIME_KEYS = new Set([
|
|
9
|
+
"ellipsis",
|
|
10
|
+
"value",
|
|
11
|
+
"minLength",
|
|
12
|
+
"maxLength",
|
|
13
|
+
"minValue",
|
|
14
|
+
"maxValue",
|
|
15
|
+
"channelTypes",
|
|
16
|
+
"nameLocalizations",
|
|
17
|
+
"descriptionLocalizations",
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
function normalizeChoices(choices) {
|
|
21
|
+
if (!Array.isArray(choices)) return undefined;
|
|
22
|
+
return choices.map((choice) => {
|
|
23
|
+
const out = {
|
|
24
|
+
name: String(choice.name),
|
|
25
|
+
value: choice.value,
|
|
26
|
+
};
|
|
27
|
+
const nameLocs = (0, CommandBuilder_js_1.normalizeNameLocalizations)(
|
|
28
|
+
choice.name_localizations ?? choice.nameLocalizations
|
|
29
|
+
);
|
|
30
|
+
if (nameLocs) {
|
|
31
|
+
out.name_localizations = nameLocs;
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
class ParamsBuilder {
|
|
38
|
+
params = [];
|
|
39
|
+
quoted = true;
|
|
40
|
+
|
|
41
|
+
setQuoted(value) {
|
|
42
|
+
this.quoted = value;
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
#normalizeParam(param, type) {
|
|
47
|
+
const normalized = { ...param, type };
|
|
48
|
+
|
|
49
|
+
if (normalized.description !== undefined) {
|
|
50
|
+
normalized.description = String(normalized.description ?? "...").slice(0, 100);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (normalized.min_length === undefined && normalized.minLength !== undefined) {
|
|
54
|
+
normalized.min_length = normalized.minLength;
|
|
55
|
+
}
|
|
56
|
+
if (normalized.max_length === undefined && normalized.maxLength !== undefined) {
|
|
57
|
+
normalized.max_length = normalized.maxLength;
|
|
58
|
+
}
|
|
59
|
+
if (normalized.min_value === undefined && normalized.minValue !== undefined) {
|
|
60
|
+
normalized.min_value = normalized.minValue;
|
|
61
|
+
}
|
|
62
|
+
if (normalized.max_value === undefined && normalized.maxValue !== undefined) {
|
|
63
|
+
normalized.max_value = normalized.maxValue;
|
|
64
|
+
}
|
|
65
|
+
if (normalized.channel_types === undefined && normalized.channelTypes !== undefined) {
|
|
66
|
+
normalized.channel_types = normalized.channelTypes;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const nameLocs = (0, CommandBuilder_js_1.normalizeNameLocalizations)(
|
|
70
|
+
normalized.name_localizations ?? normalized.nameLocalizations
|
|
71
|
+
);
|
|
72
|
+
if (nameLocs) {
|
|
73
|
+
normalized.name_localizations = nameLocs;
|
|
74
|
+
} else {
|
|
75
|
+
delete normalized.name_localizations;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const descLocs = (0, CommandBuilder_js_1.normalizeDescriptionLocalizations)(
|
|
79
|
+
normalized.description_localizations ?? normalized.descriptionLocalizations
|
|
80
|
+
);
|
|
81
|
+
if (descLocs) {
|
|
82
|
+
normalized.description_localizations = descLocs;
|
|
83
|
+
} else {
|
|
84
|
+
delete normalized.description_localizations;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
delete normalized.minLength;
|
|
88
|
+
delete normalized.maxLength;
|
|
89
|
+
delete normalized.minValue;
|
|
90
|
+
delete normalized.maxValue;
|
|
91
|
+
delete normalized.channelTypes;
|
|
92
|
+
delete normalized.nameLocalizations;
|
|
93
|
+
delete normalized.descriptionLocalizations;
|
|
94
|
+
|
|
95
|
+
if (normalized.choices !== undefined) {
|
|
96
|
+
normalized.choices = normalizeChoices(normalized.choices);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return normalized;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
addString(param) {
|
|
103
|
+
this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.String));
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
addNumber(param) {
|
|
108
|
+
this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.Number));
|
|
109
|
+
return this;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
addInteger(param) {
|
|
113
|
+
this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.Integer));
|
|
114
|
+
return this;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
addBoolean(param) {
|
|
118
|
+
this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.Boolean));
|
|
119
|
+
return this;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
addMember(param) {
|
|
123
|
+
this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.User));
|
|
124
|
+
return this;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
addUser(param) {
|
|
128
|
+
return this.addMember(param);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
addChannel(param) {
|
|
132
|
+
this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.Channel));
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
addRole(param) {
|
|
137
|
+
this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.Role));
|
|
138
|
+
return this;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
addAttachment(param) {
|
|
142
|
+
this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.Attachment));
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
addMentionable(param) {
|
|
147
|
+
this.params.push(this.#normalizeParam(param, discord_js_1.ApplicationCommandOptionType.Mentionable));
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Serializes options cleanly for Discord ApplicationCommand registration,
|
|
153
|
+
* omitting prefix-only runtime fields such as `ellipsis` and `value`.
|
|
154
|
+
*/
|
|
155
|
+
toJSON() {
|
|
156
|
+
return this.params.map((param) => {
|
|
157
|
+
const json = {};
|
|
158
|
+
for (const [key, val] of Object.entries(param)) {
|
|
159
|
+
if (INTERNAL_RUNTIME_KEYS.has(key) || val === undefined) continue;
|
|
160
|
+
json[key] = val;
|
|
161
|
+
}
|
|
162
|
+
return json;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
exports.ParamsBuilder = ParamsBuilder;
|
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { ButtonStyle } from "discord.js";
|
|
2
2
|
|
|
3
|
-
export type ButtonStyleName = "primary" | "secondary" | "success" | "danger" | "link";
|
|
3
|
+
export type ButtonStyleName = "primary" | "secondary" | "success" | "danger" | "link" | "premium";
|
|
4
4
|
export type ButtonStyleInput = ButtonStyleName | ButtonStyle;
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Sets the default fallback button style used when no explicit style is provided.
|
|
8
|
+
*/
|
|
9
|
+
export declare function setDefaultButtonStyle(style?: ButtonStyleInput | null): ButtonStyle;
|
|
10
|
+
export declare const setDefaultStyle: typeof setDefaultButtonStyle;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Returns the current default fallback button style.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getDefaultButtonStyle(): ButtonStyle;
|
|
16
|
+
export declare const getDefaultStyle: typeof getDefaultButtonStyle;
|
|
17
|
+
|
|
6
18
|
/**
|
|
7
19
|
* Maps a button style name (string) or ButtonStyle enum value to a ButtonStyle.
|
|
8
|
-
* Defaults to
|
|
20
|
+
* Defaults to the configured default button style (Secondary by default) if not recognized.
|
|
9
21
|
*/
|
|
10
22
|
export declare function mapButtonStyle(style?: ButtonStyleInput | null): ButtonStyle;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mapButtonStyle = void 0;
|
|
3
|
+
exports.getDefaultStyle = exports.setDefaultStyle = exports.getDefaultButtonStyle = exports.setDefaultButtonStyle = exports.mapButtonStyle = void 0;
|
|
4
4
|
|
|
5
5
|
const discord_js_1 = require("discord.js");
|
|
6
6
|
|
|
@@ -10,23 +10,49 @@ const STYLE_MAP = {
|
|
|
10
10
|
success: discord_js_1.ButtonStyle.Success,
|
|
11
11
|
danger: discord_js_1.ButtonStyle.Danger,
|
|
12
12
|
link: discord_js_1.ButtonStyle.Link,
|
|
13
|
+
...(discord_js_1.ButtonStyle.Premium !== undefined ? { premium: discord_js_1.ButtonStyle.Premium } : {}),
|
|
13
14
|
};
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
*/
|
|
19
|
-
function mapButtonStyle(style) {
|
|
16
|
+
let defaultButtonStyle = discord_js_1.ButtonStyle.Secondary;
|
|
17
|
+
|
|
18
|
+
function resolveStyleValue(style, fallback = defaultButtonStyle) {
|
|
20
19
|
if (style === undefined || style === null) {
|
|
21
|
-
return
|
|
20
|
+
return fallback;
|
|
22
21
|
}
|
|
23
22
|
if (typeof style === "number") {
|
|
24
23
|
return style;
|
|
25
24
|
}
|
|
26
|
-
const mapped = STYLE_MAP[style.toLowerCase()];
|
|
25
|
+
const mapped = STYLE_MAP[String(style).toLowerCase()];
|
|
27
26
|
if (mapped === undefined) {
|
|
28
|
-
return
|
|
27
|
+
return fallback;
|
|
29
28
|
}
|
|
30
29
|
return mapped;
|
|
31
30
|
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Sets the default fallback button style used when no explicit style is provided.
|
|
34
|
+
*/
|
|
35
|
+
function setDefaultButtonStyle(style) {
|
|
36
|
+
defaultButtonStyle = resolveStyleValue(style, discord_js_1.ButtonStyle.Secondary);
|
|
37
|
+
return defaultButtonStyle;
|
|
38
|
+
}
|
|
39
|
+
exports.setDefaultButtonStyle = setDefaultButtonStyle;
|
|
40
|
+
exports.setDefaultStyle = setDefaultButtonStyle;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Returns the current default fallback button style.
|
|
44
|
+
*/
|
|
45
|
+
function getDefaultButtonStyle() {
|
|
46
|
+
return defaultButtonStyle;
|
|
47
|
+
}
|
|
48
|
+
exports.getDefaultButtonStyle = getDefaultButtonStyle;
|
|
49
|
+
exports.getDefaultStyle = getDefaultButtonStyle;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Maps a button style name (string) or ButtonStyle enum value to a ButtonStyle.
|
|
53
|
+
* Defaults to the configured default button style (Secondary by default) if not recognized.
|
|
54
|
+
*/
|
|
55
|
+
function mapButtonStyle(style) {
|
|
56
|
+
return resolveStyleValue(style, defaultButtonStyle);
|
|
57
|
+
}
|
|
32
58
|
exports.mapButtonStyle = mapButtonStyle;
|
|
@@ -1,18 +1,32 @@
|
|
|
1
|
+
import { APIMessageComponent, APIMessageComponentEmoji, Message, RGBTuple } from "discord.js";
|
|
2
|
+
|
|
3
|
+
export declare const MAX_V2_TEXT_LENGTH = 4000;
|
|
4
|
+
export declare const SAFE_V2_TEXT_LENGTH = 3950;
|
|
5
|
+
export declare const MAX_V2_COMPONENTS = 40;
|
|
6
|
+
export declare const MAX_V2_TOP_LEVEL_COMPONENTS = 10;
|
|
7
|
+
|
|
8
|
+
export type AccentColorInput = number | string | RGBTuple | null | undefined;
|
|
9
|
+
export type EmojiInput = string | APIMessageComponentEmoji | null | undefined;
|
|
10
|
+
|
|
11
|
+
export interface DisableComponentsOptions {
|
|
12
|
+
disableButtons?: boolean;
|
|
13
|
+
disableSelects?: boolean;
|
|
14
|
+
disableLinks?: boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
1
17
|
/**
|
|
2
18
|
* Validates that text content is non-empty.
|
|
3
|
-
*
|
|
19
|
+
* Returns false if `ignoreEmpty` is true and content is blank.
|
|
4
20
|
*/
|
|
5
|
-
export declare function validateTextContent(content: unknown):
|
|
21
|
+
export declare function validateTextContent(content: unknown, options?: { ignoreEmpty?: boolean }): boolean;
|
|
6
22
|
|
|
7
23
|
/**
|
|
8
24
|
* Validates that a button row does not exceed 5 buttons.
|
|
9
|
-
* Throws a descriptive error if validation fails.
|
|
10
25
|
*/
|
|
11
26
|
export declare function validateButtonCount(count: number): void;
|
|
12
27
|
|
|
13
28
|
/**
|
|
14
29
|
* Validates that a select menu does not exceed 25 options.
|
|
15
|
-
* Throws a descriptive error if validation fails.
|
|
16
30
|
*/
|
|
17
31
|
export declare function validateSelectMenuOptions(count: number): void;
|
|
18
32
|
|
|
@@ -20,3 +34,53 @@ export declare function validateSelectMenuOptions(count: number): void;
|
|
|
20
34
|
* Generates a unique custom ID with an optional prefix.
|
|
21
35
|
*/
|
|
22
36
|
export declare function generateCustomId(prefix?: string): string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Resolves a hex string, RGB tuple, integer, or preset name into a 24-bit color integer.
|
|
40
|
+
*/
|
|
41
|
+
export declare function resolveAccentColor(color?: AccentColorInput, fallback?: AccentColorInput): number | null;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Checks whether a URL is valid for Discord media components (`http://`, `https://`, `attachment://`).
|
|
45
|
+
*/
|
|
46
|
+
export declare function isValidMediaUrl(url: unknown): url is string;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Checks whether a URL is valid for Discord link buttons (`http://`, `https://`, `discord://`).
|
|
50
|
+
*/
|
|
51
|
+
export declare function isValidLinkUrl(url: unknown): url is string;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Parses unicode, `<:name:id>`, `<a:name:id>`, `name:id`, snowflake ID, or emoji object into API emoji shape.
|
|
55
|
+
*/
|
|
56
|
+
export declare function parseEmoji(emoji: EmojiInput): APIMessageComponentEmoji | null;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Clips text to `maxLen`, appending `…` if truncated.
|
|
60
|
+
*/
|
|
61
|
+
export declare function clipText(text: unknown, maxLen?: number, fallback?: string): string;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Returns true if the numeric component type is a Discord Components V2 type.
|
|
65
|
+
*/
|
|
66
|
+
export declare function isV2ComponentType(type: number): boolean;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Counts total characters across all TextDisplay components in a component array.
|
|
70
|
+
*/
|
|
71
|
+
export declare function countTextLength(components: unknown[]): number;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Counts total component nodes (including nested Container, Section, ActionRow, and MediaGallery items).
|
|
75
|
+
*/
|
|
76
|
+
export declare function countComponents(components: unknown[]): number;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Recursively clones and disables buttons/selects in both V1 ActionRows and V2 Containers/Sections.
|
|
80
|
+
*/
|
|
81
|
+
export declare function disableComponents(components: unknown[], options?: DisableComponentsOptions): APIMessageComponent[];
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Edits a Discord message to recursively disable its V1 or V2 interactive components.
|
|
85
|
+
*/
|
|
86
|
+
export declare function disableMessageComponents(message: Message | null | undefined, options?: DisableComponentsOptions): Promise<Message | null>;
|