-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateAPI.ts
More file actions
45 lines (40 loc) · 1.04 KB
/
createAPI.ts
File metadata and controls
45 lines (40 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import {
type ModuleRegistry,
type NuitAPI,
type NuitCommandInput,
type NuitCommand,
type BaseCtx,
} from "./api";
export function createAPI(
registry: ModuleRegistry,
moduleName: string,
): NuitAPI {
const selfApi: NuitAPI = {
registerCommand(cmd: NuitCommandInput) {
const internal: NuitCommand = {
...cmd,
module: moduleName,
execute: (interaction, ctx: BaseCtx) =>
cmd.execute(interaction, { ...ctx, api: selfApi }),
};
registry.commands.push(internal);
},
onEvent(name, handler) {
registry.events.push({
module: moduleName,
name,
once: false,
handler,
});
},
onceEvent(name, handler) {
registry.events.push({
module: moduleName,
name,
once: true,
handler,
});
},
};
return selfApi;
}