seyfert 4.4.1 → 5.0.0
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/README.md +7 -1
- package/lib/api/Routes/cdn.d.ts +2 -2
- package/lib/api/Routes/guilds.d.ts +2 -2
- package/lib/api/Routes/invites.d.ts +2 -2
- package/lib/api/api.d.ts +20 -8
- package/lib/api/api.js +198 -44
- package/lib/api/shared.d.ts +30 -1
- package/lib/api/utils/constants.d.ts +1 -1
- package/lib/api/utils/constants.js +1 -1
- package/lib/api/utils/utils.d.ts +2 -1
- package/lib/api/utils/utils.js +1 -1
- package/lib/builders/Attachment.d.ts +1 -1
- package/lib/builders/Attachment.js +30 -8
- package/lib/builders/MediaGallery.d.ts +2 -2
- package/lib/builders/MediaGallery.js +10 -0
- package/lib/builders/Modal.d.ts +18 -8
- package/lib/builders/Modal.js +36 -7
- package/lib/builders/Poll.js +18 -0
- package/lib/builders/RadioGroup.d.ts +4 -3
- package/lib/builders/RadioGroup.js +24 -3
- package/lib/builders/SelectMenu.d.ts +8 -6
- package/lib/builders/SelectMenu.js +24 -3
- package/lib/builders/types.d.ts +3 -2
- package/lib/cache/adapters/default.d.ts +1 -1
- package/lib/cache/adapters/default.js +23 -26
- package/lib/cache/adapters/limited.d.ts +1 -0
- package/lib/cache/adapters/limited.js +47 -33
- package/lib/cache/index.d.ts +19 -25
- package/lib/cache/index.js +58 -6
- package/lib/cache/resources/bans.d.ts +1 -1
- package/lib/cache/resources/bans.js +4 -4
- package/lib/cache/resources/channels.d.ts +1 -1
- package/lib/cache/resources/channels.js +4 -4
- package/lib/cache/resources/default/base.d.ts +1 -1
- package/lib/cache/resources/default/base.js +8 -8
- package/lib/cache/resources/default/guild-based.d.ts +5 -5
- package/lib/cache/resources/default/guild-based.js +29 -16
- package/lib/cache/resources/default/guild-related.d.ts +5 -5
- package/lib/cache/resources/default/guild-related.js +14 -14
- package/lib/cache/resources/emojis.d.ts +1 -1
- package/lib/cache/resources/emojis.js +4 -4
- package/lib/cache/resources/guilds.js +28 -15
- package/lib/cache/resources/members.d.ts +1 -1
- package/lib/cache/resources/members.js +6 -6
- package/lib/cache/resources/messages.d.ts +7 -2
- package/lib/cache/resources/messages.js +43 -20
- package/lib/cache/resources/overwrites.d.ts +1 -1
- package/lib/cache/resources/overwrites.js +5 -8
- package/lib/cache/resources/roles.d.ts +1 -1
- package/lib/cache/resources/roles.js +4 -4
- package/lib/cache/resources/stickers.d.ts +1 -1
- package/lib/cache/resources/stickers.js +4 -4
- package/lib/cache/resources/users.js +4 -4
- package/lib/cache/resources/voice-states.d.ts +1 -1
- package/lib/cache/resources/voice-states.js +4 -4
- package/lib/client/base.d.ts +83 -24
- package/lib/client/base.js +594 -39
- package/lib/client/client.d.ts +29 -4
- package/lib/client/client.js +38 -13
- package/lib/client/collectors.d.ts +9 -8
- package/lib/client/collectors.js +19 -52
- package/lib/client/httpclient.d.ts +3 -0
- package/lib/client/index.d.ts +3 -1
- package/lib/client/index.js +4 -0
- package/lib/client/intents.d.ts +3 -0
- package/lib/client/intents.js +9 -0
- package/lib/client/plugins/api.d.ts +4 -0
- package/lib/client/plugins/api.js +550 -0
- package/lib/client/plugins/errors.d.ts +25 -0
- package/lib/client/plugins/errors.js +79 -0
- package/lib/client/plugins/order.d.ts +10 -0
- package/lib/client/plugins/order.js +32 -0
- package/lib/client/plugins/registry.d.ts +273 -0
- package/lib/client/plugins/registry.js +868 -0
- package/lib/client/plugins/shared.d.ts +23 -0
- package/lib/client/plugins/shared.js +193 -0
- package/lib/client/plugins/types.d.ts +398 -0
- package/lib/client/plugins/types.js +8 -0
- package/lib/client/plugins.d.ts +78 -0
- package/lib/client/plugins.js +558 -0
- package/lib/client/transformers.d.ts +33 -33
- package/lib/client/workerclient.d.ts +11 -2
- package/lib/client/workerclient.js +33 -22
- package/lib/collection.d.ts +10 -8
- package/lib/collection.js +19 -25
- package/lib/commands/applications/chat.d.ts +20 -18
- package/lib/commands/applications/chat.js +39 -14
- package/lib/commands/applications/chatcontext.d.ts +23 -15
- package/lib/commands/applications/chatcontext.js +23 -2
- package/lib/commands/applications/entryPoint.d.ts +4 -3
- package/lib/commands/applications/entryPoint.js +1 -1
- package/lib/commands/applications/entrycontext.d.ts +7 -9
- package/lib/commands/applications/entrycontext.js +3 -1
- package/lib/commands/applications/menu.d.ts +4 -3
- package/lib/commands/applications/menucontext.d.ts +7 -9
- package/lib/commands/applications/menucontext.js +3 -1
- package/lib/commands/applications/options.d.ts +23 -23
- package/lib/commands/applications/shared.d.ts +39 -17
- package/lib/commands/decorators.d.ts +50 -38
- package/lib/commands/decorators.js +15 -5
- package/lib/commands/handle.d.ts +19 -8
- package/lib/commands/handle.js +224 -143
- package/lib/commands/handler.d.ts +21 -8
- package/lib/commands/handler.js +157 -69
- package/lib/commands/index.d.ts +1 -0
- package/lib/commands/optionresolver.d.ts +2 -2
- package/lib/common/it/colors.js +12 -2
- package/lib/common/it/error.d.ts +9 -0
- package/lib/common/it/error.js +8 -0
- package/lib/common/it/fake-promise.d.ts +4 -0
- package/lib/common/it/fake-promise.js +10 -0
- package/lib/common/it/formatter.d.ts +14 -11
- package/lib/common/it/formatter.js +4 -3
- package/lib/common/it/logger.d.ts +7 -1
- package/lib/common/it/logger.js +24 -6
- package/lib/common/it/utils.d.ts +6 -8
- package/lib/common/it/utils.js +44 -42
- package/lib/common/shorters/application.d.ts +3 -3
- package/lib/common/shorters/application.js +3 -2
- package/lib/common/shorters/bans.d.ts +8 -4
- package/lib/common/shorters/bans.js +13 -5
- package/lib/common/shorters/channels.d.ts +4 -4
- package/lib/common/shorters/channels.js +4 -4
- package/lib/common/shorters/emojis.js +1 -0
- package/lib/common/shorters/guilds.d.ts +8 -8
- package/lib/common/shorters/guilds.js +14 -31
- package/lib/common/shorters/interaction.d.ts +1 -1
- package/lib/common/shorters/invites.d.ts +201 -201
- package/lib/common/shorters/members.d.ts +7 -7
- package/lib/common/shorters/members.js +13 -14
- package/lib/common/shorters/messages.d.ts +2 -2
- package/lib/common/shorters/soundboard.d.ts +5 -5
- package/lib/common/shorters/users.d.ts +1 -1
- package/lib/common/shorters/webhook.d.ts +3 -2
- package/lib/common/shorters/webhook.js +0 -7
- package/lib/common/types/options.d.ts +4 -0
- package/lib/common/types/util.d.ts +8 -0
- package/lib/common/types/write.d.ts +2 -1
- package/lib/components/BaseSelectMenuComponent.d.ts +1 -1
- package/lib/components/BaseSelectMenuComponent.js +1 -1
- package/lib/components/ButtonComponent.d.ts +3 -3
- package/lib/components/ChannelSelectMenuComponent.d.ts +2 -2
- package/lib/components/File.d.ts +1 -1
- package/lib/components/MediaGallery.d.ts +1 -1
- package/lib/components/MentionableSelectMenuComponent.d.ts +1 -1
- package/lib/components/RoleSelectMenuComponent.d.ts +1 -1
- package/lib/components/Separator.d.ts +1 -1
- package/lib/components/StringSelectMenuComponent.d.ts +1 -1
- package/lib/components/TextInputComponent.d.ts +1 -1
- package/lib/components/Thumbnail.d.ts +1 -1
- package/lib/components/UserSelectMenuComponent.d.ts +1 -1
- package/lib/components/componentcommand.d.ts +8 -7
- package/lib/components/componentcontext.d.ts +24 -36
- package/lib/components/componentcontext.js +7 -17
- package/lib/components/handler.d.ts +17 -7
- package/lib/components/handler.js +108 -49
- package/lib/components/index.d.ts +1 -0
- package/lib/components/index.js +1 -0
- package/lib/components/interactioncontext.d.ts +45 -0
- package/lib/components/interactioncontext.js +93 -0
- package/lib/components/modalcommand.d.ts +5 -4
- package/lib/components/modalcontext.d.ts +39 -20
- package/lib/components/modalcontext.js +59 -6
- package/lib/events/event.d.ts +9 -3
- package/lib/events/handler.d.ts +51 -6
- package/lib/events/handler.js +165 -36
- package/lib/events/hooks/application_command.d.ts +1 -1
- package/lib/events/hooks/auto_moderation.d.ts +2 -2
- package/lib/events/hooks/guild.d.ts +150 -150
- package/lib/events/hooks/interactions.d.ts +1 -1
- package/lib/events/hooks/invite.d.ts +20 -20
- package/lib/events/hooks/message.d.ts +27 -27
- package/lib/events/hooks/presence.d.ts +11 -11
- package/lib/events/hooks/soundboard.d.ts +6 -6
- package/lib/events/hooks/stage.d.ts +2 -2
- package/lib/events/hooks/subscriptions.d.ts +3 -3
- package/lib/events/hooks/thread.d.ts +30 -30
- package/lib/events/hooks/voice.d.ts +3 -4
- package/lib/events/hooks/voice.js +2 -1
- package/lib/events/utils.d.ts +4 -0
- package/lib/events/utils.js +59 -0
- package/lib/index.d.ts +9 -4
- package/lib/index.js +14 -8
- package/lib/langs/handler.d.ts +14 -11
- package/lib/langs/handler.js +46 -9
- package/lib/langs/router.d.ts +10 -3
- package/lib/structures/Application.d.ts +1 -1
- package/lib/structures/Emoji.d.ts +3 -3
- package/lib/structures/Emoji.js +2 -2
- package/lib/structures/Guild.d.ts +154 -154
- package/lib/structures/GuildBan.d.ts +4 -4
- package/lib/structures/GuildBan.js +3 -3
- package/lib/structures/GuildMember.d.ts +7 -7
- package/lib/structures/GuildMember.js +28 -7
- package/lib/structures/GuildRole.d.ts +1 -1
- package/lib/structures/GuildRole.js +2 -2
- package/lib/structures/Interaction.d.ts +11 -9
- package/lib/structures/Interaction.js +33 -12
- package/lib/structures/Message.d.ts +21 -14
- package/lib/structures/Message.js +29 -14
- package/lib/structures/User.d.ts +1 -1
- package/lib/structures/VoiceState.d.ts +4 -0
- package/lib/structures/VoiceState.js +13 -1
- package/lib/structures/Webhook.d.ts +9 -1
- package/lib/structures/Webhook.js +4 -1
- package/lib/structures/channels.d.ts +148 -134
- package/lib/structures/channels.js +27 -26
- package/lib/structures/extra/BitField.d.ts +4 -4
- package/lib/structures/extra/BitField.js +20 -4
- package/lib/structures/extra/DiscordBase.js +1 -1
- package/lib/structures/extra/Permissions.d.ts +2 -4
- package/lib/structures/extra/Permissions.js +1 -17
- package/lib/types/payloads/_interactions/responses.d.ts +2 -2
- package/lib/types/payloads/components.d.ts +4 -4
- package/lib/websocket/SharedTypes.d.ts +4 -4
- package/lib/websocket/constants/index.d.ts +1 -1
- package/lib/websocket/constants/index.js +3 -2
- package/lib/websocket/discord/events/memberUpdate.js +2 -2
- package/lib/websocket/discord/heartbeater.d.ts +1 -0
- package/lib/websocket/discord/heartbeater.js +7 -0
- package/lib/websocket/discord/shard.d.ts +2 -2
- package/lib/websocket/discord/shard.js +16 -14
- package/lib/websocket/discord/sharder.d.ts +8 -7
- package/lib/websocket/discord/sharder.js +26 -6
- package/lib/websocket/discord/shared.d.ts +19 -6
- package/lib/websocket/discord/socket/custom.js +5 -0
- package/lib/websocket/discord/worker.d.ts +1 -0
- package/lib/websocket/discord/worker.js +2 -0
- package/lib/websocket/discord/workermanager.d.ts +25 -11
- package/lib/websocket/discord/workermanager.js +41 -10
- package/package.json +13 -17
package/lib/commands/handle.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HandleCommand = void 0;
|
|
4
|
+
const plugins_1 = require("../client/plugins");
|
|
4
5
|
const transformers_1 = require("../client/transformers");
|
|
5
6
|
const constants_1 = require("../common/it/constants");
|
|
6
7
|
const components_1 = require("../components");
|
|
@@ -13,6 +14,9 @@ class HandleCommand {
|
|
|
13
14
|
this.client = client;
|
|
14
15
|
}
|
|
15
16
|
async autocomplete(interaction, optionsResolver, command) {
|
|
17
|
+
return (0, plugins_1.runPluginAutocompleteWrappers)(this.client, { client: this.client, command, interaction, optionsResolver }, () => this.runAutocomplete(interaction, optionsResolver, command));
|
|
18
|
+
}
|
|
19
|
+
async runAutocomplete(interaction, optionsResolver, command) {
|
|
16
20
|
// idc, is a YOU problem
|
|
17
21
|
if (!command?.autocomplete) {
|
|
18
22
|
return this.client.logger.warn(`${optionsResolver.fullCommandName} ${command?.name} command does not have 'autocomplete' callback`);
|
|
@@ -37,36 +41,43 @@ class HandleCommand {
|
|
|
37
41
|
}
|
|
38
42
|
}
|
|
39
43
|
async contextMenu(command, interaction, context) {
|
|
40
|
-
|
|
41
|
-
if (context.guildId && command.botPermissions) {
|
|
42
|
-
const permissions = this.checkPermissions(interaction.appPermissions, command.botPermissions);
|
|
43
|
-
if (permissions)
|
|
44
|
-
return await command.onBotPermissionsFail?.(context, permissions);
|
|
45
|
-
}
|
|
46
|
-
await command.onBeforeMiddlewares?.(context);
|
|
47
|
-
const resultGlobal = await this.runGlobalMiddlewares(command, context);
|
|
48
|
-
if (typeof resultGlobal === 'boolean')
|
|
49
|
-
return;
|
|
50
|
-
const resultMiddle = await this.runMiddlewares(command, context);
|
|
51
|
-
if (typeof resultMiddle === 'boolean')
|
|
52
|
-
return;
|
|
44
|
+
return (0, plugins_1.runContextScopes)(this.client.options.contextScopes, context, async () => {
|
|
53
45
|
try {
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
if (context.guildId && command.botPermissions) {
|
|
47
|
+
const permissions = this.checkPermissions(interaction.appPermissions, command.botPermissions);
|
|
48
|
+
if (permissions)
|
|
49
|
+
return await command.onBotPermissionsFail?.(context, permissions);
|
|
50
|
+
}
|
|
51
|
+
await command.onBeforeMiddlewares?.(context);
|
|
52
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onBeforeMiddlewares', context);
|
|
53
|
+
const resultGlobal = await this.runGlobalMiddlewares(command, context);
|
|
54
|
+
if (typeof resultGlobal === 'boolean')
|
|
55
|
+
return;
|
|
56
|
+
const resultMiddle = await this.runMiddlewares(command, context);
|
|
57
|
+
if (typeof resultMiddle === 'boolean')
|
|
58
|
+
return;
|
|
59
|
+
try {
|
|
60
|
+
await command.run(context);
|
|
61
|
+
await command.onAfterRun?.(context, undefined);
|
|
62
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onAfterRun', context, undefined);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
await command.onRunError?.(context, error);
|
|
66
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onRunError', context, error);
|
|
67
|
+
await command.onAfterRun?.(context, error);
|
|
68
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onAfterRun', context, error);
|
|
69
|
+
}
|
|
56
70
|
}
|
|
57
71
|
catch (error) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
catch (err) {
|
|
67
|
-
this.client.logger.error(`[${command.name}] Internal error:`, err);
|
|
72
|
+
try {
|
|
73
|
+
await command.onInternalError?.(this.client, command, error);
|
|
74
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onInternalError', this.client, command, error);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
this.client.logger.error(`[${command.name}] Internal error:`, err);
|
|
78
|
+
}
|
|
68
79
|
}
|
|
69
|
-
}
|
|
80
|
+
});
|
|
70
81
|
}
|
|
71
82
|
contextMenuMessage(command, interaction, context) {
|
|
72
83
|
return this.contextMenu(command, interaction, context);
|
|
@@ -75,78 +86,93 @@ class HandleCommand {
|
|
|
75
86
|
return this.contextMenu(command, interaction, context);
|
|
76
87
|
}
|
|
77
88
|
async entryPoint(command, interaction, context) {
|
|
78
|
-
|
|
79
|
-
if (context.guildId && command.botPermissions) {
|
|
80
|
-
const permissions = this.checkPermissions(interaction.appPermissions, command.botPermissions);
|
|
81
|
-
if (permissions)
|
|
82
|
-
return await command.onBotPermissionsFail(context, permissions);
|
|
83
|
-
}
|
|
84
|
-
await command.onBeforeMiddlewares?.(context);
|
|
85
|
-
const resultGlobal = await this.runGlobalMiddlewares(command, context);
|
|
86
|
-
if (typeof resultGlobal === 'boolean')
|
|
87
|
-
return;
|
|
88
|
-
const resultMiddle = await this.runMiddlewares(command, context);
|
|
89
|
-
if (typeof resultMiddle === 'boolean')
|
|
90
|
-
return;
|
|
91
|
-
try {
|
|
92
|
-
await command.run(context);
|
|
93
|
-
await command.onAfterRun?.(context, undefined);
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
await command.onRunError(context, error);
|
|
97
|
-
await command.onAfterRun?.(context, error);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
catch (error) {
|
|
89
|
+
return (0, plugins_1.runContextScopes)(this.client.options.contextScopes, context, async () => {
|
|
101
90
|
try {
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
catch (err) {
|
|
105
|
-
this.client.logger.error(`[${command.name}] Internal error:`, err);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
async chatInput(command, interaction, resolver, context) {
|
|
110
|
-
try {
|
|
111
|
-
if (context.guildId) {
|
|
112
|
-
if (command.botPermissions) {
|
|
91
|
+
if (context.guildId && command.botPermissions) {
|
|
113
92
|
const permissions = this.checkPermissions(interaction.appPermissions, command.botPermissions);
|
|
114
93
|
if (permissions)
|
|
115
|
-
return await command.onBotPermissionsFail
|
|
94
|
+
return await command.onBotPermissionsFail(context, permissions);
|
|
116
95
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
96
|
+
await command.onBeforeMiddlewares?.(context);
|
|
97
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onBeforeMiddlewares', context);
|
|
98
|
+
const resultGlobal = await this.runGlobalMiddlewares(command, context);
|
|
99
|
+
if (typeof resultGlobal === 'boolean')
|
|
100
|
+
return;
|
|
101
|
+
const resultMiddle = await this.runMiddlewares(command, context);
|
|
102
|
+
if (typeof resultMiddle === 'boolean')
|
|
103
|
+
return;
|
|
104
|
+
try {
|
|
105
|
+
await command.run(context);
|
|
106
|
+
await command.onAfterRun?.(context, undefined);
|
|
107
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onAfterRun', context, undefined);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
await command.onRunError(context, error);
|
|
111
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onRunError', context, error);
|
|
112
|
+
await command.onAfterRun?.(context, error);
|
|
113
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onAfterRun', context, error);
|
|
121
114
|
}
|
|
122
|
-
}
|
|
123
|
-
await command.onBeforeOptions?.(context);
|
|
124
|
-
if (!(await this.runOptions(command, context, resolver)))
|
|
125
|
-
return;
|
|
126
|
-
await command.onBeforeMiddlewares?.(context);
|
|
127
|
-
const resultGlobal = await this.runGlobalMiddlewares(command, context);
|
|
128
|
-
if (typeof resultGlobal === 'boolean')
|
|
129
|
-
return;
|
|
130
|
-
const resultMiddle = await this.runMiddlewares(command, context);
|
|
131
|
-
if (typeof resultMiddle === 'boolean')
|
|
132
|
-
return;
|
|
133
|
-
try {
|
|
134
|
-
await command.run(context);
|
|
135
|
-
await command.onAfterRun?.(context, undefined);
|
|
136
115
|
}
|
|
137
116
|
catch (error) {
|
|
138
|
-
|
|
139
|
-
|
|
117
|
+
try {
|
|
118
|
+
await command.onInternalError(this.client, command, error);
|
|
119
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onInternalError', this.client, command, error);
|
|
120
|
+
}
|
|
121
|
+
catch (err) {
|
|
122
|
+
this.client.logger.error(`[${command.name}] Internal error:`, err);
|
|
123
|
+
}
|
|
140
124
|
}
|
|
141
|
-
}
|
|
142
|
-
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
async chatInput(command, interaction, resolver, context) {
|
|
128
|
+
return (0, plugins_1.runContextScopes)(this.client.options.contextScopes, context, async () => {
|
|
143
129
|
try {
|
|
144
|
-
|
|
130
|
+
if (context.guildId) {
|
|
131
|
+
if (command.botPermissions) {
|
|
132
|
+
const permissions = this.checkPermissions(interaction.appPermissions, command.botPermissions);
|
|
133
|
+
if (permissions)
|
|
134
|
+
return await command.onBotPermissionsFail?.(context, permissions);
|
|
135
|
+
}
|
|
136
|
+
if (command.defaultMemberPermissions) {
|
|
137
|
+
const permissions = this.checkPermissions(interaction.member.permissions, command.defaultMemberPermissions);
|
|
138
|
+
if (permissions)
|
|
139
|
+
return await command.onPermissionsFail?.(context, permissions);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
await command.onBeforeOptions?.(context);
|
|
143
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onBeforeOptions', context);
|
|
144
|
+
if (!(await this.runOptions(command, context, resolver)))
|
|
145
|
+
return;
|
|
146
|
+
await command.onBeforeMiddlewares?.(context);
|
|
147
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onBeforeMiddlewares', context);
|
|
148
|
+
const resultGlobal = await this.runGlobalMiddlewares(command, context);
|
|
149
|
+
if (typeof resultGlobal === 'boolean')
|
|
150
|
+
return;
|
|
151
|
+
const resultMiddle = await this.runMiddlewares(command, context);
|
|
152
|
+
if (typeof resultMiddle === 'boolean')
|
|
153
|
+
return;
|
|
154
|
+
try {
|
|
155
|
+
await command.run(context);
|
|
156
|
+
await command.onAfterRun?.(context, undefined);
|
|
157
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onAfterRun', context, undefined);
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
await command.onRunError?.(context, error);
|
|
161
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onRunError', context, error);
|
|
162
|
+
await command.onAfterRun?.(context, error);
|
|
163
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onAfterRun', context, error);
|
|
164
|
+
}
|
|
145
165
|
}
|
|
146
|
-
catch (
|
|
147
|
-
|
|
166
|
+
catch (error) {
|
|
167
|
+
try {
|
|
168
|
+
await command.onInternalError?.(this.client, command, error);
|
|
169
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onInternalError', this.client, command, error);
|
|
170
|
+
}
|
|
171
|
+
catch (err) {
|
|
172
|
+
this.client.logger.error(`[${command.name}] Internal error:`, err);
|
|
173
|
+
}
|
|
148
174
|
}
|
|
149
|
-
}
|
|
175
|
+
});
|
|
150
176
|
}
|
|
151
177
|
async modal(interaction) {
|
|
152
178
|
const context = new components_1.ModalContext(this.client, interaction);
|
|
@@ -268,62 +294,81 @@ class HandleCommand {
|
|
|
268
294
|
try {
|
|
269
295
|
const args = this.argsParser(argsContent, command, message);
|
|
270
296
|
const { options, errors } = await this.argsOptionsParser(command, rawMessage, args, resolved);
|
|
271
|
-
const
|
|
297
|
+
const resolverOptions = command instanceof _1.SubCommand
|
|
298
|
+
? [
|
|
299
|
+
command.group
|
|
300
|
+
? {
|
|
301
|
+
type: types_1.ApplicationCommandOptionType.SubcommandGroup,
|
|
302
|
+
name: command.group,
|
|
303
|
+
options: [{ type: types_1.ApplicationCommandOptionType.Subcommand, name: command.name, options }],
|
|
304
|
+
}
|
|
305
|
+
: { type: types_1.ApplicationCommandOptionType.Subcommand, name: command.name, options },
|
|
306
|
+
]
|
|
307
|
+
: options;
|
|
308
|
+
const optionsResolver = this.makeResolver(self, resolverOptions, parent, rawMessage.guild_id, resolved);
|
|
272
309
|
const context = new _1.CommandContext(self, message, optionsResolver, shardId, command);
|
|
273
310
|
//@ts-expect-error
|
|
274
311
|
const extendContext = self.options?.context?.(message) ?? {};
|
|
275
312
|
Object.assign(context, extendContext);
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
return
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (rawMessage.guild_id) {
|
|
289
|
-
if (command.defaultMemberPermissions) {
|
|
290
|
-
const memberPermissions = await self.members.permissions(rawMessage.guild_id, rawMessage.author.id);
|
|
291
|
-
const permissions = this.checkPermissions(memberPermissions, command.defaultMemberPermissions);
|
|
292
|
-
const guild = await this.client.guilds.raw(rawMessage.guild_id);
|
|
293
|
-
if (permissions && guild.owner_id !== rawMessage.author.id) {
|
|
294
|
-
return await command.onPermissionsFail?.(context, memberPermissions.keys(permissions));
|
|
295
|
-
}
|
|
313
|
+
return await (0, plugins_1.runContextScopes)(self.options.contextScopes, context, async () => {
|
|
314
|
+
if (errors.length) {
|
|
315
|
+
return await command.onOptionsError?.(context, Object.fromEntries(errors.map(x => {
|
|
316
|
+
return [
|
|
317
|
+
x.name,
|
|
318
|
+
{
|
|
319
|
+
failed: true,
|
|
320
|
+
value: x.error,
|
|
321
|
+
parseError: x.fullError,
|
|
322
|
+
},
|
|
323
|
+
];
|
|
324
|
+
})));
|
|
296
325
|
}
|
|
297
|
-
if (
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
326
|
+
if (rawMessage.guild_id) {
|
|
327
|
+
if (command.defaultMemberPermissions) {
|
|
328
|
+
const memberPermissions = await self.members.permissions(rawMessage.guild_id, rawMessage.author.id);
|
|
329
|
+
const permissions = this.checkPermissions(memberPermissions, command.defaultMemberPermissions);
|
|
330
|
+
const guild = await this.client.guilds.raw(rawMessage.guild_id);
|
|
331
|
+
if (permissions && guild.owner_id !== rawMessage.author.id) {
|
|
332
|
+
return await command.onPermissionsFail?.(context, permissions);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
if (command.botPermissions) {
|
|
336
|
+
const appPermissions = await self.members.permissions(rawMessage.guild_id, self.botId);
|
|
337
|
+
const permissions = this.checkPermissions(appPermissions, command.botPermissions);
|
|
338
|
+
if (permissions) {
|
|
339
|
+
return await command.onBotPermissionsFail?.(context, permissions);
|
|
340
|
+
}
|
|
302
341
|
}
|
|
303
342
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
343
|
+
await command.onBeforeOptions?.(context);
|
|
344
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onBeforeOptions', context);
|
|
345
|
+
if (!(await this.runOptions(command, context, optionsResolver)))
|
|
346
|
+
return;
|
|
347
|
+
await command.onBeforeMiddlewares?.(context);
|
|
348
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onBeforeMiddlewares', context);
|
|
349
|
+
const resultGlobal = await this.runGlobalMiddlewares(command, context);
|
|
350
|
+
if (typeof resultGlobal === 'boolean')
|
|
351
|
+
return;
|
|
352
|
+
const resultMiddle = await this.runMiddlewares(command, context);
|
|
353
|
+
if (typeof resultMiddle === 'boolean')
|
|
354
|
+
return;
|
|
355
|
+
try {
|
|
356
|
+
await command.run(context);
|
|
357
|
+
await command.onAfterRun?.(context, undefined);
|
|
358
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onAfterRun', context, undefined);
|
|
359
|
+
}
|
|
360
|
+
catch (error) {
|
|
361
|
+
await command.onRunError?.(context, error);
|
|
362
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onRunError', context, error);
|
|
363
|
+
await command.onAfterRun?.(context, error);
|
|
364
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onAfterRun', context, error);
|
|
365
|
+
}
|
|
366
|
+
});
|
|
323
367
|
}
|
|
324
368
|
catch (error) {
|
|
325
369
|
try {
|
|
326
370
|
await command.onInternalError?.(this.client, command, error);
|
|
371
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onInternalError', this.client, command, error);
|
|
327
372
|
}
|
|
328
373
|
catch (err) {
|
|
329
374
|
this.client.logger.error(`[${command.name}] Internal error:`, err);
|
|
@@ -341,7 +386,7 @@ class HandleCommand {
|
|
|
341
386
|
const result = this.getCommandFromContent(content
|
|
342
387
|
.split(' ')
|
|
343
388
|
.filter(x => x)
|
|
344
|
-
.slice(0, 3));
|
|
389
|
+
.slice(0, 3), _message.guild_id);
|
|
345
390
|
if (!result.command)
|
|
346
391
|
return result;
|
|
347
392
|
let newContent = content;
|
|
@@ -353,19 +398,44 @@ class HandleCommand {
|
|
|
353
398
|
argsContent: newContent.slice(1),
|
|
354
399
|
};
|
|
355
400
|
}
|
|
356
|
-
getCommandFromContent(commandRaw) {
|
|
401
|
+
getCommandFromContent(commandRaw, guildId) {
|
|
402
|
+
return this.resolveCommandFromNameParts(commandRaw, guildId);
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Resolves a message command by its full name.
|
|
406
|
+
*
|
|
407
|
+
* Guild-scoped commands require a matching `guildId`; without one, they intentionally resolve to `undefined`.
|
|
408
|
+
*/
|
|
409
|
+
resolveByName(fullName, guildId) {
|
|
410
|
+
const parts = fullName
|
|
411
|
+
.trim()
|
|
412
|
+
.split(/\s+/)
|
|
413
|
+
.filter(x => x)
|
|
414
|
+
.slice(0, 3);
|
|
415
|
+
if (!parts.length)
|
|
416
|
+
return undefined;
|
|
417
|
+
const resolved = this.resolveCommandFromNameParts(parts, guildId, false);
|
|
418
|
+
return resolved.command ? resolved : undefined;
|
|
419
|
+
}
|
|
420
|
+
resolveCommandFromNameParts(commandRaw, guildId, allowFallback = true) {
|
|
357
421
|
const rawParentName = commandRaw[0];
|
|
358
422
|
const rawGroupName = commandRaw.length === 3 ? commandRaw[1] : undefined;
|
|
359
423
|
const rawSubcommandName = rawGroupName ? commandRaw[2] : commandRaw[1];
|
|
360
|
-
const parent = this.getParentMessageCommand(rawParentName);
|
|
424
|
+
const parent = this.getParentMessageCommand(rawParentName, guildId);
|
|
361
425
|
const fullCommandName = `${rawParentName}${rawGroupName ? ` ${rawGroupName} ${rawSubcommandName}` : `${rawSubcommandName ? ` ${rawSubcommandName}` : ''}`}`;
|
|
362
426
|
if (!(parent instanceof _1.Command))
|
|
363
427
|
return { fullCommandName };
|
|
364
|
-
if (rawGroupName && !parent.groups?.[rawGroupName] && !parent.groupsAliases?.[rawGroupName])
|
|
365
|
-
|
|
428
|
+
if (rawGroupName && !parent.groups?.[rawGroupName] && !parent.groupsAliases?.[rawGroupName]) {
|
|
429
|
+
if (!allowFallback)
|
|
430
|
+
return { fullCommandName };
|
|
431
|
+
return this.resolveCommandFromNameParts([rawParentName, rawGroupName], guildId);
|
|
432
|
+
}
|
|
366
433
|
if (rawSubcommandName &&
|
|
367
|
-
!parent.options?.some(x => x instanceof _1.SubCommand && (x.name === rawSubcommandName || x.aliases?.includes(rawSubcommandName))))
|
|
368
|
-
|
|
434
|
+
!parent.options?.some(x => x instanceof _1.SubCommand && (x.name === rawSubcommandName || x.aliases?.includes(rawSubcommandName)))) {
|
|
435
|
+
if (!allowFallback)
|
|
436
|
+
return { fullCommandName };
|
|
437
|
+
return this.resolveCommandFromNameParts([rawParentName], guildId);
|
|
438
|
+
}
|
|
369
439
|
const groupName = rawGroupName ? parent.groupsAliases?.[rawGroupName] || rawGroupName : undefined;
|
|
370
440
|
const command = groupName || rawSubcommandName
|
|
371
441
|
? parent.options?.find(opt => {
|
|
@@ -390,10 +460,16 @@ class HandleCommand {
|
|
|
390
460
|
makeResolver(...args) {
|
|
391
461
|
return transformers_1.Transformers.OptionResolver(...args);
|
|
392
462
|
}
|
|
393
|
-
getParentMessageCommand(rawParentName) {
|
|
463
|
+
getParentMessageCommand(rawParentName, guildId) {
|
|
394
464
|
return this.client.commands.values.find(x => (!('ignore' in x) || x.ignore !== _1.IgnoreCommand.Message) &&
|
|
465
|
+
this.commandCanRunInGuild(x, guildId) &&
|
|
395
466
|
(x.name === rawParentName || ('aliases' in x ? x.aliases?.includes(rawParentName) : false)));
|
|
396
467
|
}
|
|
468
|
+
commandCanRunInGuild(command, guildId) {
|
|
469
|
+
if (!command.guildId?.length)
|
|
470
|
+
return true;
|
|
471
|
+
return guildId ? command.guildId.includes(guildId) : false;
|
|
472
|
+
}
|
|
397
473
|
getCommand(data) {
|
|
398
474
|
return this.client.commands.values.find(command => {
|
|
399
475
|
if (data.guild_id) {
|
|
@@ -442,7 +518,9 @@ class HandleCommand {
|
|
|
442
518
|
return false;
|
|
443
519
|
}
|
|
444
520
|
if ('error' in resultRunGlobalMiddlewares) {
|
|
445
|
-
|
|
521
|
+
const metadata = resultRunGlobalMiddlewares.metadata ?? { middleware: 'unknown', scope: 'global' };
|
|
522
|
+
await command.onMiddlewaresError?.(context, resultRunGlobalMiddlewares.error ?? 'Unknown error', metadata);
|
|
523
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onMiddlewaresError', context, resultRunGlobalMiddlewares.error ?? 'Unknown error', metadata);
|
|
446
524
|
return false;
|
|
447
525
|
}
|
|
448
526
|
return resultRunGlobalMiddlewares;
|
|
@@ -450,6 +528,7 @@ class HandleCommand {
|
|
|
450
528
|
catch (e) {
|
|
451
529
|
try {
|
|
452
530
|
await command.onInternalError?.(this.client, command, e);
|
|
531
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onInternalError', this.client, command, e);
|
|
453
532
|
}
|
|
454
533
|
catch (err) {
|
|
455
534
|
this.client.logger.error(`[${command.name}] Internal error:`, err);
|
|
@@ -464,7 +543,9 @@ class HandleCommand {
|
|
|
464
543
|
return false;
|
|
465
544
|
}
|
|
466
545
|
if ('error' in resultRunMiddlewares) {
|
|
467
|
-
|
|
546
|
+
const metadata = resultRunMiddlewares.metadata ?? { middleware: 'unknown', scope: 'command' };
|
|
547
|
+
await command.onMiddlewaresError?.(context, resultRunMiddlewares.error ?? 'Unknown error', metadata);
|
|
548
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onMiddlewaresError', context, resultRunMiddlewares.error ?? 'Unknown error', metadata);
|
|
468
549
|
return false;
|
|
469
550
|
}
|
|
470
551
|
return resultRunMiddlewares;
|
|
@@ -472,6 +553,7 @@ class HandleCommand {
|
|
|
472
553
|
catch (e) {
|
|
473
554
|
try {
|
|
474
555
|
await command.onInternalError?.(this.client, command, e);
|
|
556
|
+
await (0, plugins_1.runPluginCommandObservers)(this.client, 'onInternalError', this.client, command, e);
|
|
475
557
|
}
|
|
476
558
|
catch (err) {
|
|
477
559
|
this.client.logger.error(`[${command.name}] Internal error:`, err);
|
|
@@ -709,7 +791,6 @@ class HandleCommand {
|
|
|
709
791
|
});
|
|
710
792
|
break;
|
|
711
793
|
}
|
|
712
|
-
break;
|
|
713
794
|
}
|
|
714
795
|
}
|
|
715
796
|
break;
|
|
@@ -12,17 +12,22 @@ export declare class CommandHandler extends BaseHandler {
|
|
|
12
12
|
entryPoint: EntryPointCommand | null;
|
|
13
13
|
filter: (path: string) => boolean;
|
|
14
14
|
constructor(logger: Logger, client: UsingClient);
|
|
15
|
-
reload(resolve: string | Command): Promise<
|
|
15
|
+
reload(resolve: string | Command): Promise<Command | EntryPointCommand | ContextMenuCommand | null>;
|
|
16
16
|
reloadAll(stopIfFail?: boolean): Promise<void>;
|
|
17
17
|
protected shouldUploadLocales(locales?: LocalizationMap | null, cachedLocales?: LocalizationMap | null): boolean;
|
|
18
|
-
protected
|
|
18
|
+
protected shouldUploadChoices(option: APIApplicationCommandOption, cached: APIApplicationCommandOption): boolean;
|
|
19
19
|
protected shouldUploadOption(option: APIApplicationCommandOption, cached: APIApplicationCommandOption): boolean;
|
|
20
20
|
shouldUpload(file: string, guildId?: string): Promise<boolean>;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
private prepareCommand;
|
|
22
|
+
checkSubCommandsLimit(command: Command): void;
|
|
23
|
+
private normalizeLoadOptions;
|
|
24
|
+
set(commands: SeteableCommand[], optionsOrTransform?: CommandLoadTransformer | CommandLoadOptions): (Command | EntryPointCommand | ContextMenuCommand)[];
|
|
25
|
+
load(commandsDir: string, client: UsingClient, options?: CommandLoadOptions): Promise<(Command | ContextMenuCommand)[]>;
|
|
26
|
+
parseLocales(command: InstanceType<HandleableCommand>): Command | EntryPointCommand | ContextMenuCommand | SubCommand;
|
|
27
|
+
protected getLocales(locale: string): ("id" | "en-US" | "en-GB" | "bg" | "zh-CN" | "zh-TW" | "hr" | "cs" | "da" | "nl" | "fi" | "fr" | "de" | "el" | "hi" | "hu" | "it" | "ja" | "ko" | "lt" | "no" | "pl" | "pt-BR" | "ro" | "ru" | "es-ES" | "es-419" | "sv-SE" | "th" | "tr" | "uk" | "vi")[];
|
|
28
|
+
protected getLocaleKey(locale: string, key: string, context: string): string | undefined;
|
|
24
29
|
parseGlobalLocales(command: InstanceType<HandleableCommand>): void;
|
|
25
|
-
parseCommandOptionLocales(option: CommandOption): void;
|
|
30
|
+
parseCommandOptionLocales(option: CommandOption, commandName?: string): void;
|
|
26
31
|
parseCommandLocales(command: Command): void;
|
|
27
32
|
parseContextMenuLocales(command: ContextMenuCommand): ContextMenuCommand;
|
|
28
33
|
parseSubCommandLocales(command: SubCommand): SubCommand;
|
|
@@ -32,12 +37,20 @@ export declare class CommandHandler extends BaseHandler {
|
|
|
32
37
|
}> | false;
|
|
33
38
|
stablishSubCommandDefaults(commandInstance: Command, option: SubCommand): SubCommand;
|
|
34
39
|
onFile(file: FileLoaded): HandleableCommand[] | undefined;
|
|
35
|
-
onCommand(file:
|
|
40
|
+
onCommand(file: SeteableCommand, create?: CommandLoadCreator): HandleableCommandInstance | false;
|
|
36
41
|
onSubCommand(file: HandleableSubCommand): SubCommand | false;
|
|
37
42
|
}
|
|
38
43
|
export type FileLoaded<T = null> = {
|
|
39
44
|
default?: NulleableCoalising<T, HandleableCommand>;
|
|
40
45
|
} & Record<string, NulleableCoalising<T, HandleableCommand>>;
|
|
41
46
|
export type HandleableCommand = new () => Command | SubCommand | ContextMenuCommand | EntryPointCommand;
|
|
42
|
-
export type
|
|
47
|
+
export type SettableCommand = new () => Exclude<InstanceType<HandleableCommand>, SubCommand>;
|
|
48
|
+
export type HandleableCommandInstance = Command | SubCommand | ContextMenuCommand | EntryPointCommand;
|
|
49
|
+
export type SeteableCommand = HandleableCommand | HandleableCommandInstance;
|
|
43
50
|
export type HandleableSubCommand = new () => SubCommand;
|
|
51
|
+
export type CommandLoadCreator = <T extends HandleableCommand>(constructor: T, next: () => InstanceType<T>) => InstanceType<T>;
|
|
52
|
+
export type CommandLoadTransformer = (command: HandleableCommandInstance) => HandleableCommandInstance | false | void;
|
|
53
|
+
export interface CommandLoadOptions {
|
|
54
|
+
create?: CommandLoadCreator;
|
|
55
|
+
transform?: CommandLoadTransformer;
|
|
56
|
+
}
|