@kyvrixon/utils 1.4.3 → 1.4.4
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kyvrixon/utils",
|
|
3
3
|
"main": "./src/index.ts",
|
|
4
|
-
"version": "1.4.
|
|
4
|
+
"version": "1.4.4",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "MIT",
|
|
@@ -21,13 +21,15 @@
|
|
|
21
21
|
},
|
|
22
22
|
"types": "./src/index.ts",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@biomejs/biome": "2.4.10",
|
|
25
|
-
"@types/bun": "1.3.11",
|
|
26
|
-
"typescript": "6.0.2"
|
|
24
|
+
"@biomejs/biome": "^2.4.10",
|
|
25
|
+
"@types/bun": "^1.3.11",
|
|
26
|
+
"typescript": "^6.0.2"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"chalk": "5.6.2"
|
|
30
|
-
|
|
29
|
+
"chalk": "^5.6.2"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"discord.js": "^14.26.2"
|
|
31
33
|
},
|
|
32
34
|
"exports": {
|
|
33
35
|
".": {
|
|
@@ -7,7 +7,10 @@ import type {
|
|
|
7
7
|
SlashCommandSubcommandsOnlyBuilder,
|
|
8
8
|
} from "discord.js";
|
|
9
9
|
|
|
10
|
-
export type CommandData =
|
|
10
|
+
export type CommandData =
|
|
11
|
+
| SlashCommandBuilder
|
|
12
|
+
| SlashCommandOptionsOnlyBuilder
|
|
13
|
+
| SlashCommandSubcommandsOnlyBuilder;
|
|
11
14
|
|
|
12
15
|
export interface DiscordCommandMetadata extends Record<string, unknown> {}
|
|
13
16
|
|
|
@@ -23,7 +26,7 @@ export interface DiscordCommandMetadata extends Record<string, unknown> {}
|
|
|
23
26
|
* }
|
|
24
27
|
* }
|
|
25
28
|
*/
|
|
26
|
-
export class DiscordCommand<C extends Client> {
|
|
29
|
+
export class DiscordCommand<C extends Client = Client> {
|
|
27
30
|
public readonly data: CommandData;
|
|
28
31
|
public readonly execute: (
|
|
29
32
|
client: C,
|
|
@@ -38,8 +41,14 @@ export class DiscordCommand<C extends Client> {
|
|
|
38
41
|
constructor(ops: {
|
|
39
42
|
data: CommandData;
|
|
40
43
|
metadata: DiscordCommandMetadata;
|
|
41
|
-
execute: (
|
|
42
|
-
|
|
44
|
+
execute: (
|
|
45
|
+
client: C,
|
|
46
|
+
interaction: ChatInputCommandInteraction,
|
|
47
|
+
) => Promise<void>;
|
|
48
|
+
autocomplete?: (
|
|
49
|
+
client: C,
|
|
50
|
+
interaction: AutocompleteInteraction,
|
|
51
|
+
) => Promise<void>;
|
|
43
52
|
}) {
|
|
44
53
|
this.data = ops.data;
|
|
45
54
|
this.metadata = ops.metadata;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** biome-ignore-all lint/suspicious/noExplicitAny: Its fine */
|
|
2
|
-
import type {Client, ClientEvents, RestEvents} from "discord.js";
|
|
2
|
+
import type { Client, ClientEvents, RestEvents } from "discord.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Augment this interface via module declaration to register custom event types.
|
|
@@ -11,50 +11,49 @@ import type {Client, ClientEvents, RestEvents} from "discord.js";
|
|
|
11
11
|
* }
|
|
12
12
|
*/
|
|
13
13
|
// biome-ignore lint/suspicious/noEmptyInterface: It's fine
|
|
14
|
-
export interface DiscordEventCustomType {
|
|
15
|
-
}
|
|
14
|
+
export interface DiscordEventCustomType {}
|
|
16
15
|
|
|
17
16
|
/** Maps an event type discriminant to its corresponding event map. */
|
|
18
17
|
export type EventMap<T extends "client" | "rest" | "custom"> =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
T extends "client"
|
|
19
|
+
? ClientEvents
|
|
20
|
+
: T extends "rest"
|
|
21
|
+
? RestEvents
|
|
22
|
+
: keyof DiscordEventCustomType extends never
|
|
23
|
+
? { "sooo.. there's no custom events..": [] }
|
|
24
|
+
: DiscordEventCustomType;
|
|
26
25
|
|
|
27
26
|
/** Resolves the argument tuple for a given event type + key pair. */
|
|
28
27
|
export type EventArgs<
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
T extends "client" | "rest" | "custom",
|
|
29
|
+
K extends keyof EventMap<T>,
|
|
31
30
|
> = Extract<EventMap<T>[K], any[]>;
|
|
32
31
|
|
|
33
32
|
/**
|
|
34
33
|
* Wraps a discord.js event handler. Supports `"client"`, `"rest"`, and `"custom"` event types.
|
|
35
34
|
*/
|
|
36
35
|
export class DiscordEvent<
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
T extends "client" | "rest" | "custom",
|
|
37
|
+
K extends keyof EventMap<T> = keyof EventMap<T>,
|
|
38
|
+
C extends Client = Client,
|
|
40
39
|
> {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
public readonly type: T;
|
|
41
|
+
public readonly name: K;
|
|
42
|
+
public readonly once: boolean;
|
|
43
|
+
public readonly method: (
|
|
44
|
+
client: C,
|
|
45
|
+
...args: EventArgs<T, K>
|
|
46
|
+
) => void | Promise<void>;
|
|
48
47
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
48
|
+
constructor(opts: {
|
|
49
|
+
type: T;
|
|
50
|
+
name: K;
|
|
51
|
+
once: boolean;
|
|
52
|
+
method: (client: C, ...args: EventArgs<T, K>) => void | Promise<void>;
|
|
53
|
+
}) {
|
|
54
|
+
this.type = opts.type;
|
|
55
|
+
this.name = opts.name;
|
|
56
|
+
this.once = opts.once;
|
|
57
|
+
this.method = opts.method;
|
|
58
|
+
}
|
|
60
59
|
}
|