seyfert 1.1.0 → 1.1.1
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/adapters/types.d.ts +23 -23
- package/lib/cache/resources/default/base.d.ts +9 -9
- package/lib/cache/resources/default/guild-based.d.ts +6 -6
- package/lib/cache/resources/default/guild-based.js +2 -1
- package/lib/cache/resources/default/guild-related.d.ts +8 -8
- package/lib/cache/resources/default/guild-related.js +2 -1
- package/lib/client/base.d.ts +15 -9
- package/lib/client/base.js +45 -7
- package/lib/client/client.d.ts +5 -3
- package/lib/client/client.js +19 -7
- package/lib/client/oninteractioncreate.js +7 -7
- package/lib/client/onmessagecreate.js +4 -1
- package/lib/client/workerclient.d.ts +8 -3
- package/lib/client/workerclient.js +14 -8
- package/lib/commands/applications/chat.d.ts +1 -1
- package/lib/commands/applications/chat.js +13 -6
- package/lib/commands/applications/chatcontext.d.ts +1 -1
- package/lib/commands/applications/menu.js +7 -5
- package/lib/commands/applications/menucontext.d.ts +1 -1
- package/lib/commands/applications/menucontext.js +1 -1
- package/lib/commands/applications/shared.d.ts +5 -4
- package/lib/commands/decorators.d.ts +1 -1
- package/lib/commands/decorators.js +1 -1
- package/lib/commands/handler.d.ts +6 -0
- package/lib/commands/handler.js +6 -1
- package/lib/common/it/utils.d.ts +1 -0
- package/lib/common/it/utils.js +2 -1
- package/lib/common/shorters/messages.d.ts +1 -1
- package/lib/common/shorters/messages.js +1 -1
- package/lib/common/shorters/users.d.ts +0 -6
- package/lib/common/shorters/users.js +0 -34
- package/lib/common/types/util.d.ts +3 -0
- package/lib/components/handler.d.ts +19 -3
- package/lib/components/handler.js +10 -8
- package/lib/events/handler.d.ts +10 -2
- package/lib/events/handler.js +6 -8
- package/lib/index.js +1 -1
- package/lib/langs/handler.d.ts +8 -0
- package/lib/langs/handler.js +1 -0
- package/lib/structures/GuildMember.d.ts +1 -0
- package/lib/structures/GuildMember.js +3 -0
- package/lib/structures/Interaction.d.ts +2 -2
- package/lib/structures/Interaction.js +1 -1
- package/lib/structures/Message.d.ts +1 -1
- package/lib/structures/User.d.ts +1 -0
- package/lib/structures/User.js +5 -0
- package/lib/structures/channels.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1,26 +1,26 @@
|
|
|
1
|
+
import type { Awaitable } from '../../common';
|
|
1
2
|
export interface Adapter {
|
|
2
3
|
isAsync: boolean;
|
|
3
|
-
scan(query: string, keys?: false):
|
|
4
|
-
scan(query: string, keys: true):
|
|
5
|
-
scan(query: string, keys?: boolean):
|
|
6
|
-
get(keys: string[]):
|
|
7
|
-
get(keys: string):
|
|
8
|
-
get(keys: string | string[]):
|
|
9
|
-
set(keyValue: [string, any][]):
|
|
10
|
-
set(id: string, data: any):
|
|
11
|
-
set(id: string | [string, any][], data?: any):
|
|
12
|
-
patch(updateOnly: boolean, keyValue: [string, any][]):
|
|
13
|
-
patch(updateOnly: boolean, id: string, data: any):
|
|
14
|
-
patch(updateOnly: boolean, id: string | [string, any][], data?: any):
|
|
15
|
-
values(to: string):
|
|
16
|
-
keys(to: string):
|
|
17
|
-
count(to: string):
|
|
18
|
-
remove(keys: string | string[]):
|
|
19
|
-
contains(to: string, keys: string):
|
|
20
|
-
getToRelationship(to: string):
|
|
21
|
-
bulkAddToRelationShip(data: Record<string, string[]>):
|
|
22
|
-
addToRelationship(to: string, keys: string | string[]):
|
|
23
|
-
removeToRelationship(to: string, keys: string | string[]):
|
|
24
|
-
removeRelationship(to: string | string[]):
|
|
4
|
+
scan(query: string, keys?: false): Awaitable<any[]>;
|
|
5
|
+
scan(query: string, keys: true): Awaitable<string[]>;
|
|
6
|
+
scan(query: string, keys?: boolean): Awaitable<(any | string)[]>;
|
|
7
|
+
get(keys: string[]): Awaitable<any[]>;
|
|
8
|
+
get(keys: string): Awaitable<any | null>;
|
|
9
|
+
get(keys: string | string[]): Awaitable<any | null>;
|
|
10
|
+
set(keyValue: [string, any][]): Awaitable<void>;
|
|
11
|
+
set(id: string, data: any): Awaitable<void>;
|
|
12
|
+
set(id: string | [string, any][], data?: any): Awaitable<void>;
|
|
13
|
+
patch(updateOnly: boolean, keyValue: [string, any][]): Awaitable<void>;
|
|
14
|
+
patch(updateOnly: boolean, id: string, data: any): Awaitable<void>;
|
|
15
|
+
patch(updateOnly: boolean, id: string | [string, any][], data?: any): Awaitable<void>;
|
|
16
|
+
values(to: string): Awaitable<any[]>;
|
|
17
|
+
keys(to: string): Awaitable<string[]>;
|
|
18
|
+
count(to: string): Awaitable<number>;
|
|
19
|
+
remove(keys: string | string[]): Awaitable<void>;
|
|
20
|
+
contains(to: string, keys: string): Awaitable<boolean>;
|
|
21
|
+
getToRelationship(to: string): Awaitable<string[]>;
|
|
22
|
+
bulkAddToRelationShip(data: Record<string, string[]>): Awaitable<void>;
|
|
23
|
+
addToRelationship(to: string, keys: string | string[]): Awaitable<void>;
|
|
24
|
+
removeToRelationship(to: string, keys: string | string[]): Awaitable<void>;
|
|
25
|
+
removeRelationship(to: string | string[]): Awaitable<void>;
|
|
25
26
|
}
|
|
26
|
-
export type RPV<V> = Promise<V> | V;
|
|
@@ -9,19 +9,19 @@ export declare class BaseResource<T = any> {
|
|
|
9
9
|
constructor(cache: Cache, client?: UsingClient);
|
|
10
10
|
get rest(): import("../../..").ApiHandler;
|
|
11
11
|
get adapter(): import("../../index").Adapter;
|
|
12
|
-
removeIfNI(intent: keyof typeof GatewayIntentBits, id: string): import("
|
|
12
|
+
removeIfNI(intent: keyof typeof GatewayIntentBits, id: string): import("../../../common").Awaitable<void>;
|
|
13
13
|
setIfNI(intent: keyof typeof GatewayIntentBits, id: string, data: any): any;
|
|
14
14
|
get(id: string): ReturnCache<T | undefined>;
|
|
15
15
|
bulk(ids: string[]): ReturnCache<T[]>;
|
|
16
|
-
set(id: string, data: any): import("
|
|
17
|
-
patch<T extends Record<any, any> = Record<any, any>>(id: string, data: T): import("
|
|
18
|
-
remove(id: string): import("
|
|
16
|
+
set(id: string, data: any): import("../../../common").Awaitable<void>;
|
|
17
|
+
patch<T extends Record<any, any> = Record<any, any>>(id: string, data: T): import("../../../common").Awaitable<void>;
|
|
18
|
+
remove(id: string): import("../../../common").Awaitable<void>;
|
|
19
19
|
keys(): ReturnCache<string[]>;
|
|
20
20
|
values(): ReturnCache<T[]>;
|
|
21
|
-
count(): import("
|
|
22
|
-
contains(id: string): import("
|
|
23
|
-
getToRelationship(): import("
|
|
24
|
-
addToRelationship(id: string | string[]): import("
|
|
25
|
-
removeToRelationship(id: string | string[]): import("
|
|
21
|
+
count(): import("../../../common").Awaitable<number>;
|
|
22
|
+
contains(id: string): import("../../../common").Awaitable<boolean>;
|
|
23
|
+
getToRelationship(): import("../../../common").Awaitable<string[]>;
|
|
24
|
+
addToRelationship(id: string | string[]): import("../../../common").Awaitable<void>;
|
|
25
|
+
removeToRelationship(id: string | string[]): import("../../../common").Awaitable<void>;
|
|
26
26
|
hashId(id: string): string;
|
|
27
27
|
}
|
|
@@ -9,7 +9,7 @@ export declare class GuildBasedResource<T = any> {
|
|
|
9
9
|
constructor(cache: Cache, client?: UsingClient);
|
|
10
10
|
parse(data: any, id: string, guild_id: string): any;
|
|
11
11
|
get adapter(): import("../../index").Adapter;
|
|
12
|
-
removeIfNI(intent: keyof typeof GatewayIntentBits, id: string | string[], guildId: string): import("
|
|
12
|
+
removeIfNI(intent: keyof typeof GatewayIntentBits, id: string | string[], guildId: string): import("../../../common").Awaitable<void>;
|
|
13
13
|
setIfNI(intent: keyof typeof GatewayIntentBits, id: string, guildId: string, data: any): any;
|
|
14
14
|
get(id: string, guild: string): ReturnCache<(T & {
|
|
15
15
|
guild_id: string;
|
|
@@ -21,17 +21,17 @@ export declare class GuildBasedResource<T = any> {
|
|
|
21
21
|
set(__keys: [string, any][], guild: string): ReturnCache<void>;
|
|
22
22
|
patch(__keys: string, guild: string, data: any): ReturnCache<void>;
|
|
23
23
|
patch(__keys: [string, any][], guild: string): ReturnCache<void>;
|
|
24
|
-
remove(id: string | string[], guild: string): import("
|
|
24
|
+
remove(id: string | string[], guild: string): import("../../../common").Awaitable<void>;
|
|
25
25
|
keys(guild: string): ReturnCache<string[]>;
|
|
26
26
|
values(guild: string): ReturnCache<(T & {
|
|
27
27
|
guild_id: string;
|
|
28
28
|
})[]>;
|
|
29
29
|
count(guild: string): ReturnCache<number>;
|
|
30
30
|
contains(id: string, guild: string): ReturnCache<boolean>;
|
|
31
|
-
getToRelationship(guild: string): import("
|
|
32
|
-
addToRelationship(id: string | string[], guild: string): import("
|
|
33
|
-
removeToRelationship(id: string | string[], guild: string): import("
|
|
34
|
-
removeRelationship(id: string | string[]): import("
|
|
31
|
+
getToRelationship(guild: string): import("../../../common").Awaitable<string[]>;
|
|
32
|
+
addToRelationship(id: string | string[], guild: string): import("../../../common").Awaitable<void>;
|
|
33
|
+
removeToRelationship(id: string | string[], guild: string): import("../../../common").Awaitable<void>;
|
|
34
|
+
removeRelationship(id: string | string[]): import("../../../common").Awaitable<void>;
|
|
35
35
|
hashId(id: string): string;
|
|
36
36
|
hashGuildId(guild: string, id: string): string;
|
|
37
37
|
}
|
|
@@ -9,7 +9,7 @@ export declare class GuildRelatedResource<T = any> {
|
|
|
9
9
|
constructor(cache: Cache, client?: UsingClient);
|
|
10
10
|
parse(data: any, id: string, guild_id: string): any;
|
|
11
11
|
get adapter(): import("../../index").Adapter;
|
|
12
|
-
removeIfNI(intent: keyof typeof GatewayIntentBits, id: string | string[], guildId: string): import("
|
|
12
|
+
removeIfNI(intent: keyof typeof GatewayIntentBits, id: string | string[], guildId: string): import("../../../common").Awaitable<void>;
|
|
13
13
|
setIfNI(intent: keyof typeof GatewayIntentBits, id: string, guildId: string, data: any): any;
|
|
14
14
|
get(id: string): ReturnCache<(T & {
|
|
15
15
|
guild_id: string;
|
|
@@ -21,16 +21,16 @@ export declare class GuildRelatedResource<T = any> {
|
|
|
21
21
|
set(__keys: [string, any][], guild: string): ReturnCache<void>;
|
|
22
22
|
patch(__keys: string, guild?: string, data?: any): ReturnCache<void>;
|
|
23
23
|
patch(__keys: [string, any][], guild?: string): ReturnCache<void>;
|
|
24
|
-
remove(id: string | string[], guild: string): import("
|
|
24
|
+
remove(id: string | string[], guild: string): import("../../../common").Awaitable<void>;
|
|
25
25
|
keys(guild: string): ReturnCache<string[]>;
|
|
26
26
|
values(guild: string): ReturnCache<(T & {
|
|
27
27
|
guild_id: string;
|
|
28
28
|
})[]>;
|
|
29
|
-
count(to: string): import("
|
|
30
|
-
contains(id: string, guild: string): import("
|
|
31
|
-
getToRelationship(guild: string): import("
|
|
32
|
-
addToRelationship(id: string | string[], guild: string): import("
|
|
33
|
-
removeToRelationship(id: string | string[], guild: string): import("
|
|
34
|
-
removeRelationship(id: string | string[]): import("
|
|
29
|
+
count(to: string): import("../../../common").Awaitable<number>;
|
|
30
|
+
contains(id: string, guild: string): import("../../../common").Awaitable<boolean>;
|
|
31
|
+
getToRelationship(guild: string): import("../../../common").Awaitable<string[]>;
|
|
32
|
+
addToRelationship(id: string | string[], guild: string): import("../../../common").Awaitable<void>;
|
|
33
|
+
removeToRelationship(id: string | string[], guild: string): import("../../../common").Awaitable<void>;
|
|
34
|
+
removeRelationship(id: string | string[]): import("../../../common").Awaitable<void>;
|
|
35
35
|
hashId(id: string): string;
|
|
36
36
|
}
|
package/lib/client/base.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { ApiHandler } from '../api';
|
|
2
2
|
import type { Adapter } from '../cache';
|
|
3
3
|
import { Cache } from '../cache';
|
|
4
|
-
import type { RegisteredMiddlewares } from '../commands';
|
|
4
|
+
import type { Command, ContextMenuCommand, RegisteredMiddlewares } from '../commands';
|
|
5
5
|
import type { InferWithPrefix, MiddlewareContext } from '../commands/applications/shared';
|
|
6
|
-
import {
|
|
6
|
+
import { type CommandHandlerLike } from '../commands/handler';
|
|
7
7
|
import { ChannelShorter, EmojiShorter, GuildShorter, Logger, MemberShorter, MessageShorter, ReactionShorter, RoleShorter, TemplateShorter, UsersShorter, WebhookShorter, type LocaleString, type MakeRequired } from '../common';
|
|
8
8
|
import type { DeepPartial, IntentStrings, OmitInsert, When } from '../common/types/util';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import type { ComponentCommand, ModalCommand } from '../components';
|
|
10
|
+
import { type ComponentHandlerLike } from '../components/handler';
|
|
11
|
+
import { type LangsHandlerLike } from '../langs/handler';
|
|
11
12
|
import type { ChatInputCommandInteraction, Message, MessageCommandInteraction, UserCommandInteraction } from '../structures';
|
|
12
13
|
export declare class BaseClient {
|
|
13
14
|
rest: ApiHandler;
|
|
@@ -24,9 +25,9 @@ export declare class BaseClient {
|
|
|
24
25
|
emojis: EmojiShorter;
|
|
25
26
|
debugger?: Logger;
|
|
26
27
|
logger: Logger;
|
|
27
|
-
langs
|
|
28
|
-
commands
|
|
29
|
-
components
|
|
28
|
+
langs?: LangsHandlerLike;
|
|
29
|
+
commands?: CommandHandlerLike;
|
|
30
|
+
components?: ComponentHandlerLike;
|
|
30
31
|
private _applicationId?;
|
|
31
32
|
private _botId?;
|
|
32
33
|
middlewares?: Record<string, MiddlewareContext>;
|
|
@@ -39,7 +40,7 @@ export declare class BaseClient {
|
|
|
39
40
|
set applicationId(id: string);
|
|
40
41
|
get applicationId(): string;
|
|
41
42
|
get proxy(): import("../api").APIRoutes;
|
|
42
|
-
setServices({ rest, cache, langs, middlewares }: ServicesOptions): void;
|
|
43
|
+
setServices({ rest, cache, langs, middlewares, handlers }: ServicesOptions): void;
|
|
43
44
|
protected execute(..._options: unknown[]): Promise<void>;
|
|
44
45
|
start(options?: Pick<DeepPartial<StartOptions>, 'langsDir' | 'commandsDir' | 'connection' | 'token' | 'componentsDir'>): Promise<void>;
|
|
45
46
|
protected onPacket(..._packet: unknown[]): Promise<void>;
|
|
@@ -107,7 +108,7 @@ export type RuntimeConfigHTTP = Omit<MakeRequired<RC, 'publicKey' | 'application
|
|
|
107
108
|
};
|
|
108
109
|
export type InternalRuntimeConfig = Omit<MakeRequired<RC, 'intents'>, 'publicKey' | 'port'>;
|
|
109
110
|
export type RuntimeConfig = OmitInsert<InternalRuntimeConfig, 'intents', {
|
|
110
|
-
intents?: IntentStrings | number;
|
|
111
|
+
intents?: IntentStrings | number[] | number;
|
|
111
112
|
}>;
|
|
112
113
|
export interface ServicesOptions {
|
|
113
114
|
rest?: ApiHandler;
|
|
@@ -120,5 +121,10 @@ export interface ServicesOptions {
|
|
|
120
121
|
aliases?: Record<string, LocaleString[]>;
|
|
121
122
|
};
|
|
122
123
|
middlewares?: Record<string, MiddlewareContext>;
|
|
124
|
+
handlers?: {
|
|
125
|
+
components?: ComponentHandlerLike | ((component: ComponentCommand | ModalCommand) => any);
|
|
126
|
+
commands?: CommandHandlerLike | ((command: Command | ContextMenuCommand) => any);
|
|
127
|
+
langs?: LangsHandlerLike | ((locale: string, record: Record<string, unknown>) => any);
|
|
128
|
+
};
|
|
123
129
|
}
|
|
124
130
|
export {};
|
package/lib/client/base.js
CHANGED
|
@@ -58,22 +58,60 @@ class BaseClient {
|
|
|
58
58
|
get proxy() {
|
|
59
59
|
return new api_1.Router(this.rest).createProxy();
|
|
60
60
|
}
|
|
61
|
-
setServices({ rest, cache, langs, middlewares }) {
|
|
61
|
+
setServices({ rest, cache, langs, middlewares, handlers }) {
|
|
62
62
|
if (rest) {
|
|
63
63
|
this.rest = rest;
|
|
64
64
|
}
|
|
65
65
|
if (cache) {
|
|
66
66
|
this.cache = new cache_1.Cache(this.cache?.intents ?? 0, cache?.adapter ?? this.cache?.adapter ?? new cache_1.MemoryAdapter(), cache.disabledCache ?? this.cache?.disabledCache ?? [], this);
|
|
67
67
|
}
|
|
68
|
+
if (middlewares) {
|
|
69
|
+
this.middlewares = middlewares;
|
|
70
|
+
}
|
|
71
|
+
if (handlers) {
|
|
72
|
+
if ('components' in handlers) {
|
|
73
|
+
if (!handlers.components) {
|
|
74
|
+
this.components = undefined;
|
|
75
|
+
}
|
|
76
|
+
else if (typeof handlers.components === 'function') {
|
|
77
|
+
this.components = new handler_2.ComponentHandler(this.logger, this);
|
|
78
|
+
this.components.__callback = handlers.components;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this.components = handlers.components;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if ('commands' in handlers) {
|
|
85
|
+
if (!handlers.commands) {
|
|
86
|
+
this.commands = undefined;
|
|
87
|
+
}
|
|
88
|
+
else if (typeof handlers.commands === 'function') {
|
|
89
|
+
this.commands = new handler_1.CommandHandler(this.logger, this);
|
|
90
|
+
this.commands.__callback = handlers.commands;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
this.commands = handlers.commands;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if ('langs' in handlers) {
|
|
97
|
+
if (!handlers.langs) {
|
|
98
|
+
this.langs = undefined;
|
|
99
|
+
}
|
|
100
|
+
else if (typeof handlers.langs === 'function') {
|
|
101
|
+
this.langs = new handler_3.LangsHandler(this.logger);
|
|
102
|
+
this.langs.__callback = handlers.langs;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
this.langs = handlers.langs;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
68
109
|
if (langs) {
|
|
69
110
|
if (langs.default)
|
|
70
111
|
this.langs.defaultLang = langs.default;
|
|
71
112
|
if (langs.aliases)
|
|
72
113
|
this.langs.aliases = Object.entries(langs.aliases);
|
|
73
114
|
}
|
|
74
|
-
if (middlewares) {
|
|
75
|
-
this.middlewares = middlewares;
|
|
76
|
-
}
|
|
77
115
|
}
|
|
78
116
|
async execute(..._options) {
|
|
79
117
|
if ((await this.getRC()).debug) {
|
|
@@ -139,21 +177,21 @@ class BaseClient {
|
|
|
139
177
|
}
|
|
140
178
|
async loadCommands(dir) {
|
|
141
179
|
dir ??= await this.getRC().then(x => x.commands);
|
|
142
|
-
if (dir) {
|
|
180
|
+
if (dir && this.commands) {
|
|
143
181
|
await this.commands.load(dir, this);
|
|
144
182
|
this.logger.info('CommandHandler loaded');
|
|
145
183
|
}
|
|
146
184
|
}
|
|
147
185
|
async loadComponents(dir) {
|
|
148
186
|
dir ??= await this.getRC().then(x => x.components);
|
|
149
|
-
if (dir) {
|
|
187
|
+
if (dir && this.components) {
|
|
150
188
|
await this.components.load(dir);
|
|
151
189
|
this.logger.info('ComponentHandler loaded');
|
|
152
190
|
}
|
|
153
191
|
}
|
|
154
192
|
async loadLangs(dir) {
|
|
155
193
|
dir ??= await this.getRC().then(x => x.langs);
|
|
156
|
-
if (dir) {
|
|
194
|
+
if (dir && this.langs) {
|
|
157
195
|
await this.langs.load(dir);
|
|
158
196
|
this.logger.info('LangsHandler loaded');
|
|
159
197
|
}
|
package/lib/client/client.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import type { Command, CommandContext, Message, SubCommand } from '..';
|
|
1
|
+
import type { ClientEvent, Command, CommandContext, EventHandlerLike, Message, SubCommand } from '..';
|
|
2
2
|
import { type DeepPartial, type GatewayDispatchPayload, type GatewayPresenceUpdateData, type If } from '../common';
|
|
3
|
-
import { EventHandler } from '../events';
|
|
4
3
|
import { ClientUser } from '../structures';
|
|
5
4
|
import { ShardManager, type ShardManagerOptions } from '../websocket';
|
|
6
5
|
import { MemberUpdateHandler } from '../websocket/discord/events/memberUpdate';
|
|
@@ -10,7 +9,7 @@ import { BaseClient } from './base';
|
|
|
10
9
|
export declare class Client<Ready extends boolean = boolean> extends BaseClient {
|
|
11
10
|
private __handleGuilds?;
|
|
12
11
|
gateway: ShardManager;
|
|
13
|
-
events
|
|
12
|
+
events?: EventHandlerLike;
|
|
14
13
|
me: If<Ready, ClientUser>;
|
|
15
14
|
options: ClientOptions | undefined;
|
|
16
15
|
memberUpdateHandler: MemberUpdateHandler;
|
|
@@ -18,6 +17,9 @@ export declare class Client<Ready extends boolean = boolean> extends BaseClient
|
|
|
18
17
|
constructor(options?: ClientOptions);
|
|
19
18
|
setServices({ gateway, ...rest }: ServicesOptions & {
|
|
20
19
|
gateway?: ShardManager;
|
|
20
|
+
handlers?: ServicesOptions['handlers'] & {
|
|
21
|
+
events?: EventHandlerLike | ((event: ClientEvent) => any);
|
|
22
|
+
};
|
|
21
23
|
}): void;
|
|
22
24
|
loadEvents(dir?: string): Promise<void>;
|
|
23
25
|
protected execute(options?: {
|
package/lib/client/client.js
CHANGED
|
@@ -32,10 +32,22 @@ class Client extends base_1.BaseClient {
|
|
|
32
32
|
};
|
|
33
33
|
this.gateway = gateway;
|
|
34
34
|
}
|
|
35
|
+
if (rest.handlers && 'events' in rest.handlers) {
|
|
36
|
+
if (!rest.handlers.events) {
|
|
37
|
+
this.events = undefined;
|
|
38
|
+
}
|
|
39
|
+
else if (typeof rest.handlers.events === 'function') {
|
|
40
|
+
this.events = new events_1.EventHandler(this.logger);
|
|
41
|
+
this.events.__callback = rest.handlers.events;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.events = rest.handlers.events;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
35
47
|
}
|
|
36
48
|
async loadEvents(dir) {
|
|
37
49
|
dir ??= await this.getRC().then(x => x.events);
|
|
38
|
-
if (dir) {
|
|
50
|
+
if (dir && this.events) {
|
|
39
51
|
await this.events.load(dir);
|
|
40
52
|
this.logger.info('EventHandler loaded');
|
|
41
53
|
}
|
|
@@ -92,21 +104,21 @@ class Client extends base_1.BaseClient {
|
|
|
92
104
|
}
|
|
93
105
|
}
|
|
94
106
|
async onPacket(shardId, packet) {
|
|
95
|
-
await this.events
|
|
107
|
+
await this.events?.runEvent('RAW', this, packet, shardId);
|
|
96
108
|
switch (packet.t) {
|
|
97
109
|
//// Cases where we must obtain the old data before updating
|
|
98
110
|
case 'GUILD_MEMBER_UPDATE':
|
|
99
111
|
if (!this.memberUpdateHandler.check(packet.d)) {
|
|
100
112
|
return;
|
|
101
113
|
}
|
|
102
|
-
await this.events
|
|
114
|
+
await this.events?.execute(packet.t, packet, this, shardId);
|
|
103
115
|
await this.cache.onPacket(packet);
|
|
104
116
|
break;
|
|
105
117
|
case 'PRESENCE_UPDATE':
|
|
106
118
|
if (!this.presenceUpdateHandler.check(packet.d)) {
|
|
107
119
|
return;
|
|
108
120
|
}
|
|
109
|
-
await this.events
|
|
121
|
+
await this.events?.execute(packet.t, packet, this, shardId);
|
|
110
122
|
await this.cache.onPacket(packet);
|
|
111
123
|
break;
|
|
112
124
|
//rest of the events
|
|
@@ -129,7 +141,7 @@ class Client extends base_1.BaseClient {
|
|
|
129
141
|
if (!this.__handleGuilds?.size ||
|
|
130
142
|
!((this.gateway.options.intents & common_1.GatewayIntentBits.Guilds) === common_1.GatewayIntentBits.Guilds)) {
|
|
131
143
|
if ([...this.gateway.values()].every(shard => shard.data.session_id)) {
|
|
132
|
-
await this.events
|
|
144
|
+
await this.events?.runEvent('BOT_READY', this, this.me, -1);
|
|
133
145
|
}
|
|
134
146
|
delete this.__handleGuilds;
|
|
135
147
|
}
|
|
@@ -139,7 +151,7 @@ class Client extends base_1.BaseClient {
|
|
|
139
151
|
if (this.__handleGuilds?.has(packet.d.id)) {
|
|
140
152
|
this.__handleGuilds.delete(packet.d.id);
|
|
141
153
|
if (!this.__handleGuilds.size && [...this.gateway.values()].every(shard => shard.data.session_id)) {
|
|
142
|
-
await this.events
|
|
154
|
+
await this.events?.runEvent('BOT_READY', this, this.me, -1);
|
|
143
155
|
}
|
|
144
156
|
if (!this.__handleGuilds.size)
|
|
145
157
|
delete this.__handleGuilds;
|
|
@@ -148,7 +160,7 @@ class Client extends base_1.BaseClient {
|
|
|
148
160
|
break;
|
|
149
161
|
}
|
|
150
162
|
}
|
|
151
|
-
await this.events
|
|
163
|
+
await this.events?.execute(packet.t, packet, this, shardId);
|
|
152
164
|
break;
|
|
153
165
|
}
|
|
154
166
|
}
|
|
@@ -9,7 +9,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
9
9
|
switch (body.type) {
|
|
10
10
|
case v10_1.InteractionType.ApplicationCommandAutocomplete:
|
|
11
11
|
{
|
|
12
|
-
const parentCommand = self.commands
|
|
12
|
+
const parentCommand = self.commands?.values.find(x => {
|
|
13
13
|
if (x.guild_id && !x.guild_id.includes(body.data.guild_id ?? '')) {
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
@@ -47,7 +47,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
47
47
|
case v10_1.ApplicationCommandType.Message:
|
|
48
48
|
case v10_1.ApplicationCommandType.User:
|
|
49
49
|
{
|
|
50
|
-
const command = self.commands
|
|
50
|
+
const command = self.commands?.values.find(x => {
|
|
51
51
|
if (x.guild_id && !x.guild_id.includes(body.data.guild_id ?? '')) {
|
|
52
52
|
return false;
|
|
53
53
|
}
|
|
@@ -103,7 +103,7 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
103
103
|
case v10_1.ApplicationCommandType.ChatInput:
|
|
104
104
|
{
|
|
105
105
|
const packetData = body.data;
|
|
106
|
-
const parentCommand = self.commands
|
|
106
|
+
const parentCommand = self.commands?.values.find(x => {
|
|
107
107
|
if (x.guild_id && !x.guild_id.includes(packetData.guild_id ?? '')) {
|
|
108
108
|
return false;
|
|
109
109
|
}
|
|
@@ -167,22 +167,22 @@ async function onInteractionCreate(self, body, shardId, __reply) {
|
|
|
167
167
|
case v10_1.InteractionType.ModalSubmit:
|
|
168
168
|
{
|
|
169
169
|
const interaction = structures_1.BaseInteraction.from(self, body, __reply);
|
|
170
|
-
if (self.components
|
|
170
|
+
if (self.components?.hasModal(interaction)) {
|
|
171
171
|
await self.components.onModalSubmit(interaction);
|
|
172
172
|
}
|
|
173
173
|
else {
|
|
174
|
-
await self.components
|
|
174
|
+
await self.components?.executeModal(interaction);
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
break;
|
|
178
178
|
case v10_1.InteractionType.MessageComponent:
|
|
179
179
|
{
|
|
180
180
|
const interaction = structures_1.BaseInteraction.from(self, body, __reply);
|
|
181
|
-
if (self.components
|
|
181
|
+
if (self.components?.hasComponent(body.message.id, interaction.customId)) {
|
|
182
182
|
await self.components.onComponent(body.message.id, interaction);
|
|
183
183
|
}
|
|
184
184
|
else {
|
|
185
|
-
await self.components
|
|
185
|
+
await self.components?.executeComponent(interaction);
|
|
186
186
|
}
|
|
187
187
|
}
|
|
188
188
|
break;
|
|
@@ -45,7 +45,10 @@ async function onMessageCreate(self, rawMessage, shardId) {
|
|
|
45
45
|
if (!prefix || !message.content.startsWith(prefix))
|
|
46
46
|
return;
|
|
47
47
|
const content = message.content.slice(prefix.length).trimStart();
|
|
48
|
-
const { fullCommandName, command, parent } = getCommandFromContent(content
|
|
48
|
+
const { fullCommandName, command, parent } = getCommandFromContent(content
|
|
49
|
+
.split(' ')
|
|
50
|
+
.filter(x => x)
|
|
51
|
+
.slice(0, 3), self);
|
|
49
52
|
if (!command)
|
|
50
53
|
return;
|
|
51
54
|
if (!command.run)
|
|
@@ -6,18 +6,18 @@
|
|
|
6
6
|
import type { Cache } from '../cache';
|
|
7
7
|
import type { GatewayDispatchPayload, When } from '../common';
|
|
8
8
|
import { Logger, type DeepPartial } from '../common';
|
|
9
|
-
import {
|
|
9
|
+
import { type EventHandlerLike } from '../events';
|
|
10
10
|
import { ClientUser } from '../structures';
|
|
11
11
|
import { Shard, type ShardManagerOptions } from '../websocket';
|
|
12
12
|
import type { WorkerShardInfo } from '../websocket/discord/worker';
|
|
13
13
|
import type { ManagerMessages } from '../websocket/discord/workermanager';
|
|
14
|
-
import type { BaseClientOptions, StartOptions } from './base';
|
|
14
|
+
import type { BaseClientOptions, ServicesOptions, StartOptions } from './base';
|
|
15
15
|
import { BaseClient } from './base';
|
|
16
16
|
import type { Client } from './client';
|
|
17
17
|
export declare class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
|
|
18
18
|
private __handleGuilds?;
|
|
19
19
|
logger: Logger;
|
|
20
|
-
events
|
|
20
|
+
events?: EventHandlerLike;
|
|
21
21
|
me: When<Ready, ClientUser>;
|
|
22
22
|
promises: Map<string, {
|
|
23
23
|
resolve: (value: any) => void;
|
|
@@ -28,6 +28,11 @@ export declare class WorkerClient<Ready extends boolean = boolean> extends BaseC
|
|
|
28
28
|
constructor(options?: WorkerClientOptions);
|
|
29
29
|
get workerId(): number;
|
|
30
30
|
get latency(): number;
|
|
31
|
+
setServices({ ...rest }: ServicesOptions & {
|
|
32
|
+
handlers?: ServicesOptions['handlers'] & {
|
|
33
|
+
events?: EventHandlerLike;
|
|
34
|
+
};
|
|
35
|
+
}): void;
|
|
31
36
|
start(options?: Omit<DeepPartial<StartOptions>, 'httpConnection' | 'token' | 'connection'>): Promise<void>;
|
|
32
37
|
loadEvents(dir?: string): Promise<void>;
|
|
33
38
|
postMessage(body: any): boolean | void;
|
|
@@ -74,6 +74,12 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
74
74
|
this.shards.forEach(s => (acc += s.latency));
|
|
75
75
|
return acc / this.shards.size;
|
|
76
76
|
}
|
|
77
|
+
setServices({ ...rest }) {
|
|
78
|
+
super.setServices(rest);
|
|
79
|
+
if (rest.handlers && 'events' in rest.handlers) {
|
|
80
|
+
this.events = rest.handlers.events;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
77
83
|
async start(options = {}) {
|
|
78
84
|
await super.start(options);
|
|
79
85
|
await this.loadEvents(options.eventsDir);
|
|
@@ -81,7 +87,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
81
87
|
}
|
|
82
88
|
async loadEvents(dir) {
|
|
83
89
|
dir ??= await this.getRC().then(x => x.events);
|
|
84
|
-
if (dir) {
|
|
90
|
+
if (dir && this.events) {
|
|
85
91
|
await this.events.load(dir);
|
|
86
92
|
this.logger.info('EventHandler loaded');
|
|
87
93
|
}
|
|
@@ -191,7 +197,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
191
197
|
}
|
|
192
198
|
break;
|
|
193
199
|
case 'BOT_READY':
|
|
194
|
-
await this.events
|
|
200
|
+
await this.events?.runEvent('BOT_READY', this, this.me, -1);
|
|
195
201
|
break;
|
|
196
202
|
case 'API_RESPONSE':
|
|
197
203
|
{
|
|
@@ -270,14 +276,14 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
270
276
|
return this.generateSendPromise(nonce);
|
|
271
277
|
}
|
|
272
278
|
async onPacket(packet, shardId) {
|
|
273
|
-
await this.events
|
|
279
|
+
await this.events?.execute('RAW', packet, this, shardId);
|
|
274
280
|
switch (packet.t) {
|
|
275
281
|
case 'GUILD_MEMBER_UPDATE':
|
|
276
|
-
await this.events
|
|
282
|
+
await this.events?.execute(packet.t, packet, this, shardId);
|
|
277
283
|
await this.cache.onPacket(packet);
|
|
278
284
|
break;
|
|
279
285
|
case 'PRESENCE_UPDATE':
|
|
280
|
-
await this.events
|
|
286
|
+
await this.events?.execute(packet.t, packet, this, shardId);
|
|
281
287
|
await this.cache.onPacket(packet);
|
|
282
288
|
break;
|
|
283
289
|
//rest of the events
|
|
@@ -298,7 +304,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
298
304
|
type: 'WORKER_READY',
|
|
299
305
|
workerId: this.workerId,
|
|
300
306
|
});
|
|
301
|
-
await this.events
|
|
307
|
+
await this.events?.runEvent('WORKER_READY', this, this.me, -1);
|
|
302
308
|
}
|
|
303
309
|
delete this.__handleGuilds;
|
|
304
310
|
}
|
|
@@ -318,7 +324,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
318
324
|
type: 'WORKER_READY',
|
|
319
325
|
workerId: this.workerId,
|
|
320
326
|
});
|
|
321
|
-
await this.events
|
|
327
|
+
await this.events?.runEvent('WORKER_READY', this, this.me, -1);
|
|
322
328
|
}
|
|
323
329
|
if (!this.__handleGuilds.size)
|
|
324
330
|
delete this.__handleGuilds;
|
|
@@ -326,7 +332,7 @@ class WorkerClient extends base_1.BaseClient {
|
|
|
326
332
|
}
|
|
327
333
|
}
|
|
328
334
|
}
|
|
329
|
-
await this.events
|
|
335
|
+
await this.events?.execute(packet.t, packet, this, shardId);
|
|
330
336
|
}
|
|
331
337
|
break;
|
|
332
338
|
}
|