seyfert 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -30
- package/lib/api/CDN.d.ts +0 -8
- package/lib/api/CDN.js +7 -13
- package/lib/api/Router.d.ts +2 -2
- package/lib/api/Router.js +1 -1
- package/lib/api/Routes/applications.d.ts +1 -1
- package/lib/api/Routes/channels.d.ts +1 -1
- package/lib/api/Routes/gateway.d.ts +1 -1
- package/lib/api/Routes/guilds.d.ts +1 -1
- package/lib/api/Routes/interactions.d.ts +1 -1
- package/lib/api/Routes/invites.d.ts +1 -1
- package/lib/api/Routes/stage-instances.d.ts +1 -1
- package/lib/api/Routes/stickers.d.ts +1 -1
- package/lib/api/Routes/users.d.ts +1 -1
- package/lib/api/Routes/voice.d.ts +1 -1
- package/lib/api/Routes/webhooks.d.ts +1 -1
- package/lib/api/api.d.ts +39 -0
- package/lib/api/api.js +318 -0
- package/lib/api/bucket.d.ts +19 -0
- package/lib/api/bucket.js +71 -0
- package/lib/api/index.d.ts +1 -1
- package/lib/api/index.js +1 -1
- package/lib/api/shared.d.ts +31 -5
- package/lib/api/shared.js +2 -7
- package/lib/api/utils/constants.d.ts +1 -30
- package/lib/api/utils/constants.js +2 -41
- package/lib/api/utils/types.d.ts +1 -320
- package/lib/api/utils/utils.d.ts +0 -38
- package/lib/api/utils/utils.js +1 -139
- package/lib/builders/ActionRow.js +1 -1
- package/lib/builders/Attachment.d.ts +14 -6
- package/lib/builders/Attachment.js +30 -7
- package/lib/builders/Button.d.ts +3 -12
- package/lib/builders/Button.js +0 -11
- package/lib/builders/{MessageEmbed.d.ts → Embed.d.ts} +15 -15
- package/lib/builders/{MessageEmbed.js → Embed.js} +16 -16
- package/lib/builders/Modal.js +1 -1
- package/lib/builders/SelectMenu.d.ts +14 -15
- package/lib/builders/SelectMenu.js +19 -18
- package/lib/builders/index.d.ts +1 -1
- package/lib/builders/index.js +1 -1
- package/lib/builders/types.d.ts +2 -2
- package/lib/cache/adapters/default.js +2 -2
- package/lib/cache/adapters/redis.d.ts +2 -3
- package/lib/cache/adapters/redis.js +13 -5
- package/lib/cache/adapters/workeradapter.d.ts +9 -1
- package/lib/cache/adapters/workeradapter.js +7 -3
- package/lib/cache/index.d.ts +20 -6
- package/lib/cache/index.js +26 -10
- package/lib/cache/resources/channels.d.ts +6 -2
- package/lib/cache/resources/channels.js +12 -6
- package/lib/cache/resources/default/base.d.ts +17 -16
- package/lib/cache/resources/default/base.js +25 -24
- package/lib/cache/resources/default/guild-based.d.ts +22 -19
- package/lib/cache/resources/default/guild-based.js +32 -31
- package/lib/cache/resources/default/guild-related.d.ts +22 -19
- package/lib/cache/resources/default/guild-related.js +37 -43
- package/lib/cache/resources/emojis.d.ts +4 -2
- package/lib/cache/resources/emojis.js +8 -6
- package/lib/cache/resources/guilds.d.ts +4 -2
- package/lib/cache/resources/guilds.js +15 -8
- package/lib/cache/resources/members.d.ts +4 -2
- package/lib/cache/resources/members.js +16 -13
- package/lib/cache/resources/overwrites.d.ts +25 -0
- package/lib/cache/resources/overwrites.js +39 -0
- package/lib/cache/resources/presence.js +3 -4
- package/lib/cache/resources/roles.d.ts +4 -2
- package/lib/cache/resources/roles.js +8 -6
- package/lib/cache/resources/stickers.d.ts +4 -2
- package/lib/cache/resources/stickers.js +8 -6
- package/lib/cache/resources/threads.d.ts +4 -2
- package/lib/cache/resources/threads.js +8 -6
- package/lib/cache/resources/users.d.ts +4 -2
- package/lib/cache/resources/users.js +8 -6
- package/lib/cache/resources/voice-states.d.ts +3 -3
- package/lib/cache/resources/voice-states.js +6 -7
- package/lib/client/base.d.ts +49 -16
- package/lib/client/base.js +21 -17
- package/lib/client/client.d.ts +14 -3
- package/lib/client/client.js +21 -21
- package/lib/client/httpclient.d.ts +3 -5
- package/lib/client/httpclient.js +29 -16
- package/lib/client/{oninteraction.d.ts → oninteractioncreate.d.ts} +1 -1
- package/lib/client/{oninteraction.js → oninteractioncreate.js} +34 -23
- package/lib/client/onmessagecreate.d.ts +3 -0
- package/lib/client/onmessagecreate.js +337 -0
- package/lib/client/workerclient.d.ts +5 -1
- package/lib/client/workerclient.js +67 -44
- package/lib/collection.d.ts +1 -1
- package/lib/collection.js +9 -6
- package/lib/commands/applications/chat.d.ts +32 -25
- package/lib/commands/applications/chat.js +51 -34
- package/lib/commands/applications/chatcontext.d.ts +34 -16
- package/lib/commands/applications/chatcontext.js +99 -20
- package/lib/commands/applications/menu.d.ts +9 -8
- package/lib/commands/applications/menu.js +14 -5
- package/lib/commands/applications/menucontext.d.ts +27 -10
- package/lib/commands/applications/menucontext.js +51 -7
- package/lib/commands/applications/options.d.ts +13 -13
- package/lib/commands/applications/shared.d.ts +7 -2
- package/lib/commands/decorators.d.ts +14 -14
- package/lib/commands/decorators.js +9 -5
- package/lib/commands/handler.d.ts +2 -1
- package/lib/commands/handler.js +60 -14
- package/lib/commands/index.d.ts +1 -1
- package/lib/commands/index.js +2 -1
- package/lib/commands/optionresolver.d.ts +6 -5
- package/lib/commands/optionresolver.js +10 -6
- package/lib/common/bot/watcher.d.ts +3 -3
- package/lib/common/bot/watcher.js +3 -1
- package/lib/common/index.d.ts +1 -1
- package/lib/common/index.js +2 -1
- package/lib/common/it/logger.d.ts +11 -0
- package/lib/common/it/logger.js +51 -2
- package/lib/common/it/utils.d.ts +3 -13
- package/lib/common/it/utils.js +9 -30
- package/lib/common/shorters/channels.d.ts +55 -5
- package/lib/common/shorters/channels.js +59 -0
- package/lib/common/shorters/guilds.d.ts +5 -2
- package/lib/common/shorters/guilds.js +18 -0
- package/lib/common/shorters/messages.js +0 -2
- package/lib/common/shorters/overwrites.d.ts +29 -0
- package/lib/common/shorters/overwrites.js +63 -0
- package/lib/common/shorters/roles.js +3 -3
- package/lib/common/shorters/webhook.d.ts +2 -2
- package/lib/common/types/util.d.ts +2 -1
- package/lib/common/types/write.d.ts +3 -7
- package/lib/components/handler.d.ts +12 -18
- package/lib/components/handler.js +58 -103
- package/lib/components/index.d.ts +0 -1
- package/lib/components/index.js +0 -1
- package/lib/components/listener.d.ts +2 -2
- package/lib/components/listener.js +2 -3
- package/lib/events/event.d.ts +2 -2
- package/lib/events/handler.d.ts +3 -2
- package/lib/events/handler.js +14 -6
- package/lib/events/hooks/dispatch.d.ts +2 -1
- package/lib/events/hooks/dispatch.js +5 -1
- package/lib/events/hooks/thread.d.ts +63 -63
- package/lib/index.d.ts +8 -5
- package/lib/index.js +20 -10
- package/lib/langs/handler.d.ts +6 -4
- package/lib/langs/handler.js +10 -8
- package/lib/langs/router.d.ts +8 -9
- package/lib/langs/router.js +5 -5
- package/lib/structures/ClientUser.d.ts +1 -16
- package/lib/structures/ClientUser.js +0 -31
- package/lib/structures/Guild.d.ts +1 -1
- package/lib/structures/GuildMember.d.ts +12 -0
- package/lib/structures/GuildMember.js +14 -0
- package/lib/structures/GuildRole.d.ts +4 -2
- package/lib/structures/GuildRole.js +4 -1
- package/lib/structures/GuildTemplate.js +1 -1
- package/lib/structures/Interaction.d.ts +2 -0
- package/lib/structures/Interaction.js +12 -13
- package/lib/structures/Message.d.ts +7 -2
- package/lib/structures/Message.js +6 -3
- package/lib/structures/Sticker.d.ts +1 -1
- package/lib/structures/Sticker.js +1 -1
- package/lib/structures/User.d.ts +5 -0
- package/lib/structures/User.js +3 -0
- package/lib/structures/Webhook.d.ts +1 -1
- package/lib/structures/Webhook.js +1 -1
- package/lib/structures/channels.d.ts +45 -6
- package/lib/structures/channels.js +23 -7
- package/lib/structures/extra/BitField.d.ts +9 -6
- package/lib/structures/extra/BitField.js +27 -3
- package/lib/structures/extra/Permissions.d.ts +6 -1
- package/lib/structures/extra/Permissions.js +7 -0
- package/lib/websocket/discord/basesocket.js +0 -1
- package/lib/websocket/discord/workermanager.d.ts +9 -1
- package/lib/websocket/discord/workermanager.js +21 -13
- package/package.json +21 -20
- package/lib/api/REST.d.ts +0 -127
- package/lib/api/REST.js +0 -424
- package/lib/api/errors/DiscordAPIError.d.ts +0 -51
- package/lib/api/errors/DiscordAPIError.js +0 -81
- package/lib/api/errors/HTTPError.d.ts +0 -20
- package/lib/api/errors/HTTPError.js +0 -28
- package/lib/api/errors/RateLimitError.d.ts +0 -19
- package/lib/api/errors/RateLimitError.js +0 -37
- package/lib/api/handlers/BurstHandler.d.ts +0 -51
- package/lib/api/handlers/BurstHandler.js +0 -124
- package/lib/api/handlers/SequentialHandler.d.ts +0 -81
- package/lib/api/handlers/SequentialHandler.js +0 -365
- package/lib/api/handlers/Shared.d.ts +0 -14
- package/lib/api/handlers/Shared.js +0 -125
- package/lib/api/interfaces/Handler.d.ts +0 -21
- package/lib/api/interfaces/Handler.js +0 -2
- package/lib/websocket/discord/handlemessage.d.ts +0 -0
- package/lib/websocket/discord/handlemessage.js +0 -1
- package/lib/websocket/discord/memberUpdate.d.ts +0 -16
- package/lib/websocket/discord/memberUpdate.js +0 -47
package/lib/client/client.js
CHANGED
|
@@ -8,8 +8,10 @@ const websocket_1 = require("../websocket");
|
|
|
8
8
|
const memberUpdate_1 = require("../websocket/discord/events/memberUpdate");
|
|
9
9
|
const presenceUpdate_1 = require("../websocket/discord/events/presenceUpdate");
|
|
10
10
|
const base_1 = require("./base");
|
|
11
|
-
const
|
|
11
|
+
const oninteractioncreate_1 = require("./oninteractioncreate");
|
|
12
|
+
const onmessagecreate_1 = require("./onmessagecreate");
|
|
12
13
|
class Client extends base_1.BaseClient {
|
|
14
|
+
__handleGuilds;
|
|
13
15
|
gateway;
|
|
14
16
|
events = new events_1.EventHandler(this.logger);
|
|
15
17
|
me;
|
|
@@ -19,6 +21,7 @@ class Client extends base_1.BaseClient {
|
|
|
19
21
|
super(options);
|
|
20
22
|
}
|
|
21
23
|
setServices({ gateway, ...rest }) {
|
|
24
|
+
this.__handleGuilds = new Set();
|
|
22
25
|
super.setServices(rest);
|
|
23
26
|
if (gateway) {
|
|
24
27
|
const onPacket = this.onPacket.bind(this);
|
|
@@ -67,13 +70,14 @@ class Client extends base_1.BaseClient {
|
|
|
67
70
|
token,
|
|
68
71
|
info: await this.proxy.gateway.bot.get(),
|
|
69
72
|
intents,
|
|
70
|
-
handlePayload: (shardId, packet) => {
|
|
73
|
+
handlePayload: async (shardId, packet) => {
|
|
74
|
+
await this.options?.handlePayload?.(shardId, packet);
|
|
71
75
|
return this.onPacket(shardId, packet);
|
|
72
76
|
},
|
|
73
77
|
presence: this.options?.presence,
|
|
74
78
|
debug: debugRC,
|
|
75
|
-
shardStart: this.options?.
|
|
76
|
-
shardEnd: this.options?.
|
|
79
|
+
shardStart: this.options?.shards?.start,
|
|
80
|
+
shardEnd: this.options?.shards?.end,
|
|
77
81
|
});
|
|
78
82
|
}
|
|
79
83
|
this.cache.intents = this.gateway.options.intents;
|
|
@@ -85,6 +89,7 @@ class Client extends base_1.BaseClient {
|
|
|
85
89
|
}
|
|
86
90
|
}
|
|
87
91
|
async onPacket(shardId, packet) {
|
|
92
|
+
await this.events.runEvent('RAW', this, packet, shardId);
|
|
88
93
|
switch (packet.t) {
|
|
89
94
|
//// Cases where we must obtain the old data before updating
|
|
90
95
|
case 'GUILD_MEMBER_UPDATE':
|
|
@@ -101,46 +106,41 @@ class Client extends base_1.BaseClient {
|
|
|
101
106
|
await this.events.execute(packet.t, packet, this, shardId);
|
|
102
107
|
await this.cache.onPacket(packet);
|
|
103
108
|
break;
|
|
104
|
-
case 'GUILD_DELETE':
|
|
105
|
-
case 'CHANNEL_UPDATE': {
|
|
106
|
-
await this.events.execute(packet.t, packet, this, shardId);
|
|
107
|
-
await this.cache.onPacket(packet);
|
|
108
|
-
break;
|
|
109
|
-
}
|
|
110
109
|
//rest of the events
|
|
111
110
|
default: {
|
|
112
111
|
await this.cache.onPacket(packet);
|
|
113
112
|
switch (packet.t) {
|
|
113
|
+
case 'INTERACTION_CREATE':
|
|
114
|
+
await (0, oninteractioncreate_1.onInteractionCreate)(this, packet.d, shardId);
|
|
115
|
+
break;
|
|
116
|
+
case 'MESSAGE_CREATE':
|
|
117
|
+
await (0, onmessagecreate_1.onMessageCreate)(this, packet.d, shardId);
|
|
118
|
+
break;
|
|
114
119
|
case 'READY':
|
|
115
120
|
for (const g of packet.d.guilds) {
|
|
116
|
-
this.__handleGuilds
|
|
121
|
+
this.__handleGuilds?.add(g.id);
|
|
117
122
|
}
|
|
118
123
|
this.botId = packet.d.user.id;
|
|
119
124
|
this.applicationId = packet.d.application.id;
|
|
120
125
|
this.me = new structures_1.ClientUser(this, packet.d.user, packet.d.application);
|
|
121
|
-
if (!this.__handleGuilds
|
|
126
|
+
if (!this.__handleGuilds?.size) {
|
|
122
127
|
if ([...this.gateway.values()].every(shard => shard.data.session_id) &&
|
|
123
128
|
this.events.values.BOT_READY &&
|
|
124
129
|
(this.events.values.BOT_READY.fired ? !this.events.values.BOT_READY.data.once : true)) {
|
|
125
|
-
this.events.
|
|
126
|
-
|
|
130
|
+
await this.events.runEvent('BOT_READY', this, this.me, -1);
|
|
131
|
+
delete this.__handleGuilds;
|
|
127
132
|
}
|
|
128
133
|
}
|
|
129
134
|
this.debugger?.debug(`#${shardId}[${packet.d.user.username}](${this.botId}) is online...`);
|
|
130
135
|
break;
|
|
131
|
-
case 'INTERACTION_CREATE': {
|
|
132
|
-
await (0, oninteraction_1.onInteraction)(shardId, packet.d, this);
|
|
133
|
-
break;
|
|
134
|
-
}
|
|
135
136
|
case 'GUILD_CREATE': {
|
|
136
|
-
if (this.__handleGuilds
|
|
137
|
+
if (this.__handleGuilds?.has(packet.d.id)) {
|
|
137
138
|
this.__handleGuilds.delete(packet.d.id);
|
|
138
139
|
if (!this.__handleGuilds.size &&
|
|
139
140
|
[...this.gateway.values()].every(shard => shard.data.session_id) &&
|
|
140
141
|
this.events.values.BOT_READY &&
|
|
141
142
|
(this.events.values.BOT_READY.fired ? !this.events.values.BOT_READY.data.once : true)) {
|
|
142
|
-
this.events.
|
|
143
|
-
await this.events.values.BOT_READY.run(this.me, this, -1);
|
|
143
|
+
await this.events.runEvent('BOT_READY', this, this.me, -1);
|
|
144
144
|
}
|
|
145
145
|
return;
|
|
146
146
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { HttpRequest, HttpResponse } from 'uWebSockets.js';
|
|
3
3
|
import type { APIInteraction, DeepPartial } from '../common';
|
|
4
|
-
import type { StartOptions } from './base';
|
|
4
|
+
import type { BaseClientOptions, StartOptions } from './base';
|
|
5
5
|
import { BaseClient } from './base';
|
|
6
|
-
declare let UWS: typeof import('uWebSockets.js');
|
|
7
6
|
export declare class HttpClient extends BaseClient {
|
|
8
|
-
app: ReturnType<typeof
|
|
7
|
+
app: ReturnType<typeof import('uWebSockets.js').App>;
|
|
9
8
|
publicKey: string;
|
|
10
9
|
publicKeyHex: Buffer;
|
|
11
|
-
constructor();
|
|
10
|
+
constructor(options?: BaseClientOptions);
|
|
12
11
|
protected static readJson<T extends Record<string, any>>(res: HttpResponse): Promise<T>;
|
|
13
12
|
protected execute(options?: {
|
|
14
13
|
publicKey?: string;
|
|
@@ -18,4 +17,3 @@ export declare class HttpClient extends BaseClient {
|
|
|
18
17
|
protected verifySignature(res: HttpResponse, req: HttpRequest): Promise<APIInteraction | undefined>;
|
|
19
18
|
onPacket(res: HttpResponse, req: HttpRequest): Promise<void>;
|
|
20
19
|
}
|
|
21
|
-
export {};
|
package/lib/client/httpclient.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.HttpClient = void 0;
|
|
7
|
-
const
|
|
4
|
+
const magic_bytes_js_1 = require("magic-bytes.js");
|
|
5
|
+
const api_1 = require("../api");
|
|
6
|
+
const utils_1 = require("../api/utils/utils");
|
|
8
7
|
const common_1 = require("../common");
|
|
9
8
|
const base_1 = require("./base");
|
|
10
|
-
const
|
|
9
|
+
const oninteractioncreate_1 = require("./oninteractioncreate");
|
|
11
10
|
let UWS;
|
|
12
11
|
let nacl;
|
|
13
12
|
try {
|
|
@@ -26,8 +25,8 @@ class HttpClient extends base_1.BaseClient {
|
|
|
26
25
|
app;
|
|
27
26
|
publicKey;
|
|
28
27
|
publicKeyHex;
|
|
29
|
-
constructor() {
|
|
30
|
-
super();
|
|
28
|
+
constructor(options) {
|
|
29
|
+
super(options);
|
|
31
30
|
if (!UWS) {
|
|
32
31
|
throw new Error('No uws installed.');
|
|
33
32
|
}
|
|
@@ -88,9 +87,9 @@ class HttpClient extends base_1.BaseClient {
|
|
|
88
87
|
}
|
|
89
88
|
// https://discord.com/developers/docs/interactions/receiving-and-responding#security-and-authorization
|
|
90
89
|
async verifySignature(res, req) {
|
|
91
|
-
const body = await HttpClient.readJson(res);
|
|
92
90
|
const timestamp = req.getHeader('x-signature-timestamp');
|
|
93
91
|
const ed25519 = req.getHeader('x-signature-ed25519');
|
|
92
|
+
const body = await HttpClient.readJson(res);
|
|
94
93
|
if (nacl.sign.detached.verify(Buffer.from(timestamp + JSON.stringify(body)), Buffer.from(ed25519, 'hex'), this.publicKeyHex)) {
|
|
95
94
|
return body;
|
|
96
95
|
}
|
|
@@ -112,19 +111,33 @@ class HttpClient extends base_1.BaseClient {
|
|
|
112
111
|
.end(JSON.stringify({ type: common_1.InteractionResponseType.Pong }));
|
|
113
112
|
break;
|
|
114
113
|
default:
|
|
115
|
-
await (0,
|
|
114
|
+
await (0, oninteractioncreate_1.onInteractionCreate)(this, rawBody, -1, async ({ body, files }) => {
|
|
116
115
|
let response;
|
|
117
|
-
|
|
118
|
-
if (files
|
|
119
|
-
response = new
|
|
120
|
-
for (const
|
|
121
|
-
const
|
|
122
|
-
|
|
116
|
+
const headers = {};
|
|
117
|
+
if (files) {
|
|
118
|
+
response = new FormData();
|
|
119
|
+
for (const [index, file] of files.entries()) {
|
|
120
|
+
const fileKey = file.key ?? `files[${index}]`;
|
|
121
|
+
if ((0, utils_1.isBufferLike)(file.data)) {
|
|
122
|
+
let contentType = file.contentType;
|
|
123
|
+
if (!contentType) {
|
|
124
|
+
const [parsedType] = (0, magic_bytes_js_1.filetypeinfo)(file.data);
|
|
125
|
+
if (parsedType) {
|
|
126
|
+
contentType =
|
|
127
|
+
api_1.OverwrittenMimeTypes[parsedType.mime] ??
|
|
128
|
+
parsedType.mime ??
|
|
129
|
+
'application/octet-stream';
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
response.append(fileKey, new Blob([file.data], { type: contentType }), file.name);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
response.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.name);
|
|
136
|
+
}
|
|
123
137
|
}
|
|
124
138
|
if (body) {
|
|
125
139
|
response.append('payload_json', JSON.stringify(body));
|
|
126
140
|
}
|
|
127
|
-
headers = Object.assign(headers, response.getHeaders());
|
|
128
141
|
}
|
|
129
142
|
else {
|
|
130
143
|
response = body ?? {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { type APIInteraction } from 'discord-api-types/v10';
|
|
2
2
|
import type { __InternalReplyFunction } from '../structures';
|
|
3
3
|
import type { BaseClient } from './base';
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function onInteractionCreate(self: BaseClient, body: APIInteraction, shardId: number, __reply?: __InternalReplyFunction): Promise<any>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.onInteractionCreate = void 0;
|
|
4
4
|
const v10_1 = require("discord-api-types/v10");
|
|
5
5
|
const commands_1 = require("../commands");
|
|
6
6
|
const structures_1 = require("../structures");
|
|
7
|
-
async function
|
|
7
|
+
async function onInteractionCreate(self, body, shardId, __reply) {
|
|
8
8
|
self.debugger?.debug(`[${v10_1.InteractionType[body.type] ?? body.type}] Interaction received.`);
|
|
9
9
|
switch (body.type) {
|
|
10
10
|
case v10_1.InteractionType.ApplicationCommandAutocomplete:
|
|
@@ -26,13 +26,14 @@ async function onInteraction(shardId, body, self, __reply) {
|
|
|
26
26
|
await command.autocomplete(interaction);
|
|
27
27
|
}
|
|
28
28
|
catch (error) {
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
if (!command.onAutocompleteError)
|
|
30
|
+
return self.logger.error(`${optionsResolver.fullCommandName} ${command.name} just threw an error, ${error ? (typeof error === 'object' && 'message' in error ? error.message : error) : 'Unknown'}`);
|
|
31
|
+
await command.onAutocompleteError(interaction, error);
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
catch (error) {
|
|
34
35
|
try {
|
|
35
|
-
await optionsResolver.getCommand()?.onInternalError(self, error);
|
|
36
|
+
await optionsResolver.getCommand()?.onInternalError?.(self, error);
|
|
36
37
|
}
|
|
37
38
|
catch {
|
|
38
39
|
// supress error
|
|
@@ -60,26 +61,31 @@ async function onInteraction(shardId, body, self, __reply) {
|
|
|
60
61
|
const extendContext = self.options?.context?.(interaction) ?? {};
|
|
61
62
|
Object.assign(context, extendContext);
|
|
62
63
|
try {
|
|
64
|
+
if (command.botPermissions && interaction.appPermissions) {
|
|
65
|
+
const permissions = interaction.appPermissions.missings(...interaction.appPermissions.values(command.botPermissions));
|
|
66
|
+
if (permissions.length) {
|
|
67
|
+
return command.onPermissionsFail?.(context, interaction.appPermissions.keys(permissions));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
63
70
|
const resultRunGlobalMiddlewares = await command.__runGlobalMiddlewares(context);
|
|
64
|
-
if (resultRunGlobalMiddlewares
|
|
71
|
+
if (resultRunGlobalMiddlewares.pass) {
|
|
65
72
|
return;
|
|
66
73
|
}
|
|
67
|
-
if (resultRunGlobalMiddlewares) {
|
|
68
|
-
return command.onMiddlewaresError
|
|
74
|
+
if ('error' in resultRunGlobalMiddlewares) {
|
|
75
|
+
return command.onMiddlewaresError(context, resultRunGlobalMiddlewares.error ?? 'Unknown error');
|
|
69
76
|
}
|
|
70
77
|
const resultRunMiddlewares = await command.__runMiddlewares(context);
|
|
71
|
-
if (resultRunMiddlewares
|
|
78
|
+
if (resultRunMiddlewares.pass) {
|
|
72
79
|
return;
|
|
73
80
|
}
|
|
74
|
-
if (
|
|
75
|
-
return command.onMiddlewaresError
|
|
81
|
+
if ('error' in resultRunMiddlewares) {
|
|
82
|
+
return command.onMiddlewaresError(context, resultRunMiddlewares.error ?? 'Unknown error');
|
|
76
83
|
}
|
|
77
84
|
try {
|
|
78
85
|
await command.run(context);
|
|
79
86
|
await command.onAfterRun?.(context, undefined);
|
|
80
87
|
}
|
|
81
88
|
catch (error) {
|
|
82
|
-
self.logger.error(`${command.name} just threw an error, ${error ? (typeof error === 'object' && 'message' in error ? error.message : error) : 'Unknown'}`);
|
|
83
89
|
await command.onRunError?.(context, error);
|
|
84
90
|
await command.onAfterRun?.(context, error);
|
|
85
91
|
}
|
|
@@ -112,37 +118,42 @@ async function onInteraction(shardId, body, self, __reply) {
|
|
|
112
118
|
const extendContext = self.options?.context?.(interaction) ?? {};
|
|
113
119
|
Object.assign(context, extendContext);
|
|
114
120
|
try {
|
|
121
|
+
if (command.botPermissions && interaction.appPermissions) {
|
|
122
|
+
const permissions = interaction.appPermissions.missings(...interaction.appPermissions.values(command.botPermissions));
|
|
123
|
+
if (permissions.length) {
|
|
124
|
+
return command.onPermissionsFail?.(context, interaction.appPermissions.keys(permissions));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
115
127
|
const [erroredOptions, result] = await command.__runOptions(context, optionsResolver);
|
|
116
128
|
if (erroredOptions) {
|
|
117
129
|
return command.onOptionsError?.(context, result);
|
|
118
130
|
}
|
|
119
131
|
const resultRunGlobalMiddlewares = await command.__runGlobalMiddlewares(context);
|
|
120
|
-
if (resultRunGlobalMiddlewares
|
|
132
|
+
if (resultRunGlobalMiddlewares.pass) {
|
|
121
133
|
return;
|
|
122
134
|
}
|
|
123
|
-
if (resultRunGlobalMiddlewares) {
|
|
124
|
-
return command.onMiddlewaresError?.(context, resultRunGlobalMiddlewares);
|
|
135
|
+
if ('error' in resultRunGlobalMiddlewares) {
|
|
136
|
+
return command.onMiddlewaresError?.(context, resultRunGlobalMiddlewares.error ?? 'Unknown error');
|
|
125
137
|
}
|
|
126
138
|
const resultRunMiddlewares = await command.__runMiddlewares(context);
|
|
127
|
-
if (resultRunMiddlewares
|
|
139
|
+
if (resultRunMiddlewares.pass) {
|
|
128
140
|
return;
|
|
129
141
|
}
|
|
130
|
-
if (resultRunMiddlewares) {
|
|
131
|
-
return command.onMiddlewaresError?.(context, resultRunMiddlewares);
|
|
142
|
+
if ('error' in resultRunMiddlewares) {
|
|
143
|
+
return command.onMiddlewaresError?.(context, resultRunMiddlewares.error ?? 'Unknown error');
|
|
132
144
|
}
|
|
133
145
|
try {
|
|
134
146
|
await command.run(context);
|
|
135
147
|
await command.onAfterRun?.(context, undefined);
|
|
136
148
|
}
|
|
137
149
|
catch (error) {
|
|
138
|
-
self.logger.error(`${optionsResolver.fullCommandName} just threw an error, ${error ? (typeof error === 'object' && 'message' in error ? error.message : error) : 'Unknown'}`);
|
|
139
150
|
await command.onRunError?.(context, error);
|
|
140
151
|
await command.onAfterRun?.(context, error);
|
|
141
152
|
}
|
|
142
153
|
}
|
|
143
154
|
catch (error) {
|
|
144
155
|
try {
|
|
145
|
-
await command.onInternalError(self, error);
|
|
156
|
+
await command.onInternalError?.(self, error);
|
|
146
157
|
}
|
|
147
158
|
catch {
|
|
148
159
|
// supress error
|
|
@@ -167,8 +178,8 @@ async function onInteraction(shardId, body, self, __reply) {
|
|
|
167
178
|
case v10_1.InteractionType.MessageComponent:
|
|
168
179
|
{
|
|
169
180
|
const interaction = structures_1.BaseInteraction.from(self, body, __reply);
|
|
170
|
-
if (self.components.hasComponent(body.message.
|
|
171
|
-
await self.components.onComponent(body.message.
|
|
181
|
+
if (self.components.hasComponent([body.message.id, body.id], interaction.customId)) {
|
|
182
|
+
await self.components.onComponent([body.message.id, body.id], interaction);
|
|
172
183
|
}
|
|
173
184
|
else {
|
|
174
185
|
await self.components.executeComponent(interaction);
|
|
@@ -177,4 +188,4 @@ async function onInteraction(shardId, body, self, __reply) {
|
|
|
177
188
|
break;
|
|
178
189
|
}
|
|
179
190
|
}
|
|
180
|
-
exports.
|
|
191
|
+
exports.onInteractionCreate = onInteractionCreate;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type GatewayMessageCreateDispatchData } from 'discord-api-types/v10';
|
|
2
|
+
import { type Client, type WorkerClient } from '..';
|
|
3
|
+
export declare function onMessageCreate(self: Client | WorkerClient, rawMessage: GatewayMessageCreateDispatchData, shardId: number): Promise<any>;
|