seyfert 1.0.1 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/api/CDN.d.ts +1 -1
- package/lib/api/CDN.js +0 -2
- package/lib/api/Router.js +2 -2
- package/lib/api/Routes/applications.d.ts +29 -33
- package/lib/api/Routes/channels.d.ts +11 -17
- package/lib/api/Routes/interactions.d.ts +3 -7
- package/lib/api/Routes/webhooks.d.ts +4 -6
- package/lib/builders/Attachment.d.ts +2 -3
- package/lib/cache/adapters/redis.js +6 -0
- package/lib/cache/adapters/types.d.ts +23 -23
- package/lib/cache/adapters/workeradapter.d.ts +4 -4
- package/lib/cache/adapters/workeradapter.js +10 -5
- package/lib/cache/index.d.ts +4 -5
- package/lib/cache/index.js +4 -3
- package/lib/cache/resources/default/base.d.ts +11 -10
- package/lib/cache/resources/default/guild-based.d.ts +8 -7
- package/lib/cache/resources/default/guild-based.js +8 -7
- package/lib/cache/resources/default/guild-related.d.ts +10 -9
- package/lib/cache/resources/default/guild-related.js +3 -2
- package/lib/cache/resources/guilds.js +2 -1
- package/lib/cache/resources/overwrites.d.ts +1 -1
- package/lib/cache/resources/overwrites.js +7 -1
- package/lib/client/base.d.ts +33 -179
- package/lib/client/base.js +56 -21
- package/lib/client/client.d.ts +10 -3
- package/lib/client/client.js +23 -8
- package/lib/client/oninteractioncreate.js +9 -9
- package/lib/client/onmessagecreate.js +192 -153
- package/lib/client/workerclient.d.ts +9 -3
- package/lib/client/workerclient.js +50 -23
- package/lib/collection.js +2 -2
- package/lib/commands/applications/chat.d.ts +16 -8
- package/lib/commands/applications/chat.js +20 -13
- package/lib/commands/applications/chatcontext.d.ts +6 -4
- package/lib/commands/applications/chatcontext.js +6 -1
- package/lib/commands/applications/menu.d.ts +5 -1
- package/lib/commands/applications/menu.js +11 -5
- package/lib/commands/applications/menucontext.d.ts +5 -3
- package/lib/commands/applications/menucontext.js +7 -2
- package/lib/commands/applications/options.d.ts +1 -2
- package/lib/commands/applications/shared.d.ts +5 -4
- package/lib/commands/decorators.d.ts +18 -6
- package/lib/commands/decorators.js +18 -8
- package/lib/commands/handler.d.ts +11 -5
- package/lib/commands/handler.js +46 -37
- package/lib/commands/optionresolver.d.ts +11 -4
- package/lib/commands/optionresolver.js +6 -4
- package/lib/common/index.d.ts +7 -0
- package/lib/common/index.js +7 -0
- package/lib/common/it/utils.d.ts +1 -0
- package/lib/common/it/utils.js +4 -1
- package/lib/common/shorters/channels.d.ts +67 -129
- package/lib/common/shorters/channels.js +119 -135
- package/lib/common/shorters/emojis.d.ts +47 -0
- package/lib/common/shorters/emojis.js +80 -0
- package/lib/common/shorters/guilds.d.ts +22 -249
- package/lib/common/shorters/guilds.js +51 -140
- package/lib/common/shorters/members.d.ts +82 -108
- package/lib/common/shorters/members.js +151 -166
- package/lib/common/shorters/messages.d.ts +11 -23
- package/lib/common/shorters/messages.js +58 -104
- package/lib/common/shorters/reactions.d.ts +10 -0
- package/lib/common/shorters/reactions.js +45 -0
- package/lib/common/shorters/roles.d.ts +39 -7
- package/lib/common/shorters/roles.js +74 -42
- package/lib/common/shorters/templates.d.ts +6 -8
- package/lib/common/shorters/templates.js +17 -21
- package/lib/common/shorters/users.d.ts +4 -6
- package/lib/common/shorters/users.js +29 -33
- package/lib/common/shorters/webhook.d.ts +62 -26
- package/lib/common/shorters/webhook.js +113 -58
- package/lib/common/types/options.d.ts +2 -2
- package/lib/common/types/util.d.ts +3 -0
- package/lib/components/handler.d.ts +28 -9
- package/lib/components/handler.js +28 -11
- package/lib/events/handler.d.ts +10 -2
- package/lib/events/handler.js +6 -8
- package/lib/index.d.ts +4 -2
- package/lib/index.js +1 -1
- package/lib/langs/handler.d.ts +8 -0
- package/lib/langs/handler.js +8 -2
- package/lib/structures/AutoModerationRule.d.ts +2 -2
- package/lib/structures/ClientUser.d.ts +2 -2
- package/lib/structures/Guild.d.ts +2 -2
- package/lib/structures/GuildEmoji.d.ts +4 -4
- package/lib/structures/GuildEmoji.js +7 -7
- package/lib/structures/GuildMember.d.ts +7 -6
- package/lib/structures/GuildMember.js +5 -2
- package/lib/structures/GuildPreview.d.ts +2 -2
- package/lib/structures/GuildRole.d.ts +2 -2
- package/lib/structures/GuildTemplate.d.ts +2 -2
- package/lib/structures/Interaction.d.ts +9 -10
- package/lib/structures/Interaction.js +2 -2
- package/lib/structures/Message.d.ts +8 -7
- package/lib/structures/Message.js +7 -4
- package/lib/structures/Sticker.d.ts +2 -2
- package/lib/structures/User.d.ts +1 -0
- package/lib/structures/User.js +5 -0
- package/lib/structures/Webhook.d.ts +2 -2
- package/lib/structures/Webhook.js +3 -3
- package/lib/structures/channels.d.ts +21 -22
- package/lib/structures/channels.js +13 -25
- package/lib/structures/extra/Base.d.ts +1 -2
- package/lib/structures/extra/DiscordBase.d.ts +2 -2
- package/lib/websocket/constants/index.js +1 -0
- package/lib/websocket/discord/shard.js +4 -2
- package/lib/websocket/discord/sharder.d.ts +3 -0
- package/lib/websocket/discord/sharder.js +12 -5
- package/lib/websocket/discord/shared.d.ts +1 -0
- package/lib/websocket/discord/worker.d.ts +2 -1
- package/lib/websocket/discord/workermanager.d.ts +8 -3
- package/lib/websocket/discord/workermanager.js +78 -30
- package/package.json +8 -6
|
@@ -12,7 +12,19 @@ const websocket_1 = require("../websocket");
|
|
|
12
12
|
const base_1 = require("./base");
|
|
13
13
|
const oninteractioncreate_1 = require("./oninteractioncreate");
|
|
14
14
|
const onmessagecreate_1 = require("./onmessagecreate");
|
|
15
|
-
|
|
15
|
+
let workerData;
|
|
16
|
+
try {
|
|
17
|
+
workerData = {
|
|
18
|
+
debug: process.env.SEYFERT_WORKER_DEBUG === 'true',
|
|
19
|
+
intents: Number.parseInt(process.env.SEYFERT_WORKER_INTENTS),
|
|
20
|
+
path: process.env.SEYFERT_WORKER_PATH,
|
|
21
|
+
shards: process.env.SEYFERT_WORKER_SHARDS.split(',').map(id => Number.parseInt(id)),
|
|
22
|
+
token: process.env.SEYFERT_WORKER_TOKEN,
|
|
23
|
+
workerId: Number.parseInt(process.env.SEYFERT_WORKER_WORKERID),
|
|
24
|
+
workerProxy: process.env.SEYFERT_WORKER_WORKERPROXY === 'true',
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
catch { }
|
|
16
28
|
class WorkerClient extends base_1.BaseClient {
|
|
17
29
|
__handleGuilds = new Set();
|
|
18
30
|
logger = new common_1.Logger({
|
|
@@ -24,13 +36,17 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
24
36
|
shards = new Map();
|
|
25
37
|
constructor(options) {
|
|
26
38
|
super(options);
|
|
27
|
-
if (!
|
|
39
|
+
if (!process.env.SEYFERT_SPAWNING) {
|
|
28
40
|
throw new Error('WorkerClient cannot spawn without manager');
|
|
29
41
|
}
|
|
30
|
-
|
|
42
|
+
this.postMessage({
|
|
43
|
+
type: 'WORKER_START',
|
|
44
|
+
workerId: workerData.workerId,
|
|
45
|
+
});
|
|
46
|
+
(node_worker_threads_1.parentPort ?? process).on('message', (data) => this.handleManagerMessages(data));
|
|
31
47
|
this.setServices({
|
|
32
48
|
cache: {
|
|
33
|
-
adapter: new cache_1.WorkerAdapter(
|
|
49
|
+
adapter: new cache_1.WorkerAdapter(workerData),
|
|
34
50
|
disabledCache: options?.disabledCache,
|
|
35
51
|
},
|
|
36
52
|
});
|
|
@@ -58,6 +74,12 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
58
74
|
this.shards.forEach(s => (acc += s.latency));
|
|
59
75
|
return acc / this.shards.size;
|
|
60
76
|
}
|
|
77
|
+
setServices({ ...rest }) {
|
|
78
|
+
super.setServices(rest);
|
|
79
|
+
if (rest.handlers && 'events' in rest.handlers) {
|
|
80
|
+
this.events = rest.handlers.events;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
61
83
|
async start(options = {}) {
|
|
62
84
|
await super.start(options);
|
|
63
85
|
await this.loadEvents(options.eventsDir);
|
|
@@ -65,11 +87,16 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
65
87
|
}
|
|
66
88
|
async loadEvents(dir) {
|
|
67
89
|
dir ??= await this.getRC().then(x => x.events);
|
|
68
|
-
if (dir) {
|
|
90
|
+
if (dir && this.events) {
|
|
69
91
|
await this.events.load(dir);
|
|
70
92
|
this.logger.info('EventHandler loaded');
|
|
71
93
|
}
|
|
72
94
|
}
|
|
95
|
+
postMessage(body) {
|
|
96
|
+
if (node_worker_threads_1.parentPort)
|
|
97
|
+
return node_worker_threads_1.parentPort.postMessage(body);
|
|
98
|
+
return process.send(body);
|
|
99
|
+
}
|
|
73
100
|
async handleManagerMessages(data) {
|
|
74
101
|
switch (data.type) {
|
|
75
102
|
case 'CACHE_RESULT':
|
|
@@ -90,7 +117,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
90
117
|
await shard.send(0, {
|
|
91
118
|
...data,
|
|
92
119
|
});
|
|
93
|
-
|
|
120
|
+
this.postMessage({
|
|
94
121
|
type: 'RESULT_PAYLOAD',
|
|
95
122
|
nonce: data.nonce,
|
|
96
123
|
workerId: this.workerId,
|
|
@@ -110,9 +137,9 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
110
137
|
break;
|
|
111
138
|
case 'SPAWN_SHARDS':
|
|
112
139
|
{
|
|
113
|
-
const cache = this.cache;
|
|
114
140
|
const onPacket = this.onPacket.bind(this);
|
|
115
141
|
const handlePayload = this.options?.handlePayload?.bind(this);
|
|
142
|
+
const self = this;
|
|
116
143
|
for (const id of workerData.shards) {
|
|
117
144
|
let shard = this.shards.get(id);
|
|
118
145
|
if (!shard) {
|
|
@@ -124,9 +151,9 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
124
151
|
debugger: this.debugger,
|
|
125
152
|
async handlePayload(shardId, payload) {
|
|
126
153
|
await handlePayload?.(shardId, payload);
|
|
127
|
-
await cache.onPacket(payload);
|
|
154
|
+
await self.cache.onPacket(payload);
|
|
128
155
|
await onPacket?.(payload, shardId);
|
|
129
|
-
|
|
156
|
+
self.postMessage({
|
|
130
157
|
workerId: workerData.workerId,
|
|
131
158
|
shardId,
|
|
132
159
|
type: 'RECEIVE_PAYLOAD',
|
|
@@ -136,7 +163,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
136
163
|
});
|
|
137
164
|
this.shards.set(id, shard);
|
|
138
165
|
}
|
|
139
|
-
|
|
166
|
+
this.postMessage({
|
|
140
167
|
type: 'CONNECT_QUEUE',
|
|
141
168
|
shardId: id,
|
|
142
169
|
workerId: workerData.workerId,
|
|
@@ -151,7 +178,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
151
178
|
this.logger.fatal('Worker trying get non-existent shard');
|
|
152
179
|
return;
|
|
153
180
|
}
|
|
154
|
-
|
|
181
|
+
this.postMessage({
|
|
155
182
|
...generateShardInfo(shard),
|
|
156
183
|
nonce: data.nonce,
|
|
157
184
|
type: 'SHARD_INFO',
|
|
@@ -161,7 +188,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
161
188
|
break;
|
|
162
189
|
case 'WORKER_INFO':
|
|
163
190
|
{
|
|
164
|
-
|
|
191
|
+
this.postMessage({
|
|
165
192
|
shards: [...this.shards.values()].map(generateShardInfo),
|
|
166
193
|
workerId: workerData.workerId,
|
|
167
194
|
type: 'WORKER_INFO',
|
|
@@ -170,7 +197,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
170
197
|
}
|
|
171
198
|
break;
|
|
172
199
|
case 'BOT_READY':
|
|
173
|
-
await this.events
|
|
200
|
+
await this.events?.runEvent('BOT_READY', this, this.me, -1);
|
|
174
201
|
break;
|
|
175
202
|
case 'API_RESPONSE':
|
|
176
203
|
{
|
|
@@ -195,7 +222,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
195
222
|
catch (e) {
|
|
196
223
|
result = e;
|
|
197
224
|
}
|
|
198
|
-
|
|
225
|
+
this.postMessage({
|
|
199
226
|
type: 'EVAL_RESPONSE',
|
|
200
227
|
response: result,
|
|
201
228
|
workerId: workerData.workerId,
|
|
@@ -239,7 +266,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
239
266
|
}
|
|
240
267
|
tellWorker(workerId, func) {
|
|
241
268
|
const nonce = this.generateNonce();
|
|
242
|
-
|
|
269
|
+
this.postMessage({
|
|
243
270
|
type: 'EVAL',
|
|
244
271
|
func: func.toString(),
|
|
245
272
|
toWorkerId: workerId,
|
|
@@ -249,14 +276,14 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
249
276
|
return this.generateSendPromise(nonce);
|
|
250
277
|
}
|
|
251
278
|
async onPacket(packet, shardId) {
|
|
252
|
-
await this.events
|
|
279
|
+
await this.events?.execute('RAW', packet, this, shardId);
|
|
253
280
|
switch (packet.t) {
|
|
254
281
|
case 'GUILD_MEMBER_UPDATE':
|
|
255
|
-
await this.events
|
|
282
|
+
await this.events?.execute(packet.t, packet, this, shardId);
|
|
256
283
|
await this.cache.onPacket(packet);
|
|
257
284
|
break;
|
|
258
285
|
case 'PRESENCE_UPDATE':
|
|
259
|
-
await this.events
|
|
286
|
+
await this.events?.execute(packet.t, packet, this, shardId);
|
|
260
287
|
await this.cache.onPacket(packet);
|
|
261
288
|
break;
|
|
262
289
|
//rest of the events
|
|
@@ -273,11 +300,11 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
273
300
|
if (!this.__handleGuilds?.size ||
|
|
274
301
|
!((workerData.intents & common_1.GatewayIntentBits.Guilds) === common_1.GatewayIntentBits.Guilds)) {
|
|
275
302
|
if ([...this.shards.values()].every(shard => shard.data.session_id)) {
|
|
276
|
-
|
|
303
|
+
this.postMessage({
|
|
277
304
|
type: 'WORKER_READY',
|
|
278
305
|
workerId: this.workerId,
|
|
279
306
|
});
|
|
280
|
-
await this.events
|
|
307
|
+
await this.events?.runEvent('WORKER_READY', this, this.me, -1);
|
|
281
308
|
}
|
|
282
309
|
delete this.__handleGuilds;
|
|
283
310
|
}
|
|
@@ -293,11 +320,11 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
293
320
|
if (this.__handleGuilds?.has(packet.d.id)) {
|
|
294
321
|
this.__handleGuilds.delete(packet.d.id);
|
|
295
322
|
if (!this.__handleGuilds.size && [...this.shards.values()].every(shard => shard.data.session_id)) {
|
|
296
|
-
|
|
323
|
+
this.postMessage({
|
|
297
324
|
type: 'WORKER_READY',
|
|
298
325
|
workerId: this.workerId,
|
|
299
326
|
});
|
|
300
|
-
await this.events
|
|
327
|
+
await this.events?.runEvent('WORKER_READY', this, this.me, -1);
|
|
301
328
|
}
|
|
302
329
|
if (!this.__handleGuilds.size)
|
|
303
330
|
delete this.__handleGuilds;
|
|
@@ -305,7 +332,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
305
332
|
}
|
|
306
333
|
}
|
|
307
334
|
}
|
|
308
|
-
await this.events
|
|
335
|
+
await this.events?.execute(packet.t, packet, this, shardId);
|
|
309
336
|
}
|
|
310
337
|
break;
|
|
311
338
|
}
|
package/lib/collection.js
CHANGED
|
@@ -197,7 +197,7 @@ exports.Collection = Collection;
|
|
|
197
197
|
class LimitedCollection {
|
|
198
198
|
static default = {
|
|
199
199
|
resetOnDemand: false,
|
|
200
|
-
limit:
|
|
200
|
+
limit: Number.POSITIVE_INFINITY,
|
|
201
201
|
expire: 0,
|
|
202
202
|
};
|
|
203
203
|
data = new Map();
|
|
@@ -233,7 +233,7 @@ class LimitedCollection {
|
|
|
233
233
|
this.delete(iter.next().value);
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
|
-
if (this.closer
|
|
236
|
+
if (this.closer?.expireOn === expireOn) {
|
|
237
237
|
this.resetTimeout();
|
|
238
238
|
}
|
|
239
239
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { SeyfertNumberOption, SeyfertStringOption } from '../..';
|
|
2
2
|
import type { Attachment } from '../../builders';
|
|
3
|
-
import type { APIApplicationCommandBasicOption, APIApplicationCommandOption, LocaleString, PermissionStrings } from '../../common';
|
|
3
|
+
import type { APIApplicationCommandBasicOption, APIApplicationCommandOption, FlatObjectKeys, LocaleString, PermissionStrings } from '../../common';
|
|
4
4
|
import { ApplicationCommandOptionType, ApplicationCommandType } from '../../common';
|
|
5
5
|
import type { AllChannels, AutocompleteInteraction, GuildRole, InteractionGuildMember, User } from '../../structures';
|
|
6
|
-
import type { Groups, RegisteredMiddlewares } from '../decorators';
|
|
6
|
+
import type { Groups, IntegrationTypes, InteractionContextTypes, RegisteredMiddlewares } from '../decorators';
|
|
7
7
|
import type { CommandContext } from './chatcontext';
|
|
8
|
-
import type { OKFunction, OnOptionsReturnObject, StopFunction, UsingClient } from './shared';
|
|
8
|
+
import type { DefaultLocale, OKFunction, OnOptionsReturnObject, StopFunction, UsingClient } from './shared';
|
|
9
9
|
export interface ReturnOptionsTypes {
|
|
10
10
|
1: never;
|
|
11
11
|
2: never;
|
|
@@ -29,6 +29,10 @@ type Wrap<N extends ApplicationCommandOptionType> = N extends ApplicationCommand
|
|
|
29
29
|
description: string;
|
|
30
30
|
description_localizations?: APIApplicationCommandBasicOption['description_localizations'];
|
|
31
31
|
name_localizations?: APIApplicationCommandBasicOption['name_localizations'];
|
|
32
|
+
locales?: {
|
|
33
|
+
name?: FlatObjectKeys<DefaultLocale>;
|
|
34
|
+
description?: FlatObjectKeys<DefaultLocale>;
|
|
35
|
+
};
|
|
32
36
|
};
|
|
33
37
|
export type __TypeWrapper<T extends ApplicationCommandOptionType> = Wrap<T>;
|
|
34
38
|
export type __TypesWrapper = {
|
|
@@ -67,7 +71,7 @@ declare class BaseCommand {
|
|
|
67
71
|
name: string | undefined;
|
|
68
72
|
description: string | undefined;
|
|
69
73
|
};
|
|
70
|
-
|
|
74
|
+
__autoload?: true;
|
|
71
75
|
__tGroups?: Record<string, {
|
|
72
76
|
name: string | undefined;
|
|
73
77
|
description: string | undefined;
|
|
@@ -79,8 +83,9 @@ declare class BaseCommand {
|
|
|
79
83
|
nsfw?: boolean;
|
|
80
84
|
description: string;
|
|
81
85
|
default_member_permissions?: string;
|
|
86
|
+
integration_types?: IntegrationTypes[];
|
|
87
|
+
contexts?: InteractionContextTypes[];
|
|
82
88
|
botPermissions?: bigint;
|
|
83
|
-
dm?: boolean;
|
|
84
89
|
name_localizations?: Partial<Record<LocaleString, string>>;
|
|
85
90
|
description_localizations?: Partial<Record<LocaleString, string>>;
|
|
86
91
|
options?: CommandOption[] | SubCommand[];
|
|
@@ -93,7 +98,8 @@ declare class BaseCommand {
|
|
|
93
98
|
description_localizations: BaseCommand['description_localizations'];
|
|
94
99
|
guild_id: BaseCommand['guild_id'];
|
|
95
100
|
default_member_permissions: BaseCommand['default_member_permissions'];
|
|
96
|
-
|
|
101
|
+
contexts: BaseCommand['contexts'];
|
|
102
|
+
integration_types: BaseCommand['integration_types'];
|
|
97
103
|
};
|
|
98
104
|
reload(): Promise<void>;
|
|
99
105
|
run?(context: CommandContext<any>): any;
|
|
@@ -117,7 +123,8 @@ export declare class Command extends BaseCommand {
|
|
|
117
123
|
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;
|
|
118
124
|
guild_id: string[] | undefined;
|
|
119
125
|
default_member_permissions: string | undefined;
|
|
120
|
-
|
|
126
|
+
contexts: InteractionContextTypes[] | undefined;
|
|
127
|
+
integration_types: IntegrationTypes[] | undefined;
|
|
121
128
|
};
|
|
122
129
|
onRunError(context: CommandContext<any>, error: unknown): any;
|
|
123
130
|
onOptionsError(context: CommandContext<{}, never>, metadata: OnOptionsReturnObject): any;
|
|
@@ -139,7 +146,8 @@ export declare abstract class SubCommand extends BaseCommand {
|
|
|
139
146
|
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;
|
|
140
147
|
guild_id: string[] | undefined;
|
|
141
148
|
default_member_permissions: string | undefined;
|
|
142
|
-
|
|
149
|
+
contexts: InteractionContextTypes[] | undefined;
|
|
150
|
+
integration_types: IntegrationTypes[] | undefined;
|
|
143
151
|
};
|
|
144
152
|
abstract run(context: CommandContext<any>): any;
|
|
145
153
|
}
|
|
@@ -6,7 +6,7 @@ class BaseCommand {
|
|
|
6
6
|
middlewares = [];
|
|
7
7
|
__filePath;
|
|
8
8
|
__t;
|
|
9
|
-
|
|
9
|
+
__autoload;
|
|
10
10
|
__tGroups;
|
|
11
11
|
guild_id;
|
|
12
12
|
name;
|
|
@@ -14,22 +14,22 @@ class BaseCommand {
|
|
|
14
14
|
nsfw;
|
|
15
15
|
description;
|
|
16
16
|
default_member_permissions;
|
|
17
|
+
integration_types;
|
|
18
|
+
contexts;
|
|
17
19
|
botPermissions;
|
|
18
|
-
dm;
|
|
19
20
|
name_localizations;
|
|
20
21
|
description_localizations;
|
|
21
22
|
options;
|
|
22
23
|
/** @internal */
|
|
23
24
|
async __runOptions(ctx, resolver) {
|
|
24
|
-
|
|
25
|
-
if (!command?.options?.length) {
|
|
25
|
+
if (!this?.options?.length) {
|
|
26
26
|
return [false, {}];
|
|
27
27
|
}
|
|
28
28
|
const data = {};
|
|
29
29
|
let errored = false;
|
|
30
|
-
for (const i of
|
|
30
|
+
for (const i of this.options ?? []) {
|
|
31
31
|
try {
|
|
32
|
-
const option =
|
|
32
|
+
const option = this.options.find(x => x.name === i.name);
|
|
33
33
|
const value = resolver.getHoisted(i.name)?.value !== undefined
|
|
34
34
|
? await new Promise((res, rej) => option.value?.({ context: ctx, value: resolver.getValue(i.name) }, res, rej) ||
|
|
35
35
|
res(resolver.getValue(i.name)))
|
|
@@ -76,19 +76,21 @@ class BaseCommand {
|
|
|
76
76
|
running = false;
|
|
77
77
|
return res({ pass: true });
|
|
78
78
|
};
|
|
79
|
-
|
|
79
|
+
function next(obj) {
|
|
80
80
|
if (!running) {
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
// biome-ignore lint/style/noArguments: yes
|
|
84
|
+
if (arguments.length) {
|
|
85
|
+
// @ts-expect-error
|
|
86
|
+
context[global ? 'globalMetadata' : 'metadata'][middlewares[index]] = obj;
|
|
87
|
+
}
|
|
86
88
|
if (++index >= middlewares.length) {
|
|
87
89
|
running = false;
|
|
88
90
|
return res({});
|
|
89
91
|
}
|
|
90
92
|
context.client.middlewares[middlewares[index]]({ context, next, stop, pass });
|
|
91
|
-
}
|
|
93
|
+
}
|
|
92
94
|
const stop = err => {
|
|
93
95
|
if (!running) {
|
|
94
96
|
return;
|
|
@@ -117,15 +119,20 @@ class BaseCommand {
|
|
|
117
119
|
description_localizations: this.description_localizations,
|
|
118
120
|
guild_id: this.guild_id,
|
|
119
121
|
default_member_permissions: this.default_member_permissions,
|
|
122
|
+
contexts: this.contexts,
|
|
123
|
+
integration_types: this.integration_types,
|
|
120
124
|
};
|
|
121
|
-
if ('dm' in this)
|
|
122
|
-
data.dm_permission = this.dm;
|
|
123
125
|
return data;
|
|
124
126
|
}
|
|
125
127
|
async reload() {
|
|
126
128
|
delete require.cache[this.__filePath];
|
|
127
129
|
const __tempCommand = await (0, common_1.magicImport)(this.__filePath).then(x => x.default ?? x);
|
|
128
130
|
Object.setPrototypeOf(this, __tempCommand.prototype);
|
|
131
|
+
for (const i of this.options ?? []) {
|
|
132
|
+
if (i instanceof SubCommand && i.__filePath) {
|
|
133
|
+
await i.reload();
|
|
134
|
+
}
|
|
135
|
+
}
|
|
129
136
|
}
|
|
130
137
|
}
|
|
131
138
|
class Command extends BaseCommand {
|
|
@@ -4,18 +4,19 @@ import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest
|
|
|
4
4
|
import { Message, type ChatInputCommandInteraction, type GuildMember, type InteractionGuildMember } from '../../structures';
|
|
5
5
|
import type { RegisteredMiddlewares } from '../decorators';
|
|
6
6
|
import type { OptionResolver } from '../optionresolver';
|
|
7
|
-
import type { ContextOptions, OptionsRecord } from './chat';
|
|
7
|
+
import type { Command, ContextOptions, OptionsRecord, SubCommand } from './chat';
|
|
8
8
|
import type { CommandMetadata, ExtendContext, GlobalMetadata, UsingClient } from './shared';
|
|
9
9
|
export interface CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never> extends ExtendContext {
|
|
10
10
|
}
|
|
11
11
|
export declare class CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never> {
|
|
12
12
|
readonly client: UsingClient;
|
|
13
|
-
resolver: OptionResolver;
|
|
13
|
+
readonly resolver: OptionResolver;
|
|
14
14
|
readonly shardId: number;
|
|
15
|
+
readonly command: Command | SubCommand;
|
|
15
16
|
message: If<InferWithPrefix, Message | undefined, undefined>;
|
|
16
17
|
interaction: If<InferWithPrefix, ChatInputCommandInteraction | undefined, ChatInputCommandInteraction>;
|
|
17
18
|
messageResponse?: If<InferWithPrefix, Message | undefined>;
|
|
18
|
-
constructor(client: UsingClient, data: ChatInputCommandInteraction | Message, resolver: OptionResolver, shardId: number);
|
|
19
|
+
constructor(client: UsingClient, data: ChatInputCommandInteraction | Message, resolver: OptionResolver, shardId: number, command: Command | SubCommand);
|
|
19
20
|
options: ContextOptions<T>;
|
|
20
21
|
metadata: CommandMetadata<UnionToTuple<M>>;
|
|
21
22
|
globalMetadata: GlobalMetadata;
|
|
@@ -23,10 +24,11 @@ export declare class CommandContext<T extends OptionsRecord = {}, M extends keyo
|
|
|
23
24
|
get t(): import("../..").__InternalParseLocale<import("./shared").DefaultLocale> & {
|
|
24
25
|
get(locale?: string | undefined): import("./shared").DefaultLocale;
|
|
25
26
|
};
|
|
27
|
+
get fullCommandName(): string;
|
|
26
28
|
write<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage | Message, void | WebhookMessage | Message>>;
|
|
27
29
|
deferReply(ephemeral?: boolean): Promise<void | Message>;
|
|
28
30
|
editResponse(body: InteractionMessageUpdateBodyRequest): Promise<Message>;
|
|
29
|
-
deleteResponse(): Promise<void>;
|
|
31
|
+
deleteResponse(): Promise<void | undefined>;
|
|
30
32
|
editOrReply<FR extends boolean = false>(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage | Message, void | WebhookMessage | Message>>;
|
|
31
33
|
fetchResponse(): Promise<If<InferWithPrefix, WebhookMessage | Message | undefined, WebhookMessage | undefined>>;
|
|
32
34
|
channel(mode?: 'rest' | 'flow'): Promise<If<InferWithPrefix, AllChannels | undefined, AllChannels>>;
|
|
@@ -8,13 +8,15 @@ class CommandContext {
|
|
|
8
8
|
client;
|
|
9
9
|
resolver;
|
|
10
10
|
shardId;
|
|
11
|
+
command;
|
|
11
12
|
message;
|
|
12
13
|
interaction;
|
|
13
14
|
messageResponse;
|
|
14
|
-
constructor(client, data, resolver, shardId) {
|
|
15
|
+
constructor(client, data, resolver, shardId, command) {
|
|
15
16
|
this.client = client;
|
|
16
17
|
this.resolver = resolver;
|
|
17
18
|
this.shardId = shardId;
|
|
19
|
+
this.command = command;
|
|
18
20
|
if (data instanceof structures_1.Message) {
|
|
19
21
|
this.message = data;
|
|
20
22
|
}
|
|
@@ -31,6 +33,9 @@ class CommandContext {
|
|
|
31
33
|
get t() {
|
|
32
34
|
return this.client.langs.get(this.interaction?.locale ?? this.client.langs.defaultLang ?? 'en-US');
|
|
33
35
|
}
|
|
36
|
+
get fullCommandName() {
|
|
37
|
+
return this.resolver.fullCommandName;
|
|
38
|
+
}
|
|
34
39
|
async write(body, fetchReply) {
|
|
35
40
|
if (this.interaction)
|
|
36
41
|
return this.interaction.write(body, fetchReply);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ApplicationCommandType, type LocaleString, type PermissionStrings } from '../../common';
|
|
2
|
-
import type { RegisteredMiddlewares } from '../decorators';
|
|
2
|
+
import type { IntegrationTypes, InteractionContextTypes, RegisteredMiddlewares } from '../decorators';
|
|
3
3
|
import type { MenuCommandContext } from './menucontext';
|
|
4
4
|
import type { UsingClient } from './shared';
|
|
5
5
|
export declare abstract class ContextMenuCommand {
|
|
@@ -13,6 +13,8 @@ export declare abstract class ContextMenuCommand {
|
|
|
13
13
|
name: string;
|
|
14
14
|
type: ApplicationCommandType.User | ApplicationCommandType.Message;
|
|
15
15
|
nsfw?: boolean;
|
|
16
|
+
integration_types?: IntegrationTypes[];
|
|
17
|
+
contexts?: InteractionContextTypes[];
|
|
16
18
|
description: string;
|
|
17
19
|
default_member_permissions?: string;
|
|
18
20
|
botPermissions?: bigint;
|
|
@@ -29,6 +31,8 @@ export declare abstract class ContextMenuCommand {
|
|
|
29
31
|
guild_id: string[] | undefined;
|
|
30
32
|
dm_permission: boolean | undefined;
|
|
31
33
|
default_member_permissions: string | undefined;
|
|
34
|
+
contexts: InteractionContextTypes[] | undefined;
|
|
35
|
+
integration_types: IntegrationTypes[] | undefined;
|
|
32
36
|
};
|
|
33
37
|
reload(): Promise<void>;
|
|
34
38
|
abstract run?(context: MenuCommandContext<any>): any;
|
|
@@ -10,6 +10,8 @@ class ContextMenuCommand {
|
|
|
10
10
|
name;
|
|
11
11
|
type;
|
|
12
12
|
nsfw;
|
|
13
|
+
integration_types;
|
|
14
|
+
contexts;
|
|
13
15
|
description;
|
|
14
16
|
default_member_permissions;
|
|
15
17
|
botPermissions;
|
|
@@ -31,19 +33,21 @@ class ContextMenuCommand {
|
|
|
31
33
|
running = false;
|
|
32
34
|
return res({ pass: true });
|
|
33
35
|
};
|
|
34
|
-
|
|
36
|
+
function next(obj) {
|
|
35
37
|
if (!running) {
|
|
36
38
|
return;
|
|
37
39
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
// biome-ignore lint/style/noArguments: yes
|
|
41
|
+
if (arguments.length) {
|
|
42
|
+
// @ts-expect-error
|
|
43
|
+
context[global ? 'globalMetadata' : 'metadata'][middlewares[index]] = obj;
|
|
44
|
+
}
|
|
41
45
|
if (++index >= middlewares.length) {
|
|
42
46
|
running = false;
|
|
43
47
|
return res({});
|
|
44
48
|
}
|
|
45
49
|
context.client.middlewares[middlewares[index]]({ context, next, stop, pass });
|
|
46
|
-
}
|
|
50
|
+
}
|
|
47
51
|
const stop = err => {
|
|
48
52
|
if (!running) {
|
|
49
53
|
return;
|
|
@@ -73,6 +77,8 @@ class ContextMenuCommand {
|
|
|
73
77
|
guild_id: this.guild_id,
|
|
74
78
|
dm_permission: this.dm,
|
|
75
79
|
default_member_permissions: this.default_member_permissions,
|
|
80
|
+
contexts: this.contexts,
|
|
81
|
+
integration_types: this.integration_types,
|
|
76
82
|
};
|
|
77
83
|
}
|
|
78
84
|
async reload() {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandContext, type ReturnCache, type WebhookMessage } from '../..';
|
|
1
|
+
import { CommandContext, type ContextMenuCommand, type ReturnCache, type WebhookMessage } from '../..';
|
|
2
2
|
import { type InteractionCreateBodyRequest, type InteractionMessageUpdateBodyRequest, type UnionToTuple, type When } from '../../common';
|
|
3
3
|
import { Message, User, type AllChannels, type Guild, type GuildMember, type MessageCommandInteraction, type UserCommandInteraction } from '../../structures';
|
|
4
4
|
import type { RegisteredMiddlewares } from '../decorators';
|
|
@@ -10,7 +10,8 @@ export declare class MenuCommandContext<T extends MessageCommandInteraction | Us
|
|
|
10
10
|
readonly client: UsingClient;
|
|
11
11
|
readonly interaction: T;
|
|
12
12
|
readonly shardId: number;
|
|
13
|
-
|
|
13
|
+
readonly command: ContextMenuCommand;
|
|
14
|
+
constructor(client: UsingClient, interaction: T, shardId: number, command: ContextMenuCommand);
|
|
14
15
|
metadata: CommandMetadata<UnionToTuple<M>>;
|
|
15
16
|
globalMetadata: GlobalMetadata;
|
|
16
17
|
get proxy(): import("../..").APIRoutes;
|
|
@@ -18,11 +19,12 @@ export declare class MenuCommandContext<T extends MessageCommandInteraction | Us
|
|
|
18
19
|
get t(): import("../..").__InternalParseLocale<import("./shared").DefaultLocale> & {
|
|
19
20
|
get(locale?: string | undefined): import("./shared").DefaultLocale;
|
|
20
21
|
};
|
|
22
|
+
get fullCommandName(): string;
|
|
21
23
|
write<FR extends boolean = false>(body: InteractionCreateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage, void | WebhookMessage>>;
|
|
22
24
|
get modal(): ((body: import("../../common").ModalCreateBodyRequest) => Promise<void>) | ((body: import("../../common").ModalCreateBodyRequest) => Promise<void>);
|
|
23
25
|
deferReply(ephemeral?: boolean): Promise<void>;
|
|
24
26
|
editResponse(body: InteractionMessageUpdateBodyRequest): Promise<Message>;
|
|
25
|
-
deleteResponse(): Promise<void>;
|
|
27
|
+
deleteResponse(): Promise<void | undefined>;
|
|
26
28
|
editOrReply<FR extends boolean = false>(body: InteractionCreateBodyRequest | InteractionMessageUpdateBodyRequest, fetchReply?: FR): Promise<When<FR, WebhookMessage | Message, void | WebhookMessage | Message>>;
|
|
27
29
|
fetchResponse(): Promise<WebhookMessage | undefined>;
|
|
28
30
|
channel(mode?: 'rest' | 'flow'): Promise<AllChannels>;
|
|
@@ -8,10 +8,12 @@ class MenuCommandContext {
|
|
|
8
8
|
client;
|
|
9
9
|
interaction;
|
|
10
10
|
shardId;
|
|
11
|
-
|
|
11
|
+
command;
|
|
12
|
+
constructor(client, interaction, shardId, command) {
|
|
12
13
|
this.client = client;
|
|
13
14
|
this.interaction = interaction;
|
|
14
15
|
this.shardId = shardId;
|
|
16
|
+
this.command = command;
|
|
15
17
|
}
|
|
16
18
|
metadata = {};
|
|
17
19
|
globalMetadata = {};
|
|
@@ -32,7 +34,10 @@ class MenuCommandContext {
|
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
get t() {
|
|
35
|
-
return this.client.langs.get(this.interaction.locale);
|
|
37
|
+
return this.client.langs.get(this.interaction.locale ?? this.client.langs.defaultLang ?? 'en-US');
|
|
38
|
+
}
|
|
39
|
+
get fullCommandName() {
|
|
40
|
+
return this.command.name;
|
|
36
41
|
}
|
|
37
42
|
write(body, fetchReply) {
|
|
38
43
|
return this.interaction.write(body, fetchReply);
|
|
@@ -63,5 +63,4 @@ export declare function createNumberOption<T extends SeyfertNumberOption = Seyfe
|
|
|
63
63
|
export declare function createAttachmentOption<T extends SeyfertAttachmentOption = SeyfertAttachmentOption>(data: T): T & {
|
|
64
64
|
readonly type: ApplicationCommandOptionType.Attachment;
|
|
65
65
|
};
|
|
66
|
-
export
|
|
67
|
-
export declare function createMiddleware<T = ParseMiddlewareType<unknown>>(data: ParseMiddlewareType<T>): ParseMiddlewareType<T>;
|
|
66
|
+
export declare function createMiddleware<T = any, C extends CommandContext | MenuCommandContext<MessageCommandInteraction<boolean> | UserCommandInteraction<boolean>> = CommandContext | MenuCommandContext<MessageCommandInteraction<boolean> | UserCommandInteraction<boolean>>>(data: MiddlewareContext<T, C>): MiddlewareContext<T, C>;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { BaseClient } from '../../client/base';
|
|
2
|
+
import type { IsStrictlyUndefined } from '../../common';
|
|
2
3
|
import type { RegisteredMiddlewares } from '../decorators';
|
|
3
4
|
export type OKFunction<T> = (value: T) => void;
|
|
4
5
|
export type StopFunction = (error: string) => void;
|
|
5
|
-
export type NextFunction<T = unknown> = (data: T) => void;
|
|
6
|
+
export type NextFunction<T = unknown> = IsStrictlyUndefined<T> extends true ? () => void : (data: T) => void;
|
|
6
7
|
export type PassFunction = () => void;
|
|
7
8
|
export type InferWithPrefix = InternalOptions extends {
|
|
8
9
|
withPrefix: infer P;
|
|
@@ -24,13 +25,13 @@ export type MiddlewareContext<T = any, C = any> = (context: {
|
|
|
24
25
|
stop: StopFunction;
|
|
25
26
|
pass: PassFunction;
|
|
26
27
|
}) => any;
|
|
27
|
-
export type MetadataMiddleware<T extends MiddlewareContext> = Parameters<Parameters<T>[0]['next']>[0];
|
|
28
|
+
export type MetadataMiddleware<T extends MiddlewareContext> = IsStrictlyUndefined<Parameters<Parameters<T>[0]['next']>[0]> extends true ? never : Parameters<Parameters<T>[0]['next']>[0];
|
|
28
29
|
export type CommandMetadata<T extends readonly (keyof RegisteredMiddlewares)[]> = T extends readonly [
|
|
29
30
|
infer first,
|
|
30
31
|
...infer rest
|
|
31
|
-
] ? first extends keyof RegisteredMiddlewares ? {
|
|
32
|
+
] ? first extends keyof RegisteredMiddlewares ? (MetadataMiddleware<RegisteredMiddlewares[first]> extends never ? {} : {
|
|
32
33
|
[key in first]: MetadataMiddleware<RegisteredMiddlewares[first]>;
|
|
33
|
-
} & (rest extends readonly (keyof RegisteredMiddlewares)[] ? CommandMetadata<rest> : {}) : {} : {};
|
|
34
|
+
}) & (rest extends readonly (keyof RegisteredMiddlewares)[] ? CommandMetadata<rest> : {}) : {} : {};
|
|
34
35
|
export type OnOptionsReturnObject = Record<string, {
|
|
35
36
|
failed: false;
|
|
36
37
|
value: unknown;
|