seyfert 1.2.2 → 1.3.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/LICENSE +190 -190
- package/README.md +46 -46
- package/lib/api/Router.d.ts +9 -0
- package/lib/api/Router.js +16 -8
- package/lib/api/Routes/cdn.d.ts +26 -15
- package/lib/api/Routes/channels.d.ts +15 -1
- package/lib/api/api.d.ts +2 -3
- package/lib/api/api.js +4 -9
- package/lib/api/index.d.ts +0 -1
- package/lib/api/index.js +0 -1
- package/lib/api/utils/utils.d.ts +1 -1
- package/lib/api/utils/utils.js +2 -2
- package/lib/builders/Modal.d.ts +4 -1
- package/lib/builders/Modal.js +4 -1
- package/lib/builders/Poll.d.ts +16 -0
- package/lib/builders/Poll.js +48 -0
- package/lib/builders/index.d.ts +1 -0
- package/lib/builders/index.js +1 -0
- package/lib/cache/adapters/default.d.ts +1 -0
- package/lib/cache/adapters/default.js +4 -0
- package/lib/cache/adapters/index.d.ts +1 -0
- package/lib/cache/adapters/index.js +1 -0
- package/lib/cache/adapters/limited.d.ts +50 -0
- package/lib/cache/adapters/limited.js +188 -0
- package/lib/cache/adapters/redis.d.ts +2 -0
- package/lib/cache/adapters/redis.js +17 -0
- package/lib/cache/adapters/types.d.ts +1 -0
- package/lib/cache/adapters/workeradapter.d.ts +1 -0
- package/lib/cache/adapters/workeradapter.js +6 -9
- package/lib/cache/index.d.ts +8 -3
- package/lib/cache/index.js +41 -7
- package/lib/cache/resources/channels.d.ts +2 -1
- package/lib/cache/resources/default/base.d.ts +3 -3
- package/lib/cache/resources/default/base.js +8 -3
- package/lib/cache/resources/default/guild-based.d.ts +2 -1
- package/lib/cache/resources/default/guild-based.js +7 -3
- package/lib/cache/resources/default/guild-related.d.ts +2 -1
- package/lib/cache/resources/default/guild-related.js +7 -3
- package/lib/cache/resources/emojis.d.ts +2 -0
- package/lib/cache/resources/emojis.js +4 -0
- package/lib/cache/resources/guilds.d.ts +2 -0
- package/lib/cache/resources/guilds.js +4 -0
- package/lib/cache/resources/members.d.ts +2 -0
- package/lib/cache/resources/members.js +5 -1
- package/lib/cache/resources/messages.d.ts +15 -0
- package/lib/cache/resources/messages.js +53 -0
- package/lib/cache/resources/overwrites.d.ts +4 -0
- package/lib/cache/resources/overwrites.js +4 -0
- package/lib/cache/resources/presence.d.ts +1 -0
- package/lib/cache/resources/presence.js +4 -0
- package/lib/cache/resources/roles.d.ts +2 -0
- package/lib/cache/resources/roles.js +4 -0
- package/lib/cache/resources/stage-instances.d.ts +1 -0
- package/lib/cache/resources/stage-instances.js +5 -1
- package/lib/cache/resources/stickers.d.ts +2 -0
- package/lib/cache/resources/stickers.js +4 -0
- package/lib/cache/resources/threads.d.ts +2 -0
- package/lib/cache/resources/threads.js +4 -0
- package/lib/cache/resources/users.d.ts +2 -0
- package/lib/cache/resources/users.js +4 -0
- package/lib/cache/resources/voice-states.d.ts +2 -1
- package/lib/cache/resources/voice-states.js +8 -4
- package/lib/client/base.d.ts +26 -14
- package/lib/client/base.js +41 -13
- package/lib/client/client.d.ts +6 -5
- package/lib/client/client.js +13 -1
- package/lib/client/oninteractioncreate.js +2 -2
- package/lib/client/onmessagecreate.js +17 -14
- package/lib/client/workerclient.d.ts +3 -3
- package/lib/client/workerclient.js +23 -14
- package/lib/collection.d.ts +8 -3
- package/lib/collection.js +22 -4
- package/lib/commands/applications/chat.d.ts +17 -20
- package/lib/commands/applications/chat.js +6 -21
- package/lib/commands/applications/chatcontext.d.ts +1 -1
- package/lib/commands/applications/menucontext.d.ts +1 -1
- package/lib/commands/applications/shared.d.ts +4 -0
- package/lib/commands/applications/shared.js +6 -0
- package/lib/commands/decorators.d.ts +11 -1
- package/lib/commands/decorators.js +24 -0
- package/lib/commands/handler.d.ts +11 -7
- package/lib/commands/handler.js +43 -14
- package/lib/common/index.d.ts +2 -0
- package/lib/common/index.js +2 -0
- package/lib/common/it/utils.d.ts +0 -1
- package/lib/common/it/utils.js +0 -1
- package/lib/common/shorters/channels.d.ts +8 -3
- package/lib/common/shorters/channels.js +27 -12
- package/lib/common/shorters/guilds.d.ts +6 -5
- package/lib/common/shorters/guilds.js +22 -4
- package/lib/common/shorters/interaction.d.ts +13 -0
- package/lib/common/shorters/interaction.js +61 -0
- package/lib/common/shorters/messages.d.ts +6 -3
- package/lib/common/shorters/messages.js +33 -15
- package/lib/common/shorters/roles.d.ts +3 -3
- package/lib/common/shorters/roles.js +12 -17
- package/lib/common/shorters/templates.d.ts +7 -6
- package/lib/common/shorters/templates.js +28 -6
- package/lib/common/shorters/threads.d.ts +39 -0
- package/lib/common/shorters/threads.js +76 -0
- package/lib/common/shorters/webhook.d.ts +1 -1
- package/lib/common/shorters/webhook.js +8 -2
- package/lib/common/types/options.d.ts +2 -2
- package/lib/common/types/write.d.ts +8 -5
- package/lib/components/ButtonComponent.js +1 -1
- package/lib/components/componentcontext.d.ts +1 -1
- package/lib/components/handler.d.ts +6 -17
- package/lib/components/handler.js +7 -2
- package/lib/events/handler.d.ts +8 -14
- package/lib/events/handler.js +9 -4
- package/lib/events/hooks/guild.d.ts +1 -1
- package/lib/events/hooks/guild.js +2 -2
- package/lib/events/hooks/message.d.ts +26 -8
- package/lib/events/hooks/message.js +18 -7
- package/lib/langs/handler.d.ts +4 -8
- package/lib/langs/handler.js +7 -2
- package/lib/structures/AutoModerationRule.d.ts +6 -6
- package/lib/structures/Guild.d.ts +15 -13
- package/lib/structures/GuildEmoji.d.ts +2 -2
- package/lib/structures/GuildEmoji.js +1 -1
- package/lib/structures/GuildMember.js +1 -1
- package/lib/structures/GuildRole.d.ts +5 -5
- package/lib/structures/GuildTemplate.d.ts +10 -10
- package/lib/structures/Interaction.d.ts +3 -3
- package/lib/structures/Interaction.js +27 -48
- package/lib/structures/Message.d.ts +5 -3
- package/lib/structures/Message.js +5 -0
- package/lib/structures/Poll.d.ts +15 -0
- package/lib/structures/Poll.js +26 -0
- package/lib/structures/User.d.ts +2 -3
- package/lib/structures/User.js +9 -4
- package/lib/structures/Webhook.d.ts +2 -2
- package/lib/structures/Webhook.js +1 -1
- package/lib/structures/channels.d.ts +11 -3
- package/lib/structures/channels.js +16 -8
- package/lib/structures/extra/BaseGuild.js +3 -3
- package/lib/structures/extra/Permissions.d.ts +1 -0
- package/lib/structures/index.d.ts +1 -0
- package/lib/structures/index.js +1 -0
- package/lib/websocket/SharedTypes.d.ts +7 -2
- package/lib/websocket/discord/worker.d.ts +1 -1
- package/lib/websocket/discord/workermanager.js +3 -9
- package/lib/websocket/structures/timeout.js +9 -12
- package/package.json +8 -8
- package/lib/api/CDN.d.ts +0 -212
- package/lib/api/CDN.js +0 -228
- package/lib/client/http/adapters/bun.d.ts +0 -14
- package/lib/client/http/adapters/bun.js +0 -117
- package/lib/client/http/adapters/index.d.ts +0 -15
- package/lib/client/http/adapters/index.js +0 -27
- package/lib/client/http/adapters/uws.d.ts +0 -17
- package/lib/client/http/adapters/uws.js +0 -142
- package/lib/client/http/httpclient.d.ts +0 -13
- package/lib/client/http/httpclient.js +0 -48
- package/lib/common/shorters/overwrites.d.ts +0 -29
- package/lib/common/shorters/overwrites.js +0 -63
- package/lib/components/listener.d.ts +0 -11
- package/lib/components/listener.js +0 -17
- package/lib/structures/extra/BaseComponent.d.ts +0 -9
- package/lib/structures/extra/BaseComponent.js +0 -12
- package/lib/structures/extra/BaseSelectMenuComponent.d.ts +0 -9
- package/lib/structures/extra/BaseSelectMenuComponent.js +0 -13
|
@@ -4,10 +4,11 @@ import { VoiceState } from '../../structures';
|
|
|
4
4
|
import { GuildBasedResource } from './default/guild-based';
|
|
5
5
|
export declare class VoiceStates extends GuildBasedResource {
|
|
6
6
|
namespace: string;
|
|
7
|
+
filter(data: GatewayVoiceState, id: string, guild_id: string): boolean;
|
|
8
|
+
parse(data: any, id: string, guild_id: string): any;
|
|
7
9
|
get(memberId: string, guildId: string): ReturnCache<VoiceState | undefined>;
|
|
8
10
|
bulk(ids: string[], guild: string): ReturnCache<VoiceState[]>;
|
|
9
11
|
values(guildId: string): ReturnCache<VoiceState[]>;
|
|
10
|
-
parse(data: any, id: string, guild_id: string): any;
|
|
11
12
|
}
|
|
12
13
|
export type VoiceStateResource = Omit<GatewayVoiceState, 'member'> & {
|
|
13
14
|
guild_id: string;
|
|
@@ -6,6 +6,14 @@ const structures_1 = require("../../structures");
|
|
|
6
6
|
const guild_based_1 = require("./default/guild-based");
|
|
7
7
|
class VoiceStates extends guild_based_1.GuildBasedResource {
|
|
8
8
|
namespace = 'voice_state';
|
|
9
|
+
//@ts-expect-error
|
|
10
|
+
filter(data, id, guild_id) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
parse(data, id, guild_id) {
|
|
14
|
+
const { member, ...rest } = super.parse(data, id, guild_id);
|
|
15
|
+
return rest;
|
|
16
|
+
}
|
|
9
17
|
get(memberId, guildId) {
|
|
10
18
|
return (0, common_1.fakePromise)(super.get(memberId, guildId)).then(state => state ? new structures_1.VoiceState(this.client, state) : undefined);
|
|
11
19
|
}
|
|
@@ -15,9 +23,5 @@ class VoiceStates extends guild_based_1.GuildBasedResource {
|
|
|
15
23
|
values(guildId) {
|
|
16
24
|
return (0, common_1.fakePromise)(super.values(guildId)).then(states => states.map(state => new structures_1.VoiceState(this.client, state)));
|
|
17
25
|
}
|
|
18
|
-
parse(data, id, guild_id) {
|
|
19
|
-
const { member, ...rest } = super.parse(data, id, guild_id);
|
|
20
|
-
return rest;
|
|
21
|
-
}
|
|
22
26
|
}
|
|
23
27
|
exports.VoiceStates = VoiceStates;
|
package/lib/client/base.d.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { ApiHandler } from '../api';
|
|
2
2
|
import type { Adapter } from '../cache';
|
|
3
3
|
import { Cache } from '../cache';
|
|
4
|
-
import type { Command,
|
|
5
|
-
import type
|
|
6
|
-
import {
|
|
7
|
-
import { ChannelShorter, EmojiShorter, GuildShorter, Logger, MemberShorter, MessageShorter, ReactionShorter, RoleShorter, TemplateShorter, UsersShorter, WebhookShorter, type MakeRequired } from '../common';
|
|
4
|
+
import type { Command, RegisteredMiddlewares } from '../commands';
|
|
5
|
+
import { type InferWithPrefix, type MiddlewareContext } from '../commands/applications/shared';
|
|
6
|
+
import { CommandHandler } from '../commands/handler';
|
|
7
|
+
import { ChannelShorter, EmojiShorter, GuildShorter, InteractionShorter, Logger, MemberShorter, MessageShorter, ReactionShorter, RoleShorter, TemplateShorter, ThreadShorter, UsersShorter, WebhookShorter, type MakeRequired } from '../common';
|
|
8
8
|
import type { LocaleString } from 'discord-api-types/rest/v10';
|
|
9
9
|
import type { DeepPartial, IntentStrings, OmitInsert, When } from '../common/types/util';
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
import { type LangsHandlerLike } from '../langs/handler';
|
|
10
|
+
import { ComponentHandler } from '../components/handler';
|
|
11
|
+
import { LangsHandler } from '../langs/handler';
|
|
13
12
|
import type { ChatInputCommandInteraction, ComponentInteraction, Message, MessageCommandInteraction, UserCommandInteraction } from '../structures';
|
|
14
13
|
export declare class BaseClient {
|
|
15
14
|
rest: ApiHandler;
|
|
@@ -24,11 +23,13 @@ export declare class BaseClient {
|
|
|
24
23
|
roles: RoleShorter;
|
|
25
24
|
reactions: ReactionShorter;
|
|
26
25
|
emojis: EmojiShorter;
|
|
26
|
+
threads: ThreadShorter;
|
|
27
|
+
interactions: InteractionShorter;
|
|
27
28
|
debugger?: Logger;
|
|
28
29
|
logger: Logger;
|
|
29
|
-
langs?:
|
|
30
|
-
commands?:
|
|
31
|
-
components?:
|
|
30
|
+
langs?: LangsHandler | undefined;
|
|
31
|
+
commands?: CommandHandler | undefined;
|
|
32
|
+
components?: ComponentHandler | undefined;
|
|
32
33
|
private _applicationId?;
|
|
33
34
|
private _botId?;
|
|
34
35
|
middlewares?: Record<string, MiddlewareContext>;
|
|
@@ -54,7 +55,7 @@ export declare class BaseClient {
|
|
|
54
55
|
};
|
|
55
56
|
getRC<T extends InternalRuntimeConfigHTTP | InternalRuntimeConfig = InternalRuntimeConfigHTTP | InternalRuntimeConfig>(): Promise<{
|
|
56
57
|
debug: boolean;
|
|
57
|
-
} & Omit<T, "
|
|
58
|
+
} & Omit<T, "locations" | "debug"> & {
|
|
58
59
|
templates: string | undefined;
|
|
59
60
|
langs: string | undefined;
|
|
60
61
|
events: string | undefined;
|
|
@@ -67,6 +68,17 @@ export declare class BaseClient {
|
|
|
67
68
|
export interface BaseClientOptions {
|
|
68
69
|
context?: (interaction: ChatInputCommandInteraction<boolean> | UserCommandInteraction<boolean> | MessageCommandInteraction<boolean> | ComponentInteraction | When<InferWithPrefix, Message, never>) => {};
|
|
69
70
|
globalMiddlewares?: readonly (keyof RegisteredMiddlewares)[];
|
|
71
|
+
commands?: {
|
|
72
|
+
defaults?: {
|
|
73
|
+
onRunError?: Command['onRunError'];
|
|
74
|
+
onPermissionsFail?: Command['onPermissionsFail'];
|
|
75
|
+
onBotPermissionsFail?: Command['onBotPermissionsFail'];
|
|
76
|
+
onInternalError?: Command['onInternalError'];
|
|
77
|
+
onMiddlewaresError?: Command['onMiddlewaresError'];
|
|
78
|
+
onOptionsError?: Command['onOptionsError'];
|
|
79
|
+
onAfterRun?: Command['onAfterRun'];
|
|
80
|
+
};
|
|
81
|
+
};
|
|
70
82
|
}
|
|
71
83
|
export interface StartOptions {
|
|
72
84
|
eventsDir: string;
|
|
@@ -123,9 +135,9 @@ export interface ServicesOptions {
|
|
|
123
135
|
};
|
|
124
136
|
middlewares?: Record<string, MiddlewareContext>;
|
|
125
137
|
handlers?: {
|
|
126
|
-
components?:
|
|
127
|
-
commands?:
|
|
128
|
-
langs?:
|
|
138
|
+
components?: ComponentHandler | ComponentHandler['callback'];
|
|
139
|
+
commands?: CommandHandler | Parameters<CommandHandler['setHandlers']>[0];
|
|
140
|
+
langs?: LangsHandler | LangsHandler['callback'];
|
|
129
141
|
};
|
|
130
142
|
}
|
|
131
143
|
export {};
|
package/lib/client/base.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.BaseClient = void 0;
|
|
|
4
4
|
const node_path_1 = require("node:path");
|
|
5
5
|
const api_1 = require("../api");
|
|
6
6
|
const cache_1 = require("../cache");
|
|
7
|
+
const shared_1 = require("../commands/applications/shared");
|
|
7
8
|
const handler_1 = require("../commands/handler");
|
|
8
9
|
const common_1 = require("../common");
|
|
9
10
|
const handler_2 = require("../components/handler");
|
|
@@ -21,6 +22,8 @@ class BaseClient {
|
|
|
21
22
|
roles = new common_1.RoleShorter(this);
|
|
22
23
|
reactions = new common_1.ReactionShorter(this);
|
|
23
24
|
emojis = new common_1.EmojiShorter(this);
|
|
25
|
+
threads = new common_1.ThreadShorter(this);
|
|
26
|
+
interactions = new common_1.InteractionShorter(this);
|
|
24
27
|
debugger;
|
|
25
28
|
logger = new common_1.Logger({
|
|
26
29
|
name: '[Seyfert]',
|
|
@@ -41,7 +44,30 @@ class BaseClient {
|
|
|
41
44
|
}
|
|
42
45
|
options;
|
|
43
46
|
constructor(options) {
|
|
44
|
-
this.options =
|
|
47
|
+
this.options = (0, common_1.MergeOptions)({
|
|
48
|
+
commands: {
|
|
49
|
+
defaults: {
|
|
50
|
+
onRunError(context, error) {
|
|
51
|
+
context.client.logger.fatal(`${context.command.name}.<onRunError>`, context.author.id, error);
|
|
52
|
+
},
|
|
53
|
+
onOptionsError(context, metadata) {
|
|
54
|
+
context.client.logger.fatal(`${context.command.name}.<onOptionsError>`, context.author.id, metadata);
|
|
55
|
+
},
|
|
56
|
+
onMiddlewaresError(context, error) {
|
|
57
|
+
context.client.logger.fatal(`${context.command.name}.<onMiddlewaresError>`, context.author.id, error);
|
|
58
|
+
},
|
|
59
|
+
onBotPermissionsFail(context, permissions) {
|
|
60
|
+
context.client.logger.fatal(`${context.command.name}.<onBotPermissionsFail>`, context.author.id, permissions);
|
|
61
|
+
},
|
|
62
|
+
onPermissionsFail(context, permissions) {
|
|
63
|
+
context.client.logger.fatal(`${context.command.name}.<onPermissionsFail>`, context.author.id, permissions);
|
|
64
|
+
},
|
|
65
|
+
onInternalError(client, command, error) {
|
|
66
|
+
client.logger.fatal(`${command.name}.<onInternalError>`, error);
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
}, options);
|
|
45
71
|
}
|
|
46
72
|
set botId(id) {
|
|
47
73
|
this._botId = id;
|
|
@@ -74,8 +100,8 @@ class BaseClient {
|
|
|
74
100
|
this.components = undefined;
|
|
75
101
|
}
|
|
76
102
|
else if (typeof handlers.components === 'function') {
|
|
77
|
-
this.components
|
|
78
|
-
this.components.
|
|
103
|
+
this.components ??= new handler_2.ComponentHandler(this.logger, this);
|
|
104
|
+
this.components.setHandlers({ callback: handlers.components });
|
|
79
105
|
}
|
|
80
106
|
else {
|
|
81
107
|
this.components = handlers.components;
|
|
@@ -85,9 +111,9 @@ class BaseClient {
|
|
|
85
111
|
if (!handlers.commands) {
|
|
86
112
|
this.commands = undefined;
|
|
87
113
|
}
|
|
88
|
-
else if (typeof handlers.commands === '
|
|
89
|
-
this.commands
|
|
90
|
-
this.commands.
|
|
114
|
+
else if (typeof handlers.commands === 'object') {
|
|
115
|
+
this.commands ??= new handler_1.CommandHandler(this.logger, this);
|
|
116
|
+
this.commands.setHandlers(handlers.commands);
|
|
91
117
|
}
|
|
92
118
|
else {
|
|
93
119
|
this.commands = handlers.commands;
|
|
@@ -98,8 +124,8 @@ class BaseClient {
|
|
|
98
124
|
this.langs = undefined;
|
|
99
125
|
}
|
|
100
126
|
else if (typeof handlers.langs === 'function') {
|
|
101
|
-
this.langs
|
|
102
|
-
this.langs.
|
|
127
|
+
this.langs ??= new handler_3.LangsHandler(this.logger);
|
|
128
|
+
this.langs.setHandlers({ callback: handlers.langs });
|
|
103
129
|
}
|
|
104
130
|
else {
|
|
105
131
|
this.langs = handlers.langs;
|
|
@@ -155,14 +181,14 @@ class BaseClient {
|
|
|
155
181
|
async uploadCommands(applicationId) {
|
|
156
182
|
applicationId ??= await this.getRC().then(x => x.applicationId ?? this.applicationId);
|
|
157
183
|
BaseClient.assertString(applicationId, 'applicationId is not a string');
|
|
158
|
-
const commands = this.commands.values
|
|
159
|
-
const filter = (0, common_1.filterSplit)(commands, command => !command.
|
|
184
|
+
const commands = this.commands.values;
|
|
185
|
+
const filter = (0, common_1.filterSplit)(commands, command => !command.guildId);
|
|
160
186
|
await this.proxy.applications(applicationId).commands.put({
|
|
161
|
-
body: filter.expect,
|
|
187
|
+
body: filter.expect.filter(cmd => !('ignore' in cmd) || cmd.ignore !== shared_1.IgnoreCommand.Slash).map(x => x.toJSON()),
|
|
162
188
|
});
|
|
163
189
|
const guilds = new Set();
|
|
164
190
|
for (const command of filter.never) {
|
|
165
|
-
for (const guild_id of command.
|
|
191
|
+
for (const guild_id of command.guildId) {
|
|
166
192
|
guilds.add(guild_id);
|
|
167
193
|
}
|
|
168
194
|
}
|
|
@@ -171,7 +197,9 @@ class BaseClient {
|
|
|
171
197
|
.applications(applicationId)
|
|
172
198
|
.guilds(guild)
|
|
173
199
|
.commands.put({
|
|
174
|
-
body: filter.never
|
|
200
|
+
body: filter.never
|
|
201
|
+
.filter(cmd => cmd.guildId?.includes(guild) && (!('ignore' in cmd) || cmd.ignore !== shared_1.IgnoreCommand.Slash))
|
|
202
|
+
.map(x => x.toJSON()),
|
|
175
203
|
});
|
|
176
204
|
}
|
|
177
205
|
}
|
package/lib/client/client.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type GatewayDispatchPayload, type GatewayPresenceUpdateData } from 'discord-api-types/v10';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Command, CommandContext, Message, SubCommand } from '..';
|
|
3
3
|
import type { DeepPartial, If } from '../common';
|
|
4
|
+
import { EventHandler } from '../events';
|
|
4
5
|
import { ClientUser } from '../structures';
|
|
5
6
|
import { ShardManager, type ShardManagerOptions } from '../websocket';
|
|
6
7
|
import { MemberUpdateHandler } from '../websocket/discord/events/memberUpdate';
|
|
@@ -10,7 +11,7 @@ import { BaseClient } from './base';
|
|
|
10
11
|
export declare class Client<Ready extends boolean = boolean> extends BaseClient {
|
|
11
12
|
private __handleGuilds?;
|
|
12
13
|
gateway: ShardManager;
|
|
13
|
-
events?:
|
|
14
|
+
events?: EventHandler | undefined;
|
|
14
15
|
me: If<Ready, ClientUser>;
|
|
15
16
|
options: ClientOptions | undefined;
|
|
16
17
|
memberUpdateHandler: MemberUpdateHandler;
|
|
@@ -19,7 +20,7 @@ export declare class Client<Ready extends boolean = boolean> extends BaseClient
|
|
|
19
20
|
setServices({ gateway, ...rest }: ServicesOptions & {
|
|
20
21
|
gateway?: ShardManager;
|
|
21
22
|
handlers?: ServicesOptions['handlers'] & {
|
|
22
|
-
events?:
|
|
23
|
+
events?: EventHandler['callback'];
|
|
23
24
|
};
|
|
24
25
|
}): void;
|
|
25
26
|
loadEvents(dir?: string): Promise<void>;
|
|
@@ -41,8 +42,8 @@ export interface ClientOptions extends BaseClientOptions {
|
|
|
41
42
|
properties?: Partial<ShardManagerOptions['properties']>;
|
|
42
43
|
compress?: ShardManagerOptions['compress'];
|
|
43
44
|
};
|
|
44
|
-
commands?: {
|
|
45
|
-
prefix
|
|
45
|
+
commands?: BaseClientOptions['commands'] & {
|
|
46
|
+
prefix?: (message: Message) => Promise<string[]> | string[];
|
|
46
47
|
deferReplyResponse?: (ctx: CommandContext) => Parameters<Message['write']>[0];
|
|
47
48
|
reply?: (ctx: CommandContext) => boolean;
|
|
48
49
|
argsParser?: (content: string, command: SubCommand | Command) => Record<string, string>;
|
package/lib/client/client.js
CHANGED
|
@@ -38,7 +38,9 @@ class Client extends base_1.BaseClient {
|
|
|
38
38
|
}
|
|
39
39
|
else if (typeof rest.handlers.events === 'function') {
|
|
40
40
|
this.events = new events_1.EventHandler(this.logger);
|
|
41
|
-
this.events.
|
|
41
|
+
this.events.setHandlers({
|
|
42
|
+
callback: rest.handlers.events,
|
|
43
|
+
});
|
|
42
44
|
}
|
|
43
45
|
else {
|
|
44
46
|
this.events = rest.handlers.events;
|
|
@@ -121,6 +123,16 @@ class Client extends base_1.BaseClient {
|
|
|
121
123
|
await this.events?.execute(packet.t, packet, this, shardId);
|
|
122
124
|
await this.cache.onPacket(packet);
|
|
123
125
|
break;
|
|
126
|
+
case 'MESSAGE_UPDATE':
|
|
127
|
+
case 'MESSAGE_DELETE_BULK':
|
|
128
|
+
case 'MESSAGE_DELETE':
|
|
129
|
+
await this.events?.execute(packet.t, packet, this, shardId);
|
|
130
|
+
await this.cache.onPacket(packet);
|
|
131
|
+
break;
|
|
132
|
+
case 'GUILD_DELETE':
|
|
133
|
+
case 'CHANNEL_UPDATE':
|
|
134
|
+
await this.events?.execute(packet.t, packet, this, shardId);
|
|
135
|
+
break;
|
|
124
136
|
//rest of the events
|
|
125
137
|
default: {
|
|
126
138
|
await this.cache.onPacket(packet);
|
|
@@ -33,7 +33,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
35
35
|
try {
|
|
36
|
-
await optionsResolver.getCommand()?.onInternalError?.(self, error);
|
|
36
|
+
await optionsResolver.getCommand()?.onInternalError?.(self, optionsResolver.getCommand(), error);
|
|
37
37
|
}
|
|
38
38
|
catch {
|
|
39
39
|
// supress error
|
|
@@ -152,7 +152,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
152
152
|
}
|
|
153
153
|
catch (error) {
|
|
154
154
|
try {
|
|
155
|
-
await command.onInternalError?.(self, error);
|
|
155
|
+
await command.onInternalError?.(self, context.command, error);
|
|
156
156
|
}
|
|
157
157
|
catch {
|
|
158
158
|
// supress error
|
|
@@ -5,18 +5,21 @@ const v10_1 = require("discord-api-types/v10");
|
|
|
5
5
|
const __1 = require("..");
|
|
6
6
|
const structures_1 = require("../structures");
|
|
7
7
|
function getCommandFromContent(commandRaw, self) {
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const parent = self.commands.values.find(x => x.
|
|
12
|
-
|
|
8
|
+
const rawParentName = commandRaw[0];
|
|
9
|
+
const rawGroupName = commandRaw.length === 3 ? commandRaw[1] : undefined;
|
|
10
|
+
const rawSubcommandName = rawGroupName ? commandRaw[2] : commandRaw[1];
|
|
11
|
+
const parent = self.commands.values.find(x => (!('ignore' in x) || x.ignore !== __1.IgnoreCommand.Message) &&
|
|
12
|
+
(x.name === rawParentName || ('aliases' in x ? x.aliases?.includes(rawParentName) : false)));
|
|
13
|
+
const fullCommandName = `${rawParentName}${rawGroupName ? ` ${rawGroupName} ${rawSubcommandName}` : `${rawSubcommandName ? ` ${rawSubcommandName}` : ''}`}`;
|
|
13
14
|
if (!(parent instanceof __1.Command))
|
|
14
15
|
return { fullCommandName };
|
|
15
|
-
if (
|
|
16
|
-
return getCommandFromContent([
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
if (rawGroupName && !parent.groups?.[rawGroupName] && !parent.groupsAliases?.[rawGroupName])
|
|
17
|
+
return getCommandFromContent([rawParentName, rawGroupName], self);
|
|
18
|
+
if (rawSubcommandName &&
|
|
19
|
+
!parent.options?.some(x => x instanceof __1.SubCommand && (x.name === rawSubcommandName || x.aliases?.includes(rawSubcommandName))))
|
|
20
|
+
return getCommandFromContent([rawParentName], self);
|
|
21
|
+
const groupName = rawGroupName ? parent.groupsAliases?.[rawGroupName] || rawGroupName : undefined;
|
|
22
|
+
const command = groupName || rawSubcommandName
|
|
20
23
|
? parent.options?.find(opt => {
|
|
21
24
|
if (opt instanceof __1.SubCommand) {
|
|
22
25
|
if (groupName) {
|
|
@@ -25,7 +28,7 @@ function getCommandFromContent(commandRaw, self) {
|
|
|
25
28
|
}
|
|
26
29
|
if (opt.group && !groupName)
|
|
27
30
|
return false;
|
|
28
|
-
return
|
|
31
|
+
return rawSubcommandName === opt.name || opt.aliases?.includes(rawSubcommandName);
|
|
29
32
|
}
|
|
30
33
|
return false;
|
|
31
34
|
})
|
|
@@ -37,10 +40,10 @@ function getCommandFromContent(commandRaw, self) {
|
|
|
37
40
|
};
|
|
38
41
|
}
|
|
39
42
|
async function onMessageCreate(self, rawMessage, shardId) {
|
|
40
|
-
if (!self.options?.commands)
|
|
43
|
+
if (!self.options?.commands?.prefix)
|
|
41
44
|
return;
|
|
42
45
|
const message = new structures_1.Message(self, rawMessage);
|
|
43
|
-
const prefixes = (
|
|
46
|
+
const prefixes = (await self.options.commands.prefix(message)).sort((a, b) => b.length - a.length);
|
|
44
47
|
const prefix = prefixes.find(x => message.content.startsWith(x));
|
|
45
48
|
if (!prefix || !message.content.startsWith(prefix))
|
|
46
49
|
return;
|
|
@@ -131,7 +134,7 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
131
134
|
}
|
|
132
135
|
catch (error) {
|
|
133
136
|
try {
|
|
134
|
-
await command.onInternalError?.(self, error);
|
|
137
|
+
await command.onInternalError?.(self, context.command, error);
|
|
135
138
|
}
|
|
136
139
|
catch {
|
|
137
140
|
// supress error
|
|
@@ -7,7 +7,7 @@ import { type GatewayDispatchPayload } from 'discord-api-types/v10';
|
|
|
7
7
|
import { Logger } from '..';
|
|
8
8
|
import type { Cache } from '../cache';
|
|
9
9
|
import { type DeepPartial, type When } from '../common';
|
|
10
|
-
import {
|
|
10
|
+
import { EventHandler } from '../events';
|
|
11
11
|
import { ClientUser } from '../structures';
|
|
12
12
|
import { Shard, type ShardManagerOptions } from '../websocket';
|
|
13
13
|
import type { WorkerShardInfo } from '../websocket/discord/worker';
|
|
@@ -18,7 +18,7 @@ import type { Client } from './client';
|
|
|
18
18
|
export declare class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
|
|
19
19
|
private __handleGuilds?;
|
|
20
20
|
logger: Logger;
|
|
21
|
-
events?:
|
|
21
|
+
events?: EventHandler | undefined;
|
|
22
22
|
me: When<Ready, ClientUser>;
|
|
23
23
|
promises: Map<string, {
|
|
24
24
|
resolve: (value: any) => void;
|
|
@@ -31,7 +31,7 @@ export declare class WorkerClient<Ready extends boolean = boolean> extends BaseC
|
|
|
31
31
|
get latency(): number;
|
|
32
32
|
setServices({ ...rest }: ServicesOptions & {
|
|
33
33
|
handlers?: ServicesOptions['handlers'] & {
|
|
34
|
-
events?:
|
|
34
|
+
events?: EventHandler['callback'];
|
|
35
35
|
};
|
|
36
36
|
}): void;
|
|
37
37
|
start(options?: Omit<DeepPartial<StartOptions>, 'httpConnection' | 'token' | 'connection'>): Promise<void>;
|
|
@@ -78,7 +78,18 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
78
78
|
setServices({ ...rest }) {
|
|
79
79
|
super.setServices(rest);
|
|
80
80
|
if (rest.handlers && 'events' in rest.handlers) {
|
|
81
|
-
|
|
81
|
+
if (!rest.handlers.events) {
|
|
82
|
+
this.events = undefined;
|
|
83
|
+
}
|
|
84
|
+
else if (typeof rest.handlers.events === 'function') {
|
|
85
|
+
this.events = new events_1.EventHandler(this.logger);
|
|
86
|
+
this.events.setHandlers({
|
|
87
|
+
callback: rest.handlers.events,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
this.events = rest.handlers.events;
|
|
92
|
+
}
|
|
82
93
|
}
|
|
83
94
|
}
|
|
84
95
|
async start(options = {}) {
|
|
@@ -216,8 +227,8 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
216
227
|
let result;
|
|
217
228
|
try {
|
|
218
229
|
// biome-ignore lint/security/noGlobalEval: yes
|
|
219
|
-
result = await eval(`
|
|
220
|
-
(${data.func})(this)
|
|
230
|
+
result = await eval(`
|
|
231
|
+
(${data.func})(this)
|
|
221
232
|
`);
|
|
222
233
|
}
|
|
223
234
|
catch (e) {
|
|
@@ -251,19 +262,13 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
251
262
|
return nonce;
|
|
252
263
|
}
|
|
253
264
|
generateSendPromise(nonce, message = 'Timeout') {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
};
|
|
257
|
-
let timeout = -1;
|
|
258
|
-
const promise = new Promise((res, rej) => {
|
|
259
|
-
resolve = res;
|
|
260
|
-
timeout = setTimeout(() => {
|
|
265
|
+
return new Promise((res, rej) => {
|
|
266
|
+
const timeout = setTimeout(() => {
|
|
261
267
|
this.promises.delete(nonce);
|
|
262
268
|
rej(new Error(message));
|
|
263
269
|
}, 60e3);
|
|
270
|
+
this.promises.set(nonce, { resolve: res, timeout });
|
|
264
271
|
});
|
|
265
|
-
this.promises.set(nonce, { resolve, timeout });
|
|
266
|
-
return promise;
|
|
267
272
|
}
|
|
268
273
|
tellWorker(workerId, func) {
|
|
269
274
|
const nonce = this.generateNonce();
|
|
@@ -280,12 +285,16 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
280
285
|
await this.events?.execute('RAW', packet, this, shardId);
|
|
281
286
|
switch (packet.t) {
|
|
282
287
|
case 'GUILD_MEMBER_UPDATE':
|
|
288
|
+
case 'PRESENCE_UPDATE':
|
|
289
|
+
case 'MESSAGE_UPDATE':
|
|
290
|
+
case 'MESSAGE_DELETE_BULK':
|
|
291
|
+
case 'MESSAGE_DELETE':
|
|
283
292
|
await this.events?.execute(packet.t, packet, this, shardId);
|
|
284
293
|
await this.cache.onPacket(packet);
|
|
285
294
|
break;
|
|
286
|
-
case '
|
|
295
|
+
case 'GUILD_DELETE':
|
|
296
|
+
case 'CHANNEL_UPDATE':
|
|
287
297
|
await this.events?.execute(packet.t, packet, this, shardId);
|
|
288
|
-
await this.cache.onPacket(packet);
|
|
289
298
|
break;
|
|
290
299
|
//rest of the events
|
|
291
300
|
default:
|
package/lib/collection.d.ts
CHANGED
|
@@ -119,9 +119,10 @@ type LimitedCollectionData<V> = {
|
|
|
119
119
|
expireOn: number;
|
|
120
120
|
value: V;
|
|
121
121
|
};
|
|
122
|
-
export interface LimitedCollectionOptions {
|
|
122
|
+
export interface LimitedCollectionOptions<K, V> {
|
|
123
123
|
limit: number;
|
|
124
124
|
expire: number;
|
|
125
|
+
onDelete?: (key: K, value: V) => void;
|
|
125
126
|
resetOnDemand: boolean;
|
|
126
127
|
}
|
|
127
128
|
/**
|
|
@@ -138,11 +139,11 @@ export interface LimitedCollectionOptions {
|
|
|
138
139
|
* console.log(mappedArray); // Output: ['1: one', '2: two', '3: three']
|
|
139
140
|
*/
|
|
140
141
|
export declare class LimitedCollection<K, V> {
|
|
141
|
-
static readonly default: LimitedCollectionOptions
|
|
142
|
+
static readonly default: LimitedCollectionOptions<any, any>;
|
|
142
143
|
private readonly data;
|
|
143
144
|
private readonly options;
|
|
144
145
|
private timeout;
|
|
145
|
-
constructor(options?: Partial<LimitedCollectionOptions
|
|
146
|
+
constructor(options?: Partial<LimitedCollectionOptions<K, V>>);
|
|
146
147
|
/**
|
|
147
148
|
* Adds an element to the limited collection.
|
|
148
149
|
* @param key The key of the element.
|
|
@@ -228,6 +229,10 @@ export declare class LimitedCollection<K, V> {
|
|
|
228
229
|
private resetTimeout;
|
|
229
230
|
private stopTimeout;
|
|
230
231
|
private startTimeout;
|
|
232
|
+
keys(): () => IterableIterator<K>;
|
|
233
|
+
values(): () => IterableIterator<LimitedCollectionData<V>>;
|
|
234
|
+
entries(): IterableIterator<[K, LimitedCollectionData<V>]>;
|
|
235
|
+
clear(): void;
|
|
231
236
|
private clearExpired;
|
|
232
237
|
}
|
|
233
238
|
export {};
|
package/lib/collection.js
CHANGED
|
@@ -230,7 +230,8 @@ class LimitedCollection {
|
|
|
230
230
|
if (this.size > this.options.limit) {
|
|
231
231
|
const iter = this.data.keys();
|
|
232
232
|
while (this.size > this.options.limit) {
|
|
233
|
-
|
|
233
|
+
const keyValue = iter.next().value;
|
|
234
|
+
this.delete(keyValue);
|
|
234
235
|
}
|
|
235
236
|
}
|
|
236
237
|
if (this.closer?.expireOn === expireOn) {
|
|
@@ -265,7 +266,7 @@ class LimitedCollection {
|
|
|
265
266
|
if (this.options.resetOnDemand && data && data.expire !== -1) {
|
|
266
267
|
const oldExpireOn = data.expireOn;
|
|
267
268
|
data.expireOn = Date.now() + data.expire;
|
|
268
|
-
if (this.closer
|
|
269
|
+
if (this.closer?.expireOn === oldExpireOn) {
|
|
269
270
|
this.resetTimeout();
|
|
270
271
|
}
|
|
271
272
|
}
|
|
@@ -296,8 +297,11 @@ class LimitedCollection {
|
|
|
296
297
|
*/
|
|
297
298
|
delete(key) {
|
|
298
299
|
const value = this.raw(key);
|
|
299
|
-
if (value
|
|
300
|
-
|
|
300
|
+
if (value) {
|
|
301
|
+
if (value.expireOn === this.closer?.expireOn)
|
|
302
|
+
setImmediate(() => this.resetTimeout());
|
|
303
|
+
this.options.onDelete?.(key, value.value);
|
|
304
|
+
}
|
|
301
305
|
return this.data.delete(key);
|
|
302
306
|
}
|
|
303
307
|
/**
|
|
@@ -360,12 +364,26 @@ class LimitedCollection {
|
|
|
360
364
|
this.resetTimeout();
|
|
361
365
|
}, expireOn - Date.now());
|
|
362
366
|
}
|
|
367
|
+
keys() {
|
|
368
|
+
return this.data.keys;
|
|
369
|
+
}
|
|
370
|
+
values() {
|
|
371
|
+
return this.data.values;
|
|
372
|
+
}
|
|
373
|
+
entries() {
|
|
374
|
+
return this.data.entries();
|
|
375
|
+
}
|
|
376
|
+
clear() {
|
|
377
|
+
this.data.clear();
|
|
378
|
+
this.resetTimeout();
|
|
379
|
+
}
|
|
363
380
|
clearExpired() {
|
|
364
381
|
for (const [key, value] of this.data) {
|
|
365
382
|
if (value.expireOn === -1) {
|
|
366
383
|
continue;
|
|
367
384
|
}
|
|
368
385
|
if (Date.now() >= value.expireOn) {
|
|
386
|
+
this.options.onDelete?.(key, value.value);
|
|
369
387
|
this.data.delete(key);
|
|
370
388
|
}
|
|
371
389
|
}
|
|
@@ -5,7 +5,7 @@ import { type FlatObjectKeys } from '../../common';
|
|
|
5
5
|
import type { AllChannels, AutocompleteInteraction, GuildRole, InteractionGuildMember, User } from '../../structures';
|
|
6
6
|
import type { Groups, IntegrationTypes, InteractionContextTypes, RegisteredMiddlewares } from '../decorators';
|
|
7
7
|
import type { CommandContext } from './chatcontext';
|
|
8
|
-
import type { DefaultLocale, OKFunction, OnOptionsReturnObject, StopFunction, UsingClient } from './shared';
|
|
8
|
+
import type { DefaultLocale, IgnoreCommand, OKFunction, OnOptionsReturnObject, StopFunction, UsingClient } from './shared';
|
|
9
9
|
export interface ReturnOptionsTypes {
|
|
10
10
|
1: never;
|
|
11
11
|
2: never;
|
|
@@ -72,11 +72,6 @@ declare class BaseCommand {
|
|
|
72
72
|
description: string | undefined;
|
|
73
73
|
};
|
|
74
74
|
__autoload?: true;
|
|
75
|
-
__tGroups?: Record<string, {
|
|
76
|
-
name: string | undefined;
|
|
77
|
-
description: string | undefined;
|
|
78
|
-
defaultDescription: string;
|
|
79
|
-
}>;
|
|
80
75
|
guildId?: string[];
|
|
81
76
|
name: string;
|
|
82
77
|
type: number;
|
|
@@ -89,6 +84,8 @@ declare class BaseCommand {
|
|
|
89
84
|
name_localizations?: Partial<Record<LocaleString, string>>;
|
|
90
85
|
description_localizations?: Partial<Record<LocaleString, string>>;
|
|
91
86
|
options?: CommandOption[] | SubCommand[];
|
|
87
|
+
ignore?: IgnoreCommand;
|
|
88
|
+
aliases?: string[];
|
|
92
89
|
toJSON(): {
|
|
93
90
|
name: BaseCommand['name'];
|
|
94
91
|
type: BaseCommand['type'];
|
|
@@ -102,18 +99,24 @@ declare class BaseCommand {
|
|
|
102
99
|
integration_types: BaseCommand['integrationTypes'];
|
|
103
100
|
};
|
|
104
101
|
reload(): Promise<void>;
|
|
105
|
-
run?(context: CommandContext
|
|
106
|
-
onAfterRun?(context: CommandContext
|
|
107
|
-
onRunError?(context: CommandContext
|
|
108
|
-
onOptionsError?(context: CommandContext
|
|
109
|
-
onMiddlewaresError?(context: CommandContext
|
|
110
|
-
onBotPermissionsFail?(context: CommandContext
|
|
111
|
-
onPermissionsFail?(context: CommandContext
|
|
112
|
-
onInternalError?(client: UsingClient, error?: unknown): any;
|
|
102
|
+
run?(context: CommandContext): any;
|
|
103
|
+
onAfterRun?(context: CommandContext, error: unknown | undefined): any;
|
|
104
|
+
onRunError?(context: CommandContext, error: unknown): any;
|
|
105
|
+
onOptionsError?(context: CommandContext, metadata: OnOptionsReturnObject): any;
|
|
106
|
+
onMiddlewaresError?(context: CommandContext, error: string): any;
|
|
107
|
+
onBotPermissionsFail?(context: CommandContext, permissions: PermissionStrings): any;
|
|
108
|
+
onPermissionsFail?(context: CommandContext, permissions: PermissionStrings): any;
|
|
109
|
+
onInternalError?(client: UsingClient, command: Command | SubCommand, error?: unknown): any;
|
|
113
110
|
}
|
|
114
111
|
export declare class Command extends BaseCommand {
|
|
115
112
|
type: ApplicationCommandType;
|
|
116
113
|
groups?: Parameters<typeof Groups>[0];
|
|
114
|
+
groupsAliases?: Record<string, string>;
|
|
115
|
+
__tGroups?: Record<string, {
|
|
116
|
+
name: string | undefined;
|
|
117
|
+
description: string | undefined;
|
|
118
|
+
defaultDescription: string;
|
|
119
|
+
}>;
|
|
117
120
|
toJSON(): {
|
|
118
121
|
options: APIApplicationCommandOption[];
|
|
119
122
|
name: string;
|
|
@@ -127,12 +130,6 @@ export declare class Command extends BaseCommand {
|
|
|
127
130
|
contexts: InteractionContextTypes[] | undefined;
|
|
128
131
|
integration_types: IntegrationTypes[] | undefined;
|
|
129
132
|
};
|
|
130
|
-
onRunError(context: CommandContext<any>, error: unknown): any;
|
|
131
|
-
onOptionsError(context: CommandContext<{}, never>, metadata: OnOptionsReturnObject): any;
|
|
132
|
-
onMiddlewaresError(context: CommandContext<{}, never>, error: string): any;
|
|
133
|
-
onBotPermissionsFail(context: CommandContext<{}, never>, permissions: PermissionStrings): any;
|
|
134
|
-
onPermissionsFail(context: CommandContext<{}, never>, permissions: PermissionStrings): any;
|
|
135
|
-
onInternalError(client: UsingClient, error?: unknown): any;
|
|
136
133
|
}
|
|
137
134
|
export declare abstract class SubCommand extends BaseCommand {
|
|
138
135
|
type: ApplicationCommandOptionType;
|