@kyvrixon/utils 1.4.0 → 1.4.2
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 +3 -3
- package/src/lib/discord-utils/Event.ts +36 -37
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.2",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "MIT",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
},
|
|
22
22
|
"types": "./src/index.ts",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@biomejs/biome": "2.4.
|
|
24
|
+
"@biomejs/biome": "2.4.10",
|
|
25
25
|
"@types/bun": "1.3.11",
|
|
26
26
|
"typescript": "6.0.2"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"chalk": "5.6.2",
|
|
30
|
-
"discord.js": "14.
|
|
30
|
+
"discord.js": "14.26.2"
|
|
31
31
|
},
|
|
32
32
|
"exports": {
|
|
33
33
|
".": {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** biome-ignore-all lint/suspicious/noExplicitAny: Its fine */
|
|
2
|
-
import type {
|
|
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.
|
|
@@ -10,52 +10,51 @@ import type { Client, ClientEvents, RestEvents } from "discord.js";
|
|
|
10
10
|
* }
|
|
11
11
|
* }
|
|
12
12
|
*/
|
|
13
|
-
// biome-ignore lint/suspicious/noEmptyInterface:
|
|
14
|
-
export interface DiscordEventCustomType {
|
|
13
|
+
// biome-ignore lint/suspicious/noEmptyInterface: It's fine
|
|
14
|
+
export interface DiscordEventCustomType {
|
|
15
|
+
}
|
|
15
16
|
|
|
16
17
|
/** Maps an event type discriminant to its corresponding event map. */
|
|
17
|
-
type EventMap<T extends "client" | "rest" | "custom"> =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
export type EventMap<T extends "client" | "rest" | "custom"> =
|
|
19
|
+
T extends "client"
|
|
20
|
+
? ClientEvents
|
|
21
|
+
: T extends "rest"
|
|
22
|
+
? RestEvents
|
|
23
|
+
: keyof DiscordEventCustomType extends never
|
|
24
|
+
? { "sooo.. there's no custom events..": [] }
|
|
25
|
+
: DiscordEventCustomType;
|
|
24
26
|
|
|
25
27
|
/** Resolves the argument tuple for a given event type + key pair. */
|
|
26
|
-
type EventArgs<
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
export type EventArgs<
|
|
29
|
+
T extends "client" | "rest" | "custom",
|
|
30
|
+
K extends keyof EventMap<T>,
|
|
29
31
|
> = Extract<EventMap<T>[K], any[]>;
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
34
|
* Wraps a discord.js event handler. Supports `"client"`, `"rest"`, and `"custom"` event types.
|
|
33
|
-
* @typeParam V - The bot's `Client` type.
|
|
34
|
-
* @typeParam T - The event source discriminant.
|
|
35
|
-
* @typeParam K - The event name within the chosen source.
|
|
36
35
|
*/
|
|
37
36
|
export class DiscordEvent<
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
C extends Client,
|
|
38
|
+
T extends "client" | "rest" | "custom",
|
|
39
|
+
K extends keyof EventMap<T> = keyof EventMap<T>,
|
|
41
40
|
> {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
public readonly type: T;
|
|
42
|
+
public readonly name: K;
|
|
43
|
+
public readonly once: boolean;
|
|
44
|
+
public readonly method: (
|
|
45
|
+
client: C,
|
|
46
|
+
...args: EventArgs<T, K>
|
|
47
|
+
) => void | Promise<void>;
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
constructor(opts: {
|
|
50
|
+
type: T;
|
|
51
|
+
name: K;
|
|
52
|
+
once: boolean;
|
|
53
|
+
method: (client: C, ...args: EventArgs<T, K>) => void | Promise<void>;
|
|
54
|
+
}) {
|
|
55
|
+
this.type = opts.type;
|
|
56
|
+
this.name = opts.name;
|
|
57
|
+
this.once = opts.once;
|
|
58
|
+
this.method = opts.method;
|
|
59
|
+
}
|
|
61
60
|
}
|