gralonium 0.4.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.
@@ -1 +1,167 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.ParamsBuilder=void 0;const discord_js_1=require("discord.js");class ParamsBuilder{params=[];quoted=!0;setQuoted(t){return this.quoted=t,this}addString(t){return t.type=discord_js_1.ApplicationCommandOptionType.String,this.params.push(t),this}addNumber(t){return t.type=discord_js_1.ApplicationCommandOptionType.Number,this.params.push(t),this}addBoolean(t){return t.type=discord_js_1.ApplicationCommandOptionType.Boolean,this.params.push(t),this}addMember(t){return t.type=discord_js_1.ApplicationCommandOptionType.User,this.params.push(t),this}addChannel(t){return t.type=discord_js_1.ApplicationCommandOptionType.Channel,this.params.push(t),this}addRole(t){return t.type=discord_js_1.ApplicationCommandOptionType.Role,this.params.push(t),this}addAttachment(t){return t.type=discord_js_1.ApplicationCommandOptionType.Attachment,this.params.push(t),this}}exports.ParamsBuilder=ParamsBuilder;
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;
@@ -3,8 +3,20 @@ import { ButtonStyle } from "discord.js";
3
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 Primary if the provided value is not recognized.
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
 
@@ -13,21 +13,46 @@ const STYLE_MAP = {
13
13
  ...(discord_js_1.ButtonStyle.Premium !== undefined ? { premium: discord_js_1.ButtonStyle.Premium } : {}),
14
14
  };
15
15
 
16
- /**
17
- * Maps a button style name (string) or ButtonStyle enum value to a ButtonStyle.
18
- * Defaults to Primary if the provided value is not recognized.
19
- */
20
- function mapButtonStyle(style) {
16
+ let defaultButtonStyle = discord_js_1.ButtonStyle.Secondary;
17
+
18
+ function resolveStyleValue(style, fallback = defaultButtonStyle) {
21
19
  if (style === undefined || style === null) {
22
- return discord_js_1.ButtonStyle.Primary;
20
+ return fallback;
23
21
  }
24
22
  if (typeof style === "number") {
25
23
  return style;
26
24
  }
27
25
  const mapped = STYLE_MAP[String(style).toLowerCase()];
28
26
  if (mapped === undefined) {
29
- return discord_js_1.ButtonStyle.Primary;
27
+ return fallback;
30
28
  }
31
29
  return mapped;
32
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
+ }
33
58
  exports.mapButtonStyle = mapButtonStyle;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gralonium",
3
3
  "description": "i know.",
4
- "version": "0.4.0",
4
+ "version": "0.4.1",
5
5
  "license": "MIT",
6
6
  "author": "carzo",
7
7
  "type": "commonjs",