@ezzi/base 1.0.0

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.
Files changed (53) hide show
  1. package/README.md +29 -0
  2. package/dist/app.d.ts +47 -0
  3. package/dist/app.js +54 -0
  4. package/dist/bootstrap.d.ts +68 -0
  5. package/dist/bootstrap.js +35 -0
  6. package/dist/client.d.ts +12 -0
  7. package/dist/client.js +42 -0
  8. package/dist/creators/commands/command.d.ts +140 -0
  9. package/dist/creators/commands/command.js +63 -0
  10. package/dist/creators/commands/context.d.ts +33 -0
  11. package/dist/creators/commands/context.js +204 -0
  12. package/dist/creators/commands/manager.d.ts +50 -0
  13. package/dist/creators/commands/manager.js +560 -0
  14. package/dist/creators/events/event.d.ts +21 -0
  15. package/dist/creators/events/event.js +10 -0
  16. package/dist/creators/events/manager.d.ts +12 -0
  17. package/dist/creators/events/manager.js +71 -0
  18. package/dist/creators/index.d.ts +5 -0
  19. package/dist/creators/index.js +11 -0
  20. package/dist/creators/manager.d.ts +6 -0
  21. package/dist/creators/manager.js +12 -0
  22. package/dist/creators/responders/emit.d.ts +12 -0
  23. package/dist/creators/responders/emit.js +10 -0
  24. package/dist/creators/responders/manager.d.ts +14 -0
  25. package/dist/creators/responders/manager.js +61 -0
  26. package/dist/creators/responders/responder.d.ts +45 -0
  27. package/dist/creators/responders/responder.js +26 -0
  28. package/dist/creators/setup.d.ts +25 -0
  29. package/dist/creators/setup.js +86 -0
  30. package/dist/env.d.ts +25 -0
  31. package/dist/env.js +15 -0
  32. package/dist/error.d.ts +7 -0
  33. package/dist/error.js +78 -0
  34. package/dist/index.d.ts +9 -0
  35. package/dist/index.js +10 -0
  36. package/dist/modules.d.ts +9 -0
  37. package/dist/modules.js +18 -0
  38. package/dist/standard-schema.d.ts +59 -0
  39. package/dist/standard-schema.js +0 -0
  40. package/dist/tools/index.d.ts +2 -0
  41. package/dist/tools/index.js +3 -0
  42. package/dist/tools/logger.d.ts +12 -0
  43. package/dist/tools/logger.js +23 -0
  44. package/dist/tools/parseCommand.d.ts +15 -0
  45. package/dist/tools/parseCommand.js +144 -0
  46. package/dist/utils/router.d.ts +9 -0
  47. package/dist/utils/router.js +24 -0
  48. package/dist/utils/types.d.ts +7 -0
  49. package/dist/utils/types.js +0 -0
  50. package/dist/version.d.ts +7 -0
  51. package/dist/version.js +5 -0
  52. package/package.json +79 -0
  53. package/tsconfig/base.json +21 -0
@@ -0,0 +1,144 @@
1
+ // src/tools/parseCommand.ts
2
+ import {
3
+ ApplicationCommandOptionType
4
+ } from "discord.js";
5
+ import { EzziApp } from "../app.js";
6
+ import {
7
+ IgnoreCommand
8
+ } from "../creators/commands/command.js";
9
+ var optionTypes = {
10
+ 3: "string",
11
+ 4: "integer",
12
+ 5: "boolean",
13
+ 6: "user",
14
+ 7: "channel",
15
+ 8: "role",
16
+ 9: "mention",
17
+ 10: "number",
18
+ 11: "file"
19
+ };
20
+ function sanitizeLocalizations(localizations) {
21
+ if (!localizations)
22
+ return;
23
+ const sanitized = {};
24
+ for (const [locale, translation] of Object.entries(localizations)) {
25
+ if (translation === null) {
26
+ sanitized[locale] = null;
27
+ continue;
28
+ }
29
+ sanitized[locale] = translation;
30
+ }
31
+ return sanitized;
32
+ }
33
+ function parseCommands(client) {
34
+ const discordCommands = client.application?.commands.cache;
35
+ const app = EzziApp.getInstance();
36
+ const localCommands = app.commands["collection"];
37
+ if (!localCommands)
38
+ return [];
39
+ const parsedList = [];
40
+ for (const [_, localCmd] of localCommands) {
41
+ const discordCmd = discordCommands?.find((c) => c.name === localCmd.name);
42
+ const isRootSlashIgnored = localCmd.ignore === IgnoreCommand.Slash;
43
+ if (!discordCmd && !isRootSlashIgnored)
44
+ continue;
45
+ const id = discordCmd?.id ?? null;
46
+ const category = localCmd.category || "Utils";
47
+ const cmdAliases = localCmd.aliases;
48
+ if (!localCmd.modules || localCmd.modules.length === 0) {
49
+ parsedList.push({
50
+ id,
51
+ name: localCmd.name,
52
+ description: localCmd.description || "",
53
+ category,
54
+ options: formatOptions(localCmd.options || []),
55
+ slash: isRootSlashIgnored || !id ? null : { id, name: localCmd.name },
56
+ localizations: sanitizeLocalizations(localCmd.descriptionLocalizations),
57
+ aliases: cmdAliases
58
+ });
59
+ continue;
60
+ }
61
+ if (localCmd.modules) {
62
+ const subcommands = localCmd.modules.filter((m) => m.type === ApplicationCommandOptionType.Subcommand && !m.group);
63
+ const groups = localCmd.modules.filter((m) => m.type === ApplicationCommandOptionType.SubcommandGroup);
64
+ for (const localSub of subcommands) {
65
+ const isSlashIgnored = localSub.ignore === IgnoreCommand.Slash;
66
+ const isMessageIgnored = localSub.ignore === IgnoreCommand.Message;
67
+ const fullAliases = [];
68
+ if (!isMessageIgnored) {
69
+ const cmdNames = [localCmd.name, ...cmdAliases ?? []];
70
+ const subNames = [localSub.name, ...localSub.aliases ?? []];
71
+ for (const c of cmdNames) {
72
+ for (const s of subNames) {
73
+ if (c === localCmd.name && s === localSub.name)
74
+ continue;
75
+ fullAliases.push(`${c} ${s}`);
76
+ }
77
+ }
78
+ if (localSub.shortcut) {
79
+ fullAliases.push(localSub.name, ...localSub.aliases ?? []);
80
+ }
81
+ }
82
+ parsedList.push({
83
+ id,
84
+ name: `${localCmd.name} ${localSub.name}`,
85
+ description: localSub.description || "",
86
+ category,
87
+ options: formatOptions(localSub.options || []),
88
+ slash: isSlashIgnored || !id ? null : { id, name: `${localCmd.name} ${localSub.name}` },
89
+ localizations: sanitizeLocalizations(localSub.descriptionLocalizations),
90
+ aliases: isMessageIgnored ? [] : fullAliases.length ? fullAliases : undefined
91
+ });
92
+ }
93
+ for (const localGroup of groups) {
94
+ const groupSubs = localCmd.modules.filter((m) => m.type === ApplicationCommandOptionType.Subcommand && m.group === localGroup.name);
95
+ for (const localSub of groupSubs) {
96
+ const isSlashIgnored = localSub.ignore === IgnoreCommand.Slash;
97
+ const isMessageIgnored = localSub.ignore === IgnoreCommand.Message;
98
+ const fullAliases = [];
99
+ if (!isMessageIgnored) {
100
+ const cmdNames = [localCmd.name, ...cmdAliases ?? []];
101
+ const groupNames = [localGroup.name, ...localGroup.aliases ?? []];
102
+ const subNames = [localSub.name, ...localSub.aliases ?? []];
103
+ for (const c of cmdNames) {
104
+ for (const g of groupNames) {
105
+ for (const s of subNames) {
106
+ if (c === localCmd.name && g === localGroup.name && s === localSub.name)
107
+ continue;
108
+ fullAliases.push(`${c} ${g} ${s}`);
109
+ }
110
+ }
111
+ }
112
+ if (localSub.shortcut) {
113
+ fullAliases.push(localSub.name, ...localSub.aliases ?? []);
114
+ }
115
+ }
116
+ parsedList.push({
117
+ id,
118
+ name: `${localCmd.name} ${localGroup.name} ${localSub.name}`,
119
+ description: localSub.description || "",
120
+ category,
121
+ options: formatOptions(localSub.options || []),
122
+ slash: isSlashIgnored || !id ? null : {
123
+ id,
124
+ name: `${localCmd.name} ${localGroup.name} ${localSub.name}`
125
+ },
126
+ localizations: sanitizeLocalizations(localSub.descriptionLocalizations),
127
+ aliases: isMessageIgnored ? [] : fullAliases.length ? fullAliases : undefined
128
+ });
129
+ }
130
+ }
131
+ }
132
+ }
133
+ return parsedList;
134
+ }
135
+ function formatOptions(options) {
136
+ return options.filter((opt) => opt.type !== ApplicationCommandOptionType.Subcommand && opt.type !== ApplicationCommandOptionType.SubcommandGroup).map((opt) => {
137
+ const typeName = optionTypes[opt.type] || "any";
138
+ const formatted = `${opt.name}: ${typeName}`;
139
+ return opt.required ? `<${formatted}>` : `[${formatted}]`;
140
+ }).join(", ");
141
+ }
142
+ export {
143
+ parseCommands
144
+ };
@@ -0,0 +1,9 @@
1
+ import { type MatchedRoute } from "rou3";
2
+ export declare class Router<T> {
3
+ private router;
4
+ constructor();
5
+ add(method: string, path: string, data?: T): void;
6
+ find(method: string, path: string): MatchedRoute<T> | undefined;
7
+ remove(method: string, path: string): void;
8
+ private resolvePath;
9
+ }
@@ -0,0 +1,24 @@
1
+ // src/utils/router.ts
2
+ import { addRoute, createRouter, findRoute, removeRoute } from "rou3";
3
+
4
+ class Router {
5
+ router;
6
+ constructor() {
7
+ this.router = createRouter();
8
+ }
9
+ add(method, path, data) {
10
+ addRoute(this.router, method.toUpperCase(), this.resolvePath(path), data);
11
+ }
12
+ find(method, path) {
13
+ return findRoute(this.router, method.toUpperCase(), this.resolvePath(path));
14
+ }
15
+ remove(method, path) {
16
+ removeRoute(this.router, method.toUpperCase(), this.resolvePath(path));
17
+ }
18
+ resolvePath(path) {
19
+ return path.startsWith("/") ? path : `/${path}`;
20
+ }
21
+ }
22
+ export {
23
+ Router
24
+ };
@@ -0,0 +1,7 @@
1
+ export type Prettify<T> = {
2
+ [K in keyof T]: T[K];
3
+ } & {};
4
+ export type NotEmptyArray<T> = T extends never[] ? never : T;
5
+ export type UniqueArray<T> = T extends readonly [infer X, ...infer Rest] ? InArray<Rest, X> extends true ? ["Encountered value with duplicates:", X] : readonly [X, ...UniqueArray<Rest>] : T;
6
+ type InArray<T, X> = T extends readonly [X, ...infer _Rest] ? true : T extends readonly [X] ? true : T extends readonly [infer _, ...infer Rest] ? InArray<Rest, X> : false;
7
+ export {};
File without changes
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Represents the current lib version.
3
+ *
4
+ * The version follows semantic versioning (SemVer), typically in the format:
5
+ * `"MAJOR.MINOR.PATCH"` — for example: `"1.0.0"`.
6
+ */
7
+ export declare const version: string;
@@ -0,0 +1,5 @@
1
+ // src/version.ts
2
+ var version = "1.0.0";
3
+ export {
4
+ version
5
+ };
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "@ezzi/base",
3
+ "version": "1.0.0",
4
+ "description": "Library with structures and functions for creating modern Discord applications.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "publishConfig": {
8
+ "access": "public"
9
+ },
10
+ "keywords": [
11
+ "modern",
12
+ "base",
13
+ "discord",
14
+ "bot",
15
+ "discord bot",
16
+ "discord app",
17
+ "discord application",
18
+ "discord api",
19
+ "discord.js",
20
+ "typescript",
21
+ "app",
22
+ "api",
23
+ "tools",
24
+ "router",
25
+ "handlers",
26
+ "managers",
27
+ "loaders",
28
+ "modules",
29
+ "development",
30
+ "es6",
31
+ "node",
32
+ "bun"
33
+ ],
34
+ "repository": {
35
+ "url": "https://github.com/eufelipw0/ezzi",
36
+ "type": "git",
37
+ "directory": "packages/core"
38
+ },
39
+ "author": {
40
+ "name": "eufelipw0",
41
+ "url": "https://github.com/eufelipw0"
42
+ },
43
+ "exports": {
44
+ ".": {
45
+ "import": "./dist/index.js",
46
+ "types": "./dist/index.d.ts"
47
+ },
48
+ "./tsconfig": "./tsconfig/base.json"
49
+ },
50
+ "files": [
51
+ "dist",
52
+ "tsconfig"
53
+ ],
54
+ "imports": {
55
+ "#package": [
56
+ "./src/index.ts"
57
+ ]
58
+ },
59
+ "scripts": {
60
+ "check": "tsc --noEmit",
61
+ "typegen": "tsc",
62
+ "build": "bun run ./build.ts",
63
+ "prepublish": "bun run build",
64
+ "dev": "bun run ./playground/index.ts"
65
+ },
66
+ "dependencies": {
67
+ "@magicyan/discord": "1.5.1",
68
+ "chalk": "5.4.1",
69
+ "rou3": "^0.8.1",
70
+ "tinyglobby": "^0.2.16"
71
+ },
72
+ "peerDependencies": {
73
+ "discord.js": ">=14.25.0"
74
+ },
75
+ "devDependencies": {
76
+ "@ezzi/config": "*",
77
+ "typescript": "^5.8.2"
78
+ }
79
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "$schema": "https://www.schemastore.org/tsconfig",
3
+ "compilerOptions": {
4
+ "esModuleInterop": true,
5
+ "forceConsistentCasingInFileNames": true,
6
+ "skipLibCheck": true,
7
+ "resolveJsonModule": true,
8
+ "strict": true,
9
+
10
+ "lib": ["ESNext"],
11
+ "target": "ESNext",
12
+ "module": "NodeNext",
13
+ "moduleResolution": "NodeNext",
14
+
15
+ "noUnusedLocals": true,
16
+ "noUnusedParameters": true,
17
+ "noImplicitReturns": true,
18
+ "noImplicitOverride": true,
19
+ "noEmitOnError": true,
20
+ }
21
+ }