this repo has no description
1import {
2 APPLICATION_ID,
3 Commands,
4 LegacyCommand,
5 RegisteredCommand
6} from "@moonlight-mod/types/coreExtensions/commands";
7
8type LegacyCommands = Record<string, LegacyCommand>;
9let legacyCommands: LegacyCommands | undefined;
10let queuedLegacyCommands: Record<string, LegacyCommand> | null = {};
11
12const registeredCommands: RegisteredCommand[] = [];
13
14export function _getLegacyCommands(commands: LegacyCommands) {
15 legacyCommands = commands;
16 if (queuedLegacyCommands != null) {
17 for (const [key, value] of Object.entries(queuedLegacyCommands)) {
18 legacyCommands[key] = value;
19 }
20 queuedLegacyCommands = null;
21 }
22}
23
24export const commands: Commands = {
25 registerCommand(command) {
26 const registered: RegisteredCommand = {
27 ...command,
28 untranslatedName: command.id,
29 displayName: command.id,
30 applicationId: APPLICATION_ID,
31 untranslatedDescription: command.description,
32 displayDescription: command.description,
33 options: command.options.map((o) => ({
34 ...o,
35 displayName: o.name,
36 displayDescription: o.description
37 }))
38 };
39 registeredCommands.push(registered);
40 },
41
42 registerLegacyCommand(id, command) {
43 if (!legacyCommands) {
44 queuedLegacyCommands![id] = command;
45 } else {
46 legacyCommands[id] = command;
47 }
48 },
49
50 _getCommands() {
51 return [...registeredCommands];
52 }
53};
54
55export default commands;