@kyvrixon/utils 1.0.10 → 1.0.11
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/README.md +1 -3
- package/package.json +4 -4
- package/src/index.ts +1 -1
- package/src/lib/discord-utils/Event.ts +25 -31
- package/src/lib/discord-utils/createPagination.ts +1 -1
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kyvrixon/utils",
|
|
3
3
|
"main": "./src/index.ts",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.11",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "MIT",
|
|
@@ -9,20 +9,20 @@
|
|
|
9
9
|
"src"
|
|
10
10
|
],
|
|
11
11
|
"engines": {
|
|
12
|
-
"bun": "1.3.
|
|
12
|
+
"bun": "1.3.11"
|
|
13
13
|
},
|
|
14
14
|
"repository": {
|
|
15
15
|
"url": "https://github.com/kyvrixon/utils"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
|
-
"pub": "bun
|
|
18
|
+
"pub": "bun publish --access public",
|
|
19
19
|
"pretty": "bun biome format --write ."
|
|
20
20
|
},
|
|
21
21
|
"packageManager": "bun@1.3.10",
|
|
22
22
|
"types": "./src/index.ts",
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@biomejs/biome": "2.4.6",
|
|
25
|
-
"@types/bun": "1.3.
|
|
25
|
+
"@types/bun": "1.3.11",
|
|
26
26
|
"typescript": "5.9.3"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
package/src/index.ts
CHANGED
|
@@ -3,59 +3,53 @@ import type { Client, ClientEvents, RestEvents } from "discord.js";
|
|
|
3
3
|
|
|
4
4
|
// biome-ignore lint/suspicious/noEmptyInterface: Its fine
|
|
5
5
|
export interface DiscordEventCustomType {}
|
|
6
|
+
|
|
7
|
+
/** Maps an event type discriminant to its corresponding event map. */
|
|
8
|
+
type EventMap<T extends "client" | "rest" | "custom"> = T extends "client"
|
|
9
|
+
? ClientEvents
|
|
10
|
+
: T extends "rest"
|
|
11
|
+
? RestEvents
|
|
12
|
+
: keyof DiscordEventCustomType extends never
|
|
13
|
+
? { "sooo.. there's no custom events..": [] }
|
|
14
|
+
: DiscordEventCustomType;
|
|
15
|
+
|
|
16
|
+
/** Resolves the argument tuple for a given event type + key pair. */
|
|
17
|
+
type EventArgs<
|
|
18
|
+
T extends "client" | "rest" | "custom",
|
|
19
|
+
K extends keyof EventMap<T>,
|
|
20
|
+
> = Extract<EventMap<T>[K], any[]>;
|
|
21
|
+
|
|
6
22
|
/**
|
|
7
23
|
* To define custom types:
|
|
8
24
|
* @example
|
|
9
25
|
* declare module "@kyvrixon/utils" {
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* }
|
|
14
|
-
* // You can also add these to `ClientEvents` if you wish for better typing like so:
|
|
15
|
-
* declare module "discord.js" {
|
|
16
|
-
* interface ClientEvents extends DiscordEventCustomType {}
|
|
26
|
+
* interface DiscordEventCustomType {
|
|
27
|
+
* myEventName: [data: string];
|
|
28
|
+
* }
|
|
17
29
|
* }
|
|
18
30
|
*/
|
|
19
31
|
export class DiscordEvent<
|
|
20
32
|
V extends Client,
|
|
21
|
-
T extends "client" | "
|
|
22
|
-
K extends T
|
|
23
|
-
? keyof DiscordEventCustomType
|
|
24
|
-
: T extends "client"
|
|
25
|
-
? keyof ClientEvents
|
|
26
|
-
: keyof RestEvents = T extends "custom"
|
|
27
|
-
? keyof DiscordEventCustomType
|
|
28
|
-
: T extends "client"
|
|
29
|
-
? keyof ClientEvents
|
|
30
|
-
: keyof RestEvents,
|
|
33
|
+
T extends "client" | "rest" | "custom",
|
|
34
|
+
K extends keyof EventMap<T> = keyof EventMap<T>,
|
|
31
35
|
> {
|
|
32
36
|
public readonly type: T;
|
|
33
37
|
public readonly name: K;
|
|
34
38
|
public readonly once: boolean;
|
|
35
39
|
public readonly method: (
|
|
36
40
|
client: V,
|
|
37
|
-
...args: T
|
|
38
|
-
|
|
39
|
-
? ClientEvents[K]
|
|
40
|
-
: any[]
|
|
41
|
-
: T extends "rest"
|
|
42
|
-
? K extends keyof RestEvents
|
|
43
|
-
? RestEvents[K]
|
|
44
|
-
: any[]
|
|
45
|
-
: K extends keyof DiscordEventCustomType
|
|
46
|
-
? DiscordEventCustomType[K]
|
|
47
|
-
: any[]
|
|
48
|
-
) => Promise<void>;
|
|
41
|
+
...args: EventArgs<T, K>
|
|
42
|
+
) => void | Promise<void>;
|
|
49
43
|
|
|
50
44
|
constructor(opts: {
|
|
51
45
|
type: T;
|
|
52
46
|
name: K;
|
|
53
|
-
once
|
|
47
|
+
once: boolean;
|
|
54
48
|
method: DiscordEvent<V, T, K>["method"];
|
|
55
49
|
}) {
|
|
56
50
|
this.type = opts.type;
|
|
57
51
|
this.name = opts.name;
|
|
58
|
-
this.once = opts.once
|
|
52
|
+
this.once = opts.once;
|
|
59
53
|
this.method = opts.method;
|
|
60
54
|
}
|
|
61
55
|
}
|