seyfert 1.0.0 → 1.1.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/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/api/api.d.ts +5 -0
- package/lib/api/api.js +36 -0
- package/lib/api/shared.d.ts +5 -3
- package/lib/builders/Attachment.d.ts +2 -3
- package/lib/builders/Button.d.ts +2 -2
- package/lib/cache/adapters/default.d.ts +1 -0
- package/lib/cache/adapters/default.js +1 -0
- package/lib/cache/adapters/redis.d.ts +1 -0
- package/lib/cache/adapters/redis.js +7 -0
- package/lib/cache/adapters/types.d.ts +1 -0
- package/lib/cache/adapters/workeradapter.d.ts +5 -4
- package/lib/cache/adapters/workeradapter.js +11 -5
- package/lib/cache/index.d.ts +4 -6
- package/lib/cache/index.js +5 -6
- package/lib/cache/resources/default/base.d.ts +2 -1
- package/lib/cache/resources/default/guild-based.d.ts +2 -1
- package/lib/cache/resources/default/guild-based.js +6 -6
- package/lib/cache/resources/default/guild-related.d.ts +2 -1
- package/lib/cache/resources/default/guild-related.js +1 -1
- 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 +18 -171
- package/lib/client/base.js +12 -15
- package/lib/client/client.d.ts +6 -1
- package/lib/client/client.js +13 -12
- package/lib/client/oninteractioncreate.js +4 -4
- package/lib/client/onmessagecreate.js +188 -152
- package/lib/client/workerclient.d.ts +15 -1
- package/lib/client/workerclient.js +135 -27
- package/lib/collection.js +2 -2
- package/lib/commands/applications/chat.d.ts +15 -7
- package/lib/commands/applications/chat.js +7 -7
- package/lib/commands/applications/chatcontext.d.ts +6 -4
- package/lib/commands/applications/chatcontext.js +12 -7
- package/lib/commands/applications/menu.d.ts +5 -1
- package/lib/commands/applications/menu.js +4 -0
- package/lib/commands/applications/menucontext.d.ts +5 -3
- package/lib/commands/applications/menucontext.js +9 -4
- package/lib/commands/applications/options.d.ts +1 -2
- package/lib/commands/decorators.d.ts +17 -5
- package/lib/commands/decorators.js +17 -7
- package/lib/commands/handler.d.ts +5 -5
- package/lib/commands/handler.js +40 -36
- 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.js +2 -0
- 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 -0
- package/lib/common/shorters/users.js +30 -0
- 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 +1 -1
- package/lib/components/handler.d.ts +11 -8
- package/lib/components/handler.js +34 -22
- package/lib/index.d.ts +4 -2
- package/lib/langs/handler.js +7 -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 +6 -6
- package/lib/structures/GuildMember.js +2 -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 +7 -8
- package/lib/structures/Interaction.js +1 -1
- package/lib/structures/Message.d.ts +7 -6
- package/lib/structures/Message.js +7 -4
- package/lib/structures/Sticker.d.ts +2 -2
- package/lib/structures/Webhook.d.ts +2 -2
- package/lib/structures/Webhook.js +3 -3
- package/lib/structures/channels.d.ts +19 -20
- 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 +2 -3
- 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 +3 -0
- package/lib/websocket/discord/worker.d.ts +24 -7
- package/lib/websocket/discord/workermanager.d.ts +30 -6
- package/lib/websocket/discord/workermanager.js +160 -51
- package/package.json +8 -5
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateShardInfo = exports.WorkerClient = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
4
5
|
const node_worker_threads_1 = require("node:worker_threads");
|
|
6
|
+
const __1 = require("..");
|
|
5
7
|
const cache_1 = require("../cache");
|
|
6
8
|
const common_1 = require("../common");
|
|
7
9
|
const events_1 = require("../events");
|
|
@@ -10,25 +12,41 @@ const websocket_1 = require("../websocket");
|
|
|
10
12
|
const base_1 = require("./base");
|
|
11
13
|
const oninteractioncreate_1 = require("./oninteractioncreate");
|
|
12
14
|
const onmessagecreate_1 = require("./onmessagecreate");
|
|
13
|
-
|
|
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 { }
|
|
14
28
|
class WorkerClient extends base_1.BaseClient {
|
|
15
|
-
__handleGuilds;
|
|
29
|
+
__handleGuilds = new Set();
|
|
16
30
|
logger = new common_1.Logger({
|
|
17
31
|
name: `[Worker #${workerData.workerId}]`,
|
|
18
32
|
});
|
|
19
33
|
events = new events_1.EventHandler(this.logger);
|
|
20
34
|
me;
|
|
35
|
+
promises = new Map();
|
|
21
36
|
shards = new Map();
|
|
22
37
|
constructor(options) {
|
|
23
38
|
super(options);
|
|
24
|
-
|
|
25
|
-
if (!node_worker_threads_1.parentPort) {
|
|
39
|
+
if (!process.env.SEYFERT_SPAWNING) {
|
|
26
40
|
throw new Error('WorkerClient cannot spawn without manager');
|
|
27
41
|
}
|
|
28
|
-
|
|
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));
|
|
29
47
|
this.setServices({
|
|
30
48
|
cache: {
|
|
31
|
-
adapter: new cache_1.WorkerAdapter(
|
|
49
|
+
adapter: new cache_1.WorkerAdapter(workerData),
|
|
32
50
|
disabledCache: options?.disabledCache,
|
|
33
51
|
},
|
|
34
52
|
});
|
|
@@ -38,10 +56,24 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
38
56
|
logLevel: common_1.LogLevels.Debug,
|
|
39
57
|
});
|
|
40
58
|
}
|
|
59
|
+
if (workerData.workerProxy) {
|
|
60
|
+
this.setServices({
|
|
61
|
+
rest: new __1.ApiHandler({
|
|
62
|
+
token: workerData.token,
|
|
63
|
+
workerProxy: true,
|
|
64
|
+
debug: workerData.debug,
|
|
65
|
+
}),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
41
68
|
}
|
|
42
69
|
get workerId() {
|
|
43
70
|
return workerData.workerId;
|
|
44
71
|
}
|
|
72
|
+
get latency() {
|
|
73
|
+
let acc = 0;
|
|
74
|
+
this.shards.forEach(s => (acc += s.latency));
|
|
75
|
+
return acc / this.shards.size;
|
|
76
|
+
}
|
|
45
77
|
async start(options = {}) {
|
|
46
78
|
await super.start(options);
|
|
47
79
|
await this.loadEvents(options.eventsDir);
|
|
@@ -54,6 +86,11 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
54
86
|
this.logger.info('EventHandler loaded');
|
|
55
87
|
}
|
|
56
88
|
}
|
|
89
|
+
postMessage(body) {
|
|
90
|
+
if (node_worker_threads_1.parentPort)
|
|
91
|
+
return node_worker_threads_1.parentPort.postMessage(body);
|
|
92
|
+
return process.send(body);
|
|
93
|
+
}
|
|
57
94
|
async handleManagerMessages(data) {
|
|
58
95
|
switch (data.type) {
|
|
59
96
|
case 'CACHE_RESULT':
|
|
@@ -74,9 +111,10 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
74
111
|
await shard.send(0, {
|
|
75
112
|
...data,
|
|
76
113
|
});
|
|
77
|
-
|
|
114
|
+
this.postMessage({
|
|
78
115
|
type: 'RESULT_PAYLOAD',
|
|
79
116
|
nonce: data.nonce,
|
|
117
|
+
workerId: this.workerId,
|
|
80
118
|
});
|
|
81
119
|
}
|
|
82
120
|
break;
|
|
@@ -93,9 +131,9 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
93
131
|
break;
|
|
94
132
|
case 'SPAWN_SHARDS':
|
|
95
133
|
{
|
|
96
|
-
const cache = this.cache;
|
|
97
134
|
const onPacket = this.onPacket.bind(this);
|
|
98
135
|
const handlePayload = this.options?.handlePayload?.bind(this);
|
|
136
|
+
const self = this;
|
|
99
137
|
for (const id of workerData.shards) {
|
|
100
138
|
let shard = this.shards.get(id);
|
|
101
139
|
if (!shard) {
|
|
@@ -107,9 +145,9 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
107
145
|
debugger: this.debugger,
|
|
108
146
|
async handlePayload(shardId, payload) {
|
|
109
147
|
await handlePayload?.(shardId, payload);
|
|
110
|
-
await cache.onPacket(payload);
|
|
148
|
+
await self.cache.onPacket(payload);
|
|
111
149
|
await onPacket?.(payload, shardId);
|
|
112
|
-
|
|
150
|
+
self.postMessage({
|
|
113
151
|
workerId: workerData.workerId,
|
|
114
152
|
shardId,
|
|
115
153
|
type: 'RECEIVE_PAYLOAD',
|
|
@@ -119,7 +157,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
119
157
|
});
|
|
120
158
|
this.shards.set(id, shard);
|
|
121
159
|
}
|
|
122
|
-
|
|
160
|
+
this.postMessage({
|
|
123
161
|
type: 'CONNECT_QUEUE',
|
|
124
162
|
shardId: id,
|
|
125
163
|
workerId: workerData.workerId,
|
|
@@ -134,16 +172,17 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
134
172
|
this.logger.fatal('Worker trying get non-existent shard');
|
|
135
173
|
return;
|
|
136
174
|
}
|
|
137
|
-
|
|
175
|
+
this.postMessage({
|
|
138
176
|
...generateShardInfo(shard),
|
|
139
177
|
nonce: data.nonce,
|
|
140
178
|
type: 'SHARD_INFO',
|
|
179
|
+
workerId: this.workerId,
|
|
141
180
|
});
|
|
142
181
|
}
|
|
143
182
|
break;
|
|
144
183
|
case 'WORKER_INFO':
|
|
145
184
|
{
|
|
146
|
-
|
|
185
|
+
this.postMessage({
|
|
147
186
|
shards: [...this.shards.values()].map(generateShardInfo),
|
|
148
187
|
workerId: workerData.workerId,
|
|
149
188
|
type: 'WORKER_INFO',
|
|
@@ -152,13 +191,84 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
152
191
|
}
|
|
153
192
|
break;
|
|
154
193
|
case 'BOT_READY':
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
194
|
+
await this.events.runEvent('BOT_READY', this, this.me, -1);
|
|
195
|
+
break;
|
|
196
|
+
case 'API_RESPONSE':
|
|
197
|
+
{
|
|
198
|
+
const promise = this.rest.workerPromises.get(data.nonce);
|
|
199
|
+
if (!promise)
|
|
200
|
+
return;
|
|
201
|
+
this.rest.workerPromises.delete(data.nonce);
|
|
202
|
+
if (data.error)
|
|
203
|
+
return promise.reject(data.error);
|
|
204
|
+
promise.resolve(data.response);
|
|
205
|
+
}
|
|
206
|
+
break;
|
|
207
|
+
case 'EXECUTE_EVAL':
|
|
208
|
+
{
|
|
209
|
+
let result;
|
|
210
|
+
try {
|
|
211
|
+
// biome-ignore lint/security/noGlobalEval: yes
|
|
212
|
+
result = await eval(`
|
|
213
|
+
(${data.func})(this)
|
|
214
|
+
`);
|
|
215
|
+
}
|
|
216
|
+
catch (e) {
|
|
217
|
+
result = e;
|
|
218
|
+
}
|
|
219
|
+
this.postMessage({
|
|
220
|
+
type: 'EVAL_RESPONSE',
|
|
221
|
+
response: result,
|
|
222
|
+
workerId: workerData.workerId,
|
|
223
|
+
nonce: data.nonce,
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
break;
|
|
227
|
+
case 'EVAL_RESPONSE':
|
|
228
|
+
{
|
|
229
|
+
const evalResponse = this.promises.get(data.nonce);
|
|
230
|
+
if (!evalResponse)
|
|
231
|
+
return;
|
|
232
|
+
this.promises.delete(data.nonce);
|
|
233
|
+
clearTimeout(evalResponse.timeout);
|
|
234
|
+
evalResponse.resolve(data.response);
|
|
158
235
|
}
|
|
159
236
|
break;
|
|
160
237
|
}
|
|
161
238
|
}
|
|
239
|
+
generateNonce(large = true) {
|
|
240
|
+
const uuid = (0, node_crypto_1.randomUUID)();
|
|
241
|
+
const nonce = large ? uuid : uuid.split('-')[0];
|
|
242
|
+
if (this.promises.has(nonce))
|
|
243
|
+
return this.generateNonce(large);
|
|
244
|
+
return nonce;
|
|
245
|
+
}
|
|
246
|
+
generateSendPromise(nonce, message = 'Timeout') {
|
|
247
|
+
let resolve = (_) => {
|
|
248
|
+
/**/
|
|
249
|
+
};
|
|
250
|
+
let timeout = -1;
|
|
251
|
+
const promise = new Promise((res, rej) => {
|
|
252
|
+
resolve = res;
|
|
253
|
+
timeout = setTimeout(() => {
|
|
254
|
+
this.promises.delete(nonce);
|
|
255
|
+
rej(new Error(message));
|
|
256
|
+
}, 60e3);
|
|
257
|
+
});
|
|
258
|
+
this.promises.set(nonce, { resolve, timeout });
|
|
259
|
+
return promise;
|
|
260
|
+
}
|
|
261
|
+
tellWorker(workerId, func) {
|
|
262
|
+
const nonce = this.generateNonce();
|
|
263
|
+
this.postMessage({
|
|
264
|
+
type: 'EVAL',
|
|
265
|
+
func: func.toString(),
|
|
266
|
+
toWorkerId: workerId,
|
|
267
|
+
workerId: workerData.workerId,
|
|
268
|
+
nonce,
|
|
269
|
+
});
|
|
270
|
+
return this.generateSendPromise(nonce);
|
|
271
|
+
}
|
|
162
272
|
async onPacket(packet, shardId) {
|
|
163
273
|
await this.events.execute('RAW', packet, this, shardId);
|
|
164
274
|
switch (packet.t) {
|
|
@@ -181,17 +291,16 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
181
291
|
this.botId = packet.d.user.id;
|
|
182
292
|
this.applicationId = packet.d.application.id;
|
|
183
293
|
this.me = new structures_1.ClientUser(this, packet.d.user, packet.d.application);
|
|
184
|
-
if (!this.__handleGuilds?.size
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
node_worker_threads_1.parentPort.postMessage({
|
|
294
|
+
if (!this.__handleGuilds?.size ||
|
|
295
|
+
!((workerData.intents & common_1.GatewayIntentBits.Guilds) === common_1.GatewayIntentBits.Guilds)) {
|
|
296
|
+
if ([...this.shards.values()].every(shard => shard.data.session_id)) {
|
|
297
|
+
this.postMessage({
|
|
189
298
|
type: 'WORKER_READY',
|
|
190
299
|
workerId: this.workerId,
|
|
191
300
|
});
|
|
192
301
|
await this.events.runEvent('WORKER_READY', this, this.me, -1);
|
|
193
|
-
delete this.__handleGuilds;
|
|
194
302
|
}
|
|
303
|
+
delete this.__handleGuilds;
|
|
195
304
|
}
|
|
196
305
|
this.debugger?.debug(`#${shardId} [${packet.d.user.username}](${this.botId}) is online...`);
|
|
197
306
|
break;
|
|
@@ -204,16 +313,15 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
204
313
|
case 'GUILD_CREATE': {
|
|
205
314
|
if (this.__handleGuilds?.has(packet.d.id)) {
|
|
206
315
|
this.__handleGuilds.delete(packet.d.id);
|
|
207
|
-
if (!this.__handleGuilds.size &&
|
|
208
|
-
|
|
209
|
-
this.events.values.WORKER_READY &&
|
|
210
|
-
(this.events.values.WORKER_READY.fired ? !this.events.values.WORKER_READY.data.once : true)) {
|
|
211
|
-
node_worker_threads_1.parentPort.postMessage({
|
|
316
|
+
if (!this.__handleGuilds.size && [...this.shards.values()].every(shard => shard.data.session_id)) {
|
|
317
|
+
this.postMessage({
|
|
212
318
|
type: 'WORKER_READY',
|
|
213
319
|
workerId: this.workerId,
|
|
214
320
|
});
|
|
215
321
|
await this.events.runEvent('WORKER_READY', this, this.me, -1);
|
|
216
322
|
}
|
|
323
|
+
if (!this.__handleGuilds.size)
|
|
324
|
+
delete this.__handleGuilds;
|
|
217
325
|
return;
|
|
218
326
|
}
|
|
219
327
|
}
|
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 = {
|
|
@@ -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
|
}
|
|
@@ -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)))
|
|
@@ -117,9 +117,9 @@ class BaseCommand {
|
|
|
117
117
|
description_localizations: this.description_localizations,
|
|
118
118
|
guild_id: this.guild_id,
|
|
119
119
|
default_member_permissions: this.default_member_permissions,
|
|
120
|
+
contexts: this.contexts,
|
|
121
|
+
integration_types: this.integration_types,
|
|
120
122
|
};
|
|
121
|
-
if ('dm' in this)
|
|
122
|
-
data.dm_permission = this.dm;
|
|
123
123
|
return data;
|
|
124
124
|
}
|
|
125
125
|
async reload() {
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
import { MenuCommandContext, User, type AllChannels, type Guild, type InferWithPrefix, type MessageCommandInteraction, type ReturnCache, type UserCommandInteraction, type WebhookMessage } from '../..';
|
|
2
|
-
import { type
|
|
2
|
+
import { type If, type UnionToTuple, type When } from '../../common';
|
|
3
3
|
import type { InteractionCreateBodyRequest, InteractionMessageUpdateBodyRequest } from '../../common/types/write';
|
|
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,6 +24,7 @@ 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>;
|
|
@@ -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);
|
|
@@ -69,22 +74,22 @@ class CommandContext {
|
|
|
69
74
|
}
|
|
70
75
|
channel(mode = 'cache') {
|
|
71
76
|
if (this.interaction?.channel && mode === 'cache')
|
|
72
|
-
return this.client.cache.
|
|
77
|
+
return this.client.cache.adapter.isAsync ? Promise.resolve(this.interaction.channel) : this.interaction.channel;
|
|
73
78
|
switch (mode) {
|
|
74
79
|
case 'cache':
|
|
75
80
|
return (this.client.cache.channels?.get(this.channelId) ||
|
|
76
|
-
(this.client.cache.
|
|
81
|
+
(this.client.cache.adapter.isAsync ? Promise.resolve() : undefined));
|
|
77
82
|
default:
|
|
78
83
|
return this.client.channels.fetch(this.channelId, mode === 'rest');
|
|
79
84
|
}
|
|
80
85
|
}
|
|
81
86
|
me(mode = 'cache') {
|
|
82
87
|
if (!this.guildId)
|
|
83
|
-
return mode === 'cache' ? (this.client.cache.
|
|
88
|
+
return mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve();
|
|
84
89
|
switch (mode) {
|
|
85
90
|
case 'cache':
|
|
86
91
|
return (this.client.cache.members?.get(this.client.botId, this.guildId) ||
|
|
87
|
-
(this.client.cache.
|
|
92
|
+
(this.client.cache.adapter.isAsync ? Promise.resolve() : undefined));
|
|
88
93
|
default:
|
|
89
94
|
return this.client.members.fetch(this.guildId, this.client.botId, mode === 'rest');
|
|
90
95
|
}
|
|
@@ -92,14 +97,14 @@ class CommandContext {
|
|
|
92
97
|
guild(mode = 'cache') {
|
|
93
98
|
if (!this.guildId)
|
|
94
99
|
return (mode === 'cache'
|
|
95
|
-
? this.client.cache.
|
|
100
|
+
? this.client.cache.adapter.isAsync
|
|
96
101
|
? Promise.resolve()
|
|
97
102
|
: undefined
|
|
98
103
|
: Promise.resolve());
|
|
99
104
|
switch (mode) {
|
|
100
105
|
case 'cache':
|
|
101
106
|
return (this.client.cache.guilds?.get(this.guildId) ||
|
|
102
|
-
(this.client.cache.
|
|
107
|
+
(this.client.cache.adapter.isAsync ? Promise.resolve() : undefined));
|
|
103
108
|
default:
|
|
104
109
|
return this.client.guilds.fetch(this.guildId, mode === 'rest');
|
|
105
110
|
}
|
|
@@ -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;
|
|
@@ -73,6 +75,8 @@ class ContextMenuCommand {
|
|
|
73
75
|
guild_id: this.guild_id,
|
|
74
76
|
dm_permission: this.dm,
|
|
75
77
|
default_member_permissions: this.default_member_permissions,
|
|
78
|
+
contexts: this.contexts,
|
|
79
|
+
integration_types: this.integration_types,
|
|
76
80
|
};
|
|
77
81
|
}
|
|
78
82
|
async reload() {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CommandContext, type
|
|
2
|
-
import { type
|
|
1
|
+
import { CommandContext, type ContextMenuCommand, type ReturnCache, type WebhookMessage } from '../..';
|
|
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';
|
|
5
5
|
import type { CommandMetadata, ExtendContext, GlobalMetadata, UsingClient } from './shared';
|
|
@@ -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,6 +19,7 @@ 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>;
|
|
@@ -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 = {};
|
|
@@ -34,6 +36,9 @@ class MenuCommandContext {
|
|
|
34
36
|
get t() {
|
|
35
37
|
return this.client.langs.get(this.interaction.locale);
|
|
36
38
|
}
|
|
39
|
+
get fullCommandName() {
|
|
40
|
+
return this.command.name;
|
|
41
|
+
}
|
|
37
42
|
write(body, fetchReply) {
|
|
38
43
|
return this.interaction.write(body, fetchReply);
|
|
39
44
|
}
|
|
@@ -57,12 +62,12 @@ class MenuCommandContext {
|
|
|
57
62
|
}
|
|
58
63
|
channel(mode = 'cache') {
|
|
59
64
|
if (this.interaction?.channel && mode === 'cache')
|
|
60
|
-
return this.client.cache.
|
|
65
|
+
return this.client.cache.adapter.isAsync ? Promise.resolve(this.interaction.channel) : this.interaction.channel;
|
|
61
66
|
return this.client.channels.fetch(this.channelId, mode === 'rest');
|
|
62
67
|
}
|
|
63
68
|
me(mode = 'cache') {
|
|
64
69
|
if (!this.guildId)
|
|
65
|
-
return mode === 'cache' ? (this.client.cache.
|
|
70
|
+
return mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve();
|
|
66
71
|
switch (mode) {
|
|
67
72
|
case 'cache':
|
|
68
73
|
return this.client.cache.members?.get(this.client.botId, this.guildId);
|
|
@@ -72,7 +77,7 @@ class MenuCommandContext {
|
|
|
72
77
|
}
|
|
73
78
|
guild(mode = 'cache') {
|
|
74
79
|
if (!this.guildId)
|
|
75
|
-
return (mode === 'cache' ? (this.client.cache.
|
|
80
|
+
return (mode === 'cache' ? (this.client.cache.adapter.isAsync ? Promise.resolve() : undefined) : Promise.resolve());
|
|
76
81
|
switch (mode) {
|
|
77
82
|
case 'cache':
|
|
78
83
|
return this.client.cache.guilds?.get(this.guildId);
|
|
@@ -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>;
|