oopscord.js 0.0.24 → 0.0.26
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/structures/Constants.d.ts +2 -0
- package/dist/structures/Constants.d.ts.map +1 -1
- package/dist/structures/Constants.js +1 -0
- package/dist/structures/DiscordApp.d.ts +79 -2
- package/dist/structures/DiscordApp.d.ts.map +1 -1
- package/dist/structures/DiscordApp.js +215 -56
- package/dist/structures/components/BaseButton.d.ts +35 -1
- package/dist/structures/components/BaseButton.d.ts.map +1 -1
- package/dist/structures/components/BaseButton.js +70 -24
- package/dist/structures/components/BaseModal.d.ts +75 -6
- package/dist/structures/components/BaseModal.d.ts.map +1 -1
- package/dist/structures/components/BaseModal.js +133 -17
- package/dist/structures/components/BaseModal.test.d.ts +2 -0
- package/dist/structures/components/BaseModal.test.d.ts.map +1 -0
- package/dist/structures/components/BaseModal.test.js +109 -0
- package/dist/structures/components/BaseSelectMenu.d.ts +74 -4
- package/dist/structures/components/BaseSelectMenu.d.ts.map +1 -1
- package/dist/structures/components/BaseSelectMenu.js +117 -46
- package/dist/structures/decorators/Constants.d.ts +4 -1
- package/dist/structures/decorators/Constants.d.ts.map +1 -1
- package/dist/structures/decorators/Constants.js +5 -2
- package/dist/structures/decorators/DiscordModuleDecorator.d.ts +27 -0
- package/dist/structures/decorators/DiscordModuleDecorator.d.ts.map +1 -1
- package/dist/structures/decorators/DiscordModuleDecorator.js +27 -0
- package/dist/structures/decorators/MessageComponentDecorator.d.ts +72 -6
- package/dist/structures/decorators/MessageComponentDecorator.d.ts.map +1 -1
- package/dist/structures/decorators/MessageComponentDecorator.js +141 -20
- package/dist/utils/Util.d.ts +3 -0
- package/dist/utils/Util.d.ts.map +1 -1
- package/dist/utils/Util.js +15 -2
- package/package.json +4 -3
|
@@ -3,60 +3,131 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BaseSelectMenu = void 0;
|
|
4
4
|
const discord_js_1 = require("discord.js");
|
|
5
5
|
const __1 = require("..");
|
|
6
|
+
const Util_1 = require("../../utils/Util");
|
|
7
|
+
/**
|
|
8
|
+
* The base class for select menus created with the {@link StringSelectMenu}, {@link UserSelectMenu}, {@link RoleSelectMenu}, {@link ChannelSelectMenu}, and {@link MentionableSelectMenu} decorators. This class is used to create a select menu from the options defined in the class, and to override the default options with new options when creating the select menu.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* The select menu type is determined by the decorator used to create the select menu class, and can be one of the following:
|
|
12
|
+
* - `string` for {@link StringSelectMenu}
|
|
13
|
+
* - `user` for {@link UserSelectMenu}
|
|
14
|
+
* - `role` for {@link RoleSelectMenu}
|
|
15
|
+
* - `channel` for {@link ChannelSelectMenu}
|
|
16
|
+
* - `mentionable` for {@link MentionableSelectMenu}
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { StringSelectMenuInteraction } from "discord.js";
|
|
20
|
+
* import { StringSelectMenu, BaseSelectMenu, Interaction, Run } from "oopscord.js";
|
|
21
|
+
*
|
|
22
|
+
* @StringSelectMenu({
|
|
23
|
+
* customId: "my_select_menu",
|
|
24
|
+
* options: [
|
|
25
|
+
* { label: "Option 1", value: "option_1" },
|
|
26
|
+
* { label: "Option 2", value: "option_2" },
|
|
27
|
+
* { label: "Option 3", value: "option_3" }
|
|
28
|
+
* ]
|
|
29
|
+
* })
|
|
30
|
+
* class MySelectMenu extends BaseSelectMenu {
|
|
31
|
+
* constructor(@Interaction readonly interaction: StringSelectMenuInteraction) {
|
|
32
|
+
* super();
|
|
33
|
+
* }
|
|
34
|
+
*
|
|
35
|
+
* @Run
|
|
36
|
+
* async run() {
|
|
37
|
+
* await this.interaction.reply(`You selected: ${this.interaction.values.join(", ")}`);
|
|
38
|
+
* }
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
6
42
|
class BaseSelectMenu {
|
|
7
|
-
static
|
|
43
|
+
static genericSelectMenu;
|
|
44
|
+
static options;
|
|
45
|
+
/** Returns a new {@link SelectMenuBuilder} that was created from the select menu options. */
|
|
8
46
|
static getSelectMenu() {
|
|
9
|
-
if (this.
|
|
10
|
-
return this.
|
|
11
|
-
let selectMenu;
|
|
47
|
+
if (this.genericSelectMenu)
|
|
48
|
+
return this.genericSelectMenu.copy();
|
|
12
49
|
const type = Reflect.getMetadata(__1.SELECT_MENU_TYPE_KEY, this);
|
|
13
50
|
const options = Reflect.getMetadata(__1.SELECT_MENU_OPTIONS_KEY, this);
|
|
14
51
|
if (!options)
|
|
15
52
|
throw new TypeError("Failed to get the select menu.");
|
|
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
|
-
|
|
53
|
+
this.genericSelectMenu = new GenericSelectMenu(type);
|
|
54
|
+
this.genericSelectMenu.create(options);
|
|
55
|
+
this.options = options;
|
|
56
|
+
return this.genericSelectMenu.copy();
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns a new {@link SelectMenuBuilder} with the specified options merged with the default options defined in the class, and the specified values merged with the default values defined in the class if the options include a `options` property (for StringSelectMenu) or `defaultUsers`/`defaultRoles`/`defaultChannels` property (for UserSelectMenu, RoleSelectMenu, ChannelSelectMenu, and MentionableSelectMenu).
|
|
60
|
+
*
|
|
61
|
+
* @param options The options to merge with the default options.
|
|
62
|
+
* @param values The component values to merge with the default components. The `customId` property is used to match the values with the correct components, and the `type` property is used to determine which type of component the value is for.
|
|
63
|
+
*/
|
|
64
|
+
static override(options = {}, ...values) {
|
|
65
|
+
if (!this.genericSelectMenu) {
|
|
66
|
+
this.getSelectMenu();
|
|
67
|
+
}
|
|
68
|
+
const currentOptions = (this.options ?? Reflect.getMetadata(__1.SELECT_MENU_OPTIONS_KEY, this));
|
|
69
|
+
if (!currentOptions)
|
|
70
|
+
throw new TypeError("Failed to get the select menu options.");
|
|
71
|
+
if (values.length > 0 && !this.genericSelectMenu.isStringSelect())
|
|
72
|
+
throw new TypeError("Values can only be overridden for StringSelectMenu.");
|
|
73
|
+
const newOptions = values.length > 0 ? Util_1.Util.mergeDefault(currentOptions, { ...options, options: values }) : Util_1.Util.mergeDefault(currentOptions, options);
|
|
74
|
+
return this.genericSelectMenu.create(newOptions);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.BaseSelectMenu = BaseSelectMenu;
|
|
78
|
+
const SelectMenuBuilders = {
|
|
79
|
+
string: discord_js_1.StringSelectMenuBuilder,
|
|
80
|
+
user: discord_js_1.UserSelectMenuBuilder,
|
|
81
|
+
role: discord_js_1.RoleSelectMenuBuilder,
|
|
82
|
+
channel: discord_js_1.ChannelSelectMenuBuilder,
|
|
83
|
+
mentionable: discord_js_1.MentionableSelectMenuBuilder,
|
|
84
|
+
};
|
|
85
|
+
class GenericSelectMenu {
|
|
86
|
+
kind;
|
|
87
|
+
selectMenu = null;
|
|
88
|
+
constructor(kind) {
|
|
89
|
+
this.kind = kind;
|
|
90
|
+
}
|
|
91
|
+
isStringSelect() { return this.kind === "string"; }
|
|
92
|
+
isUserSelect() { return this.kind === "user"; }
|
|
93
|
+
isRoleSelect() { return this.kind === "role"; }
|
|
94
|
+
isChannelSelect() { return this.kind === "channel"; }
|
|
95
|
+
isMentionableSelect() { return this.kind === "mentionable"; }
|
|
96
|
+
create(options) {
|
|
97
|
+
const Builder = SelectMenuBuilders[this.kind];
|
|
98
|
+
const menu = new Builder();
|
|
99
|
+
if (this.isStringSelect() && "options" in options) {
|
|
100
|
+
menu.addOptions(options.options);
|
|
41
101
|
}
|
|
42
|
-
|
|
43
|
-
.
|
|
44
|
-
|
|
102
|
+
else if (this.isUserSelect() && "defaultUsers" in options) {
|
|
103
|
+
menu.setDefaultUsers(options.defaultUsers ?? []);
|
|
104
|
+
}
|
|
105
|
+
else if (this.isRoleSelect() && "defaultRoles" in options) {
|
|
106
|
+
menu.setDefaultRoles(options.defaultRoles ?? []);
|
|
107
|
+
}
|
|
108
|
+
else if (this.isChannelSelect() && "channelTypes" in options) {
|
|
109
|
+
menu.setChannelTypes(options.channelTypes ?? [])
|
|
110
|
+
.setDefaultChannels(options.defaultChannels ?? []);
|
|
111
|
+
}
|
|
112
|
+
else if (this.isMentionableSelect() && "defaultUsers" in options && "defaultRoles" in options) {
|
|
113
|
+
menu.addDefaultUsers(options.defaultUsers ?? [])
|
|
114
|
+
.addDefaultRoles(options.defaultRoles ?? []);
|
|
115
|
+
}
|
|
116
|
+
menu.setCustomId(options.customId);
|
|
117
|
+
if (options.placeholder)
|
|
118
|
+
menu.setPlaceholder(options.placeholder);
|
|
45
119
|
if (options.disabled)
|
|
46
|
-
|
|
47
|
-
if (typeof options.minValues
|
|
48
|
-
|
|
49
|
-
if (typeof options.maxValues
|
|
50
|
-
|
|
51
|
-
this.
|
|
52
|
-
return
|
|
120
|
+
menu.setDisabled(options.disabled);
|
|
121
|
+
if (typeof options.minValues === 'number')
|
|
122
|
+
menu.setMinValues(options.minValues);
|
|
123
|
+
if (typeof options.maxValues === 'number')
|
|
124
|
+
menu.setMaxValues(options.maxValues);
|
|
125
|
+
this.selectMenu = menu;
|
|
126
|
+
return Builder.from(menu.toJSON());
|
|
53
127
|
}
|
|
54
|
-
|
|
55
|
-
if (this.
|
|
56
|
-
throw new TypeError("
|
|
57
|
-
|
|
58
|
-
selectMenu.setOptions(values);
|
|
59
|
-
return selectMenu;
|
|
128
|
+
copy() {
|
|
129
|
+
if (!this.selectMenu)
|
|
130
|
+
throw new TypeError("Select menu has not been created yet.");
|
|
131
|
+
return this.selectMenu.constructor.from(this.selectMenu.toJSON());
|
|
60
132
|
}
|
|
61
133
|
}
|
|
62
|
-
exports.BaseSelectMenu = BaseSelectMenu;
|
|
@@ -20,9 +20,12 @@ export declare const MESSAGE_COMPONENT_MODULE_COMPONENTS_KEY: unique symbol;
|
|
|
20
20
|
export declare const BUTTON_OPTIONS_KEY: unique symbol;
|
|
21
21
|
export declare const SELECT_MENU_TYPE_KEY: unique symbol;
|
|
22
22
|
export declare const SELECT_MENU_OPTIONS_KEY: unique symbol;
|
|
23
|
+
export declare const SELECT_MENU_VALUES_INDEX_KEY: unique symbol;
|
|
23
24
|
export declare const MODAL_OPTIONS_KEY: unique symbol;
|
|
24
25
|
export declare const MODAL_COMPONENTS_KEY: unique symbol;
|
|
25
|
-
export declare const
|
|
26
|
+
export declare const MODAL_TEXT_INPUT_VALUE_INDEX_KEY: unique symbol;
|
|
27
|
+
export declare const MODAL_SELECT_MENU_VALUE_INDEX_KEY: unique symbol;
|
|
28
|
+
export declare const MODAL_FILE_UPLOAD_VALUE_INDEX_KEY: unique symbol;
|
|
26
29
|
export declare enum ModuleType {
|
|
27
30
|
COMMAND = 0,
|
|
28
31
|
MESSAGE_COMPONENT = 1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Constants.d.ts","sourceRoot":"","sources":["../../../src/structures/decorators/Constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,eAAiB,CAAC;AAE9C,eAAO,MAAM,2BAA2B,eAAqB,CAAC;AAE9D,eAAO,MAAM,iCAAiC,eAA8B,CAAC;AAE7E,eAAO,MAAM,0BAA0B,eAAuB,CAAC;AAC/D,eAAO,MAAM,+BAA+B,eAAwC,CAAC;AACrF,eAAO,MAAM,oBAAoB,eAAiB,CAAC;AAEnD,eAAO,MAAM,gBAAgB,eAAiB,CAAC;AAC/C,eAAO,MAAM,uBAAuB,eAAwB,CAAC;AAC7D,eAAO,MAAM,mBAAmB,eAAoB,CAAC;AACrD,eAAO,MAAM,yBAAyB,eAA0B,CAAC;AACjE,eAAO,MAAM,mBAAmB,eAAo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C5E,eAAO,MAAM,kCAAkC,eAA4B,CAAC;AAE5E,eAAO,MAAM,uCAAuC,eAAuB,CAAC;AAE5E,eAAO,MAAM,kBAAkB,eAAoB,CAAC;AAEpD,eAAO,MAAM,oBAAoB,eAAiB,CAAC;AACnD,eAAO,MAAM,uBAAuB,eAAoB,CAAC;AACzD,eAAO,MAAM,4BAA4B,eAAyB,CAAC;AAEnE,eAAO,MAAM,iBAAiB,eAAoB,CAAC;AACnD,eAAO,MAAM,oBAAoB,eAAuB,CAAC;AACzD,eAAO,MAAM,gCAAgC,eAAwB,CAAC;AACtE,eAAO,MAAM,iCAAiC,eAAwB,CAAC;AACvE,eAAO,MAAM,iCAAiC,eAAwB,CAAC;AAEvE,oBAAY,UAAU;IAClB,OAAO,IAAA;IACP,iBAAiB,IAAA;CACpB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ModuleType = exports.
|
|
3
|
+
exports.ModuleType = exports.MODAL_FILE_UPLOAD_VALUE_INDEX_KEY = exports.MODAL_SELECT_MENU_VALUE_INDEX_KEY = exports.MODAL_TEXT_INPUT_VALUE_INDEX_KEY = exports.MODAL_COMPONENTS_KEY = exports.MODAL_OPTIONS_KEY = exports.SELECT_MENU_VALUES_INDEX_KEY = exports.SELECT_MENU_OPTIONS_KEY = exports.SELECT_MENU_TYPE_KEY = exports.BUTTON_OPTIONS_KEY = exports.MESSAGE_COMPONENT_MODULE_COMPONENTS_KEY = exports.DISCORD_MODULE_EXTERNAL_EVENTS_KEY = exports.DISCORD_MODULE_INTERNAL_EVENTS_KEY = exports.DICSORD_MODULE_OPTIONS_KEY = exports.OPTIONS_PARAMETER_INDEX_KEY = exports.CONTEXT_MENU_TYPE_KEY = exports.COMMAND_SUBCOMMANDS_KEY = exports.COMMAND_SUBCOMMAND_GROUPS_KEY = exports.COMMAND_OPTIONS_KEY = exports.COMMAND_PRIVATE_GUILD_KEY = exports.COMMAND_PRIVATE_KEY = exports.COMMAND_DESCRIPTION_KEY = exports.COMMAND_NAME_KEY = exports.INTERACTION_TYPE_KEY = exports.INTERACTION_PARAMETER_INDEX_KEY = exports.INTERACTION_RUN_METHOD_KEY = exports.INTERACTION_INTEGRATION_TYPES_KEY = exports.COMMAND_MODULE_COMMANDS_KEY = exports.MODULE_TYPE_KEY = void 0;
|
|
4
4
|
exports.MODULE_TYPE_KEY = Symbol("type");
|
|
5
5
|
exports.COMMAND_MODULE_COMMANDS_KEY = Symbol("commands");
|
|
6
6
|
exports.INTERACTION_INTEGRATION_TYPES_KEY = Symbol("integration_types");
|
|
@@ -23,9 +23,12 @@ exports.MESSAGE_COMPONENT_MODULE_COMPONENTS_KEY = Symbol("components");
|
|
|
23
23
|
exports.BUTTON_OPTIONS_KEY = Symbol("options");
|
|
24
24
|
exports.SELECT_MENU_TYPE_KEY = Symbol("type");
|
|
25
25
|
exports.SELECT_MENU_OPTIONS_KEY = Symbol("options");
|
|
26
|
+
exports.SELECT_MENU_VALUES_INDEX_KEY = Symbol("values_index");
|
|
26
27
|
exports.MODAL_OPTIONS_KEY = Symbol("options");
|
|
27
28
|
exports.MODAL_COMPONENTS_KEY = Symbol("components");
|
|
28
|
-
exports.
|
|
29
|
+
exports.MODAL_TEXT_INPUT_VALUE_INDEX_KEY = Symbol("field_index");
|
|
30
|
+
exports.MODAL_SELECT_MENU_VALUE_INDEX_KEY = Symbol("field_index");
|
|
31
|
+
exports.MODAL_FILE_UPLOAD_VALUE_INDEX_KEY = Symbol("field_index");
|
|
29
32
|
var ModuleType;
|
|
30
33
|
(function (ModuleType) {
|
|
31
34
|
ModuleType[ModuleType["COMMAND"] = 0] = "COMMAND";
|
|
@@ -8,11 +8,38 @@ export interface ModuleOptions extends ClientOptions {
|
|
|
8
8
|
};
|
|
9
9
|
disableCache?: boolean;
|
|
10
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Default configuration options for Discord modules.
|
|
13
|
+
*/
|
|
11
14
|
export declare const defaultModuleOptions: ModuleOptions;
|
|
12
15
|
export interface DiscordModuleEvents {
|
|
13
16
|
eventName: keyof ClientEvents;
|
|
14
17
|
methodName: string;
|
|
15
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Decorator that marks a class as a Discord module.
|
|
21
|
+
*
|
|
22
|
+
* @param option1 - The configuration options for the module
|
|
23
|
+
* @returns A decorator function that applies module metadata to the target class
|
|
24
|
+
*
|
|
25
|
+
* @throws {TypeError} If any of the imported modules are not valid Discord modules
|
|
26
|
+
*/
|
|
16
27
|
export declare function DiscordModule(option1: ModuleOptions): <TFunction extends Function>(constructor: TFunction) => void;
|
|
28
|
+
/**
|
|
29
|
+
* Decorator that registers a method as an event handler for a Discord client event.
|
|
30
|
+
*
|
|
31
|
+
* @param eventName - The name of the Discord client event to listen for
|
|
32
|
+
* @returns A method decorator that registers the decorated method as an event handler
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* class MyModule {
|
|
37
|
+
* @EventHandler('messageCreate')
|
|
38
|
+
* onMessageCreate(message: Message) {
|
|
39
|
+
* // Handle message creation
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
17
44
|
export declare function EventHandler(eventName: keyof ClientEvents): MethodDecorator;
|
|
18
45
|
//# sourceMappingURL=DiscordModuleDecorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiscordModuleDecorator.d.ts","sourceRoot":"","sources":["../../../src/structures/decorators/DiscordModuleDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGzD,MAAM,WAAW,aAAc,SAAQ,aAAa;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC;IACzC,IAAI,CAAC,EAAE;QACH,MAAM,EAAE,OAAO,CAAC;QAChB,KAAK,EAAE,IAAI,GAAG,MAAM,CAAA;KACvB,CAAC;IACF,YAAY,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,eAAO,MAAM,oBAAoB,EAAE,aASlC,CAAA;AAED,MAAM,WAAW,mBAAmB;IAChC,SAAS,EAAE,MAAM,YAAY,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;CACtB;AAQD,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,IAChC,SAAS,SAAS,QAAQ,EAAE,aAAa,SAAS,UASrE;
|
|
1
|
+
{"version":3,"file":"DiscordModuleDecorator.d.ts","sourceRoot":"","sources":["../../../src/structures/decorators/DiscordModuleDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAGzD,MAAM,WAAW,aAAc,SAAQ,aAAa;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC;IACzC,IAAI,CAAC,EAAE;QACH,MAAM,EAAE,OAAO,CAAC;QAChB,KAAK,EAAE,IAAI,GAAG,MAAM,CAAA;KACvB,CAAC;IACF,YAAY,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,eAAO,MAAM,oBAAoB,EAAE,aASlC,CAAA;AAED,MAAM,WAAW,mBAAmB;IAChC,SAAS,EAAE,MAAM,YAAY,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;CACtB;AAQD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,IAChC,SAAS,SAAS,QAAQ,EAAE,aAAa,SAAS,UASrE;AAGD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,YAAY,GAAG,eAAe,CAQ3E"}
|
|
@@ -4,6 +4,9 @@ exports.defaultModuleOptions = void 0;
|
|
|
4
4
|
exports.DiscordModule = DiscordModule;
|
|
5
5
|
exports.EventHandler = EventHandler;
|
|
6
6
|
const Constants_1 = require("./Constants");
|
|
7
|
+
/**
|
|
8
|
+
* Default configuration options for Discord modules.
|
|
9
|
+
*/
|
|
7
10
|
exports.defaultModuleOptions = {
|
|
8
11
|
token: "",
|
|
9
12
|
imports: [],
|
|
@@ -19,6 +22,14 @@ exports.defaultModuleOptions = {
|
|
|
19
22
|
// methodName: string;
|
|
20
23
|
// eventEmitter: EventEmitter;
|
|
21
24
|
// }
|
|
25
|
+
/**
|
|
26
|
+
* Decorator that marks a class as a Discord module.
|
|
27
|
+
*
|
|
28
|
+
* @param option1 - The configuration options for the module
|
|
29
|
+
* @returns A decorator function that applies module metadata to the target class
|
|
30
|
+
*
|
|
31
|
+
* @throws {TypeError} If any of the imported modules are not valid Discord modules
|
|
32
|
+
*/
|
|
22
33
|
function DiscordModule(option1) {
|
|
23
34
|
return function (constructor) {
|
|
24
35
|
const options = mergeDefault(exports.defaultModuleOptions, option1);
|
|
@@ -29,6 +40,22 @@ function DiscordModule(option1) {
|
|
|
29
40
|
Reflect.defineMetadata(Constants_1.DICSORD_MODULE_OPTIONS_KEY, options, constructor);
|
|
30
41
|
};
|
|
31
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Decorator that registers a method as an event handler for a Discord client event.
|
|
45
|
+
*
|
|
46
|
+
* @param eventName - The name of the Discord client event to listen for
|
|
47
|
+
* @returns A method decorator that registers the decorated method as an event handler
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* class MyModule {
|
|
52
|
+
* @EventHandler('messageCreate')
|
|
53
|
+
* onMessageCreate(message: Message) {
|
|
54
|
+
* // Handle message creation
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
32
59
|
function EventHandler(eventName) {
|
|
33
60
|
return function (target, propertyKey, propertyDescriptor) {
|
|
34
61
|
const events = Reflect.getMetadata(Constants_1.DISCORD_MODULE_INTERNAL_EVENTS_KEY, target.constructor) ?? [];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ComponentEmojiResolvable } from "discord.js";
|
|
2
|
-
import { ButtonStyle, TextInputStyle } from "discord-api-types/v10";
|
|
1
|
+
import { ComponentEmojiResolvable, LabelBuilder, TextDisplayBuilder } from "discord.js";
|
|
2
|
+
import { ButtonStyle, ChannelType, TextInputStyle } from "discord-api-types/v10";
|
|
3
|
+
type DistributiveOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never;
|
|
3
4
|
export type ButtonOptions = InteractionButtonOptions | LinkButtonOptions | PremiumButtonOptions;
|
|
4
5
|
export type MessageComponentModuleOptions = {
|
|
5
6
|
components: (new (...args: any[]) => any)[];
|
|
@@ -25,7 +26,7 @@ export type PremiumButtonOptions = {
|
|
|
25
26
|
};
|
|
26
27
|
export type BaseSelectMenuOptions = {
|
|
27
28
|
customId: string;
|
|
28
|
-
placeholder
|
|
29
|
+
placeholder?: string;
|
|
29
30
|
disabled?: boolean;
|
|
30
31
|
minValues?: number;
|
|
31
32
|
maxValues?: number;
|
|
@@ -43,6 +44,7 @@ export type UserSelectMenuOptions = BaseSelectMenuOptions & {
|
|
|
43
44
|
};
|
|
44
45
|
export type ChannelSelectMenuOptions = BaseSelectMenuOptions & {
|
|
45
46
|
defaultChannels?: string[];
|
|
47
|
+
channelTypes?: ChannelType[];
|
|
46
48
|
};
|
|
47
49
|
export type RoleSelectMenuOptions = BaseSelectMenuOptions & {
|
|
48
50
|
defaultRoles?: string[];
|
|
@@ -51,13 +53,25 @@ export type MentionableSelectMenuOptions = BaseSelectMenuOptions & {
|
|
|
51
53
|
defaultUsers?: string[];
|
|
52
54
|
defaultRoles?: string[];
|
|
53
55
|
};
|
|
56
|
+
export type ModalLabelComponentData = {
|
|
57
|
+
customId: string;
|
|
58
|
+
component: LabelBuilder;
|
|
59
|
+
outerType: "label";
|
|
60
|
+
innerType: "string_select" | "user_select" | "channel_select" | "role_select" | "mentionable_select" | "text_input" | "file_upload";
|
|
61
|
+
};
|
|
62
|
+
export type ModalTextDisplayComponentData = {
|
|
63
|
+
customId: string;
|
|
64
|
+
component: TextDisplayBuilder;
|
|
65
|
+
outerType: "text_display";
|
|
66
|
+
};
|
|
67
|
+
export type ModalComponentData = ModalLabelComponentData | ModalTextDisplayComponentData;
|
|
54
68
|
export type ModalOptions = {
|
|
55
69
|
customId: string;
|
|
56
70
|
title: string;
|
|
57
71
|
};
|
|
58
|
-
export type
|
|
72
|
+
export type ModalTextInput = {
|
|
73
|
+
type: "text_input";
|
|
59
74
|
customId: string;
|
|
60
|
-
label: string;
|
|
61
75
|
style: TextInputStyle;
|
|
62
76
|
placeholder?: string;
|
|
63
77
|
value?: string;
|
|
@@ -65,10 +79,58 @@ export type TextInputOptions = {
|
|
|
65
79
|
minLength?: number;
|
|
66
80
|
maxLength?: number;
|
|
67
81
|
};
|
|
82
|
+
export type ModalStringSelect = StringSelectMenuOptions & {
|
|
83
|
+
type: "string_select";
|
|
84
|
+
};
|
|
85
|
+
export type ModalUserSelect = UserSelectMenuOptions & {
|
|
86
|
+
type: "user_select";
|
|
87
|
+
};
|
|
88
|
+
export type ModalChannelSelect = ChannelSelectMenuOptions & {
|
|
89
|
+
type: "channel_select";
|
|
90
|
+
};
|
|
91
|
+
export type ModalRoleSelect = RoleSelectMenuOptions & {
|
|
92
|
+
type: "role_select";
|
|
93
|
+
};
|
|
94
|
+
export type ModalMentionableSelect = MentionableSelectMenuOptions & {
|
|
95
|
+
type: "mentionable_select";
|
|
96
|
+
};
|
|
97
|
+
export type ModalFileUploadOptions = {
|
|
98
|
+
type: "file_upload";
|
|
99
|
+
customId: string;
|
|
100
|
+
minValues?: number;
|
|
101
|
+
maxValues?: number;
|
|
102
|
+
required?: boolean;
|
|
103
|
+
};
|
|
104
|
+
export type ModalTextDisplayOptions = {
|
|
105
|
+
customId: string;
|
|
106
|
+
content: string;
|
|
107
|
+
};
|
|
108
|
+
export type ModalLabelOptions = {
|
|
109
|
+
customId: string;
|
|
110
|
+
label: string;
|
|
111
|
+
description?: string;
|
|
112
|
+
component: ModalLabelComponent;
|
|
113
|
+
};
|
|
114
|
+
export type ModalComponentBuilder = LabelBuilder | TextDisplayBuilder;
|
|
115
|
+
type ModalComponentBase = ModalTextInput | ModalFileUploadOptions | ModalStringSelect | ModalUserSelect | ModalChannelSelect | ModalRoleSelect | ModalMentionableSelect;
|
|
116
|
+
export type ModalLabelComponent = DistributiveOmit<ModalComponentBase & {
|
|
117
|
+
required?: boolean;
|
|
118
|
+
disabled?: never;
|
|
119
|
+
}, "disabled">;
|
|
68
120
|
export type FieldIndex = {
|
|
69
121
|
index: number;
|
|
70
122
|
customId: string;
|
|
71
123
|
};
|
|
124
|
+
export type TextInputFieldIndex = FieldIndex & {
|
|
125
|
+
type: "text_input";
|
|
126
|
+
};
|
|
127
|
+
export type SelectMenuFieldIndex = FieldIndex & {
|
|
128
|
+
type: "select_menu";
|
|
129
|
+
};
|
|
130
|
+
export type FileUploadFieldIndex = FieldIndex & {
|
|
131
|
+
type: "file_upload";
|
|
132
|
+
};
|
|
133
|
+
export type ModalFieldIndex = TextInputFieldIndex | SelectMenuFieldIndex | FileUploadFieldIndex;
|
|
72
134
|
export declare function MessageComponentModule(options: MessageComponentModuleOptions): <T extends Function>(constructor: T) => void;
|
|
73
135
|
export declare function Button(options: InteractionButtonOptions | LinkButtonOptions): <T extends Function>(constructor: T) => void;
|
|
74
136
|
export declare function StringSelectMenu(options: StringSelectMenuOptions): <T extends Function>(constructor: T) => void;
|
|
@@ -77,6 +139,10 @@ export declare function ChannelSelectMenu(options: ChannelSelectMenuOptions): <T
|
|
|
77
139
|
export declare function RoleSelectMenu(options: RoleSelectMenuOptions): <T extends Function>(constructor: T) => void;
|
|
78
140
|
export declare function MentionableSelectMenu(options: MentionableSelectMenuOptions): <T extends Function>(constructor: T) => void;
|
|
79
141
|
export declare function Modal(options: ModalOptions): <T extends Function>(constructor: T) => void;
|
|
80
|
-
export declare function
|
|
142
|
+
export declare function ModalLabel(options: ModalLabelOptions): <T extends Function>(constructor: T) => void;
|
|
143
|
+
export declare function ModalTextDisplay(options: ModalTextDisplayOptions): <T extends Function>(constructor: T) => void;
|
|
81
144
|
export declare function TextInputFieldInjection(customId: string): (target: Object, _propertyKey: string | symbol | undefined, parameterIndex: number) => void;
|
|
145
|
+
export declare function SelectMenuFieldInjection(customId: string): (target: Object, _propertyKey: string | symbol | undefined, parameterIndex: number) => void;
|
|
146
|
+
export declare function FileUploadFieldInjection(customId: string): (target: Object, _propertyKey: string | symbol | undefined, parameterIndex: number) => void;
|
|
147
|
+
export {};
|
|
82
148
|
//# sourceMappingURL=MessageComponentDecorator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageComponentDecorator.d.ts","sourceRoot":"","sources":["../../../src/structures/decorators/MessageComponentDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"MessageComponentDecorator.d.ts","sourceRoot":"","sources":["../../../src/structures/decorators/MessageComponentDecorator.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,wBAAwB,EAAqB,YAAY,EAAgF,kBAAkB,EAA2C,MAAM,YAAY,CAAC;AAC5P,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAIjF,KAAK,gBAAgB,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,CAAC,SAAS,OAAO,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,CAAC;AAErF,MAAM,MAAM,aAAa,GAAG,wBAAwB,GAAG,iBAAiB,GAAG,oBAAoB,CAAC;AAChG,MAAM,MAAM,6BAA6B,GAAG;IAAE,UAAU,EAAE,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,G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,SAAS,QAAQ,EAAE,aAAa,CAAC,UAKrD;AAED,wBAAgB,KAAK,CAAC,OAAO,EAAE,YAAY,IACvB,CAAC,SAAS,QAAQ,EAAE,aAAa,CAAC,UAIrD;AAED,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,IACjC,CAAC,SAAS,QAAQ,EAAE,aAAa,CAAC,UA2GrD;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,IAC7C,CAAC,SAAS,QAAQ,EAAE,aAAa,CAAC,UAUrD;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,IACnC,QAAQ,MAAM,EAAE,cAAc,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,gBAAgB,MAAM,UAOrG;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,IACpC,QAAQ,MAAM,EAAE,cAAc,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,gBAAgB,MAAM,UAOrG;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,IACpC,QAAQ,MAAM,EAAE,cAAc,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,gBAAgB,MAAM,UAOrG"}
|
|
@@ -8,8 +8,11 @@ exports.ChannelSelectMenu = ChannelSelectMenu;
|
|
|
8
8
|
exports.RoleSelectMenu = RoleSelectMenu;
|
|
9
9
|
exports.MentionableSelectMenu = MentionableSelectMenu;
|
|
10
10
|
exports.Modal = Modal;
|
|
11
|
-
exports.
|
|
11
|
+
exports.ModalLabel = ModalLabel;
|
|
12
|
+
exports.ModalTextDisplay = ModalTextDisplay;
|
|
12
13
|
exports.TextInputFieldInjection = TextInputFieldInjection;
|
|
14
|
+
exports.SelectMenuFieldInjection = SelectMenuFieldInjection;
|
|
15
|
+
exports.FileUploadFieldInjection = FileUploadFieldInjection;
|
|
13
16
|
const discord_js_1 = require("discord.js");
|
|
14
17
|
const _1 = require(".");
|
|
15
18
|
const Constants_1 = require("../Constants");
|
|
@@ -66,31 +69,149 @@ function Modal(options) {
|
|
|
66
69
|
Reflect.defineMetadata(_1.MODAL_OPTIONS_KEY, options, constructor);
|
|
67
70
|
};
|
|
68
71
|
}
|
|
69
|
-
function
|
|
72
|
+
function ModalLabel(options) {
|
|
70
73
|
return function (constructor) {
|
|
71
74
|
const components = Reflect.getMetadata(_1.MODAL_COMPONENTS_KEY, constructor) ?? [];
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
75
|
+
const label = new discord_js_1.LabelBuilder();
|
|
76
|
+
label.setLabel(options.label);
|
|
77
|
+
if (options.description)
|
|
78
|
+
label.setDescription(options.description);
|
|
79
|
+
const component = options.component;
|
|
80
|
+
switch (component.type) {
|
|
81
|
+
case "text_input":
|
|
82
|
+
const textInput = new discord_js_1.TextInputBuilder()
|
|
83
|
+
.setCustomId(component.customId)
|
|
84
|
+
.setStyle(component.style);
|
|
85
|
+
if ("placeholder" in component)
|
|
86
|
+
textInput.setPlaceholder(component.placeholder);
|
|
87
|
+
if ("value" in component)
|
|
88
|
+
textInput.setValue(component.value);
|
|
89
|
+
if ("minLength" in component)
|
|
90
|
+
textInput.setMinLength(component.minLength);
|
|
91
|
+
if ("maxLength" in component)
|
|
92
|
+
textInput.setMaxLength(component.maxLength);
|
|
93
|
+
if ("required" in component)
|
|
94
|
+
textInput.setRequired(component.required);
|
|
95
|
+
label.setTextInputComponent(textInput);
|
|
96
|
+
break;
|
|
97
|
+
case "string_select":
|
|
98
|
+
const selectMenu = new discord_js_1.StringSelectMenuBuilder()
|
|
99
|
+
.setCustomId(component.customId)
|
|
100
|
+
.addOptions(component.options);
|
|
101
|
+
if (component.placeholder)
|
|
102
|
+
selectMenu.setPlaceholder(component.placeholder);
|
|
103
|
+
if (typeof component.minValues == "number")
|
|
104
|
+
selectMenu.setMinValues(component.minValues);
|
|
105
|
+
if (typeof component.maxValues == "number")
|
|
106
|
+
selectMenu.setMaxValues(component.maxValues);
|
|
107
|
+
if ("required" in component)
|
|
108
|
+
selectMenu.setRequired(component.required);
|
|
109
|
+
label.setStringSelectMenuComponent(selectMenu);
|
|
110
|
+
break;
|
|
111
|
+
case "user_select":
|
|
112
|
+
const userSelectMenu = new discord_js_1.UserSelectMenuBuilder()
|
|
113
|
+
.setCustomId(component.customId);
|
|
114
|
+
if (component.placeholder)
|
|
115
|
+
userSelectMenu.setPlaceholder(component.placeholder);
|
|
116
|
+
if (typeof component.minValues == "number")
|
|
117
|
+
userSelectMenu.setMinValues(component.minValues);
|
|
118
|
+
if (typeof component.maxValues == "number")
|
|
119
|
+
userSelectMenu.setMaxValues(component.maxValues);
|
|
120
|
+
if (component && component.defaultUsers)
|
|
121
|
+
userSelectMenu.setDefaultUsers(component.defaultUsers);
|
|
122
|
+
if ("required" in component)
|
|
123
|
+
userSelectMenu.setRequired(component.required);
|
|
124
|
+
label.setUserSelectMenuComponent(userSelectMenu);
|
|
125
|
+
break;
|
|
126
|
+
case "channel_select":
|
|
127
|
+
const channelSelectMenu = new discord_js_1.ChannelSelectMenuBuilder()
|
|
128
|
+
.setCustomId(component.customId);
|
|
129
|
+
if (component.placeholder)
|
|
130
|
+
channelSelectMenu.setPlaceholder(component.placeholder);
|
|
131
|
+
if (typeof component.minValues == "number")
|
|
132
|
+
channelSelectMenu.setMinValues(component.minValues);
|
|
133
|
+
if (typeof component.maxValues == "number")
|
|
134
|
+
channelSelectMenu.setMaxValues(component.maxValues);
|
|
135
|
+
if (component && component.defaultChannels)
|
|
136
|
+
channelSelectMenu.setDefaultChannels(component.defaultChannels);
|
|
137
|
+
if (component.channelTypes)
|
|
138
|
+
channelSelectMenu.setChannelTypes(component.channelTypes);
|
|
139
|
+
if ("required" in component)
|
|
140
|
+
channelSelectMenu.setRequired(component.required);
|
|
141
|
+
label.setChannelSelectMenuComponent(channelSelectMenu);
|
|
142
|
+
break;
|
|
143
|
+
case "role_select":
|
|
144
|
+
const roleSelectMenu = new discord_js_1.RoleSelectMenuBuilder()
|
|
145
|
+
.setCustomId(component.customId);
|
|
146
|
+
if (component.placeholder)
|
|
147
|
+
roleSelectMenu.setPlaceholder(component.placeholder);
|
|
148
|
+
if (typeof component.minValues == "number")
|
|
149
|
+
roleSelectMenu.setMinValues(component.minValues);
|
|
150
|
+
if (typeof component.maxValues == "number")
|
|
151
|
+
roleSelectMenu.setMaxValues(component.maxValues);
|
|
152
|
+
if (component && component.defaultRoles)
|
|
153
|
+
roleSelectMenu.setDefaultRoles(component.defaultRoles);
|
|
154
|
+
if ("required" in component)
|
|
155
|
+
roleSelectMenu.setRequired(component.required);
|
|
156
|
+
label.setRoleSelectMenuComponent(roleSelectMenu);
|
|
157
|
+
break;
|
|
158
|
+
case "mentionable_select":
|
|
159
|
+
const mentionableSelectMenu = new discord_js_1.MentionableSelectMenuBuilder()
|
|
160
|
+
.setCustomId(component.customId);
|
|
161
|
+
if (component.placeholder)
|
|
162
|
+
mentionableSelectMenu.setPlaceholder(component.placeholder);
|
|
163
|
+
if (typeof component.minValues == "number")
|
|
164
|
+
mentionableSelectMenu.setMinValues(component.minValues);
|
|
165
|
+
if (typeof component.maxValues == "number")
|
|
166
|
+
mentionableSelectMenu.setMaxValues(component.maxValues);
|
|
167
|
+
if (component && component.defaultUsers)
|
|
168
|
+
mentionableSelectMenu.addDefaultUsers(component.defaultUsers);
|
|
169
|
+
if (component && component.defaultRoles)
|
|
170
|
+
mentionableSelectMenu.addDefaultRoles(component.defaultRoles);
|
|
171
|
+
if ("required" in component)
|
|
172
|
+
mentionableSelectMenu.setRequired(component.required);
|
|
173
|
+
label.setMentionableSelectMenuComponent(mentionableSelectMenu);
|
|
174
|
+
break;
|
|
175
|
+
case "file_upload":
|
|
176
|
+
const fileUpload = new discord_js_1.FileUploadBuilder()
|
|
177
|
+
.setCustomId(component.customId)
|
|
178
|
+
.setMinValues(component.minValues ?? 1)
|
|
179
|
+
.setMaxValues(component.maxValues ?? 1);
|
|
180
|
+
if ("required" in component)
|
|
181
|
+
fileUpload.setRequired(component.required);
|
|
182
|
+
label.setFileUploadComponent(fileUpload);
|
|
183
|
+
}
|
|
184
|
+
components.push({ customId: component.customId, component: label, outerType: "label", innerType: component.type });
|
|
185
|
+
Reflect.defineMetadata(_1.MODAL_COMPONENTS_KEY, components, constructor);
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function ModalTextDisplay(options) {
|
|
189
|
+
return function (constructor) {
|
|
190
|
+
const components = Reflect.getMetadata(_1.MODAL_COMPONENTS_KEY, constructor) ?? [];
|
|
191
|
+
const textDisplay = new discord_js_1.TextDisplayBuilder()
|
|
192
|
+
.setContent(options.content);
|
|
193
|
+
components.push({ customId: options.customId, component: textDisplay, outerType: "text_display" });
|
|
87
194
|
Reflect.defineMetadata(_1.MODAL_COMPONENTS_KEY, components, constructor);
|
|
88
195
|
};
|
|
89
196
|
}
|
|
90
197
|
function TextInputFieldInjection(customId) {
|
|
91
198
|
return function (target, _propertyKey, parameterIndex) {
|
|
92
|
-
const fields = Reflect.getMetadata(_1.
|
|
93
|
-
fields.push({ index: parameterIndex, customId });
|
|
94
|
-
Reflect.defineMetadata(_1.
|
|
199
|
+
const fields = Reflect.getMetadata(_1.MODAL_TEXT_INPUT_VALUE_INDEX_KEY, target) ?? [];
|
|
200
|
+
fields.push({ index: parameterIndex, customId, type: "text_input" });
|
|
201
|
+
Reflect.defineMetadata(_1.MODAL_TEXT_INPUT_VALUE_INDEX_KEY, fields, target);
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function SelectMenuFieldInjection(customId) {
|
|
205
|
+
return function (target, _propertyKey, parameterIndex) {
|
|
206
|
+
const fields = Reflect.getMetadata(_1.MODAL_SELECT_MENU_VALUE_INDEX_KEY, target) ?? [];
|
|
207
|
+
fields.push({ index: parameterIndex, customId, type: "select_menu" });
|
|
208
|
+
Reflect.defineMetadata(_1.MODAL_SELECT_MENU_VALUE_INDEX_KEY, fields, target);
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
function FileUploadFieldInjection(customId) {
|
|
212
|
+
return function (target, _propertyKey, parameterIndex) {
|
|
213
|
+
const fields = Reflect.getMetadata(_1.MODAL_FILE_UPLOAD_VALUE_INDEX_KEY, target) ?? [];
|
|
214
|
+
fields.push({ index: parameterIndex, customId, type: "file_upload" });
|
|
215
|
+
Reflect.defineMetadata(_1.MODAL_FILE_UPLOAD_VALUE_INDEX_KEY, fields, target);
|
|
95
216
|
};
|
|
96
217
|
}
|