seyfert 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/lib/api/Router.js +3 -1
- package/lib/api/Routes/guilds.d.ts +4 -1
- package/lib/cache/index.d.ts +6 -2
- package/lib/cache/index.js +18 -0
- package/lib/cache/resources/bans.d.ts +12 -0
- package/lib/cache/resources/bans.js +35 -0
- package/lib/cache/resources/members.js +4 -4
- package/lib/cache/resources/messages.js +8 -6
- package/lib/client/base.d.ts +7 -3
- package/lib/client/base.js +43 -24
- package/lib/client/client.d.ts +17 -5
- package/lib/client/client.js +39 -43
- package/lib/client/collectors.d.ts +36 -0
- package/lib/client/collectors.js +85 -0
- package/lib/client/httpclient.js +6 -6
- package/lib/client/onmessagecreate.d.ts +12 -2
- package/lib/client/onmessagecreate.js +32 -17
- package/lib/client/workerclient.d.ts +4 -1
- package/lib/client/workerclient.js +59 -67
- package/lib/collection.d.ts +2 -2
- package/lib/collection.js +2 -2
- package/lib/commands/applications/chat.d.ts +10 -9
- package/lib/commands/applications/chat.js +21 -7
- package/lib/commands/applications/menu.d.ts +8 -7
- package/lib/commands/applications/menu.js +3 -2
- package/lib/commands/applications/shared.d.ts +12 -0
- package/lib/commands/decorators.d.ts +11 -17
- package/lib/commands/decorators.js +7 -14
- package/lib/commands/handler.js +39 -29
- package/lib/common/index.d.ts +1 -0
- package/lib/common/index.js +3 -1
- package/lib/common/it/formatter.d.ts +155 -0
- package/lib/common/it/formatter.js +184 -0
- package/lib/common/it/logger.js +5 -5
- package/lib/common/it/utils.js +2 -4
- package/lib/common/shorters/bans.d.ts +43 -0
- package/lib/common/shorters/bans.js +78 -0
- package/lib/common/shorters/emojis.d.ts +1 -1
- package/lib/common/shorters/emojis.js +4 -3
- package/lib/common/shorters/interaction.js +9 -7
- package/lib/common/shorters/messages.js +2 -2
- package/lib/common/shorters/webhook.js +2 -2
- package/lib/components/componentcommand.d.ts +3 -2
- package/lib/components/componentcommand.js +2 -1
- package/lib/components/componentcontext.d.ts +1 -1
- package/lib/components/handler.d.ts +1 -1
- package/lib/components/handler.js +25 -28
- package/lib/components/modalcommand.d.ts +2 -1
- package/lib/components/modalcommand.js +1 -0
- package/lib/components/modalcontext.d.ts +1 -1
- package/lib/events/event.d.ts +4 -3
- package/lib/events/handler.d.ts +8 -5
- package/lib/events/handler.js +58 -13
- package/lib/events/hooks/guild.d.ts +18 -73
- package/lib/events/hooks/integration.d.ts +57 -0
- package/lib/events/hooks/invite.d.ts +3 -0
- package/lib/events/hooks/message.d.ts +11 -6
- package/lib/events/hooks/presence.d.ts +4 -0
- package/lib/events/hooks/thread.d.ts +14 -3
- package/lib/events/hooks/typing.d.ts +1 -0
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -2
- package/lib/structures/Guild.d.ts +9 -1
- package/lib/structures/Guild.js +2 -0
- package/lib/structures/GuildBan.d.ts +25 -0
- package/lib/structures/GuildBan.js +36 -0
- package/lib/structures/GuildEmoji.d.ts +1 -1
- package/lib/structures/GuildMember.d.ts +7 -2
- package/lib/structures/GuildMember.js +4 -4
- package/lib/structures/Interaction.d.ts +3 -2
- package/lib/structures/Interaction.js +21 -9
- package/lib/structures/Message.d.ts +69 -8
- package/lib/structures/Message.js +59 -17
- package/lib/structures/Sticker.d.ts +3 -3
- package/lib/structures/User.d.ts +1 -0
- package/lib/structures/User.js +4 -1
- package/lib/structures/channels.d.ts +4 -1
- package/lib/structures/channels.js +36 -6
- package/lib/structures/extra/functions.js +1 -1
- package/lib/websocket/discord/basesocket.d.ts +1 -0
- package/lib/websocket/discord/basesocket.js +17 -0
- package/lib/websocket/discord/shard.d.ts +1 -0
- package/lib/websocket/discord/shard.js +6 -0
- package/package.json +8 -8
package/lib/client/client.js
CHANGED
|
@@ -11,16 +11,25 @@ const presenceUpdate_1 = require("../websocket/discord/events/presenceUpdate");
|
|
|
11
11
|
const base_1 = require("./base");
|
|
12
12
|
const oninteractioncreate_1 = require("./oninteractioncreate");
|
|
13
13
|
const onmessagecreate_1 = require("./onmessagecreate");
|
|
14
|
+
const collectors_1 = require("./collectors");
|
|
14
15
|
let parentPort;
|
|
15
16
|
class Client extends base_1.BaseClient {
|
|
16
17
|
__handleGuilds = new Set();
|
|
17
18
|
gateway;
|
|
18
|
-
events = new events_1.EventHandler(this.logger);
|
|
19
19
|
me;
|
|
20
20
|
memberUpdateHandler = new memberUpdate_1.MemberUpdateHandler();
|
|
21
21
|
presenceUpdateHandler = new presenceUpdate_1.PresenceUpdateHandler();
|
|
22
|
+
collectors = new collectors_1.Collectors();
|
|
23
|
+
events = new events_1.EventHandler(this);
|
|
22
24
|
constructor(options) {
|
|
23
25
|
super(options);
|
|
26
|
+
this.options = (0, common_1.MergeOptions)({
|
|
27
|
+
commands: {
|
|
28
|
+
argsParser: options?.commands?.argsParser ?? onmessagecreate_1.defaultArgsParser,
|
|
29
|
+
optionsParser: options?.commands?.optionsParser ??
|
|
30
|
+
onmessagecreate_1.defaultOptionsParser,
|
|
31
|
+
},
|
|
32
|
+
}, this.options);
|
|
24
33
|
}
|
|
25
34
|
setServices({ gateway, ...rest }) {
|
|
26
35
|
super.setServices(rest);
|
|
@@ -38,7 +47,7 @@ class Client extends base_1.BaseClient {
|
|
|
38
47
|
this.events = undefined;
|
|
39
48
|
}
|
|
40
49
|
else if (typeof rest.handlers.events === 'function') {
|
|
41
|
-
this.events = new events_1.EventHandler(this
|
|
50
|
+
this.events = new events_1.EventHandler(this);
|
|
42
51
|
this.events.setHandlers({
|
|
43
52
|
callback: rest.handlers.events,
|
|
44
53
|
});
|
|
@@ -49,7 +58,7 @@ class Client extends base_1.BaseClient {
|
|
|
49
58
|
}
|
|
50
59
|
}
|
|
51
60
|
async loadEvents(dir) {
|
|
52
|
-
dir ??= await this.getRC().then(x => x.events);
|
|
61
|
+
dir ??= await this.getRC().then((x) => x.events);
|
|
53
62
|
if (dir && this.events) {
|
|
54
63
|
await this.events.load(dir);
|
|
55
64
|
this.logger.info('EventHandler loaded');
|
|
@@ -61,10 +70,7 @@ class Client extends base_1.BaseClient {
|
|
|
61
70
|
if (worker_threads?.parentPort) {
|
|
62
71
|
parentPort = worker_threads.parentPort;
|
|
63
72
|
}
|
|
64
|
-
if (
|
|
65
|
-
await this.gateway.spawnShards();
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
73
|
+
if (worker_threads?.workerData?.__USING_WATCHER__) {
|
|
68
74
|
parentPort?.on('message', (data) => {
|
|
69
75
|
switch (data.type) {
|
|
70
76
|
case 'PAYLOAD':
|
|
@@ -76,11 +82,14 @@ class Client extends base_1.BaseClient {
|
|
|
76
82
|
}
|
|
77
83
|
});
|
|
78
84
|
}
|
|
85
|
+
else {
|
|
86
|
+
await this.gateway.spawnShards();
|
|
87
|
+
}
|
|
79
88
|
}
|
|
80
89
|
async start(options = {}, execute = true) {
|
|
81
90
|
await super.start(options);
|
|
82
91
|
await this.loadEvents(options.eventsDir);
|
|
83
|
-
const { token: tokenRC, intents: intentsRC, debug: debugRC } = await this.getRC();
|
|
92
|
+
const { token: tokenRC, intents: intentsRC, debug: debugRC, } = await this.getRC();
|
|
84
93
|
const token = options?.token ?? tokenRC;
|
|
85
94
|
const intents = options?.connection?.intents ?? intentsRC;
|
|
86
95
|
if (!this.gateway) {
|
|
@@ -98,7 +107,10 @@ class Client extends base_1.BaseClient {
|
|
|
98
107
|
shardStart: this.options?.shards?.start,
|
|
99
108
|
shardEnd: this.options?.shards?.end ?? this.options?.shards?.total,
|
|
100
109
|
totalShards: this.options?.shards?.total ?? this.options?.shards?.end,
|
|
101
|
-
properties: {
|
|
110
|
+
properties: {
|
|
111
|
+
...websocket_1.properties,
|
|
112
|
+
...this.options?.gateway?.properties,
|
|
113
|
+
},
|
|
102
114
|
compress: this.options?.gateway?.compress,
|
|
103
115
|
});
|
|
104
116
|
}
|
|
@@ -119,35 +131,30 @@ class Client extends base_1.BaseClient {
|
|
|
119
131
|
return;
|
|
120
132
|
}
|
|
121
133
|
await this.events?.execute(packet.t, packet, this, shardId);
|
|
122
|
-
await this.cache.onPacket(packet);
|
|
123
134
|
break;
|
|
124
135
|
case 'PRESENCE_UPDATE':
|
|
125
136
|
if (!this.presenceUpdateHandler.check(packet.d)) {
|
|
126
137
|
return;
|
|
127
138
|
}
|
|
128
139
|
await this.events?.execute(packet.t, packet, this, shardId);
|
|
129
|
-
await this.cache.onPacket(packet);
|
|
130
140
|
break;
|
|
131
|
-
case '
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
case 'VOICE_STATE_UPDATE':
|
|
143
|
-
case 'STAGE_INSTANCE_UPDATE':
|
|
144
|
-
case 'GUILD_STICKERS_UPDATE':
|
|
141
|
+
case 'GUILD_CREATE': {
|
|
142
|
+
if (this.__handleGuilds?.has(packet.d.id)) {
|
|
143
|
+
this.__handleGuilds.delete(packet.d.id);
|
|
144
|
+
if (!this.__handleGuilds.size &&
|
|
145
|
+
[...this.gateway.values()].every((shard) => shard.data.session_id)) {
|
|
146
|
+
await this.events?.runEvent('BOT_READY', this, this.me, -1);
|
|
147
|
+
}
|
|
148
|
+
if (!this.__handleGuilds.size)
|
|
149
|
+
delete this.__handleGuilds;
|
|
150
|
+
return this.cache.onPacket(packet);
|
|
151
|
+
}
|
|
145
152
|
await this.events?.execute(packet.t, packet, this, shardId);
|
|
146
|
-
await this.cache.onPacket(packet);
|
|
147
153
|
break;
|
|
154
|
+
}
|
|
148
155
|
//rest of the events
|
|
149
156
|
default: {
|
|
150
|
-
await this.
|
|
157
|
+
await this.events?.execute(packet.t, packet, this, shardId);
|
|
151
158
|
switch (packet.t) {
|
|
152
159
|
case 'INTERACTION_CREATE':
|
|
153
160
|
await (0, oninteractioncreate_1.onInteractionCreate)(this, packet.d, shardId);
|
|
@@ -162,29 +169,18 @@ class Client extends base_1.BaseClient {
|
|
|
162
169
|
this.botId = packet.d.user.id;
|
|
163
170
|
this.applicationId = packet.d.application.id;
|
|
164
171
|
this.me = new structures_1.ClientUser(this, packet.d.user, packet.d.application);
|
|
165
|
-
if (!this.__handleGuilds?.size
|
|
166
|
-
|
|
167
|
-
|
|
172
|
+
if (!(this.__handleGuilds?.size &&
|
|
173
|
+
(this.gateway.options.intents &
|
|
174
|
+
v10_1.GatewayIntentBits.Guilds) ===
|
|
175
|
+
v10_1.GatewayIntentBits.Guilds)) {
|
|
176
|
+
if ([...this.gateway.values()].every((shard) => shard.data.session_id)) {
|
|
168
177
|
await this.events?.runEvent('BOT_READY', this, this.me, -1);
|
|
169
178
|
}
|
|
170
179
|
delete this.__handleGuilds;
|
|
171
180
|
}
|
|
172
181
|
this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`);
|
|
173
182
|
break;
|
|
174
|
-
case 'GUILD_CREATE': {
|
|
175
|
-
if (this.__handleGuilds?.has(packet.d.id)) {
|
|
176
|
-
this.__handleGuilds.delete(packet.d.id);
|
|
177
|
-
if (!this.__handleGuilds.size && [...this.gateway.values()].every(shard => shard.data.session_id)) {
|
|
178
|
-
await this.events?.runEvent('BOT_READY', this, this.me, -1);
|
|
179
|
-
}
|
|
180
|
-
if (!this.__handleGuilds.size)
|
|
181
|
-
delete this.__handleGuilds;
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
break;
|
|
185
|
-
}
|
|
186
183
|
}
|
|
187
|
-
await this.events?.execute(packet.t, packet, this, shardId);
|
|
188
184
|
break;
|
|
189
185
|
}
|
|
190
186
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Awaitable, CamelCase } from '../common';
|
|
3
|
+
import type { CallbackEventHandler, CustomEventsKeys, GatewayEvents } from '../events';
|
|
4
|
+
export type AllClientEvents = CustomEventsKeys | GatewayEvents;
|
|
5
|
+
export type ParseClientEventName<T extends AllClientEvents> = T extends CustomEventsKeys ? T : CamelCase<T>;
|
|
6
|
+
type RunData<T extends AllClientEvents> = {
|
|
7
|
+
options: {
|
|
8
|
+
event: T;
|
|
9
|
+
idle?: number;
|
|
10
|
+
timeout?: number;
|
|
11
|
+
onStop?: (reason: string) => unknown;
|
|
12
|
+
onStopError?: (reason: string, error: unknown) => unknown;
|
|
13
|
+
filter: (arg: Awaited<Parameters<CallbackEventHandler[ParseClientEventName<T>]>[0]>) => Awaitable<boolean>;
|
|
14
|
+
run: (arg: Awaited<Parameters<CallbackEventHandler[ParseClientEventName<T>]>[0]>, stop: (reason?: string) => void) => unknown;
|
|
15
|
+
onRunError?: (arg: Awaited<Parameters<CallbackEventHandler[ParseClientEventName<T>]>[0]>, error: unknown, stop: (reason?: string) => void) => unknown;
|
|
16
|
+
};
|
|
17
|
+
idle?: NodeJS.Timeout;
|
|
18
|
+
timeout?: NodeJS.Timeout;
|
|
19
|
+
nonce: string;
|
|
20
|
+
};
|
|
21
|
+
export declare class Collectors {
|
|
22
|
+
readonly values: Map<AllClientEvents, RunData<any>[]>;
|
|
23
|
+
private generateRandomUUID;
|
|
24
|
+
create<T extends AllClientEvents>(options: RunData<T>['options']): {
|
|
25
|
+
event: T;
|
|
26
|
+
idle?: number | undefined;
|
|
27
|
+
timeout?: number | undefined;
|
|
28
|
+
onStop?: ((reason: string) => unknown) | undefined;
|
|
29
|
+
onStopError?: ((reason: string, error: unknown) => unknown) | undefined;
|
|
30
|
+
filter: (arg: Awaited<Parameters<CallbackEventHandler[ParseClientEventName<T>]>[0]>) => Awaitable<boolean>;
|
|
31
|
+
run: (arg: Awaited<Parameters<CallbackEventHandler[ParseClientEventName<T>]>[0]>, stop: (reason?: string | undefined) => void) => unknown;
|
|
32
|
+
onRunError?: ((arg: Awaited<Parameters<CallbackEventHandler[ParseClientEventName<T>]>[0]>, error: unknown, stop: (reason?: string | undefined) => void) => unknown) | undefined;
|
|
33
|
+
};
|
|
34
|
+
private delete;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Collectors = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const node_console_1 = require("node:console");
|
|
6
|
+
class Collectors {
|
|
7
|
+
values = new Map();
|
|
8
|
+
generateRandomUUID(name) {
|
|
9
|
+
const collectors = this.values.get(name);
|
|
10
|
+
if (!collectors)
|
|
11
|
+
return '*';
|
|
12
|
+
let nonce = (0, node_crypto_1.randomUUID)();
|
|
13
|
+
while (collectors.find(x => x.nonce === nonce)) {
|
|
14
|
+
nonce = (0, node_crypto_1.randomUUID)();
|
|
15
|
+
}
|
|
16
|
+
return nonce;
|
|
17
|
+
}
|
|
18
|
+
create(options) {
|
|
19
|
+
const nonce = this.generateRandomUUID(options.event);
|
|
20
|
+
if (!this.values.has(options.event)) {
|
|
21
|
+
this.values.set(options.event, []);
|
|
22
|
+
}
|
|
23
|
+
this.values.get(options.event).push({
|
|
24
|
+
options: {
|
|
25
|
+
...options,
|
|
26
|
+
name: options.event,
|
|
27
|
+
},
|
|
28
|
+
idle: options.idle && options.idle > 0
|
|
29
|
+
? setTimeout(() => {
|
|
30
|
+
return this.delete(options.event, nonce, 'idle');
|
|
31
|
+
}, options.idle)
|
|
32
|
+
: undefined,
|
|
33
|
+
timeout: options.timeout && options.timeout > 0
|
|
34
|
+
? setTimeout(() => {
|
|
35
|
+
return this.delete(options.event, nonce, 'timeout');
|
|
36
|
+
}, options.timeout)
|
|
37
|
+
: undefined,
|
|
38
|
+
nonce,
|
|
39
|
+
});
|
|
40
|
+
return options;
|
|
41
|
+
}
|
|
42
|
+
async delete(name, nonce, reason = 'unknown') {
|
|
43
|
+
const collectors = this.values.get(name);
|
|
44
|
+
if (!collectors?.length) {
|
|
45
|
+
if (collectors)
|
|
46
|
+
this.values.delete(name);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const index = collectors.findIndex(x => x.nonce === nonce);
|
|
50
|
+
if (index === -1)
|
|
51
|
+
return;
|
|
52
|
+
const collector = collectors[index];
|
|
53
|
+
clearTimeout(collector.idle);
|
|
54
|
+
clearTimeout(collector.timeout);
|
|
55
|
+
collectors.splice(index, 1);
|
|
56
|
+
try {
|
|
57
|
+
await collector.options.onStop?.(reason);
|
|
58
|
+
}
|
|
59
|
+
catch (e) {
|
|
60
|
+
await collector.options.onStopError?.(reason, node_console_1.error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**@internal */
|
|
64
|
+
async run(name, data) {
|
|
65
|
+
const collectors = this.values.get(name);
|
|
66
|
+
if (!collectors)
|
|
67
|
+
return;
|
|
68
|
+
for (const i of collectors) {
|
|
69
|
+
if (await i.options.filter(data)) {
|
|
70
|
+
i.idle?.refresh();
|
|
71
|
+
const stop = (reason = 'unknown') => {
|
|
72
|
+
return this.delete(i.options.event, i.nonce, reason);
|
|
73
|
+
};
|
|
74
|
+
try {
|
|
75
|
+
await i.options.run(data, stop);
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
await i.options.onRunError?.(data, e, stop);
|
|
79
|
+
}
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
exports.Collectors = Collectors;
|
package/lib/client/httpclient.js
CHANGED
|
@@ -176,12 +176,7 @@ class HttpClient extends base_1.BaseClient {
|
|
|
176
176
|
}
|
|
177
177
|
async onPacket(res, req) {
|
|
178
178
|
const rawBody = await this.verifySignature(res, req);
|
|
179
|
-
if (
|
|
180
|
-
this.debugger?.debug('Invalid request/No info, returning 418 status.');
|
|
181
|
-
// I'm a teapot
|
|
182
|
-
res.writeStatus('418').end();
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
179
|
+
if (rawBody) {
|
|
185
180
|
switch (rawBody.type) {
|
|
186
181
|
case v10_1.InteractionType.Ping:
|
|
187
182
|
this.debugger?.debug('Ping interaction received, responding.');
|
|
@@ -232,6 +227,11 @@ class HttpClient extends base_1.BaseClient {
|
|
|
232
227
|
break;
|
|
233
228
|
}
|
|
234
229
|
}
|
|
230
|
+
else {
|
|
231
|
+
this.debugger?.debug('Invalid request/No info, returning 418 status.');
|
|
232
|
+
// I'm a teapot
|
|
233
|
+
res.writeStatus('418').end();
|
|
234
|
+
}
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
exports.HttpClient = HttpClient;
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
import { type GatewayMessageCreateDispatchData } from 'discord-api-types/v10';
|
|
2
|
-
import { type Client, type WorkerClient } from '..';
|
|
1
|
+
import { type APIApplicationCommandInteractionDataOption, type GatewayMessageCreateDispatchData } from 'discord-api-types/v10';
|
|
2
|
+
import { Command, type MessageCommandOptionErrors, SubCommand, type UsingClient, type Client, type ContextOptionsResolved, type WorkerClient } from '..';
|
|
3
|
+
import type { MakeRequired } from '../common';
|
|
3
4
|
export declare function onMessageCreate(self: Client | WorkerClient, rawMessage: GatewayMessageCreateDispatchData, shardId: number): Promise<any>;
|
|
5
|
+
export declare function defaultOptionsParser(self: UsingClient, command: Command | SubCommand, message: GatewayMessageCreateDispatchData, args: Partial<Record<string, string>>, resolved: MakeRequired<ContextOptionsResolved>): Promise<{
|
|
6
|
+
errors: {
|
|
7
|
+
name: string;
|
|
8
|
+
error: string;
|
|
9
|
+
fullError: MessageCommandOptionErrors;
|
|
10
|
+
}[];
|
|
11
|
+
options: APIApplicationCommandInteractionDataOption[];
|
|
12
|
+
}>;
|
|
13
|
+
export declare function defaultArgsParser(content: string): Record<string, string>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.onMessageCreate = void 0;
|
|
3
|
+
exports.defaultArgsParser = exports.defaultOptionsParser = exports.onMessageCreate = void 0;
|
|
4
4
|
const v10_1 = require("discord-api-types/v10");
|
|
5
5
|
const __1 = require("..");
|
|
6
6
|
const structures_1 = require("../structures");
|
|
@@ -45,7 +45,7 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
45
45
|
const message = new structures_1.Message(self, rawMessage);
|
|
46
46
|
const prefixes = (await self.options.commands.prefix(message)).sort((a, b) => b.length - a.length);
|
|
47
47
|
const prefix = prefixes.find(x => message.content.startsWith(x));
|
|
48
|
-
if (!prefix
|
|
48
|
+
if (!(prefix !== undefined && message.content.startsWith(prefix)))
|
|
49
49
|
return;
|
|
50
50
|
const content = message.content.slice(prefix.length).trimStart();
|
|
51
51
|
const { fullCommandName, command, parent } = getCommandFromContent(content
|
|
@@ -56,7 +56,9 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
56
56
|
return;
|
|
57
57
|
if (!command.run)
|
|
58
58
|
return self.logger.warn(`${fullCommandName} command does not have 'run' callback`);
|
|
59
|
-
if (!command.contexts
|
|
59
|
+
if (!command.contexts.includes(v10_1.InteractionContextType.BotDM) && !message.guildId)
|
|
60
|
+
return;
|
|
61
|
+
if (!command.contexts.includes(v10_1.InteractionContextType.Guild) && message.guildId)
|
|
60
62
|
return;
|
|
61
63
|
if (command.guildId && !command.guildId?.includes(message.guildId))
|
|
62
64
|
return;
|
|
@@ -71,14 +73,26 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
71
73
|
for (const i of fullCommandName.split(' ')) {
|
|
72
74
|
newContent = newContent.slice(newContent.indexOf(i) + i.length);
|
|
73
75
|
}
|
|
74
|
-
const args =
|
|
75
|
-
const { options, errors } = await
|
|
76
|
+
const args = self.options.commands.argsParser(newContent.slice(1), command, message);
|
|
77
|
+
const { options, errors } = await self.options.commands.optionsParser(self, command, rawMessage, args, resolved);
|
|
76
78
|
const optionsResolver = new __1.OptionResolver(self, options, parent, message.guildId, resolved);
|
|
77
79
|
const context = new __1.CommandContext(self, message, optionsResolver, shardId, command);
|
|
78
80
|
//@ts-expect-error
|
|
79
81
|
const extendContext = self.options?.context?.(message) ?? {};
|
|
80
82
|
Object.assign(context, extendContext);
|
|
81
83
|
try {
|
|
84
|
+
if (errors.length) {
|
|
85
|
+
return command.onOptionsError?.(context, Object.fromEntries(errors.map(x => {
|
|
86
|
+
return [
|
|
87
|
+
x.name,
|
|
88
|
+
{
|
|
89
|
+
failed: true,
|
|
90
|
+
value: x.error,
|
|
91
|
+
parseError: x.fullError,
|
|
92
|
+
},
|
|
93
|
+
];
|
|
94
|
+
})));
|
|
95
|
+
}
|
|
82
96
|
if (command.defaultMemberPermissions && message.guildId) {
|
|
83
97
|
const memberPermissions = await self.members.permissions(message.guildId, message.author.id);
|
|
84
98
|
const permissions = memberPermissions.missings(...memberPermissions.values([command.defaultMemberPermissions]));
|
|
@@ -98,17 +112,6 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
98
112
|
return command.onBotPermissionsFail?.(context, appPermissions.keys(permissions));
|
|
99
113
|
}
|
|
100
114
|
}
|
|
101
|
-
if (errors.length) {
|
|
102
|
-
return command.onOptionsError?.(context, Object.fromEntries(errors.map(x => {
|
|
103
|
-
return [
|
|
104
|
-
x.name,
|
|
105
|
-
{
|
|
106
|
-
failed: true,
|
|
107
|
-
value: x.error,
|
|
108
|
-
},
|
|
109
|
-
];
|
|
110
|
-
})));
|
|
111
|
-
}
|
|
112
115
|
const [erroredOptions, result] = await command.__runOptions(context, optionsResolver);
|
|
113
116
|
if (erroredOptions) {
|
|
114
117
|
return command.onOptionsError?.(context, result);
|
|
@@ -146,7 +149,7 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
146
149
|
}
|
|
147
150
|
}
|
|
148
151
|
exports.onMessageCreate = onMessageCreate;
|
|
149
|
-
async function
|
|
152
|
+
async function defaultOptionsParser(self, command, message, args, resolved) {
|
|
150
153
|
const options = [];
|
|
151
154
|
const errors = [];
|
|
152
155
|
for (const i of (command.options ?? [])) {
|
|
@@ -179,6 +182,7 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
179
182
|
error: `The entered channel type is not one of ${i
|
|
180
183
|
.channel_types.map(t => v10_1.ChannelType[t])
|
|
181
184
|
.join(', ')}`,
|
|
185
|
+
fullError: ['CHANNEL_TYPES', i.channel_types],
|
|
182
186
|
});
|
|
183
187
|
break;
|
|
184
188
|
}
|
|
@@ -274,6 +278,7 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
274
278
|
errors.push({
|
|
275
279
|
name: i.name,
|
|
276
280
|
error: `The entered string has less than ${option.min_length} characters. The minimum required is ${option.min_length} characters.`,
|
|
281
|
+
fullError: ['STRING_MIN_LENGTH', option.min_length],
|
|
277
282
|
});
|
|
278
283
|
break;
|
|
279
284
|
}
|
|
@@ -284,6 +289,7 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
284
289
|
errors.push({
|
|
285
290
|
name: i.name,
|
|
286
291
|
error: `The entered string has more than ${option.max_length} characters. The maximum required is ${option.max_length} characters.`,
|
|
292
|
+
fullError: ['STRING_MAX_LENGTH', option.max_length],
|
|
287
293
|
});
|
|
288
294
|
break;
|
|
289
295
|
}
|
|
@@ -297,6 +303,7 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
297
303
|
error: `The entered choice is invalid. Please choose one of the following options: ${option.choices
|
|
298
304
|
.map(x => x.name)
|
|
299
305
|
.join(', ')}.`,
|
|
306
|
+
fullError: ['STRING_INVALID_CHOICE', option.choices],
|
|
300
307
|
});
|
|
301
308
|
break;
|
|
302
309
|
}
|
|
@@ -319,6 +326,7 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
319
326
|
errors.push({
|
|
320
327
|
name: i.name,
|
|
321
328
|
error: 'The entered choice is an invalid number.',
|
|
329
|
+
fullError: ['NUMBER_NAN', args[i.name]],
|
|
322
330
|
});
|
|
323
331
|
break;
|
|
324
332
|
}
|
|
@@ -328,6 +336,7 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
328
336
|
errors.push({
|
|
329
337
|
name: i.name,
|
|
330
338
|
error: `The entered number is less than ${option.min_value}. The minimum allowed is ${option.min_value}`,
|
|
339
|
+
fullError: ['NUMBER_MIN_VALUE', option.min_value],
|
|
331
340
|
});
|
|
332
341
|
break;
|
|
333
342
|
}
|
|
@@ -338,6 +347,7 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
338
347
|
errors.push({
|
|
339
348
|
name: i.name,
|
|
340
349
|
error: `The entered number is greater than ${option.max_value}. The maximum allowed is ${option.max_value}`,
|
|
350
|
+
fullError: ['NUMBER_MAX_VALUE', option.max_value],
|
|
341
351
|
});
|
|
342
352
|
break;
|
|
343
353
|
}
|
|
@@ -352,6 +362,7 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
352
362
|
error: `The entered choice is invalid. Please choose one of the following options: ${option.choices
|
|
353
363
|
.map(x => x.name)
|
|
354
364
|
.join(', ')}.`,
|
|
365
|
+
fullError: ['NUMBER_INVALID_CHOICE', option.choices],
|
|
355
366
|
});
|
|
356
367
|
break;
|
|
357
368
|
}
|
|
@@ -373,17 +384,20 @@ async function parseOptions(self, command, message, args, resolved) {
|
|
|
373
384
|
errors.push({
|
|
374
385
|
error: 'Option is required but returned undefined',
|
|
375
386
|
name: i.name,
|
|
387
|
+
fullError: ['OPTION_REQUIRED'],
|
|
376
388
|
});
|
|
377
389
|
}
|
|
378
390
|
catch (e) {
|
|
379
391
|
errors.push({
|
|
380
392
|
error: e && typeof e === 'object' && 'message' in e ? e.message : `${e}`,
|
|
381
393
|
name: i.name,
|
|
394
|
+
fullError: ['UNKNOWN', e],
|
|
382
395
|
});
|
|
383
396
|
}
|
|
384
397
|
}
|
|
385
398
|
return { errors, options };
|
|
386
399
|
}
|
|
400
|
+
exports.defaultOptionsParser = defaultOptionsParser;
|
|
387
401
|
function defaultArgsParser(content) {
|
|
388
402
|
const args = {};
|
|
389
403
|
for (const i of content.match(/-(.*?)(?=\s-|$)/gs) ?? []) {
|
|
@@ -391,5 +405,6 @@ function defaultArgsParser(content) {
|
|
|
391
405
|
}
|
|
392
406
|
return args;
|
|
393
407
|
}
|
|
408
|
+
exports.defaultArgsParser = defaultArgsParser;
|
|
394
409
|
//-(.*?)(?=\s-|$)/gs
|
|
395
410
|
//-(?<text>[^-]*)/gm
|
|
@@ -14,10 +14,12 @@ import type { WorkerShardInfo } from '../websocket/discord/worker';
|
|
|
14
14
|
import type { ManagerMessages } from '../websocket/discord/workermanager';
|
|
15
15
|
import type { BaseClientOptions, ServicesOptions, StartOptions } from './base';
|
|
16
16
|
import { BaseClient } from './base';
|
|
17
|
-
import type { Client } from './client';
|
|
17
|
+
import type { Client, ClientOptions } from './client';
|
|
18
|
+
import { Collectors } from './collectors';
|
|
18
19
|
export declare class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
|
|
19
20
|
private __handleGuilds?;
|
|
20
21
|
logger: Logger;
|
|
22
|
+
collectors: Collectors;
|
|
21
23
|
events?: EventHandler | undefined;
|
|
22
24
|
me: When<Ready, ClientUser>;
|
|
23
25
|
promises: Map<string, {
|
|
@@ -48,5 +50,6 @@ interface WorkerClientOptions extends BaseClientOptions {
|
|
|
48
50
|
disabledCache: Cache['disabledCache'];
|
|
49
51
|
commands?: NonNullable<Client['options']>['commands'];
|
|
50
52
|
handlePayload?: ShardManagerOptions['handlePayload'];
|
|
53
|
+
gateway?: ClientOptions['gateway'];
|
|
51
54
|
}
|
|
52
55
|
export {};
|