seyfert 2.1.1-dev-11768778519.0 → 2.1.1-dev-11845956119.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/cache/index.d.ts +4 -3
- package/lib/cache/index.js +26 -65
- package/lib/cache/resources/default/base.d.ts +2 -2
- package/lib/cache/resources/default/base.js +0 -6
- package/lib/cache/resources/default/guild-based.d.ts +2 -2
- package/lib/cache/resources/default/guild-based.js +0 -6
- package/lib/cache/resources/default/guild-related.d.ts +2 -2
- package/lib/cache/resources/default/guild-related.js +0 -6
- package/lib/client/base.d.ts +16 -5
- package/lib/client/base.js +50 -18
- package/lib/client/httpclient.d.ts +0 -7
- package/lib/client/httpclient.js +0 -32
- package/lib/client/types.d.ts +2 -2
- package/lib/client/workerclient.js +3 -10
- package/lib/commands/applications/chatcontext.d.ts +1 -1
- package/lib/commands/applications/entrycontext.d.ts +1 -1
- package/lib/commands/applications/menu.d.ts +4 -4
- package/lib/commands/applications/menu.js +0 -12
- package/lib/commands/applications/menucontext.d.ts +1 -1
- package/lib/commands/handle.js +3 -3
- package/lib/commands/handler.js +4 -8
- package/lib/components/componentcontext.d.ts +1 -1
- package/lib/components/modalcontext.d.ts +1 -1
- package/package.json +1 -1
package/lib/cache/index.d.ts
CHANGED
|
@@ -34,7 +34,6 @@ export type DisabledCache = {
|
|
|
34
34
|
export declare class Cache {
|
|
35
35
|
intents: number;
|
|
36
36
|
adapter: Adapter;
|
|
37
|
-
readonly disabledCache: DisabledCache;
|
|
38
37
|
users?: Users;
|
|
39
38
|
guilds?: Guilds;
|
|
40
39
|
members?: Members;
|
|
@@ -49,7 +48,8 @@ export declare class Cache {
|
|
|
49
48
|
messages?: Messages;
|
|
50
49
|
bans?: Bans;
|
|
51
50
|
__logger__?: Logger;
|
|
52
|
-
constructor(intents: number, adapter: Adapter, disabledCache
|
|
51
|
+
constructor(intents: number, adapter: Adapter, disabledCache: DisabledCache, client: UsingClient);
|
|
52
|
+
buildCache(disabledCache: DisabledCache, client: UsingClient): void;
|
|
53
53
|
flush(): ReturnCache<void>;
|
|
54
54
|
hasIntent(intent: keyof typeof GatewayIntentBits): boolean;
|
|
55
55
|
get hasGuildsIntent(): boolean;
|
|
@@ -76,7 +76,6 @@ export declare class Cache {
|
|
|
76
76
|
members: import("..").GuildMember[];
|
|
77
77
|
users: import("..").User[];
|
|
78
78
|
channels: NonNullable<ReturnCache<import("..").AllChannels | undefined>>[];
|
|
79
|
-
messages: import("..").Message[];
|
|
80
79
|
voiceStates: import("..").VoiceState[];
|
|
81
80
|
presences: (Omit<import("../types").GatewayPresenceUpdate, "user"> & {
|
|
82
81
|
id: string;
|
|
@@ -94,6 +93,7 @@ export declare class Cache {
|
|
|
94
93
|
allow: import("../structures/extra/Permissions").PermissionsBitField;
|
|
95
94
|
guildId: string;
|
|
96
95
|
}[][];
|
|
96
|
+
messages: import("..").Message[];
|
|
97
97
|
bans: import("../structures/GuildBan").GuildBan[];
|
|
98
98
|
}>>;
|
|
99
99
|
bulkPatch(keys: (readonly [
|
|
@@ -117,6 +117,7 @@ export declare class Cache {
|
|
|
117
117
|
string
|
|
118
118
|
])[]): Promise<void>;
|
|
119
119
|
onPacket(event: GatewayDispatchPayload): Promise<void>;
|
|
120
|
+
protected onPacketDefault(event: GatewayDispatchPayload): Promise<void>;
|
|
120
121
|
testAdapter(): Promise<void>;
|
|
121
122
|
private testUsersAndMembers;
|
|
122
123
|
private testChannelsAndOverwrites;
|
package/lib/cache/index.js
CHANGED
|
@@ -40,7 +40,6 @@ __exportStar(require("./adapters/index"), exports);
|
|
|
40
40
|
class Cache {
|
|
41
41
|
intents;
|
|
42
42
|
adapter;
|
|
43
|
-
disabledCache;
|
|
44
43
|
// non-guild based
|
|
45
44
|
users;
|
|
46
45
|
guilds;
|
|
@@ -58,74 +57,33 @@ class Cache {
|
|
|
58
57
|
messages;
|
|
59
58
|
bans;
|
|
60
59
|
__logger__;
|
|
61
|
-
constructor(intents, adapter, disabledCache
|
|
60
|
+
constructor(intents, adapter, disabledCache, client) {
|
|
62
61
|
this.intents = intents;
|
|
63
62
|
this.adapter = adapter;
|
|
64
|
-
this.disabledCache
|
|
63
|
+
this.buildCache(disabledCache, client);
|
|
64
|
+
}
|
|
65
|
+
buildCache(disabledCache, client) {
|
|
65
66
|
// non-guild based
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
69
|
-
if (!this.disabledCache.guilds) {
|
|
70
|
-
this.guilds = new guilds_1.Guilds(this, client);
|
|
71
|
-
}
|
|
67
|
+
this.users = disabledCache.users ? undefined : new users_1.Users(this, client);
|
|
68
|
+
this.guilds = disabledCache.guilds ? undefined : new guilds_1.Guilds(this, client);
|
|
72
69
|
// guild related
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
if (!this.disabledCache.voiceStates) {
|
|
77
|
-
this.voiceStates = new voice_states_1.VoiceStates(this, client);
|
|
78
|
-
}
|
|
70
|
+
this.members = disabledCache.members ? undefined : new members_1.Members(this, client);
|
|
71
|
+
this.voiceStates = disabledCache.voiceStates ? undefined : new voice_states_1.VoiceStates(this, client);
|
|
79
72
|
// guild based
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
this.
|
|
94
|
-
}
|
|
95
|
-
if (!this.disabledCache.presences) {
|
|
96
|
-
this.presences = new presence_1.Presences(this, client);
|
|
97
|
-
}
|
|
98
|
-
if (!this.disabledCache.stageInstances) {
|
|
99
|
-
this.stageInstances = new stage_instances_1.StageInstances(this, client);
|
|
100
|
-
}
|
|
101
|
-
if (!this.disabledCache.messages) {
|
|
102
|
-
this.messages = new messages_1.Messages(this, client);
|
|
103
|
-
}
|
|
104
|
-
if (!this.disabledCache.bans) {
|
|
105
|
-
this.bans = new bans_1.Bans(this, client);
|
|
106
|
-
}
|
|
107
|
-
if (this.disabledCache.onPacket) {
|
|
108
|
-
//@ts-expect-error
|
|
109
|
-
this.onPacket = () => {
|
|
110
|
-
// disable cache
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
/** @internal */
|
|
115
|
-
__setClient(client) {
|
|
116
|
-
this.users?.__setClient(client);
|
|
117
|
-
this.guilds?.__setClient(client);
|
|
118
|
-
this.members?.__setClient(client);
|
|
119
|
-
this.voiceStates?.__setClient(client);
|
|
120
|
-
this.roles?.__setClient(client);
|
|
121
|
-
this.overwrites?.__setClient(client);
|
|
122
|
-
this.channels?.__setClient(client);
|
|
123
|
-
this.emojis?.__setClient(client);
|
|
124
|
-
this.stickers?.__setClient(client);
|
|
125
|
-
this.presences?.__setClient(client);
|
|
126
|
-
this.stageInstances?.__setClient(client);
|
|
127
|
-
this.messages?.__setClient(client);
|
|
128
|
-
this.bans?.__setClient(client);
|
|
73
|
+
this.roles = disabledCache.roles ? undefined : new roles_1.Roles(this, client);
|
|
74
|
+
this.overwrites = disabledCache.overwrites ? undefined : new overwrites_1.Overwrites(this, client);
|
|
75
|
+
this.channels = disabledCache.channels ? undefined : new channels_1.Channels(this, client);
|
|
76
|
+
this.emojis = disabledCache.emojis ? undefined : new emojis_1.Emojis(this, client);
|
|
77
|
+
this.stickers = disabledCache.stickers ? undefined : new stickers_1.Stickers(this, client);
|
|
78
|
+
this.presences = disabledCache.presences ? undefined : new presence_1.Presences(this, client);
|
|
79
|
+
this.stageInstances = disabledCache.stageInstances ? undefined : new stage_instances_1.StageInstances(this, client);
|
|
80
|
+
this.messages = disabledCache.messages ? undefined : new messages_1.Messages(this, client);
|
|
81
|
+
this.bans = disabledCache.bans ? undefined : new bans_1.Bans(this, client);
|
|
82
|
+
this.onPacket = disabledCache.onPacket
|
|
83
|
+
? (() => {
|
|
84
|
+
//
|
|
85
|
+
})
|
|
86
|
+
: this.onPacketDefault.bind(this);
|
|
129
87
|
}
|
|
130
88
|
flush() {
|
|
131
89
|
return this.adapter.flush();
|
|
@@ -353,7 +311,10 @@ class Cache {
|
|
|
353
311
|
await this.adapter.bulkAddToRelationShip(relationshipsData);
|
|
354
312
|
await this.adapter.bulkSet(allData);
|
|
355
313
|
}
|
|
356
|
-
|
|
314
|
+
onPacket(event) {
|
|
315
|
+
return this.onPacketDefault(event);
|
|
316
|
+
}
|
|
317
|
+
async onPacketDefault(event) {
|
|
357
318
|
switch (event.t) {
|
|
358
319
|
case 'READY':
|
|
359
320
|
await this.users?.set(event.d.user.id, event.d.user);
|
|
@@ -3,9 +3,9 @@ import type { GatewayIntentBits } from '../../../types';
|
|
|
3
3
|
import type { Cache, ReturnCache } from '../../index';
|
|
4
4
|
export declare class BaseResource<T = any, S = any> {
|
|
5
5
|
protected cache: Cache;
|
|
6
|
-
client: UsingClient;
|
|
6
|
+
readonly client: UsingClient;
|
|
7
7
|
namespace: string;
|
|
8
|
-
constructor(cache: Cache, client
|
|
8
|
+
constructor(cache: Cache, client: UsingClient);
|
|
9
9
|
filter(data: any, id: string): boolean;
|
|
10
10
|
get adapter(): import("../../index").Adapter;
|
|
11
11
|
removeIfNI(intent: keyof typeof GatewayIntentBits, id: string): import("../../../common").Awaitable<void>;
|
|
@@ -3,9 +3,9 @@ import type { GatewayIntentBits } from '../../../types';
|
|
|
3
3
|
import type { Cache, ReturnCache } from '../../index';
|
|
4
4
|
export declare class GuildBasedResource<T = any, S = any> {
|
|
5
5
|
protected cache: Cache;
|
|
6
|
-
client: UsingClient;
|
|
6
|
+
readonly client: UsingClient;
|
|
7
7
|
namespace: string;
|
|
8
|
-
constructor(cache: Cache, client
|
|
8
|
+
constructor(cache: Cache, client: UsingClient);
|
|
9
9
|
filter(data: any, id: string, guild_id: string): boolean;
|
|
10
10
|
parse(data: any, id: string, guild_id: string): any;
|
|
11
11
|
get adapter(): import("../../index").Adapter;
|
|
@@ -3,9 +3,9 @@ import type { GatewayIntentBits } from '../../../types';
|
|
|
3
3
|
import type { Cache, ReturnCache } from '../../index';
|
|
4
4
|
export declare class GuildRelatedResource<T = any, S = any> {
|
|
5
5
|
protected cache: Cache;
|
|
6
|
-
client: UsingClient;
|
|
6
|
+
readonly client: UsingClient;
|
|
7
7
|
namespace: string;
|
|
8
|
-
constructor(cache: Cache, client
|
|
8
|
+
constructor(cache: Cache, client: UsingClient);
|
|
9
9
|
filter(data: any, id: string, guild_id?: string): boolean;
|
|
10
10
|
parse(data: any, id: string, guild_id: string): any;
|
|
11
11
|
get adapter(): import("../../index").Adapter;
|
package/lib/client/base.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ApiHandler } from '../api';
|
|
2
|
-
import type { Adapter } from '../cache';
|
|
2
|
+
import type { Adapter, DisabledCache } from '../cache';
|
|
3
3
|
import { Cache } from '../cache';
|
|
4
4
|
import type { Command, CommandContext, ContextMenuCommand, ExtendedRC, ExtendedRCLocations, ExtraProps, MenuCommandContext, RegisteredMiddlewares, SubCommand, UsingClient } from '../commands';
|
|
5
5
|
import { type InferWithPrefix, type MiddlewareContext } from '../commands/applications/shared';
|
|
@@ -13,7 +13,7 @@ import type { ComponentCommand, ModalCommand } from '../components';
|
|
|
13
13
|
import { ComponentHandler } from '../components/handler';
|
|
14
14
|
import { LangsHandler } from '../langs/handler';
|
|
15
15
|
import type { ChatInputCommandInteraction, ComponentInteraction, EntryPointInteraction, MessageCommandInteraction, ModalSubmitInteraction, UserCommandInteraction } from '../structures';
|
|
16
|
-
import type { LocaleString, RESTPostAPIChannelMessageJSONBody } from '../types';
|
|
16
|
+
import type { APIInteraction, APIInteractionResponse, LocaleString, RESTPostAPIChannelMessageJSONBody } from '../types';
|
|
17
17
|
import type { MessageStructure } from './transformers';
|
|
18
18
|
export declare class BaseClient {
|
|
19
19
|
rest: ApiHandler;
|
|
@@ -55,6 +55,17 @@ export declare class BaseClient {
|
|
|
55
55
|
protected execute(..._options: unknown[]): Promise<void>;
|
|
56
56
|
start(options?: Pick<DeepPartial<StartOptions>, 'langsDir' | 'commandsDir' | 'connection' | 'token' | 'componentsDir'>): Promise<void>;
|
|
57
57
|
protected onPacket(..._packet: unknown[]): Promise<any>;
|
|
58
|
+
/**
|
|
59
|
+
*
|
|
60
|
+
* @param rawBody body of interaction
|
|
61
|
+
* @returns
|
|
62
|
+
*/
|
|
63
|
+
protected onInteractionRequest(rawBody: APIInteraction): Promise<{
|
|
64
|
+
headers: {
|
|
65
|
+
'Content-Type'?: string;
|
|
66
|
+
};
|
|
67
|
+
response: APIInteractionResponse | FormData;
|
|
68
|
+
}>;
|
|
58
69
|
private shouldUploadCommands;
|
|
59
70
|
private syncCachePath;
|
|
60
71
|
uploadCommands({ applicationId, cachePath }?: {
|
|
@@ -74,7 +85,7 @@ export declare class BaseClient {
|
|
|
74
85
|
}>;
|
|
75
86
|
}
|
|
76
87
|
export interface BaseClientOptions {
|
|
77
|
-
context?: (interaction: ChatInputCommandInteraction<boolean> | UserCommandInteraction<boolean> | MessageCommandInteraction<boolean> | ComponentInteraction | ModalSubmitInteraction | EntryPointInteraction<boolean> | When<InferWithPrefix, MessageStructure, never>) =>
|
|
88
|
+
context?: (interaction: ChatInputCommandInteraction<boolean> | UserCommandInteraction<boolean> | MessageCommandInteraction<boolean> | ComponentInteraction | ModalSubmitInteraction | EntryPointInteraction<boolean> | When<InferWithPrefix, MessageStructure, never>) => Record<string, unknown>;
|
|
78
89
|
globalMiddlewares?: readonly (keyof RegisteredMiddlewares)[];
|
|
79
90
|
commands?: {
|
|
80
91
|
defaults?: {
|
|
@@ -147,7 +158,7 @@ export type InternalRuntimeConfigHTTP = Omit<MakeRequired<RC, 'publicKey' | 'por
|
|
|
147
158
|
export type RuntimeConfigHTTP = Omit<MakeRequired<RC, 'publicKey' | 'applicationId'>, 'intents' | 'locations'> & {
|
|
148
159
|
locations: Omit<RC['locations'], 'events'>;
|
|
149
160
|
};
|
|
150
|
-
export type InternalRuntimeConfig =
|
|
161
|
+
export type InternalRuntimeConfig = MakeRequired<RC, 'intents'>;
|
|
151
162
|
export type RuntimeConfig = OmitInsert<InternalRuntimeConfig, 'intents', {
|
|
152
163
|
intents?: IntentStrings | number[] | number;
|
|
153
164
|
}>;
|
|
@@ -155,7 +166,7 @@ export interface ServicesOptions {
|
|
|
155
166
|
rest?: ApiHandler;
|
|
156
167
|
cache?: {
|
|
157
168
|
adapter?: Adapter;
|
|
158
|
-
disabledCache?: boolean |
|
|
169
|
+
disabledCache?: boolean | DisabledCache | ((cacheType: keyof DisabledCache) => boolean);
|
|
159
170
|
};
|
|
160
171
|
langs?: {
|
|
161
172
|
default?: string;
|
package/lib/client/base.js
CHANGED
|
@@ -8,6 +8,7 @@ const shared_1 = require("../commands/applications/shared");
|
|
|
8
8
|
const handler_1 = require("../commands/handler");
|
|
9
9
|
const common_1 = require("../common");
|
|
10
10
|
const node_fs_1 = require("node:fs");
|
|
11
|
+
const utils_1 = require("../api/utils/utils");
|
|
11
12
|
const handle_1 = require("../commands/handle");
|
|
12
13
|
const bans_1 = require("../common/shorters/bans");
|
|
13
14
|
const voiceStates_1 = require("../common/shorters/voiceStates");
|
|
@@ -15,7 +16,7 @@ const handler_2 = require("../components/handler");
|
|
|
15
16
|
const handler_3 = require("../langs/handler");
|
|
16
17
|
class BaseClient {
|
|
17
18
|
rest = new api_1.ApiHandler({ token: 'INVALID' });
|
|
18
|
-
cache = new cache_1.Cache(0, new cache_1.MemoryAdapter());
|
|
19
|
+
cache = new cache_1.Cache(0, new cache_1.MemoryAdapter(), {}, this);
|
|
19
20
|
applications = new common_1.ApplicationShorter(this);
|
|
20
21
|
users = new common_1.UsersShorter(this);
|
|
21
22
|
channels = new common_1.ChannelShorter(this);
|
|
@@ -142,7 +143,7 @@ class BaseClient {
|
|
|
142
143
|
'users',
|
|
143
144
|
'voiceStates',
|
|
144
145
|
];
|
|
145
|
-
let disabledCache =
|
|
146
|
+
let disabledCache = {};
|
|
146
147
|
if (typeof cache.disabledCache === 'boolean') {
|
|
147
148
|
for (const i of caches) {
|
|
148
149
|
disabledCache[i] = cache.disabledCache;
|
|
@@ -156,7 +157,10 @@ class BaseClient {
|
|
|
156
157
|
else if (typeof cache.disabledCache === 'object') {
|
|
157
158
|
disabledCache = cache.disabledCache;
|
|
158
159
|
}
|
|
159
|
-
|
|
160
|
+
if (cache.adapter)
|
|
161
|
+
this.cache.adapter = cache.adapter;
|
|
162
|
+
if (cache.disabledCache)
|
|
163
|
+
this.cache.buildCache(disabledCache, this);
|
|
160
164
|
}
|
|
161
165
|
if (middlewares) {
|
|
162
166
|
this.middlewares = middlewares;
|
|
@@ -179,23 +183,16 @@ class BaseClient {
|
|
|
179
183
|
});
|
|
180
184
|
}
|
|
181
185
|
}
|
|
182
|
-
async start(options = {
|
|
183
|
-
token: undefined,
|
|
184
|
-
langsDir: undefined,
|
|
185
|
-
commandsDir: undefined,
|
|
186
|
-
connection: undefined,
|
|
187
|
-
componentsDir: undefined,
|
|
188
|
-
}) {
|
|
186
|
+
async start(options = {}) {
|
|
189
187
|
await this.loadLangs(options.langsDir);
|
|
190
188
|
await this.loadCommands(options.commandsDir);
|
|
191
189
|
await this.loadComponents(options.componentsDir);
|
|
192
190
|
const { token: tokenRC, debug } = await this.getRC();
|
|
193
|
-
const token = options
|
|
191
|
+
const token = options.token ?? tokenRC;
|
|
194
192
|
BaseClient.assertString(token, 'token is not a string');
|
|
195
193
|
if (this.rest.options.token === 'INVALID')
|
|
196
194
|
this.rest.options.token = token;
|
|
197
195
|
this.rest.debug = debug;
|
|
198
|
-
this.cache.__setClient(this);
|
|
199
196
|
if (!this.handleCommand)
|
|
200
197
|
this.handleCommand = new handle_1.HandleCommand(this);
|
|
201
198
|
// The reason of this method is so for adapters that need to connect somewhere, have time to connect.
|
|
@@ -205,14 +202,49 @@ class BaseClient {
|
|
|
205
202
|
async onPacket(..._packet) {
|
|
206
203
|
throw new Error('Function not implemented');
|
|
207
204
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
205
|
+
/**
|
|
206
|
+
*
|
|
207
|
+
* @param rawBody body of interaction
|
|
208
|
+
* @returns
|
|
209
|
+
*/
|
|
210
|
+
async onInteractionRequest(rawBody) {
|
|
211
|
+
return new Promise(async (r) => {
|
|
212
|
+
await this.handleCommand.interaction(rawBody, -1, async ({ body, files }) => {
|
|
213
|
+
let response;
|
|
214
|
+
const headers = {};
|
|
215
|
+
if (files) {
|
|
216
|
+
response = new FormData();
|
|
217
|
+
for (const [index, file] of files.entries()) {
|
|
218
|
+
const fileKey = file.key ?? `files[${index}]`;
|
|
219
|
+
if ((0, utils_1.isBufferLike)(file.data)) {
|
|
220
|
+
response.append(fileKey, new Blob([file.data], { type: file.contentType }), file.filename);
|
|
221
|
+
}
|
|
222
|
+
else {
|
|
223
|
+
response.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.filename);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
if (body) {
|
|
227
|
+
response.append('payload_json', JSON.stringify(body));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
response = body ?? {};
|
|
232
|
+
headers['Content-Type'] = 'application/json';
|
|
233
|
+
}
|
|
234
|
+
return r({
|
|
235
|
+
headers,
|
|
236
|
+
response,
|
|
237
|
+
});
|
|
238
|
+
});
|
|
214
239
|
});
|
|
215
240
|
}
|
|
241
|
+
async shouldUploadCommands(cachePath, guildId) {
|
|
242
|
+
const should = await this.commands.shouldUpload(cachePath, guildId);
|
|
243
|
+
this.logger.debug(should
|
|
244
|
+
? `[${guildId ?? 'global'}] Change(s) detected, uploading commands`
|
|
245
|
+
: `[${guildId ?? 'global'}] commands seems to be up to date`);
|
|
246
|
+
return should;
|
|
247
|
+
}
|
|
216
248
|
syncCachePath(cachePath) {
|
|
217
249
|
return node_fs_1.promises.writeFile(cachePath, JSON.stringify(this.commands.values.filter(cmd => !('ignore' in cmd) || cmd.ignore !== shared_1.IgnoreCommand.Slash).map(x => x.toJSON())));
|
|
218
250
|
}
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import type { DeepPartial } from '../common';
|
|
2
|
-
import type { APIInteraction, APIInteractionResponse } from '../types';
|
|
3
2
|
import type { BaseClientOptions, StartOptions } from './base';
|
|
4
3
|
import { BaseClient } from './base';
|
|
5
4
|
export declare class HttpClient extends BaseClient {
|
|
6
5
|
constructor(options?: BaseClientOptions);
|
|
7
6
|
start(options?: DeepPartial<Omit<StartOptions, 'connection' | 'eventsDir'>>): Promise<void>;
|
|
8
|
-
onPacket(rawBody: APIInteraction): Promise<{
|
|
9
|
-
headers: {
|
|
10
|
-
'Content-Type'?: string;
|
|
11
|
-
};
|
|
12
|
-
response: APIInteractionResponse | FormData;
|
|
13
|
-
}>;
|
|
14
7
|
}
|
package/lib/client/httpclient.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.HttpClient = void 0;
|
|
4
|
-
const utils_1 = require("../api/utils/utils");
|
|
5
4
|
const base_1 = require("./base");
|
|
6
5
|
class HttpClient extends base_1.BaseClient {
|
|
7
6
|
constructor(options) {
|
|
@@ -11,36 +10,5 @@ class HttpClient extends base_1.BaseClient {
|
|
|
11
10
|
await super.start(options);
|
|
12
11
|
return this.execute(options.httpConnection ?? {});
|
|
13
12
|
}
|
|
14
|
-
async onPacket(rawBody) {
|
|
15
|
-
return new Promise(async (r) => {
|
|
16
|
-
await this.handleCommand.interaction(rawBody, -1, async ({ body, files }) => {
|
|
17
|
-
let response;
|
|
18
|
-
const headers = {};
|
|
19
|
-
if (files) {
|
|
20
|
-
response = new FormData();
|
|
21
|
-
for (const [index, file] of files.entries()) {
|
|
22
|
-
const fileKey = file.key ?? `files[${index}]`;
|
|
23
|
-
if ((0, utils_1.isBufferLike)(file.data)) {
|
|
24
|
-
response.append(fileKey, new Blob([file.data], { type: file.contentType }), file.filename);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
response.append(fileKey, new Blob([`${file.data}`], { type: file.contentType }), file.filename);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (body) {
|
|
31
|
-
response.append('payload_json', JSON.stringify(body));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
response = body ?? {};
|
|
36
|
-
headers['Content-Type'] = 'application/json';
|
|
37
|
-
}
|
|
38
|
-
return r({
|
|
39
|
-
headers,
|
|
40
|
-
response,
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
13
|
}
|
|
46
14
|
exports.HttpClient = HttpClient;
|
package/lib/client/types.d.ts
CHANGED
|
@@ -64,7 +64,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
64
64
|
}
|
|
65
65
|
setServices(rest) {
|
|
66
66
|
super.setServices(rest);
|
|
67
|
-
if (rest.cache) {
|
|
67
|
+
if (rest.cache?.adapter) {
|
|
68
68
|
this.__setServicesCache = true;
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -84,13 +84,8 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
84
84
|
this.logger = new __1.Logger({
|
|
85
85
|
name: `[Worker #${workerData.workerId}]`,
|
|
86
86
|
});
|
|
87
|
-
if (this.__setServicesCache)
|
|
88
|
-
this.
|
|
89
|
-
cache: {
|
|
90
|
-
disabledCache: this.cache.disabledCache,
|
|
91
|
-
},
|
|
92
|
-
});
|
|
93
|
-
}
|
|
87
|
+
if (this.__setServicesCache)
|
|
88
|
+
delete this.__setServicesCache;
|
|
94
89
|
else {
|
|
95
90
|
const adapter = new cache_1.WorkerAdapter(workerData);
|
|
96
91
|
if (this.options.postMessage) {
|
|
@@ -99,11 +94,9 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
99
94
|
this.setServices({
|
|
100
95
|
cache: {
|
|
101
96
|
adapter,
|
|
102
|
-
disabledCache: this.cache.disabledCache,
|
|
103
97
|
},
|
|
104
98
|
});
|
|
105
99
|
}
|
|
106
|
-
delete this.__setServicesCache;
|
|
107
100
|
if (workerData.debug) {
|
|
108
101
|
this.debugger = new __1.Logger({
|
|
109
102
|
name: `[Worker #${workerData.workerId}]`,
|
|
@@ -45,7 +45,7 @@ export declare class CommandContext<T extends OptionsRecord = {}, M extends keyo
|
|
|
45
45
|
isChat(): this is CommandContext<T, M>;
|
|
46
46
|
inGuild(): this is GuildCommandContext<T, M>;
|
|
47
47
|
}
|
|
48
|
-
export interface GuildCommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never> extends Omit<MakeRequired<CommandContext<T, M>, 'guildId'>, 'guild'> {
|
|
48
|
+
export interface GuildCommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never> extends Omit<MakeRequired<CommandContext<T, M>, 'guildId' | 'member'>, 'guild'> {
|
|
49
49
|
guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'>>;
|
|
50
50
|
guild(mode?: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
|
|
51
51
|
}
|
|
@@ -40,7 +40,7 @@ export declare class EntryPointContext<M extends keyof RegisteredMiddlewares = n
|
|
|
40
40
|
isEntryPoint(): this is EntryPointContext<M>;
|
|
41
41
|
inGuild(): this is GuildEntryPointContext<M>;
|
|
42
42
|
}
|
|
43
|
-
export interface GuildEntryPointContext<M extends keyof RegisteredMiddlewares = never> extends Omit<MakeRequired<EntryPointContext<M>, 'guildId'>, 'guild'> {
|
|
43
|
+
export interface GuildEntryPointContext<M extends keyof RegisteredMiddlewares = never> extends Omit<MakeRequired<EntryPointContext<M>, 'guildId' | 'member'>, 'guild'> {
|
|
44
44
|
guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'>>;
|
|
45
45
|
guild(mode?: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
|
|
46
46
|
}
|
|
@@ -39,8 +39,8 @@ export declare abstract class ContextMenuCommand {
|
|
|
39
39
|
reload(): Promise<void>;
|
|
40
40
|
abstract run?(context: MenuCommandContext<any>): any;
|
|
41
41
|
onAfterRun?(context: MenuCommandContext<any>, error: unknown | undefined): any;
|
|
42
|
-
onRunError(context: MenuCommandContext<any, never>, error: unknown): any;
|
|
43
|
-
onMiddlewaresError(context: MenuCommandContext<any, never>, error: string): any;
|
|
44
|
-
onBotPermissionsFail(context: MenuCommandContext<any, never>, permissions: PermissionStrings): any;
|
|
45
|
-
onInternalError(client: UsingClient, command: ContextMenuCommand, error?: unknown): any;
|
|
42
|
+
onRunError?(context: MenuCommandContext<any, never>, error: unknown): any;
|
|
43
|
+
onMiddlewaresError?(context: MenuCommandContext<any, never>, error: string): any;
|
|
44
|
+
onBotPermissionsFail?(context: MenuCommandContext<any, never>, permissions: PermissionStrings): any;
|
|
45
|
+
onInternalError?(client: UsingClient, command: ContextMenuCommand, error?: unknown): any;
|
|
46
46
|
}
|
|
@@ -39,17 +39,5 @@ class ContextMenuCommand {
|
|
|
39
39
|
const __tempCommand = await (0, common_1.magicImport)(this.__filePath).then(x => x.default ?? x);
|
|
40
40
|
Object.setPrototypeOf(this, __tempCommand.prototype);
|
|
41
41
|
}
|
|
42
|
-
onRunError(context, error) {
|
|
43
|
-
context.client.logger.fatal(`${this.name}.<onRunError>`, context.author.id, error);
|
|
44
|
-
}
|
|
45
|
-
onMiddlewaresError(context, error) {
|
|
46
|
-
context.client.logger.fatal(`${this.name}.<onMiddlewaresError>`, context.author.id, error);
|
|
47
|
-
}
|
|
48
|
-
onBotPermissionsFail(context, permissions) {
|
|
49
|
-
context.client.logger.fatal(`${this.name}.<onBotPermissionsFail>`, context.author.id, permissions);
|
|
50
|
-
}
|
|
51
|
-
onInternalError(client, command, error) {
|
|
52
|
-
client.logger.fatal(command.name, error);
|
|
53
|
-
}
|
|
54
42
|
}
|
|
55
43
|
exports.ContextMenuCommand = ContextMenuCommand;
|
|
@@ -43,7 +43,7 @@ export declare class MenuCommandContext<T extends MessageCommandInteraction | Us
|
|
|
43
43
|
isMenuMessage(): this is MenuCommandContext<MessageCommandInteraction>;
|
|
44
44
|
inGuild(): this is GuildMenuCommandContext<T, M>;
|
|
45
45
|
}
|
|
46
|
-
export interface GuildMenuCommandContext<T extends MessageCommandInteraction | UserCommandInteraction, M extends keyof RegisteredMiddlewares = never> extends Omit<MakeRequired<MenuCommandContext<T, M>, 'guildId'>, 'guild'> {
|
|
46
|
+
export interface GuildMenuCommandContext<T extends MessageCommandInteraction | UserCommandInteraction, M extends keyof RegisteredMiddlewares = never> extends Omit<MakeRequired<MenuCommandContext<T, M>, 'guildId' | 'member'>, 'guild'> {
|
|
47
47
|
guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'>>;
|
|
48
48
|
guild(mode?: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
|
|
49
49
|
}
|
package/lib/commands/handle.js
CHANGED
|
@@ -40,7 +40,7 @@ class HandleCommand {
|
|
|
40
40
|
if (context.guildId && command.botPermissions) {
|
|
41
41
|
const permissions = this.checkPermissions(interaction.appPermissions, command.botPermissions);
|
|
42
42
|
if (permissions)
|
|
43
|
-
return command.onBotPermissionsFail(context, permissions);
|
|
43
|
+
return command.onBotPermissionsFail?.(context, permissions);
|
|
44
44
|
}
|
|
45
45
|
const resultGlobal = await this.runGlobalMiddlewares(command, context);
|
|
46
46
|
if (typeof resultGlobal === 'boolean')
|
|
@@ -54,13 +54,13 @@ class HandleCommand {
|
|
|
54
54
|
await command.onAfterRun?.(context, undefined);
|
|
55
55
|
}
|
|
56
56
|
catch (error) {
|
|
57
|
-
await command.onRunError(context, error);
|
|
57
|
+
await command.onRunError?.(context, error);
|
|
58
58
|
await command.onAfterRun?.(context, error);
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
catch (error) {
|
|
62
62
|
try {
|
|
63
|
-
await command.onInternalError(this.client, command, error);
|
|
63
|
+
await command.onInternalError?.(this.client, command, error);
|
|
64
64
|
}
|
|
65
65
|
catch {
|
|
66
66
|
// pass
|
package/lib/commands/handler.js
CHANGED
|
@@ -448,14 +448,10 @@ class CommandHandler extends common_1.BaseHandler {
|
|
|
448
448
|
if (!(commandInstance instanceof menu_1.ContextMenuCommand))
|
|
449
449
|
return false;
|
|
450
450
|
commandInstance.onAfterRun ??= this.client.options.commands?.defaults?.onAfterRun;
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
if (this.client.options.commands?.defaults?.onMiddlewaresError)
|
|
456
|
-
commandInstance.onMiddlewaresError ??= this.client.options.commands.defaults.onMiddlewaresError;
|
|
457
|
-
if (this.client.options.commands?.defaults?.onRunError)
|
|
458
|
-
commandInstance.onRunError ??= this.client.options.commands.defaults.onRunError;
|
|
451
|
+
commandInstance.onBotPermissionsFail ??= this.client.options.commands?.defaults?.onBotPermissionsFail;
|
|
452
|
+
commandInstance.onInternalError ??= this.client.options.commands?.defaults?.onInternalError;
|
|
453
|
+
commandInstance.onMiddlewaresError ??= this.client.options.commands?.defaults?.onMiddlewaresError;
|
|
454
|
+
commandInstance.onRunError ??= this.client.options.commands?.defaults?.onRunError;
|
|
459
455
|
return commandInstance;
|
|
460
456
|
}
|
|
461
457
|
stablishCommandDefaults(commandInstance) {
|
|
@@ -126,7 +126,7 @@ export interface ContextComponentCommandInteractionMap {
|
|
|
126
126
|
MentionableSelect: MentionableSelectMenuInteraction;
|
|
127
127
|
ChannelSelect: ChannelSelectMenuInteraction;
|
|
128
128
|
}
|
|
129
|
-
export interface GuildComponentContext<Type extends keyof ContextComponentCommandInteractionMap, M extends keyof RegisteredMiddlewares = never> extends Omit<MakeRequired<ComponentContext<Type, M>, 'guildId'>, 'guild'> {
|
|
129
|
+
export interface GuildComponentContext<Type extends keyof ContextComponentCommandInteractionMap, M extends keyof RegisteredMiddlewares = never> extends Omit<MakeRequired<ComponentContext<Type, M>, 'guildId' | 'member'>, 'guild'> {
|
|
130
130
|
guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'>>;
|
|
131
131
|
guild(mode?: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
|
|
132
132
|
}
|
|
@@ -109,7 +109,7 @@ export declare class ModalContext<M extends keyof RegisteredMiddlewares = never>
|
|
|
109
109
|
isModal(): this is ModalContext<M>;
|
|
110
110
|
inGuild(): this is GuildModalContext<M>;
|
|
111
111
|
}
|
|
112
|
-
export interface GuildModalContext<M extends keyof RegisteredMiddlewares = never> extends Omit<MakeRequired<ModalContext<M>, 'guildId'>, 'guild'> {
|
|
112
|
+
export interface GuildModalContext<M extends keyof RegisteredMiddlewares = never> extends Omit<MakeRequired<ModalContext<M>, 'guildId' | 'member'>, 'guild'> {
|
|
113
113
|
guild(mode?: 'rest' | 'flow'): Promise<GuildStructure<'cached' | 'api'>>;
|
|
114
114
|
guild(mode?: 'cache'): ReturnCache<GuildStructure<'cached'> | undefined>;
|
|
115
115
|
}
|