seyfert 0.1.0 → 1.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 +19 -30
- package/lib/api/CDN.d.ts +0 -8
- package/lib/api/CDN.js +7 -13
- package/lib/api/Router.d.ts +2 -2
- package/lib/api/Router.js +1 -1
- package/lib/api/Routes/applications.d.ts +1 -1
- package/lib/api/Routes/channels.d.ts +1 -1
- package/lib/api/Routes/gateway.d.ts +1 -1
- package/lib/api/Routes/guilds.d.ts +1 -1
- package/lib/api/Routes/interactions.d.ts +1 -1
- package/lib/api/Routes/invites.d.ts +1 -1
- package/lib/api/Routes/stage-instances.d.ts +1 -1
- package/lib/api/Routes/stickers.d.ts +1 -1
- package/lib/api/Routes/users.d.ts +1 -1
- package/lib/api/Routes/voice.d.ts +1 -1
- package/lib/api/Routes/webhooks.d.ts +1 -1
- package/lib/api/api.d.ts +39 -0
- package/lib/api/api.js +318 -0
- package/lib/api/bucket.d.ts +19 -0
- package/lib/api/bucket.js +71 -0
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.js +1 -1
- package/lib/api/shared.d.ts +31 -5
- package/lib/api/shared.js +2 -7
- package/lib/api/utils/constants.d.ts +1 -30
- package/lib/api/utils/constants.js +2 -41
- package/lib/api/utils/types.d.ts +1 -320
- package/lib/api/utils/utils.d.ts +0 -38
- package/lib/api/utils/utils.js +1 -139
- package/lib/builders/ActionRow.js +1 -1
- package/lib/builders/Attachment.d.ts +14 -6
- package/lib/builders/Attachment.js +30 -7
- package/lib/builders/Button.d.ts +3 -12
- package/lib/builders/Button.js +0 -11
- package/lib/builders/{MessageEmbed.d.ts → Embed.d.ts} +15 -15
- package/lib/builders/{MessageEmbed.js → Embed.js} +16 -16
- package/lib/builders/Modal.js +1 -1
- package/lib/builders/SelectMenu.d.ts +14 -15
- package/lib/builders/SelectMenu.js +19 -18
- package/lib/builders/index.d.ts +1 -1
- package/lib/builders/index.js +1 -1
- package/lib/builders/types.d.ts +2 -2
- package/lib/cache/adapters/default.js +2 -2
- package/lib/cache/adapters/redis.d.ts +2 -3
- package/lib/cache/adapters/redis.js +13 -5
- package/lib/cache/adapters/workeradapter.d.ts +9 -1
- package/lib/cache/adapters/workeradapter.js +7 -3
- package/lib/cache/index.d.ts +20 -6
- package/lib/cache/index.js +26 -10
- package/lib/cache/resources/channels.d.ts +6 -2
- package/lib/cache/resources/channels.js +12 -6
- package/lib/cache/resources/default/base.d.ts +17 -16
- package/lib/cache/resources/default/base.js +25 -24
- package/lib/cache/resources/default/guild-based.d.ts +22 -19
- package/lib/cache/resources/default/guild-based.js +32 -31
- package/lib/cache/resources/default/guild-related.d.ts +22 -19
- package/lib/cache/resources/default/guild-related.js +37 -43
- package/lib/cache/resources/emojis.d.ts +4 -2
- package/lib/cache/resources/emojis.js +8 -6
- package/lib/cache/resources/guilds.d.ts +4 -2
- package/lib/cache/resources/guilds.js +15 -8
- package/lib/cache/resources/members.d.ts +4 -2
- package/lib/cache/resources/members.js +16 -13
- package/lib/cache/resources/overwrites.d.ts +25 -0
- package/lib/cache/resources/overwrites.js +39 -0
- package/lib/cache/resources/presence.js +3 -4
- package/lib/cache/resources/roles.d.ts +4 -2
- package/lib/cache/resources/roles.js +8 -6
- package/lib/cache/resources/stickers.d.ts +4 -2
- package/lib/cache/resources/stickers.js +8 -6
- package/lib/cache/resources/threads.d.ts +4 -2
- package/lib/cache/resources/threads.js +8 -6
- package/lib/cache/resources/users.d.ts +4 -2
- package/lib/cache/resources/users.js +8 -6
- package/lib/cache/resources/voice-states.d.ts +3 -3
- package/lib/cache/resources/voice-states.js +6 -7
- package/lib/client/base.d.ts +49 -16
- package/lib/client/base.js +21 -17
- package/lib/client/client.d.ts +14 -3
- package/lib/client/client.js +21 -21
- package/lib/client/httpclient.d.ts +3 -5
- package/lib/client/httpclient.js +29 -16
- package/lib/client/{oninteraction.d.ts → oninteractioncreate.d.ts} +1 -1
- package/lib/client/{oninteraction.js → oninteractioncreate.js} +34 -23
- package/lib/client/onmessagecreate.d.ts +3 -0
- package/lib/client/onmessagecreate.js +337 -0
- package/lib/client/workerclient.d.ts +5 -1
- package/lib/client/workerclient.js +67 -44
- package/lib/collection.d.ts +1 -1
- package/lib/collection.js +9 -6
- package/lib/commands/applications/chat.d.ts +32 -25
- package/lib/commands/applications/chat.js +51 -34
- package/lib/commands/applications/chatcontext.d.ts +34 -16
- package/lib/commands/applications/chatcontext.js +99 -20
- package/lib/commands/applications/menu.d.ts +9 -8
- package/lib/commands/applications/menu.js +14 -5
- package/lib/commands/applications/menucontext.d.ts +27 -10
- package/lib/commands/applications/menucontext.js +51 -7
- package/lib/commands/applications/options.d.ts +13 -13
- package/lib/commands/applications/shared.d.ts +7 -2
- package/lib/commands/decorators.d.ts +14 -14
- package/lib/commands/decorators.js +9 -5
- package/lib/commands/handler.d.ts +2 -1
- package/lib/commands/handler.js +60 -14
- package/lib/commands/index.d.ts +1 -1
- package/lib/commands/index.js +2 -1
- package/lib/commands/optionresolver.d.ts +6 -5
- package/lib/commands/optionresolver.js +10 -6
- package/lib/common/bot/watcher.d.ts +3 -3
- package/lib/common/bot/watcher.js +3 -1
- package/lib/common/index.d.ts +1 -1
- package/lib/common/index.js +2 -1
- package/lib/common/it/logger.d.ts +11 -0
- package/lib/common/it/logger.js +51 -2
- package/lib/common/it/utils.d.ts +3 -13
- package/lib/common/it/utils.js +9 -30
- package/lib/common/shorters/channels.d.ts +55 -5
- package/lib/common/shorters/channels.js +59 -0
- package/lib/common/shorters/guilds.d.ts +5 -2
- package/lib/common/shorters/guilds.js +18 -0
- package/lib/common/shorters/messages.js +0 -2
- package/lib/common/shorters/overwrites.d.ts +29 -0
- package/lib/common/shorters/overwrites.js +63 -0
- package/lib/common/shorters/roles.js +3 -3
- package/lib/common/shorters/webhook.d.ts +2 -2
- package/lib/common/types/util.d.ts +2 -1
- package/lib/common/types/write.d.ts +3 -7
- package/lib/components/handler.d.ts +12 -18
- package/lib/components/handler.js +58 -103
- package/lib/components/index.d.ts +0 -1
- package/lib/components/index.js +0 -1
- package/lib/components/listener.d.ts +2 -2
- package/lib/components/listener.js +2 -3
- package/lib/events/event.d.ts +2 -2
- package/lib/events/handler.d.ts +3 -2
- package/lib/events/handler.js +14 -6
- package/lib/events/hooks/dispatch.d.ts +2 -1
- package/lib/events/hooks/dispatch.js +5 -1
- package/lib/events/hooks/thread.d.ts +63 -63
- package/lib/index.d.ts +8 -5
- package/lib/index.js +20 -10
- package/lib/langs/handler.d.ts +6 -4
- package/lib/langs/handler.js +10 -8
- package/lib/langs/router.d.ts +8 -9
- package/lib/langs/router.js +5 -5
- package/lib/structures/ClientUser.d.ts +1 -16
- package/lib/structures/ClientUser.js +0 -31
- package/lib/structures/Guild.d.ts +1 -1
- package/lib/structures/GuildMember.d.ts +12 -0
- package/lib/structures/GuildMember.js +14 -0
- package/lib/structures/GuildRole.d.ts +4 -2
- package/lib/structures/GuildRole.js +4 -1
- package/lib/structures/GuildTemplate.js +1 -1
- package/lib/structures/Interaction.d.ts +2 -0
- package/lib/structures/Interaction.js +12 -13
- package/lib/structures/Message.d.ts +7 -2
- package/lib/structures/Message.js +6 -3
- package/lib/structures/Sticker.d.ts +1 -1
- package/lib/structures/Sticker.js +1 -1
- package/lib/structures/User.d.ts +5 -0
- package/lib/structures/User.js +3 -0
- package/lib/structures/Webhook.d.ts +1 -1
- package/lib/structures/Webhook.js +1 -1
- package/lib/structures/channels.d.ts +45 -6
- package/lib/structures/channels.js +23 -7
- package/lib/structures/extra/BitField.d.ts +9 -6
- package/lib/structures/extra/BitField.js +27 -3
- package/lib/structures/extra/Permissions.d.ts +6 -1
- package/lib/structures/extra/Permissions.js +7 -0
- package/lib/websocket/discord/basesocket.js +0 -1
- package/lib/websocket/discord/workermanager.d.ts +9 -1
- package/lib/websocket/discord/workermanager.js +21 -13
- package/package.json +21 -20
- package/lib/api/REST.d.ts +0 -127
- package/lib/api/REST.js +0 -424
- package/lib/api/errors/DiscordAPIError.d.ts +0 -51
- package/lib/api/errors/DiscordAPIError.js +0 -81
- package/lib/api/errors/HTTPError.d.ts +0 -20
- package/lib/api/errors/HTTPError.js +0 -28
- package/lib/api/errors/RateLimitError.d.ts +0 -19
- package/lib/api/errors/RateLimitError.js +0 -37
- package/lib/api/handlers/BurstHandler.d.ts +0 -51
- package/lib/api/handlers/BurstHandler.js +0 -124
- package/lib/api/handlers/SequentialHandler.d.ts +0 -81
- package/lib/api/handlers/SequentialHandler.js +0 -365
- package/lib/api/handlers/Shared.d.ts +0 -14
- package/lib/api/handlers/Shared.js +0 -125
- package/lib/api/interfaces/Handler.d.ts +0 -21
- package/lib/api/interfaces/Handler.js +0 -2
- package/lib/websocket/discord/handlemessage.d.ts +0 -0
- package/lib/websocket/discord/handlemessage.js +0 -1
- package/lib/websocket/discord/memberUpdate.d.ts +0 -16
- package/lib/websocket/discord/memberUpdate.js +0 -47
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SeyfertNumberOption, SeyfertStringOption } from '../..';
|
|
2
|
+
import type { Attachment } from '../../builders';
|
|
3
|
+
import type { APIApplicationCommandBasicOption, APIApplicationCommandOption, LocaleString, PermissionStrings } from '../../common';
|
|
2
4
|
import { ApplicationCommandOptionType, ApplicationCommandType } from '../../common';
|
|
3
5
|
import type { AllChannels, AutocompleteInteraction, GuildRole, InteractionGuildMember, User } from '../../structures';
|
|
4
6
|
import type { Groups, RegisteredMiddlewares } from '../decorators';
|
|
@@ -15,7 +17,7 @@ export interface ReturnOptionsTypes {
|
|
|
15
17
|
8: GuildRole;
|
|
16
18
|
9: GuildRole | AllChannels | User;
|
|
17
19
|
10: number;
|
|
18
|
-
11:
|
|
20
|
+
11: Attachment;
|
|
19
21
|
}
|
|
20
22
|
type Wrap<N extends ApplicationCommandOptionType> = N extends ApplicationCommandOptionType.Subcommand | ApplicationCommandOptionType.SubcommandGroup ? never : {
|
|
21
23
|
required?: boolean;
|
|
@@ -53,22 +55,22 @@ type KeysWithoutRequired<T extends OptionsRecord> = {
|
|
|
53
55
|
[K in keyof T]-?: T[K]['required'] extends true ? never : K;
|
|
54
56
|
}[keyof T];
|
|
55
57
|
type ContextOptionsAux<T extends OptionsRecord> = {
|
|
56
|
-
[K in Exclude<keyof T, KeysWithoutRequired<T>>]: T[K]['value'] extends (...args: any) => any ?
|
|
58
|
+
[K in Exclude<keyof T, KeysWithoutRequired<T>>]: T[K]['value'] extends (...args: any) => any ? Parameters<Parameters<T[K]['value']>[1]>[0] : T[K] extends SeyfertStringOption | SeyfertNumberOption ? T[K]['choices'] extends NonNullable<SeyfertStringOption['choices'] | SeyfertNumberOption['choices']> ? T[K]['choices'][number]['value'] : ReturnOptionsTypes[T[K]['type']] : ReturnOptionsTypes[T[K]['type']];
|
|
57
59
|
} & {
|
|
58
|
-
[K in KeysWithoutRequired<T>]?: T[K]['value'] extends (...args: any) => any ? T[K]['
|
|
60
|
+
[K in KeysWithoutRequired<T>]?: T[K]['value'] extends (...args: any) => any ? Parameters<Parameters<T[K]['value']>[1]>[0] : T[K] extends SeyfertStringOption | SeyfertNumberOption ? T[K]['choices'] extends NonNullable<SeyfertStringOption['choices'] | SeyfertNumberOption['choices']> ? T[K]['choices'][number]['value'] : ReturnOptionsTypes[T[K]['type']] : ReturnOptionsTypes[T[K]['type']];
|
|
59
61
|
};
|
|
60
62
|
export type ContextOptions<T extends OptionsRecord> = ContextOptionsAux<T>;
|
|
61
63
|
declare class BaseCommand {
|
|
62
64
|
middlewares: (keyof RegisteredMiddlewares)[];
|
|
63
65
|
__filePath?: string;
|
|
64
66
|
__t?: {
|
|
65
|
-
name: string;
|
|
66
|
-
description: string;
|
|
67
|
+
name: string | undefined;
|
|
68
|
+
description: string | undefined;
|
|
67
69
|
};
|
|
68
70
|
__d?: true;
|
|
69
71
|
__tGroups?: Record<string, {
|
|
70
|
-
name: string;
|
|
71
|
-
description: string;
|
|
72
|
+
name: string | undefined;
|
|
73
|
+
description: string | undefined;
|
|
72
74
|
defaultDescription: string;
|
|
73
75
|
}>;
|
|
74
76
|
guild_id?: string[];
|
|
@@ -77,29 +79,30 @@ declare class BaseCommand {
|
|
|
77
79
|
nsfw?: boolean;
|
|
78
80
|
description: string;
|
|
79
81
|
default_member_permissions?: string;
|
|
80
|
-
|
|
82
|
+
botPermissions?: bigint;
|
|
81
83
|
dm?: boolean;
|
|
82
84
|
name_localizations?: Partial<Record<LocaleString, string>>;
|
|
83
85
|
description_localizations?: Partial<Record<LocaleString, string>>;
|
|
84
86
|
options?: CommandOption[] | SubCommand[];
|
|
85
87
|
toJSON(): {
|
|
86
|
-
name:
|
|
87
|
-
type:
|
|
88
|
-
nsfw:
|
|
89
|
-
description:
|
|
90
|
-
name_localizations:
|
|
91
|
-
description_localizations:
|
|
92
|
-
guild_id:
|
|
93
|
-
|
|
94
|
-
|
|
88
|
+
name: BaseCommand['name'];
|
|
89
|
+
type: BaseCommand['type'];
|
|
90
|
+
nsfw: BaseCommand['nsfw'];
|
|
91
|
+
description: BaseCommand['description'];
|
|
92
|
+
name_localizations: BaseCommand['name_localizations'];
|
|
93
|
+
description_localizations: BaseCommand['description_localizations'];
|
|
94
|
+
guild_id: BaseCommand['guild_id'];
|
|
95
|
+
default_member_permissions: BaseCommand['default_member_permissions'];
|
|
96
|
+
dm_permission?: boolean | undefined;
|
|
95
97
|
};
|
|
96
98
|
reload(): Promise<void>;
|
|
97
99
|
run?(context: CommandContext<any>): any;
|
|
98
100
|
onAfterRun?(context: CommandContext<any>, error: unknown | undefined): any;
|
|
99
101
|
onRunError?(context: CommandContext<any>, error: unknown): any;
|
|
100
102
|
onOptionsError?(context: CommandContext<{}, never>, metadata: OnOptionsReturnObject): any;
|
|
101
|
-
onMiddlewaresError?(context: CommandContext<{}, never>, error:
|
|
102
|
-
|
|
103
|
+
onMiddlewaresError?(context: CommandContext<{}, never>, error: string): any;
|
|
104
|
+
onPermissionsFail?(context: CommandContext<{}, never>, permissions: PermissionStrings): any;
|
|
105
|
+
onInternalError?(client: UsingClient, error?: unknown): any;
|
|
103
106
|
}
|
|
104
107
|
export declare class Command extends BaseCommand {
|
|
105
108
|
type: ApplicationCommandType;
|
|
@@ -108,14 +111,19 @@ export declare class Command extends BaseCommand {
|
|
|
108
111
|
options: APIApplicationCommandOption[];
|
|
109
112
|
name: string;
|
|
110
113
|
type: number;
|
|
111
|
-
nsfw: boolean;
|
|
114
|
+
nsfw: boolean | undefined;
|
|
112
115
|
description: string;
|
|
113
116
|
name_localizations: Partial<Record<"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", string>> | undefined;
|
|
114
117
|
description_localizations: Partial<Record<"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", string>> | undefined;
|
|
115
118
|
guild_id: string[] | undefined;
|
|
116
|
-
dm_permission: boolean | undefined;
|
|
117
119
|
default_member_permissions: string | undefined;
|
|
120
|
+
dm_permission?: boolean | undefined;
|
|
118
121
|
};
|
|
122
|
+
onRunError(context: CommandContext<any>, error: unknown): any;
|
|
123
|
+
onOptionsError(context: CommandContext<{}, never>, metadata: OnOptionsReturnObject): any;
|
|
124
|
+
onMiddlewaresError(context: CommandContext<{}, never>, error: string): any;
|
|
125
|
+
onPermissionsFail(context: CommandContext<{}, never>, permissions: PermissionStrings): any;
|
|
126
|
+
onInternalError(client: UsingClient, error?: unknown): any;
|
|
119
127
|
}
|
|
120
128
|
export declare abstract class SubCommand extends BaseCommand {
|
|
121
129
|
type: ApplicationCommandOptionType;
|
|
@@ -125,15 +133,14 @@ export declare abstract class SubCommand extends BaseCommand {
|
|
|
125
133
|
options: APIApplicationCommandBasicOption[];
|
|
126
134
|
name: string;
|
|
127
135
|
type: number;
|
|
128
|
-
nsfw: boolean;
|
|
136
|
+
nsfw: boolean | undefined;
|
|
129
137
|
description: string;
|
|
130
138
|
name_localizations: Partial<Record<"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", string>> | undefined;
|
|
131
139
|
description_localizations: Partial<Record<"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", string>> | undefined;
|
|
132
140
|
guild_id: string[] | undefined;
|
|
133
|
-
dm_permission: boolean | undefined;
|
|
134
141
|
default_member_permissions: string | undefined;
|
|
142
|
+
dm_permission?: boolean | undefined;
|
|
135
143
|
};
|
|
136
144
|
abstract run(context: CommandContext<any>): any;
|
|
137
|
-
onRunError?(context: CommandContext<any>, error: unknown): any;
|
|
138
145
|
}
|
|
139
146
|
export {};
|
|
@@ -14,7 +14,7 @@ class BaseCommand {
|
|
|
14
14
|
nsfw;
|
|
15
15
|
description;
|
|
16
16
|
default_member_permissions;
|
|
17
|
-
|
|
17
|
+
botPermissions;
|
|
18
18
|
dm;
|
|
19
19
|
name_localizations;
|
|
20
20
|
description_localizations;
|
|
@@ -22,46 +22,49 @@ class BaseCommand {
|
|
|
22
22
|
/** @internal */
|
|
23
23
|
async __runOptions(ctx, resolver) {
|
|
24
24
|
const command = resolver.getCommand();
|
|
25
|
-
if (!
|
|
25
|
+
if (!command?.options?.length) {
|
|
26
26
|
return [false, {}];
|
|
27
27
|
}
|
|
28
28
|
const data = {};
|
|
29
29
|
let errored = false;
|
|
30
|
-
for (const i of
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
for (const i of command.options ?? []) {
|
|
31
|
+
try {
|
|
32
|
+
const option = command.options.find(x => x.name === i.name);
|
|
33
|
+
const value = resolver.getHoisted(i.name)?.value !== undefined
|
|
34
|
+
? await new Promise((res, rej) => option.value?.({ context: ctx, value: resolver.getValue(i.name) }, res, rej) ||
|
|
35
|
+
res(resolver.getValue(i.name)))
|
|
36
|
+
: undefined;
|
|
37
|
+
if (value === undefined) {
|
|
38
|
+
if (option.required) {
|
|
39
|
+
errored = true;
|
|
40
|
+
data[i.name] = {
|
|
41
|
+
failed: true,
|
|
42
|
+
value: `${i.name} is required but returned no value`,
|
|
43
|
+
};
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// @ts-expect-error
|
|
48
|
+
ctx.options[i.name] = value;
|
|
36
49
|
data[i.name] = {
|
|
37
|
-
failed:
|
|
50
|
+
failed: false,
|
|
38
51
|
value,
|
|
39
52
|
};
|
|
40
|
-
continue;
|
|
41
53
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
};
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
errored = true;
|
|
56
|
+
data[i.name] = {
|
|
57
|
+
failed: true,
|
|
58
|
+
value: e instanceof Error ? e.message : `${e}`,
|
|
59
|
+
};
|
|
51
60
|
}
|
|
52
|
-
// @ts-expect-error
|
|
53
|
-
ctx.options[i.name] = value;
|
|
54
|
-
data[i.name] = {
|
|
55
|
-
failed: false,
|
|
56
|
-
value,
|
|
57
|
-
};
|
|
58
61
|
}
|
|
59
62
|
return [errored, data];
|
|
60
63
|
}
|
|
61
64
|
/** @internal */
|
|
62
65
|
static __runMiddlewares(context, middlewares, global) {
|
|
63
66
|
if (!middlewares.length) {
|
|
64
|
-
return Promise.resolve(
|
|
67
|
+
return Promise.resolve({});
|
|
65
68
|
}
|
|
66
69
|
let index = 0;
|
|
67
70
|
return new Promise(res => {
|
|
@@ -71,7 +74,7 @@ class BaseCommand {
|
|
|
71
74
|
return;
|
|
72
75
|
}
|
|
73
76
|
running = false;
|
|
74
|
-
return res(
|
|
77
|
+
return res({ pass: true });
|
|
75
78
|
};
|
|
76
79
|
const next = obj => {
|
|
77
80
|
if (!running) {
|
|
@@ -82,7 +85,7 @@ class BaseCommand {
|
|
|
82
85
|
context[global ? 'globalMetadata' : 'metadata'][middlewares[index]] = obj;
|
|
83
86
|
if (++index >= middlewares.length) {
|
|
84
87
|
running = false;
|
|
85
|
-
return res(
|
|
88
|
+
return res({});
|
|
86
89
|
}
|
|
87
90
|
context.client.middlewares[middlewares[index]]({ context, next, stop, pass });
|
|
88
91
|
};
|
|
@@ -91,7 +94,7 @@ class BaseCommand {
|
|
|
91
94
|
return;
|
|
92
95
|
}
|
|
93
96
|
running = false;
|
|
94
|
-
return res(err);
|
|
97
|
+
return res({ error: err });
|
|
95
98
|
};
|
|
96
99
|
context.client.middlewares[middlewares[0]]({ context, next, stop, pass });
|
|
97
100
|
});
|
|
@@ -105,7 +108,7 @@ class BaseCommand {
|
|
|
105
108
|
return BaseCommand.__runMiddlewares(context, (context.client.options?.globalMiddlewares ?? []), true);
|
|
106
109
|
}
|
|
107
110
|
toJSON() {
|
|
108
|
-
|
|
111
|
+
const data = {
|
|
109
112
|
name: this.name,
|
|
110
113
|
type: this.type,
|
|
111
114
|
nsfw: this.nsfw || false,
|
|
@@ -113,18 +116,17 @@ class BaseCommand {
|
|
|
113
116
|
name_localizations: this.name_localizations,
|
|
114
117
|
description_localizations: this.description_localizations,
|
|
115
118
|
guild_id: this.guild_id,
|
|
116
|
-
dm_permission: this.dm,
|
|
117
119
|
default_member_permissions: this.default_member_permissions,
|
|
118
120
|
};
|
|
121
|
+
if ('dm' in this)
|
|
122
|
+
data.dm_permission = this.dm;
|
|
123
|
+
return data;
|
|
119
124
|
}
|
|
120
125
|
async reload() {
|
|
121
126
|
delete require.cache[this.__filePath];
|
|
122
127
|
const __tempCommand = await (0, common_1.magicImport)(this.__filePath).then(x => x.default ?? x);
|
|
123
128
|
Object.setPrototypeOf(this, __tempCommand.prototype);
|
|
124
129
|
}
|
|
125
|
-
onInternalError(client, error) {
|
|
126
|
-
client.logger.fatal(error);
|
|
127
|
-
}
|
|
128
130
|
}
|
|
129
131
|
class Command extends BaseCommand {
|
|
130
132
|
type = common_1.ApplicationCommandType.ChatInput;
|
|
@@ -158,6 +160,21 @@ class Command extends BaseCommand {
|
|
|
158
160
|
options,
|
|
159
161
|
};
|
|
160
162
|
}
|
|
163
|
+
onRunError(context, error) {
|
|
164
|
+
context.client.logger.fatal(`${this.name}.<onRunError>`, context.author.id, error);
|
|
165
|
+
}
|
|
166
|
+
onOptionsError(context, metadata) {
|
|
167
|
+
context.client.logger.fatal(`${this.name}.<onOptionsError>`, context.author.id, metadata);
|
|
168
|
+
}
|
|
169
|
+
onMiddlewaresError(context, error) {
|
|
170
|
+
context.client.logger.fatal(`${this.name}.<onMiddlewaresError>`, context.author.id, error);
|
|
171
|
+
}
|
|
172
|
+
onPermissionsFail(context, permissions) {
|
|
173
|
+
context.client.logger.fatal(`${this.name}.<onPermissionsFail>`, context.author.id, permissions);
|
|
174
|
+
}
|
|
175
|
+
onInternalError(client, error) {
|
|
176
|
+
client.logger.fatal(`${this.name}.<onInternalError>`, error);
|
|
177
|
+
}
|
|
161
178
|
}
|
|
162
179
|
exports.Command = Command;
|
|
163
180
|
class SubCommand extends BaseCommand {
|
|
@@ -1,28 +1,46 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type
|
|
3
|
-
import type {
|
|
1
|
+
import { MenuCommandContext, User, type AllChannels, type Guild, type InferWithPrefix, type MessageCommandInteraction, type ReturnCache, type UserCommandInteraction, type WebhookMessage } from '../..';
|
|
2
|
+
import { type When, type If, type UnionToTuple } from '../../common';
|
|
3
|
+
import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest } from '../../common/types/write';
|
|
4
|
+
import { Message, type ChatInputCommandInteraction, type GuildMember, type InteractionGuildMember } from '../../structures';
|
|
4
5
|
import type { RegisteredMiddlewares } from '../decorators';
|
|
5
6
|
import type { OptionResolver } from '../optionresolver';
|
|
6
7
|
import type { ContextOptions, OptionsRecord } from './chat';
|
|
7
|
-
import type { CommandMetadata,
|
|
8
|
-
export
|
|
8
|
+
import type { CommandMetadata, ExtendContext, GlobalMetadata, UsingClient } from './shared';
|
|
9
|
+
export interface CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never> extends ExtendContext {
|
|
10
|
+
}
|
|
11
|
+
export declare class CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never> {
|
|
9
12
|
readonly client: UsingClient;
|
|
10
|
-
readonly interaction: ChatInputCommandInteraction;
|
|
11
13
|
resolver: OptionResolver;
|
|
12
14
|
readonly shardId: number;
|
|
13
|
-
|
|
15
|
+
message: If<InferWithPrefix, Message | undefined, undefined>;
|
|
16
|
+
interaction: If<InferWithPrefix, ChatInputCommandInteraction | undefined, ChatInputCommandInteraction>;
|
|
17
|
+
messageResponse?: If<InferWithPrefix, Message | undefined>;
|
|
18
|
+
constructor(client: UsingClient, data: ChatInputCommandInteraction | Message, resolver: OptionResolver, shardId: number);
|
|
14
19
|
options: ContextOptions<T>;
|
|
15
20
|
metadata: CommandMetadata<UnionToTuple<M>>;
|
|
16
21
|
globalMetadata: GlobalMetadata;
|
|
17
22
|
get proxy(): import("../..").APIRoutes;
|
|
18
|
-
get t(): DefaultLocale
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
+
get t(): import("../..").__InternalParseLocale<import("./shared").DefaultLocale> & {
|
|
24
|
+
get(locale?: string | undefined): import("./shared").DefaultLocale;
|
|
25
|
+
};
|
|
26
|
+
write<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage | Message, void | WebhookMessage | Message>>;
|
|
27
|
+
deferReply(ephemeral?: boolean): Promise<void | Message>;
|
|
28
|
+
editResponse(body: InteractionMessageUpdateBodyRequest): Promise<Message>;
|
|
23
29
|
deleteResponse(): Promise<void>;
|
|
24
|
-
editOrReply(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest): Promise<void
|
|
25
|
-
fetchResponse(): Promise<
|
|
26
|
-
|
|
27
|
-
|
|
30
|
+
editOrReply<FR extends boolean = false>(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage | Message, void | WebhookMessage | Message>>;
|
|
31
|
+
fetchResponse(): Promise<If<InferWithPrefix, WebhookMessage | Message | undefined, WebhookMessage | undefined>>;
|
|
32
|
+
channel(mode?: 'rest' | 'flow'): Promise<If<InferWithPrefix, AllChannels | undefined, AllChannels>>;
|
|
33
|
+
channel(mode?: 'cache'): ReturnCache<If<InferWithPrefix, AllChannels | undefined, AllChannels>>;
|
|
34
|
+
me(mode?: 'rest' | 'flow'): Promise<GuildMember>;
|
|
35
|
+
me(mode?: 'cache'): ReturnCache<GuildMember | undefined>;
|
|
36
|
+
guild(mode?: 'rest' | 'flow'): Promise<Guild<'cached' | 'api'> | undefined>;
|
|
37
|
+
guild(mode?: 'cache'): ReturnCache<Guild<'cached'> | undefined>;
|
|
38
|
+
get guildId(): string | undefined;
|
|
39
|
+
get channelId(): string;
|
|
40
|
+
get author(): User;
|
|
41
|
+
get member(): If<InferWithPrefix, GuildMember | InteractionGuildMember | undefined, InteractionGuildMember | undefined>;
|
|
42
|
+
isChat(): this is CommandContext;
|
|
43
|
+
isMenu(): this is MenuCommandContext<any>;
|
|
44
|
+
isMenuUser(): this is MenuCommandContext<UserCommandInteraction>;
|
|
45
|
+
isMenuMessage(): this is MenuCommandContext<MessageCommandInteraction>;
|
|
28
46
|
}
|
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommandContext = void 0;
|
|
4
|
+
const __1 = require("../..");
|
|
4
5
|
const common_1 = require("../../common");
|
|
6
|
+
const structures_1 = require("../../structures");
|
|
5
7
|
class CommandContext {
|
|
6
8
|
client;
|
|
7
|
-
interaction;
|
|
8
9
|
resolver;
|
|
9
10
|
shardId;
|
|
10
|
-
|
|
11
|
+
message;
|
|
12
|
+
interaction;
|
|
13
|
+
messageResponse;
|
|
14
|
+
constructor(client, data, resolver, shardId) {
|
|
11
15
|
this.client = client;
|
|
12
|
-
this.interaction = interaction;
|
|
13
16
|
this.resolver = resolver;
|
|
14
17
|
this.shardId = shardId;
|
|
18
|
+
if (data instanceof structures_1.Message) {
|
|
19
|
+
this.message = data;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
this.interaction = data;
|
|
23
|
+
}
|
|
15
24
|
}
|
|
16
25
|
options = {};
|
|
17
26
|
metadata = {};
|
|
@@ -20,34 +29,104 @@ class CommandContext {
|
|
|
20
29
|
return this.client.proxy;
|
|
21
30
|
}
|
|
22
31
|
get t() {
|
|
23
|
-
return this.client.langs.get(this.interaction.
|
|
24
|
-
}
|
|
25
|
-
write(body) {
|
|
26
|
-
return this.interaction.write(body);
|
|
32
|
+
return this.client.langs.get(this.interaction?.locale ?? this.client.langs.defaultLang ?? 'en-US');
|
|
27
33
|
}
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
async write(body, fetchReply) {
|
|
35
|
+
if (this.interaction)
|
|
36
|
+
return this.interaction.write(body, fetchReply);
|
|
37
|
+
const options = this.client.options?.commands;
|
|
38
|
+
return (this.messageResponse = await this.message[!this.messageResponse && options?.reply?.(this) ? 'reply' : 'write'](body));
|
|
30
39
|
}
|
|
31
|
-
deferReply(ephemeral = false) {
|
|
32
|
-
|
|
40
|
+
async deferReply(ephemeral = false) {
|
|
41
|
+
if (this.interaction)
|
|
42
|
+
return this.interaction.deferReply(ephemeral ? common_1.MessageFlags.Ephemeral : undefined);
|
|
43
|
+
const options = this.client.options?.commands;
|
|
44
|
+
return (this.messageResponse = await this.message[options?.reply?.(this) ? 'reply' : 'write'](options?.deferReplyResponse?.(this) ?? { content: 'Thinking...' }));
|
|
33
45
|
}
|
|
34
|
-
editResponse(body) {
|
|
35
|
-
|
|
46
|
+
async editResponse(body) {
|
|
47
|
+
if (this.interaction)
|
|
48
|
+
return this.interaction.editResponse(body);
|
|
49
|
+
return (this.messageResponse = await this.messageResponse.edit(body));
|
|
36
50
|
}
|
|
37
51
|
deleteResponse() {
|
|
38
|
-
|
|
52
|
+
if (this.interaction)
|
|
53
|
+
return this.interaction.deleteResponse();
|
|
54
|
+
return this.messageResponse.delete();
|
|
55
|
+
}
|
|
56
|
+
editOrReply(body, fetchReply) {
|
|
57
|
+
if (this.interaction)
|
|
58
|
+
return this.interaction.editOrReply(body, fetchReply);
|
|
59
|
+
if (this.messageResponse) {
|
|
60
|
+
return this.editResponse(body);
|
|
61
|
+
}
|
|
62
|
+
return this.write(body, fetchReply);
|
|
63
|
+
}
|
|
64
|
+
async fetchResponse() {
|
|
65
|
+
if (this.interaction)
|
|
66
|
+
return this.interaction.fetchResponse();
|
|
67
|
+
this.messageResponse = await this.messageResponse?.fetch();
|
|
68
|
+
return this.messageResponse;
|
|
69
|
+
}
|
|
70
|
+
channel(mode = 'cache') {
|
|
71
|
+
if (this.interaction?.channel && mode === 'cache')
|
|
72
|
+
return this.client.cache.asyncCache ? Promise.resolve(this.interaction.channel) : this.interaction.channel;
|
|
73
|
+
switch (mode) {
|
|
74
|
+
case 'cache':
|
|
75
|
+
return (this.client.cache.channels?.get(this.channelId) ||
|
|
76
|
+
(this.client.cache.asyncCache ? Promise.resolve() : undefined));
|
|
77
|
+
default:
|
|
78
|
+
return this.client.channels.fetch(this.channelId, mode === 'rest');
|
|
79
|
+
}
|
|
39
80
|
}
|
|
40
|
-
|
|
41
|
-
|
|
81
|
+
me(mode = 'cache') {
|
|
82
|
+
if (!this.guildId)
|
|
83
|
+
return mode === 'cache' ? (this.client.cache.asyncCache ? Promise.resolve() : undefined) : Promise.resolve();
|
|
84
|
+
switch (mode) {
|
|
85
|
+
case 'cache':
|
|
86
|
+
return (this.client.cache.members?.get(this.client.botId, this.guildId) ||
|
|
87
|
+
(this.client.cache.asyncCache ? Promise.resolve() : undefined));
|
|
88
|
+
default:
|
|
89
|
+
return this.client.members.fetch(this.guildId, this.client.botId, mode === 'rest');
|
|
90
|
+
}
|
|
42
91
|
}
|
|
43
|
-
|
|
44
|
-
|
|
92
|
+
guild(mode = 'cache') {
|
|
93
|
+
if (!this.guildId)
|
|
94
|
+
return (mode === 'cache'
|
|
95
|
+
? this.client.cache.asyncCache
|
|
96
|
+
? Promise.resolve()
|
|
97
|
+
: undefined
|
|
98
|
+
: Promise.resolve());
|
|
99
|
+
switch (mode) {
|
|
100
|
+
case 'cache':
|
|
101
|
+
return (this.client.cache.guilds?.get(this.guildId) ||
|
|
102
|
+
(this.client.cache.asyncCache ? Promise.resolve() : undefined));
|
|
103
|
+
default:
|
|
104
|
+
return this.client.guilds.fetch(this.guildId, mode === 'rest');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
get guildId() {
|
|
108
|
+
return this.interaction?.guildId || this.message?.guildId;
|
|
109
|
+
}
|
|
110
|
+
get channelId() {
|
|
111
|
+
return this.interaction?.channelId || this.message.channelId;
|
|
45
112
|
}
|
|
46
113
|
get author() {
|
|
47
|
-
return this.interaction.
|
|
114
|
+
return this.interaction?.user || this.message.author;
|
|
48
115
|
}
|
|
49
116
|
get member() {
|
|
50
|
-
return this.interaction.member;
|
|
117
|
+
return this.interaction?.member || this.message?.member;
|
|
118
|
+
}
|
|
119
|
+
isChat() {
|
|
120
|
+
return this instanceof CommandContext;
|
|
121
|
+
}
|
|
122
|
+
isMenu() {
|
|
123
|
+
return this instanceof __1.MenuCommandContext;
|
|
124
|
+
}
|
|
125
|
+
isMenuUser() {
|
|
126
|
+
return this instanceof __1.MenuCommandContext && this.target instanceof __1.User;
|
|
127
|
+
}
|
|
128
|
+
isMenuMessage() {
|
|
129
|
+
return this instanceof __1.MenuCommandContext && this.target instanceof structures_1.Message;
|
|
51
130
|
}
|
|
52
131
|
}
|
|
53
132
|
exports.CommandContext = CommandContext;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type ApplicationCommandType, type LocaleString } from '../../common';
|
|
1
|
+
import { type ApplicationCommandType, type LocaleString, type PermissionStrings } from '../../common';
|
|
3
2
|
import type { RegisteredMiddlewares } from '../decorators';
|
|
4
3
|
import type { MenuCommandContext } from './menucontext';
|
|
4
|
+
import type { UsingClient } from './shared';
|
|
5
5
|
export declare abstract class ContextMenuCommand {
|
|
6
6
|
middlewares: (keyof RegisteredMiddlewares)[];
|
|
7
7
|
__filePath?: string;
|
|
8
8
|
__t?: {
|
|
9
|
-
name: string;
|
|
10
|
-
description: string;
|
|
9
|
+
name: string | undefined;
|
|
10
|
+
description: string | undefined;
|
|
11
11
|
};
|
|
12
12
|
guild_id?: string[];
|
|
13
13
|
name: string;
|
|
@@ -15,7 +15,7 @@ export declare abstract class ContextMenuCommand {
|
|
|
15
15
|
nsfw?: boolean;
|
|
16
16
|
description: string;
|
|
17
17
|
default_member_permissions?: string;
|
|
18
|
-
|
|
18
|
+
botPermissions?: bigint;
|
|
19
19
|
dm?: boolean;
|
|
20
20
|
name_localizations?: Partial<Record<LocaleString, string>>;
|
|
21
21
|
description_localizations?: Partial<Record<LocaleString, string>>;
|
|
@@ -33,7 +33,8 @@ export declare abstract class ContextMenuCommand {
|
|
|
33
33
|
reload(): Promise<void>;
|
|
34
34
|
abstract run?(context: MenuCommandContext<any>): any;
|
|
35
35
|
onAfterRun?(context: MenuCommandContext<any>, error: unknown | undefined): any;
|
|
36
|
-
onRunError
|
|
37
|
-
onMiddlewaresError
|
|
38
|
-
|
|
36
|
+
onRunError(context: MenuCommandContext<any, never>, error: unknown): any;
|
|
37
|
+
onMiddlewaresError(context: MenuCommandContext<any, never>, error: string): any;
|
|
38
|
+
onPermissionsFail(context: MenuCommandContext<any, never>, permissions: PermissionStrings): any;
|
|
39
|
+
onInternalError(client: UsingClient, error?: unknown): any;
|
|
39
40
|
}
|
|
@@ -12,14 +12,14 @@ class ContextMenuCommand {
|
|
|
12
12
|
nsfw;
|
|
13
13
|
description;
|
|
14
14
|
default_member_permissions;
|
|
15
|
-
|
|
15
|
+
botPermissions;
|
|
16
16
|
dm;
|
|
17
17
|
name_localizations;
|
|
18
18
|
description_localizations;
|
|
19
19
|
/** @internal */
|
|
20
20
|
static __runMiddlewares(context, middlewares, global) {
|
|
21
21
|
if (!middlewares.length) {
|
|
22
|
-
return Promise.resolve(
|
|
22
|
+
return Promise.resolve({});
|
|
23
23
|
}
|
|
24
24
|
let index = 0;
|
|
25
25
|
return new Promise(res => {
|
|
@@ -29,7 +29,7 @@ class ContextMenuCommand {
|
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
running = false;
|
|
32
|
-
return res(
|
|
32
|
+
return res({ pass: true });
|
|
33
33
|
};
|
|
34
34
|
const next = obj => {
|
|
35
35
|
if (!running) {
|
|
@@ -40,7 +40,7 @@ class ContextMenuCommand {
|
|
|
40
40
|
context[global ? 'globalMetadata' : 'metadata'][middlewares[index]] = obj;
|
|
41
41
|
if (++index >= middlewares.length) {
|
|
42
42
|
running = false;
|
|
43
|
-
return res(
|
|
43
|
+
return res({});
|
|
44
44
|
}
|
|
45
45
|
context.client.middlewares[middlewares[index]]({ context, next, stop, pass });
|
|
46
46
|
};
|
|
@@ -49,7 +49,7 @@ class ContextMenuCommand {
|
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
51
|
running = false;
|
|
52
|
-
return res(err);
|
|
52
|
+
return res({ error: err });
|
|
53
53
|
};
|
|
54
54
|
context.client.middlewares[middlewares[0]]({ context, next, stop, pass });
|
|
55
55
|
});
|
|
@@ -80,6 +80,15 @@ class ContextMenuCommand {
|
|
|
80
80
|
const __tempCommand = await (0, common_1.magicImport)(this.__filePath).then(x => x.default ?? x);
|
|
81
81
|
Object.setPrototypeOf(this, __tempCommand.prototype);
|
|
82
82
|
}
|
|
83
|
+
onRunError(context, error) {
|
|
84
|
+
context.client.logger.fatal(`${this.name}.<onRunError>`, context.author.id, error);
|
|
85
|
+
}
|
|
86
|
+
onMiddlewaresError(context, error) {
|
|
87
|
+
context.client.logger.fatal(`${this.name}.<onMiddlewaresError>`, context.author.id, error);
|
|
88
|
+
}
|
|
89
|
+
onPermissionsFail(context, permissions) {
|
|
90
|
+
context.client.logger.fatal(`${this.name}.<onPermissionsFail>`, context.author.id, permissions);
|
|
91
|
+
}
|
|
83
92
|
onInternalError(client, error) {
|
|
84
93
|
client.logger.fatal(error);
|
|
85
94
|
}
|