seyfert 1.2.1 → 1.2.3
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/LICENSE +190 -190
- package/README.md +46 -46
- package/lib/api/Router.d.ts +9 -0
- package/lib/api/Router.js +16 -8
- package/lib/api/Routes/cdn.d.ts +26 -15
- package/lib/api/api.d.ts +2 -3
- package/lib/api/api.js +4 -9
- package/lib/api/index.d.ts +0 -1
- package/lib/api/index.js +0 -1
- package/lib/builders/Modal.d.ts +4 -1
- package/lib/builders/Modal.js +4 -1
- package/lib/cache/adapters/default.d.ts +1 -0
- package/lib/cache/adapters/default.js +4 -0
- package/lib/cache/adapters/redis.d.ts +2 -0
- package/lib/cache/adapters/redis.js +17 -0
- package/lib/cache/adapters/types.d.ts +1 -0
- package/lib/cache/adapters/workeradapter.d.ts +1 -0
- package/lib/cache/adapters/workeradapter.js +6 -9
- package/lib/cache/index.d.ts +4 -6
- package/lib/cache/index.js +3 -0
- package/lib/cache/resources/overwrites.d.ts +2 -0
- package/lib/cache/resources/voice-states.d.ts +7 -2
- package/lib/cache/resources/voice-states.js +11 -0
- package/lib/client/base.d.ts +1 -1
- package/lib/client/base.js +8 -5
- package/lib/client/oninteractioncreate.js +7 -7
- package/lib/client/onmessagecreate.js +27 -15
- package/lib/client/workerclient.js +6 -12
- package/lib/commands/applications/chat.d.ts +20 -15
- package/lib/commands/applications/chat.js +13 -7
- package/lib/commands/applications/chatcontext.d.ts +2 -1
- package/lib/commands/applications/chatcontext.js +3 -0
- package/lib/commands/applications/menu.d.ts +4 -3
- package/lib/commands/applications/menu.js +9 -6
- package/lib/commands/applications/menucontext.d.ts +4 -1
- package/lib/commands/applications/menucontext.js +9 -0
- package/lib/commands/applications/shared.d.ts +4 -0
- package/lib/commands/applications/shared.js +6 -0
- package/lib/commands/basecontex.d.ts +1 -1
- package/lib/commands/basecontex.js +5 -11
- package/lib/commands/decorators.d.ts +14 -4
- package/lib/commands/decorators.js +29 -5
- package/lib/commands/handler.js +2 -0
- package/lib/common/shorters/channels.d.ts +12 -2
- package/lib/common/shorters/channels.js +16 -2
- package/lib/common/shorters/members.d.ts +6 -0
- package/lib/common/shorters/members.js +6 -0
- package/lib/common/shorters/messages.d.ts +2 -2
- package/lib/common/shorters/messages.js +7 -3
- package/lib/common/types/options.d.ts +2 -2
- package/lib/components/componentcontext.d.ts +1 -0
- package/lib/components/componentcontext.js +3 -0
- package/lib/structures/GuildEmoji.d.ts +2 -2
- package/lib/structures/GuildEmoji.js +1 -1
- package/lib/structures/GuildMember.d.ts +1 -5
- package/lib/structures/GuildMember.js +3 -3
- package/lib/structures/Message.d.ts +1 -1
- package/lib/structures/User.d.ts +2 -3
- package/lib/structures/User.js +9 -4
- package/lib/structures/VoiceState.d.ts +18 -0
- package/lib/structures/VoiceState.js +48 -0
- package/lib/structures/Webhook.js +1 -1
- package/lib/structures/channels.d.ts +11 -3
- package/lib/structures/channels.js +14 -1
- package/lib/structures/extra/BaseGuild.js +3 -3
- package/lib/structures/extra/Permissions.d.ts +1 -1
- package/lib/structures/index.d.ts +1 -0
- package/lib/structures/index.js +1 -0
- package/lib/websocket/discord/shard.d.ts +4 -4
- package/lib/websocket/discord/shard.js +12 -17
- package/lib/websocket/discord/sharder.d.ts +1 -1
- package/lib/websocket/discord/sharder.js +2 -2
- package/lib/websocket/discord/worker.d.ts +1 -1
- package/lib/websocket/discord/workermanager.js +4 -10
- package/lib/websocket/structures/index.d.ts +6 -99
- package/lib/websocket/structures/index.js +29 -211
- package/lib/websocket/structures/timeout.d.ts +2 -2
- package/lib/websocket/structures/timeout.js +13 -16
- package/package.json +2 -2
- package/lib/api/CDN.d.ts +0 -212
- package/lib/api/CDN.js +0 -228
- package/lib/common/shorters/overwrites.d.ts +0 -29
- package/lib/common/shorters/overwrites.js +0 -63
- package/lib/components/listener.d.ts +0 -11
- package/lib/components/listener.js +0 -17
- package/lib/structures/extra/BaseComponent.d.ts +0 -9
- package/lib/structures/extra/BaseComponent.js +0 -12
- package/lib/structures/extra/BaseSelectMenuComponent.d.ts +0 -9
- package/lib/structures/extra/BaseSelectMenuComponent.js +0 -13
package/lib/api/api.js
CHANGED
|
@@ -7,7 +7,7 @@ const promises_1 = require("node:timers/promises");
|
|
|
7
7
|
const node_worker_threads_1 = require("node:worker_threads");
|
|
8
8
|
const common_1 = require("../common");
|
|
9
9
|
const functions_1 = require("../structures/extra/functions");
|
|
10
|
-
const
|
|
10
|
+
const Router_1 = require("./Router");
|
|
11
11
|
const bucket_1 = require("./bucket");
|
|
12
12
|
const shared_1 = require("./shared");
|
|
13
13
|
const utils_1 = require("./utils/utils");
|
|
@@ -16,7 +16,7 @@ class ApiHandler {
|
|
|
16
16
|
globalBlock = false;
|
|
17
17
|
ratelimits = new Map();
|
|
18
18
|
readyQueue = [];
|
|
19
|
-
cdn =
|
|
19
|
+
cdn = Router_1.CDNRouter.createProxy();
|
|
20
20
|
debugger;
|
|
21
21
|
workerPromises;
|
|
22
22
|
constructor(options) {
|
|
@@ -62,14 +62,9 @@ class ApiHandler {
|
|
|
62
62
|
}, request.files
|
|
63
63
|
?.filter(x => !['string', 'boolean', 'number'].includes(typeof x.data))
|
|
64
64
|
.map(x => x.data));
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const promise = new Promise((res, rej) => {
|
|
68
|
-
resolve = res;
|
|
69
|
-
reject = rej;
|
|
65
|
+
return new Promise((res, rej) => {
|
|
66
|
+
this.workerPromises.set(nonce, { reject: rej, resolve: res });
|
|
70
67
|
});
|
|
71
|
-
this.workerPromises.set(nonce, { reject, resolve });
|
|
72
|
-
return promise;
|
|
73
68
|
}
|
|
74
69
|
const route = request.route || this.routefy(url, method);
|
|
75
70
|
let attempts = 0;
|
package/lib/api/index.d.ts
CHANGED
package/lib/api/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./CDN"), exports);
|
|
18
17
|
__exportStar(require("./Router"), exports);
|
|
19
18
|
__exportStar(require("./Routes"), exports);
|
|
20
19
|
__exportStar(require("./api"), exports);
|
package/lib/builders/Modal.d.ts
CHANGED
|
@@ -9,7 +9,10 @@ import type { ModalBuilderComponents, ModalSubmitCallback } from './types';
|
|
|
9
9
|
* @example
|
|
10
10
|
* const modal = new Modal();
|
|
11
11
|
* modal.setTitle("Sample Modal");
|
|
12
|
-
* modal.addComponents(
|
|
12
|
+
* modal.addComponents(
|
|
13
|
+
* new ActionRow<TextInput>()
|
|
14
|
+
* .addComponents(new TextInput().setLabel("Enter text"))
|
|
15
|
+
* ));
|
|
13
16
|
* modal.run((interaction) => {
|
|
14
17
|
* // Handle modal submission
|
|
15
18
|
* });
|
package/lib/builders/Modal.js
CHANGED
|
@@ -10,7 +10,10 @@ const index_1 = require("./index");
|
|
|
10
10
|
* @example
|
|
11
11
|
* const modal = new Modal();
|
|
12
12
|
* modal.setTitle("Sample Modal");
|
|
13
|
-
* modal.addComponents(
|
|
13
|
+
* modal.addComponents(
|
|
14
|
+
* new ActionRow<TextInput>()
|
|
15
|
+
* .addComponents(new TextInput().setLabel("Enter text"))
|
|
16
|
+
* ));
|
|
14
17
|
* modal.run((interaction) => {
|
|
15
18
|
* // Handle modal submission
|
|
16
19
|
* });
|
|
@@ -16,6 +16,7 @@ export declare class MemoryAdapter implements Adapter {
|
|
|
16
16
|
count(to: string): number;
|
|
17
17
|
remove(keys: string): void;
|
|
18
18
|
remove(keys: string[]): void;
|
|
19
|
+
flush(): void;
|
|
19
20
|
contains(to: string, keys: string): boolean;
|
|
20
21
|
getToRelationship(to: string): string[];
|
|
21
22
|
bulkAddToRelationShip(data: Record<string, string[]>): void;
|
|
@@ -12,6 +12,7 @@ export declare class RedisAdapter implements Adapter {
|
|
|
12
12
|
} | {
|
|
13
13
|
redisOptions: RedisOptions;
|
|
14
14
|
}) & RedisAdapterOptions);
|
|
15
|
+
private __scanSets;
|
|
15
16
|
scan(query: string, returnKeys?: false): Promise<any[]>;
|
|
16
17
|
scan(query: string, returnKeys: true): Promise<string[]>;
|
|
17
18
|
get(keys: string[]): Promise<any[]>;
|
|
@@ -24,6 +25,7 @@ export declare class RedisAdapter implements Adapter {
|
|
|
24
25
|
keys(to: string): Promise<string[]>;
|
|
25
26
|
count(to: string): Promise<number>;
|
|
26
27
|
remove(keys: string | string[]): Promise<void>;
|
|
28
|
+
flush(): Promise<void>;
|
|
27
29
|
contains(to: string, keys: string): Promise<boolean>;
|
|
28
30
|
getToRelationship(to: string): Promise<string[]>;
|
|
29
31
|
bulkAddToRelationShip(data: Record<string, string[]>): Promise<void>;
|
|
@@ -19,6 +19,20 @@ class RedisAdapter {
|
|
|
19
19
|
this.client = 'client' in data ? data.client : new Redis(data.redisOptions);
|
|
20
20
|
this.namespace = data.namespace ?? 'seyfert';
|
|
21
21
|
}
|
|
22
|
+
__scanSets(query, returnKeys = false) {
|
|
23
|
+
const match = this.buildKey(query);
|
|
24
|
+
return new Promise((r, j) => {
|
|
25
|
+
const stream = this.client.scanStream({
|
|
26
|
+
match,
|
|
27
|
+
type: 'set',
|
|
28
|
+
});
|
|
29
|
+
const keys = [];
|
|
30
|
+
stream
|
|
31
|
+
.on('data', resultKeys => keys.push(...resultKeys))
|
|
32
|
+
.on('end', () => (returnKeys ? r(keys.map(x => this.buildKey(x))) : r(this.get(keys))))
|
|
33
|
+
.on('error', err => j(err));
|
|
34
|
+
});
|
|
35
|
+
}
|
|
22
36
|
scan(query, returnKeys = false) {
|
|
23
37
|
const match = this.buildKey(query);
|
|
24
38
|
return new Promise((r, j) => {
|
|
@@ -107,6 +121,9 @@ class RedisAdapter {
|
|
|
107
121
|
}
|
|
108
122
|
await this.client.del(...keys.map(x => this.buildKey(x)));
|
|
109
123
|
}
|
|
124
|
+
async flush() {
|
|
125
|
+
await this.remove(await Promise.all([this.scan(this.buildKey('*'), true), this.__scanSets(this.buildKey('*'), true)]).then(x => x.flat()));
|
|
126
|
+
}
|
|
110
127
|
async contains(to, keys) {
|
|
111
128
|
return (await this.client.sismember(`${this.buildKey(to)}:set`, keys)) === 1;
|
|
112
129
|
}
|
|
@@ -17,6 +17,7 @@ export interface Adapter {
|
|
|
17
17
|
keys(to: string): Awaitable<string[]>;
|
|
18
18
|
count(to: string): Awaitable<number>;
|
|
19
19
|
remove(keys: string | string[]): Awaitable<void>;
|
|
20
|
+
flush(): Awaitable<void>;
|
|
20
21
|
contains(to: string, keys: string): Awaitable<boolean>;
|
|
21
22
|
getToRelationship(to: string): Awaitable<string[]>;
|
|
22
23
|
bulkAddToRelationShip(data: Record<string, string[]>): Awaitable<void>;
|
|
@@ -24,6 +24,7 @@ export declare class WorkerAdapter implements Adapter {
|
|
|
24
24
|
keys(...rest: any[]): Promise<any>;
|
|
25
25
|
count(...rest: any[]): Promise<any>;
|
|
26
26
|
remove(...rest: any[]): Promise<any>;
|
|
27
|
+
flush(): Promise<any>;
|
|
27
28
|
contains(...rest: any[]): Promise<any>;
|
|
28
29
|
getToRelationship(...rest: any[]): Promise<any>;
|
|
29
30
|
bulkAddToRelationShip(...rest: any[]): Promise<any>;
|
|
@@ -26,19 +26,13 @@ class WorkerAdapter {
|
|
|
26
26
|
method,
|
|
27
27
|
workerId: this.workerData.workerId,
|
|
28
28
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
let timeout = -1;
|
|
33
|
-
const promise = new Promise((res, rej) => {
|
|
34
|
-
resolve = res;
|
|
35
|
-
timeout = setTimeout(() => {
|
|
29
|
+
return new Promise((res, rej) => {
|
|
30
|
+
const timeout = setTimeout(() => {
|
|
36
31
|
this.promises.delete(nonce);
|
|
37
32
|
rej(new Error('Timeout cache request'));
|
|
38
33
|
}, 60e3);
|
|
34
|
+
this.promises.set(nonce, { resolve: res, timeout });
|
|
39
35
|
});
|
|
40
|
-
this.promises.set(nonce, { resolve, timeout });
|
|
41
|
-
return promise;
|
|
42
36
|
}
|
|
43
37
|
scan(...rest) {
|
|
44
38
|
return this.send('scan', ...rest);
|
|
@@ -64,6 +58,9 @@ class WorkerAdapter {
|
|
|
64
58
|
remove(...rest) {
|
|
65
59
|
return this.send('remove', ...rest);
|
|
66
60
|
}
|
|
61
|
+
flush() {
|
|
62
|
+
return this.send('flush');
|
|
63
|
+
}
|
|
67
64
|
contains(...rest) {
|
|
68
65
|
return this.send('contains', ...rest);
|
|
69
66
|
}
|
package/lib/cache/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { StageInstances } from './resources/stage-instances';
|
|
|
11
11
|
import { Stickers } from './resources/stickers';
|
|
12
12
|
import { Threads } from './resources/threads';
|
|
13
13
|
import { VoiceStates } from './resources/voice-states';
|
|
14
|
-
import { type GatewayDispatchPayload
|
|
14
|
+
import { GatewayIntentBits, type GatewayDispatchPayload } from 'discord-api-types/v10';
|
|
15
15
|
import type { InternalOptions, UsingClient } from '../commands';
|
|
16
16
|
import { Overwrites } from './resources/overwrites';
|
|
17
17
|
export type InferAsyncCache = InternalOptions extends {
|
|
@@ -40,6 +40,7 @@ export declare class Cache {
|
|
|
40
40
|
presences?: Presences;
|
|
41
41
|
stageInstances?: StageInstances;
|
|
42
42
|
constructor(intents: number, adapter: Adapter, disabledCache?: (NonGuildBased | GuildBased | GuildRelated)[], client?: UsingClient);
|
|
43
|
+
flush(): ReturnCache<void>;
|
|
43
44
|
hasIntent(intent: keyof typeof GatewayIntentBits): boolean;
|
|
44
45
|
get hasGuildsIntent(): boolean;
|
|
45
46
|
get hasRolesIntent(): boolean;
|
|
@@ -70,11 +71,7 @@ export declare class Cache {
|
|
|
70
71
|
} & {
|
|
71
72
|
guild_id: string;
|
|
72
73
|
})[];
|
|
73
|
-
voiceStates:
|
|
74
|
-
guild_id: string;
|
|
75
|
-
} & {
|
|
76
|
-
guild_id: string;
|
|
77
|
-
})[];
|
|
74
|
+
voiceStates: import("..").VoiceState[];
|
|
78
75
|
stageInstances: (import("discord-api-types/v10").APIStageInstance & {
|
|
79
76
|
guild_id: string;
|
|
80
77
|
})[];
|
|
@@ -83,6 +80,7 @@ export declare class Cache {
|
|
|
83
80
|
id: string;
|
|
84
81
|
deny: import("../structures/extra/Permissions").PermissionsBitField;
|
|
85
82
|
allow: import("../structures/extra/Permissions").PermissionsBitField;
|
|
83
|
+
guildId: string;
|
|
86
84
|
}[][];
|
|
87
85
|
}>>;
|
|
88
86
|
bulkPatch(keys: (readonly [
|
package/lib/cache/index.js
CHANGED
|
@@ -107,6 +107,9 @@ class Cache {
|
|
|
107
107
|
this.threads?.__setClient(client);
|
|
108
108
|
this.stageInstances?.__setClient(client);
|
|
109
109
|
}
|
|
110
|
+
flush() {
|
|
111
|
+
return this.adapter.flush();
|
|
112
|
+
}
|
|
110
113
|
// internal use ./structures
|
|
111
114
|
hasIntent(intent) {
|
|
112
115
|
return (this.intents & v10_1.GatewayIntentBits[intent]) === v10_1.GatewayIntentBits[intent];
|
|
@@ -9,12 +9,14 @@ export declare class Overwrites extends GuildRelatedResource {
|
|
|
9
9
|
id: string;
|
|
10
10
|
deny: PermissionsBitField;
|
|
11
11
|
allow: PermissionsBitField;
|
|
12
|
+
guildId: string;
|
|
12
13
|
}[] | undefined>;
|
|
13
14
|
values(guild: string): ReturnCache<{
|
|
14
15
|
type: number;
|
|
15
16
|
id: string;
|
|
16
17
|
deny: PermissionsBitField;
|
|
17
18
|
allow: PermissionsBitField;
|
|
19
|
+
guildId: string;
|
|
18
20
|
}[][]>;
|
|
19
21
|
bulk(ids: string[]): ReturnCache<{
|
|
20
22
|
type: number;
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import type { GatewayVoiceState } from 'discord-api-types/v10';
|
|
2
|
+
import type { ReturnCache } from '../..';
|
|
3
|
+
import { VoiceState } from '../../structures';
|
|
2
4
|
import { GuildBasedResource } from './default/guild-based';
|
|
3
|
-
export declare class VoiceStates extends GuildBasedResource
|
|
5
|
+
export declare class VoiceStates extends GuildBasedResource {
|
|
4
6
|
namespace: string;
|
|
5
|
-
|
|
7
|
+
get(memberId: string, guildId: string): ReturnCache<VoiceState | undefined>;
|
|
8
|
+
bulk(ids: string[], guild: string): ReturnCache<VoiceState[]>;
|
|
9
|
+
values(guildId: string): ReturnCache<VoiceState[]>;
|
|
10
|
+
parse(data: any, id: string, guild_id: string): any;
|
|
6
11
|
}
|
|
7
12
|
export type VoiceStateResource = Omit<GatewayVoiceState, 'member'> & {
|
|
8
13
|
guild_id: string;
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VoiceStates = void 0;
|
|
4
|
+
const common_1 = require("../../common");
|
|
5
|
+
const structures_1 = require("../../structures");
|
|
4
6
|
const guild_based_1 = require("./default/guild-based");
|
|
5
7
|
class VoiceStates extends guild_based_1.GuildBasedResource {
|
|
6
8
|
namespace = 'voice_state';
|
|
9
|
+
get(memberId, guildId) {
|
|
10
|
+
return (0, common_1.fakePromise)(super.get(memberId, guildId)).then(state => state ? new structures_1.VoiceState(this.client, state) : undefined);
|
|
11
|
+
}
|
|
12
|
+
bulk(ids, guild) {
|
|
13
|
+
return (0, common_1.fakePromise)(super.bulk(ids, guild)).then(states => states.map(state => (state ? new structures_1.VoiceState(this.client, state) : undefined)).filter(y => !!y));
|
|
14
|
+
}
|
|
15
|
+
values(guildId) {
|
|
16
|
+
return (0, common_1.fakePromise)(super.values(guildId)).then(states => states.map(state => new structures_1.VoiceState(this.client, state)));
|
|
17
|
+
}
|
|
7
18
|
parse(data, id, guild_id) {
|
|
8
19
|
const { member, ...rest } = super.parse(data, id, guild_id);
|
|
9
20
|
return rest;
|
package/lib/client/base.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ApiHandler } from '../api';
|
|
|
2
2
|
import type { Adapter } from '../cache';
|
|
3
3
|
import { Cache } from '../cache';
|
|
4
4
|
import type { Command, ContextMenuCommand, RegisteredMiddlewares } from '../commands';
|
|
5
|
-
import type
|
|
5
|
+
import { type InferWithPrefix, type MiddlewareContext } from '../commands/applications/shared';
|
|
6
6
|
import { type CommandHandlerLike } from '../commands/handler';
|
|
7
7
|
import { ChannelShorter, EmojiShorter, GuildShorter, Logger, MemberShorter, MessageShorter, ReactionShorter, RoleShorter, TemplateShorter, UsersShorter, WebhookShorter, type MakeRequired } from '../common';
|
|
8
8
|
import type { LocaleString } from 'discord-api-types/rest/v10';
|
package/lib/client/base.js
CHANGED
|
@@ -4,6 +4,7 @@ exports.BaseClient = void 0;
|
|
|
4
4
|
const node_path_1 = require("node:path");
|
|
5
5
|
const api_1 = require("../api");
|
|
6
6
|
const cache_1 = require("../cache");
|
|
7
|
+
const shared_1 = require("../commands/applications/shared");
|
|
7
8
|
const handler_1 = require("../commands/handler");
|
|
8
9
|
const common_1 = require("../common");
|
|
9
10
|
const handler_2 = require("../components/handler");
|
|
@@ -155,14 +156,14 @@ class BaseClient {
|
|
|
155
156
|
async uploadCommands(applicationId) {
|
|
156
157
|
applicationId ??= await this.getRC().then(x => x.applicationId ?? this.applicationId);
|
|
157
158
|
BaseClient.assertString(applicationId, 'applicationId is not a string');
|
|
158
|
-
const commands = this.commands.values
|
|
159
|
-
const filter = (0, common_1.filterSplit)(commands, command => !command.
|
|
159
|
+
const commands = this.commands.values;
|
|
160
|
+
const filter = (0, common_1.filterSplit)(commands, command => !command.guildId);
|
|
160
161
|
await this.proxy.applications(applicationId).commands.put({
|
|
161
|
-
body: filter.expect,
|
|
162
|
+
body: filter.expect.filter(cmd => !('ignore' in cmd) || cmd.ignore !== shared_1.IgnoreCommand.Slash).map(x => x.toJSON()),
|
|
162
163
|
});
|
|
163
164
|
const guilds = new Set();
|
|
164
165
|
for (const command of filter.never) {
|
|
165
|
-
for (const guild_id of command.
|
|
166
|
+
for (const guild_id of command.guildId) {
|
|
166
167
|
guilds.add(guild_id);
|
|
167
168
|
}
|
|
168
169
|
}
|
|
@@ -171,7 +172,9 @@ class BaseClient {
|
|
|
171
172
|
.applications(applicationId)
|
|
172
173
|
.guilds(guild)
|
|
173
174
|
.commands.put({
|
|
174
|
-
body: filter.never
|
|
175
|
+
body: filter.never
|
|
176
|
+
.filter(cmd => cmd.guildId?.includes(guild) && (!('ignore' in cmd) || cmd.ignore !== shared_1.IgnoreCommand.Slash))
|
|
177
|
+
.map(x => x.toJSON()),
|
|
175
178
|
});
|
|
176
179
|
}
|
|
177
180
|
}
|
|
@@ -11,7 +11,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
11
11
|
{
|
|
12
12
|
const parentCommand = self.commands?.values.find(x => {
|
|
13
13
|
if (body.data.guild_id) {
|
|
14
|
-
return x.
|
|
14
|
+
return x.guildId?.includes(body.data.guild_id) && x.name === body.data.name;
|
|
15
15
|
}
|
|
16
16
|
return x.name === body.data.name;
|
|
17
17
|
});
|
|
@@ -49,7 +49,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
49
49
|
{
|
|
50
50
|
const command = self.commands?.values.find(x => {
|
|
51
51
|
if (body.data.guild_id) {
|
|
52
|
-
return x.
|
|
52
|
+
return x.guildId?.includes(body.data.guild_id) && x.name === body.data.name;
|
|
53
53
|
}
|
|
54
54
|
return x.name === body.data.name;
|
|
55
55
|
});
|
|
@@ -63,8 +63,8 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
63
63
|
try {
|
|
64
64
|
if (command.botPermissions && interaction.appPermissions) {
|
|
65
65
|
const permissions = interaction.appPermissions.missings(...interaction.appPermissions.values([command.botPermissions]));
|
|
66
|
-
if (permissions.length) {
|
|
67
|
-
return command.
|
|
66
|
+
if (!interaction.appPermissions.has('Administrator') && permissions.length) {
|
|
67
|
+
return command.onBotPermissionsFail?.(context, interaction.appPermissions.keys(permissions));
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
const resultRunGlobalMiddlewares = await command.__runGlobalMiddlewares(context);
|
|
@@ -104,7 +104,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
104
104
|
{
|
|
105
105
|
const parentCommand = self.commands?.values.find(x => {
|
|
106
106
|
if (body.data.guild_id) {
|
|
107
|
-
return x.
|
|
107
|
+
return x.guildId?.includes(body.data.guild_id) && x.name === body.data.name;
|
|
108
108
|
}
|
|
109
109
|
return x.name === body.data.name;
|
|
110
110
|
});
|
|
@@ -119,8 +119,8 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
119
119
|
try {
|
|
120
120
|
if (command.botPermissions && interaction.appPermissions) {
|
|
121
121
|
const permissions = interaction.appPermissions.missings(...interaction.appPermissions.values([command.botPermissions]));
|
|
122
|
-
if (permissions.length) {
|
|
123
|
-
return command.
|
|
122
|
+
if (!interaction.appPermissions.has('Administrator') && permissions.length) {
|
|
123
|
+
return command.onBotPermissionsFail?.(context, interaction.appPermissions.keys(permissions));
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
const [erroredOptions, result] = await command.__runOptions(context, optionsResolver);
|
|
@@ -5,18 +5,21 @@ const v10_1 = require("discord-api-types/v10");
|
|
|
5
5
|
const __1 = require("..");
|
|
6
6
|
const structures_1 = require("../structures");
|
|
7
7
|
function getCommandFromContent(commandRaw, self) {
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const parent = self.commands.values.find(x => x.
|
|
12
|
-
|
|
8
|
+
const rawParentName = commandRaw[0];
|
|
9
|
+
const rawGroupName = commandRaw.length === 3 ? commandRaw[1] : undefined;
|
|
10
|
+
const rawSubcommandName = rawGroupName ? commandRaw[2] : commandRaw[1];
|
|
11
|
+
const parent = self.commands.values.find(x => (!('ignore' in x) || x.ignore !== __1.IgnoreCommand.Message) &&
|
|
12
|
+
(x.name === rawParentName || ('aliases' in x ? x.aliases?.includes(rawParentName) : false)));
|
|
13
|
+
const fullCommandName = `${rawParentName}${rawGroupName ? ` ${rawGroupName} ${rawSubcommandName}` : `${rawSubcommandName ? ` ${rawSubcommandName}` : ''}`}`;
|
|
13
14
|
if (!(parent instanceof __1.Command))
|
|
14
15
|
return { fullCommandName };
|
|
15
|
-
if (
|
|
16
|
-
return getCommandFromContent([
|
|
17
|
-
if (
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
if (rawGroupName && !parent.groups?.[rawGroupName] && !parent.groupsAliases?.[rawGroupName])
|
|
17
|
+
return getCommandFromContent([rawParentName, rawGroupName], self);
|
|
18
|
+
if (rawSubcommandName &&
|
|
19
|
+
!parent.options?.some(x => x instanceof __1.SubCommand && (x.name === rawSubcommandName || x.aliases?.includes(rawSubcommandName))))
|
|
20
|
+
return getCommandFromContent([rawParentName], self);
|
|
21
|
+
const groupName = rawGroupName ? parent.groupsAliases?.[rawGroupName] || rawGroupName : undefined;
|
|
22
|
+
const command = groupName || rawSubcommandName
|
|
20
23
|
? parent.options?.find(opt => {
|
|
21
24
|
if (opt instanceof __1.SubCommand) {
|
|
22
25
|
if (groupName) {
|
|
@@ -25,7 +28,7 @@ function getCommandFromContent(commandRaw, self) {
|
|
|
25
28
|
}
|
|
26
29
|
if (opt.group && !groupName)
|
|
27
30
|
return false;
|
|
28
|
-
return
|
|
31
|
+
return rawSubcommandName === opt.name || opt.aliases?.includes(rawSubcommandName);
|
|
29
32
|
}
|
|
30
33
|
return false;
|
|
31
34
|
})
|
|
@@ -40,7 +43,7 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
40
43
|
if (!self.options?.commands)
|
|
41
44
|
return;
|
|
42
45
|
const message = new structures_1.Message(self, rawMessage);
|
|
43
|
-
const prefixes = (
|
|
46
|
+
const prefixes = (await self.options.commands.prefix(message)).sort((a, b) => b.length - a.length);
|
|
44
47
|
const prefix = prefixes.find(x => message.content.startsWith(x));
|
|
45
48
|
if (!prefix || !message.content.startsWith(prefix))
|
|
46
49
|
return;
|
|
@@ -55,7 +58,7 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
55
58
|
return self.logger.warn(`${fullCommandName} command does not have 'run' callback`);
|
|
56
59
|
if (!command.contexts?.includes(__1.InteractionContextTypes.BOT_DM) && !message.guildId)
|
|
57
60
|
return;
|
|
58
|
-
if (command.
|
|
61
|
+
if (command.guildId && !command.guildId?.includes(message.guildId))
|
|
59
62
|
return;
|
|
60
63
|
const resolved = {
|
|
61
64
|
channels: {},
|
|
@@ -72,14 +75,23 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
72
75
|
const extendContext = self.options?.context?.(message) ?? {};
|
|
73
76
|
Object.assign(context, extendContext);
|
|
74
77
|
try {
|
|
78
|
+
if (command.defaultMemberPermissions && message.guildId) {
|
|
79
|
+
const memberPermissions = await self.members.permissions(message.guildId, message.author.id);
|
|
80
|
+
const permissions = memberPermissions.missings(...memberPermissions.values([command.defaultMemberPermissions]));
|
|
81
|
+
if (!memberPermissions.has('Administrator') &&
|
|
82
|
+
permissions.length &&
|
|
83
|
+
(await message.guild()).ownerId !== message.author.id) {
|
|
84
|
+
return command.onPermissionsFail?.(context, memberPermissions.keys(permissions));
|
|
85
|
+
}
|
|
86
|
+
}
|
|
75
87
|
if (command.botPermissions && message.guildId) {
|
|
76
88
|
const meMember = await self.cache.members?.get(self.botId, message.guildId);
|
|
77
89
|
if (!meMember)
|
|
78
90
|
return; //enable member cache and "Guilds" intent, lol
|
|
79
91
|
const appPermissions = await meMember.fetchPermissions();
|
|
80
92
|
const permissions = appPermissions.missings(...appPermissions.values([command.botPermissions]));
|
|
81
|
-
if (permissions.length) {
|
|
82
|
-
return command.
|
|
93
|
+
if (!appPermissions.has('Administrator') && permissions.length) {
|
|
94
|
+
return command.onBotPermissionsFail?.(context, appPermissions.keys(permissions));
|
|
83
95
|
}
|
|
84
96
|
}
|
|
85
97
|
if (errors.length) {
|
|
@@ -115,7 +115,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
115
115
|
this.logger.fatal('Worker trying send payload by non-existent shard');
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
|
-
await shard.send(
|
|
118
|
+
await shard.send(true, {
|
|
119
119
|
...data,
|
|
120
120
|
});
|
|
121
121
|
this.postMessage({
|
|
@@ -216,8 +216,8 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
216
216
|
let result;
|
|
217
217
|
try {
|
|
218
218
|
// biome-ignore lint/security/noGlobalEval: yes
|
|
219
|
-
result = await eval(`
|
|
220
|
-
(${data.func})(this)
|
|
219
|
+
result = await eval(`
|
|
220
|
+
(${data.func})(this)
|
|
221
221
|
`);
|
|
222
222
|
}
|
|
223
223
|
catch (e) {
|
|
@@ -251,19 +251,13 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
251
251
|
return nonce;
|
|
252
252
|
}
|
|
253
253
|
generateSendPromise(nonce, message = 'Timeout') {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
};
|
|
257
|
-
let timeout = -1;
|
|
258
|
-
const promise = new Promise((res, rej) => {
|
|
259
|
-
resolve = res;
|
|
260
|
-
timeout = setTimeout(() => {
|
|
254
|
+
return new Promise((res, rej) => {
|
|
255
|
+
const timeout = setTimeout(() => {
|
|
261
256
|
this.promises.delete(nonce);
|
|
262
257
|
rej(new Error(message));
|
|
263
258
|
}, 60e3);
|
|
259
|
+
this.promises.set(nonce, { resolve: res, timeout });
|
|
264
260
|
});
|
|
265
|
-
this.promises.set(nonce, { resolve, timeout });
|
|
266
|
-
return promise;
|
|
267
261
|
}
|
|
268
262
|
tellWorker(workerId, func) {
|
|
269
263
|
const nonce = this.generateNonce();
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type APIApplicationCommandBasicOption, type APIApplicationCommandOption,
|
|
1
|
+
import { ApplicationCommandOptionType, ApplicationCommandType, type APIApplicationCommandBasicOption, type APIApplicationCommandOption, type LocaleString } from 'discord-api-types/v10';
|
|
2
2
|
import type { PermissionStrings, SeyfertNumberOption, SeyfertStringOption } from '../..';
|
|
3
3
|
import type { Attachment } from '../../builders';
|
|
4
4
|
import { type FlatObjectKeys } from '../../common';
|
|
5
5
|
import type { AllChannels, AutocompleteInteraction, GuildRole, InteractionGuildMember, User } from '../../structures';
|
|
6
6
|
import type { Groups, IntegrationTypes, InteractionContextTypes, RegisteredMiddlewares } from '../decorators';
|
|
7
7
|
import type { CommandContext } from './chatcontext';
|
|
8
|
-
import type { DefaultLocale, OKFunction, OnOptionsReturnObject, StopFunction, UsingClient } from './shared';
|
|
8
|
+
import type { DefaultLocale, IgnoreCommand, OKFunction, OnOptionsReturnObject, StopFunction, UsingClient } from './shared';
|
|
9
9
|
export interface ReturnOptionsTypes {
|
|
10
10
|
1: never;
|
|
11
11
|
2: never;
|
|
@@ -72,23 +72,20 @@ declare class BaseCommand {
|
|
|
72
72
|
description: string | undefined;
|
|
73
73
|
};
|
|
74
74
|
__autoload?: true;
|
|
75
|
-
|
|
76
|
-
name: string | undefined;
|
|
77
|
-
description: string | undefined;
|
|
78
|
-
defaultDescription: string;
|
|
79
|
-
}>;
|
|
80
|
-
guild_id?: string[];
|
|
75
|
+
guildId?: string[];
|
|
81
76
|
name: string;
|
|
82
77
|
type: number;
|
|
83
78
|
nsfw?: boolean;
|
|
84
79
|
description: string;
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
defaultMemberPermissions?: bigint;
|
|
81
|
+
integrationTypes?: IntegrationTypes[];
|
|
87
82
|
contexts?: InteractionContextTypes[];
|
|
88
83
|
botPermissions?: bigint;
|
|
89
84
|
name_localizations?: Partial<Record<LocaleString, string>>;
|
|
90
85
|
description_localizations?: Partial<Record<LocaleString, string>>;
|
|
91
86
|
options?: CommandOption[] | SubCommand[];
|
|
87
|
+
ignore?: IgnoreCommand;
|
|
88
|
+
aliases?: string[];
|
|
92
89
|
toJSON(): {
|
|
93
90
|
name: BaseCommand['name'];
|
|
94
91
|
type: BaseCommand['type'];
|
|
@@ -96,10 +93,10 @@ declare class BaseCommand {
|
|
|
96
93
|
description: BaseCommand['description'];
|
|
97
94
|
name_localizations: BaseCommand['name_localizations'];
|
|
98
95
|
description_localizations: BaseCommand['description_localizations'];
|
|
99
|
-
guild_id: BaseCommand['
|
|
100
|
-
default_member_permissions:
|
|
96
|
+
guild_id: BaseCommand['guildId'];
|
|
97
|
+
default_member_permissions: string;
|
|
101
98
|
contexts: BaseCommand['contexts'];
|
|
102
|
-
integration_types: BaseCommand['
|
|
99
|
+
integration_types: BaseCommand['integrationTypes'];
|
|
103
100
|
};
|
|
104
101
|
reload(): Promise<void>;
|
|
105
102
|
run?(context: CommandContext<any>): any;
|
|
@@ -107,12 +104,19 @@ declare class BaseCommand {
|
|
|
107
104
|
onRunError?(context: CommandContext<any>, error: unknown): any;
|
|
108
105
|
onOptionsError?(context: CommandContext<{}, never>, metadata: OnOptionsReturnObject): any;
|
|
109
106
|
onMiddlewaresError?(context: CommandContext<{}, never>, error: string): any;
|
|
107
|
+
onBotPermissionsFail?(context: CommandContext<{}, never>, permissions: PermissionStrings): any;
|
|
110
108
|
onPermissionsFail?(context: CommandContext<{}, never>, permissions: PermissionStrings): any;
|
|
111
109
|
onInternalError?(client: UsingClient, error?: unknown): any;
|
|
112
110
|
}
|
|
113
111
|
export declare class Command extends BaseCommand {
|
|
114
112
|
type: ApplicationCommandType;
|
|
115
113
|
groups?: Parameters<typeof Groups>[0];
|
|
114
|
+
groupsAliases?: Record<string, string>;
|
|
115
|
+
__tGroups?: Record<string, {
|
|
116
|
+
name: string | undefined;
|
|
117
|
+
description: string | undefined;
|
|
118
|
+
defaultDescription: string;
|
|
119
|
+
}>;
|
|
116
120
|
toJSON(): {
|
|
117
121
|
options: APIApplicationCommandOption[];
|
|
118
122
|
name: string;
|
|
@@ -122,13 +126,14 @@ export declare class Command extends BaseCommand {
|
|
|
122
126
|
name_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;
|
|
123
127
|
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;
|
|
124
128
|
guild_id: string[] | undefined;
|
|
125
|
-
default_member_permissions: string
|
|
129
|
+
default_member_permissions: string;
|
|
126
130
|
contexts: InteractionContextTypes[] | undefined;
|
|
127
131
|
integration_types: IntegrationTypes[] | undefined;
|
|
128
132
|
};
|
|
129
133
|
onRunError(context: CommandContext<any>, error: unknown): any;
|
|
130
134
|
onOptionsError(context: CommandContext<{}, never>, metadata: OnOptionsReturnObject): any;
|
|
131
135
|
onMiddlewaresError(context: CommandContext<{}, never>, error: string): any;
|
|
136
|
+
onBotPermissionsFail(context: CommandContext<{}, never>, permissions: PermissionStrings): any;
|
|
132
137
|
onPermissionsFail(context: CommandContext<{}, never>, permissions: PermissionStrings): any;
|
|
133
138
|
onInternalError(client: UsingClient, error?: unknown): any;
|
|
134
139
|
}
|
|
@@ -145,7 +150,7 @@ export declare abstract class SubCommand extends BaseCommand {
|
|
|
145
150
|
name_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;
|
|
146
151
|
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;
|
|
147
152
|
guild_id: string[] | undefined;
|
|
148
|
-
default_member_permissions: string
|
|
153
|
+
default_member_permissions: string;
|
|
149
154
|
contexts: InteractionContextTypes[] | undefined;
|
|
150
155
|
integration_types: IntegrationTypes[] | undefined;
|
|
151
156
|
};
|