@open-discord-bots/framework 0.2.11 → 0.2.13
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/dist/api/index.d.ts +26 -26
- package/dist/api/index.js +26 -42
- package/dist/api/main.d.ts +24 -24
- package/dist/api/main.js +7 -11
- package/dist/api/modules/action.d.ts +12 -12
- package/dist/api/modules/action.js +11 -17
- package/dist/api/modules/base.d.ts +7 -5
- package/dist/api/modules/base.js +22 -67
- package/dist/api/modules/builder.d.ts +44 -44
- package/dist/api/modules/builder.js +81 -142
- package/dist/api/modules/checker.d.ts +7 -7
- package/dist/api/modules/checker.js +55 -87
- package/dist/api/modules/client.d.ts +4 -4
- package/dist/api/modules/client.js +71 -118
- package/dist/api/modules/code.d.ts +2 -2
- package/dist/api/modules/code.js +3 -8
- package/dist/api/modules/config.d.ts +2 -2
- package/dist/api/modules/config.js +21 -63
- package/dist/api/modules/console.d.ts +16 -16
- package/dist/api/modules/console.js +61 -83
- package/dist/api/modules/cooldown.d.ts +2 -2
- package/dist/api/modules/cooldown.js +13 -23
- package/dist/api/modules/database.d.ts +2 -2
- package/dist/api/modules/database.js +19 -29
- package/dist/api/modules/event.d.ts +2 -2
- package/dist/api/modules/event.js +6 -11
- package/dist/api/modules/flag.d.ts +2 -2
- package/dist/api/modules/flag.js +3 -8
- package/dist/api/modules/fuse.js +2 -7
- package/dist/api/modules/helpmenu.d.ts +2 -2
- package/dist/api/modules/helpmenu.js +8 -16
- package/dist/api/modules/language.d.ts +2 -2
- package/dist/api/modules/language.js +12 -21
- package/dist/api/modules/permission.d.ts +3 -3
- package/dist/api/modules/permission.js +9 -47
- package/dist/api/modules/plugin.d.ts +2 -2
- package/dist/api/modules/plugin.js +9 -18
- package/dist/api/modules/post.d.ts +3 -3
- package/dist/api/modules/post.js +3 -8
- package/dist/api/modules/progressbar.d.ts +2 -2
- package/dist/api/modules/progressbar.js +14 -26
- package/dist/api/modules/responder.d.ts +42 -42
- package/dist/api/modules/responder.js +79 -138
- package/dist/api/modules/session.d.ts +2 -2
- package/dist/api/modules/session.js +4 -42
- package/dist/api/modules/startscreen.d.ts +4 -4
- package/dist/api/modules/startscreen.js +28 -44
- package/dist/api/modules/statistic.d.ts +3 -3
- package/dist/api/modules/statistic.js +11 -22
- package/dist/api/modules/verifybar.d.ts +5 -5
- package/dist/api/modules/verifybar.js +6 -11
- package/dist/api/modules/worker.d.ts +15 -15
- package/dist/api/modules/worker.js +12 -17
- package/dist/cli/editConfig.d.ts +2 -2
- package/dist/cli/editConfig.js +194 -248
- package/dist/cli/index.d.ts +2 -2
- package/dist/cli/index.js +37 -62
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -13
- package/dist/startup/compilation.d.ts +1 -1
- package/dist/startup/compilation.js +35 -42
- package/dist/startup/dump.d.ts +1 -1
- package/dist/startup/dump.js +4 -41
- package/dist/startup/errorHandling.d.ts +1 -1
- package/dist/startup/errorHandling.js +2 -38
- package/dist/startup/pluginLauncher.d.ts +1 -1
- package/dist/startup/pluginLauncher.js +14 -52
- package/dist/utilities/index.d.ts +3 -3
- package/dist/utilities/index.js +20 -71
- package/package.json +5 -4
- package/src/api/index.ts +26 -26
- package/src/api/main.ts +25 -25
- package/src/api/modules/action.ts +13 -13
- package/src/api/modules/base.ts +14 -10
- package/src/api/modules/builder.ts +56 -56
- package/src/api/modules/checker.ts +7 -7
- package/src/api/modules/client.ts +18 -18
- package/src/api/modules/code.ts +2 -2
- package/src/api/modules/component.txt +350 -0
- package/src/api/modules/config.ts +3 -3
- package/src/api/modules/console.ts +28 -28
- package/src/api/modules/cooldown.ts +2 -2
- package/src/api/modules/database.ts +3 -3
- package/src/api/modules/event.ts +5 -5
- package/src/api/modules/flag.ts +2 -2
- package/src/api/modules/helpmenu.ts +4 -4
- package/src/api/modules/language.ts +3 -3
- package/src/api/modules/permission.ts +3 -3
- package/src/api/modules/plugin.ts +4 -4
- package/src/api/modules/post.ts +3 -3
- package/src/api/modules/progressbar.ts +5 -3
- package/src/api/modules/responder.ts +48 -48
- package/src/api/modules/session.ts +2 -2
- package/src/api/modules/startscreen.ts +4 -4
- package/src/api/modules/statistic.ts +3 -4
- package/src/api/modules/verifybar.ts +5 -5
- package/src/api/modules/worker.ts +25 -25
- package/src/cli/editConfig.ts +23 -37
- package/src/cli/index.ts +3 -3
- package/src/index.ts +5 -5
- package/src/startup/compilation.ts +2 -2
- package/src/startup/dump.ts +2 -2
- package/src/startup/errorHandling.ts +2 -2
- package/src/startup/pluginLauncher.ts +11 -8
- package/src/utilities/index.ts +4 -4
- package/tools/cleanup.js +1 -1
- package/tsconfig.json +2 -1
package/dist/cli/editConfig.js
CHANGED
|
@@ -1,48 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.ODCliEditConfigInstance = void 0;
|
|
40
|
-
const api = __importStar(require("../api/index"));
|
|
41
|
-
const utilities = __importStar(require("../utilities/index"));
|
|
42
|
-
const terminal_kit_1 = require("terminal-kit");
|
|
43
|
-
const ansis_1 = __importDefault(require("ansis"));
|
|
44
|
-
const _1 = require(".");
|
|
45
|
-
class ODCliEditConfigInstance {
|
|
1
|
+
import * as api from "../api/index.js";
|
|
2
|
+
import * as utilities from "../utilities/index.js";
|
|
3
|
+
import { terminal } from "terminal-kit";
|
|
4
|
+
import ansis from "ansis";
|
|
5
|
+
import { renderHeader } from "./index.js";
|
|
6
|
+
export class ODCliEditConfigInstance {
|
|
46
7
|
opts;
|
|
47
8
|
opendiscord;
|
|
48
9
|
constructor(opts, opendiscord) {
|
|
@@ -50,17 +11,17 @@ class ODCliEditConfigInstance {
|
|
|
50
11
|
this.opendiscord = opendiscord;
|
|
51
12
|
}
|
|
52
13
|
async renderEditConfig(backFn) {
|
|
53
|
-
|
|
54
|
-
|
|
14
|
+
renderHeader(this.opts, []);
|
|
15
|
+
terminal(ansis.bold.green("Please select which config you would like to edit.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
55
16
|
const checkerList = this.opendiscord.checkers.getAll();
|
|
56
17
|
const checkerNameList = checkerList.map((checker) => (checker.options.cliDisplayName ? checker.options.cliDisplayName + " (" + checker.config.file + ")" : checker.config.file));
|
|
57
18
|
const checkerNameLength = utilities.getLongestLength(checkerNameList);
|
|
58
|
-
const finalCheckerNameList = checkerNameList.map((name, index) => name.padEnd(checkerNameLength + 5, " ") +
|
|
59
|
-
const answer = await
|
|
19
|
+
const finalCheckerNameList = checkerNameList.map((name, index) => name.padEnd(checkerNameLength + 5, " ") + ansis.gray(checkerList[index].options.cliDisplayDescription ? "=> " + checkerList[index].options.cliDisplayDescription : ""));
|
|
20
|
+
const answer = await terminal.singleColumnMenu(finalCheckerNameList, {
|
|
60
21
|
leftPadding: "> ",
|
|
61
|
-
style:
|
|
62
|
-
selectedStyle:
|
|
63
|
-
submittedStyle:
|
|
22
|
+
style: terminal.cyan,
|
|
23
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
24
|
+
submittedStyle: terminal.bgBlue,
|
|
64
25
|
extraLines: 2,
|
|
65
26
|
cancelable: true
|
|
66
27
|
}).promise;
|
|
@@ -90,28 +51,28 @@ class ODCliEditConfigInstance {
|
|
|
90
51
|
else if (structure instanceof api.ODCheckerTypeSwitchStructure)
|
|
91
52
|
await this.renderConfigTypeSwitchStructureEditor(checker, backFn, structure, data, parent, parentIndex, path);
|
|
92
53
|
else
|
|
93
|
-
|
|
54
|
+
terminal.red.bold("❌ Unable to detect type of variable! Please try to edit this property in the JSON file itself!");
|
|
94
55
|
}
|
|
95
56
|
async renderConfigObjectStructureSelector(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
96
57
|
if (typeof data != "object" || Array.isArray(data))
|
|
97
58
|
throw new api.ODSystemError("OD CLI => Property is not of the type 'object'. Please check your config for possible errors. (index: " + parentIndex + ", path: " + path.join(".") + ")");
|
|
98
|
-
|
|
99
|
-
|
|
59
|
+
renderHeader(this.opts, path);
|
|
60
|
+
terminal(ansis.bold.green("Please select which variable you would like to edit.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
100
61
|
if (!structure.options.children)
|
|
101
62
|
return await backFn();
|
|
102
63
|
if (structure.options.cliDisplayName) {
|
|
103
|
-
|
|
104
|
-
|
|
64
|
+
terminal.gray("\nProperty: " + ansis.bold.blue(structure.options.cliDisplayName) + "\n");
|
|
65
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
105
66
|
}
|
|
106
67
|
const list = structure.options.children.filter((child) => !child.cliHideInEditMode);
|
|
107
68
|
const nameList = list.map((child) => (child.checker.options.cliDisplayName ? child.checker.options.cliDisplayName : child.key));
|
|
108
69
|
const nameLength = utilities.getLongestLength(nameList);
|
|
109
|
-
const finalnameList = nameList.map((name, index) => name.padEnd(nameLength + 5, " ") +
|
|
110
|
-
const answer = await
|
|
70
|
+
const finalnameList = nameList.map((name, index) => name.padEnd(nameLength + 5, " ") + ansis.gray((!list[index].checker.options.cliHideDescriptionInParent && list[index].checker.options.cliDisplayDescription) ? "=> " + list[index].checker.options.cliDisplayDescription : ""));
|
|
71
|
+
const answer = await terminal.singleColumnMenu(finalnameList, {
|
|
111
72
|
leftPadding: "> ",
|
|
112
|
-
style:
|
|
113
|
-
selectedStyle:
|
|
114
|
-
submittedStyle:
|
|
73
|
+
style: terminal.cyan,
|
|
74
|
+
selectedStyle: terminal.bgDefaultColor.bold.defaultColor,
|
|
75
|
+
submittedStyle: terminal.bgBlue,
|
|
115
76
|
extraLines: 2,
|
|
116
77
|
cancelable: true
|
|
117
78
|
}).promise;
|
|
@@ -158,16 +119,16 @@ class ODCliEditConfigInstance {
|
|
|
158
119
|
async renderConfigArrayStructureSelector(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
159
120
|
if (!Array.isArray(data))
|
|
160
121
|
throw new api.ODSystemError("OD CLI => Property is not of the type 'array'. Please check your config for possible errors. (index: " + parentIndex + ", path: " + path.join(".") + ")");
|
|
161
|
-
|
|
162
|
-
|
|
122
|
+
renderHeader(this.opts, path);
|
|
123
|
+
terminal(ansis.bold.green("Please select what you would like to do.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
163
124
|
if (!structure.options.propertyChecker)
|
|
164
125
|
return await backFn();
|
|
165
126
|
if (structure.options.cliDisplayName || typeof parentIndex == "string" || !isNaN(parentIndex)) {
|
|
166
|
-
|
|
167
|
-
|
|
127
|
+
terminal.gray("\nProperty: " + ansis.bold.blue(structure.options.cliDisplayName ?? parentIndex.toString()) + "\n");
|
|
128
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
168
129
|
}
|
|
169
130
|
const propertyName = structure.options.cliDisplayPropertyName ?? "index";
|
|
170
|
-
const answer = await
|
|
131
|
+
const answer = await terminal.singleColumnMenu(data.length < 1 ? ["Add " + propertyName] : [
|
|
171
132
|
"Add " + propertyName,
|
|
172
133
|
"Edit " + propertyName,
|
|
173
134
|
"Move " + propertyName,
|
|
@@ -175,9 +136,9 @@ class ODCliEditConfigInstance {
|
|
|
175
136
|
"Duplicate " + propertyName
|
|
176
137
|
], {
|
|
177
138
|
leftPadding: "> ",
|
|
178
|
-
style:
|
|
179
|
-
selectedStyle:
|
|
180
|
-
submittedStyle:
|
|
139
|
+
style: terminal.cyan,
|
|
140
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
141
|
+
submittedStyle: terminal.bgBlue,
|
|
181
142
|
extraLines: 2,
|
|
182
143
|
cancelable: true
|
|
183
144
|
}).promise;
|
|
@@ -201,15 +162,15 @@ class ODCliEditConfigInstance {
|
|
|
201
162
|
}
|
|
202
163
|
async renderConfigArrayStructureEditSelector(checker, backFn, arrayStructure, structure, data, parent, parentIndex, path) {
|
|
203
164
|
const propertyName = arrayStructure.options.cliDisplayPropertyName ?? "index";
|
|
204
|
-
|
|
205
|
-
|
|
165
|
+
renderHeader(this.opts, path);
|
|
166
|
+
terminal(ansis.bold.green("Please select the " + propertyName + " you would like to edit.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
206
167
|
const longestDataListName = Math.max(...data.map((d, i) => this.getArrayPreviewStructureNameLength(structure, d, data, i)));
|
|
207
168
|
const dataList = data.map((d, i) => (i + 1) + ". " + this.getArrayPreviewFromStructure(structure, d, data, i, longestDataListName));
|
|
208
|
-
const dataAnswer = await
|
|
169
|
+
const dataAnswer = await terminal.singleColumnMenu(dataList, {
|
|
209
170
|
leftPadding: "> ",
|
|
210
|
-
style:
|
|
211
|
-
selectedStyle:
|
|
212
|
-
submittedStyle:
|
|
171
|
+
style: terminal.cyan,
|
|
172
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
173
|
+
submittedStyle: terminal.bgBlue,
|
|
213
174
|
extraLines: 2,
|
|
214
175
|
cancelable: true
|
|
215
176
|
}).promise;
|
|
@@ -220,27 +181,27 @@ class ODCliEditConfigInstance {
|
|
|
220
181
|
}
|
|
221
182
|
async renderConfigArrayStructureMoveSelector(checker, backFn, arrayStructure, structure, data, parent, parentIndex, path) {
|
|
222
183
|
const propertyName = arrayStructure.options.cliDisplayPropertyName ?? "index";
|
|
223
|
-
|
|
224
|
-
|
|
184
|
+
renderHeader(this.opts, path);
|
|
185
|
+
terminal(ansis.bold.green("Please select the " + propertyName + " you would like to move.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
225
186
|
const longestDataListName = Math.max(...data.map((d, i) => this.getArrayPreviewStructureNameLength(structure, d, data, i)));
|
|
226
187
|
const dataList = data.map((d, i) => (i + 1) + ". " + this.getArrayPreviewFromStructure(structure, d, data, i, longestDataListName));
|
|
227
|
-
const dataAnswer = await
|
|
188
|
+
const dataAnswer = await terminal.singleColumnMenu(dataList, {
|
|
228
189
|
leftPadding: "> ",
|
|
229
|
-
style:
|
|
230
|
-
selectedStyle:
|
|
231
|
-
submittedStyle:
|
|
190
|
+
style: terminal.cyan,
|
|
191
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
192
|
+
submittedStyle: terminal.bgBlue,
|
|
232
193
|
extraLines: 2,
|
|
233
194
|
cancelable: true
|
|
234
195
|
}).promise;
|
|
235
196
|
if (dataAnswer.canceled)
|
|
236
197
|
return await backFn();
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const moveAnswer = await
|
|
198
|
+
renderHeader(this.opts, [...path, dataAnswer.selectedIndex]);
|
|
199
|
+
terminal(ansis.bold.green("Please select the position you would like to move to.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
200
|
+
const moveAnswer = await terminal.singleColumnMenu(data.map((d, i) => "Position " + (i + 1)), {
|
|
240
201
|
leftPadding: "> ",
|
|
241
|
-
style:
|
|
242
|
-
selectedStyle:
|
|
243
|
-
submittedStyle:
|
|
202
|
+
style: terminal.cyan,
|
|
203
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
204
|
+
submittedStyle: terminal.bgBlue,
|
|
244
205
|
extraLines: 2,
|
|
245
206
|
cancelable: true
|
|
246
207
|
}).promise;
|
|
@@ -251,21 +212,21 @@ class ODCliEditConfigInstance {
|
|
|
251
212
|
const insertedData = [...slicedData.slice(0, moveAnswer.selectedIndex), subData, ...slicedData.slice(moveAnswer.selectedIndex)];
|
|
252
213
|
insertedData.forEach((d, i) => data[i] = d);
|
|
253
214
|
await checker.config.save();
|
|
254
|
-
|
|
215
|
+
terminal.bold.blue("\n\n✅ Property moved succesfully!");
|
|
255
216
|
await utilities.timer(400);
|
|
256
217
|
await backFn();
|
|
257
218
|
}
|
|
258
219
|
async renderConfigArrayStructureRemoveSelector(checker, backFn, arrayStructure, structure, data, parent, parentIndex, path) {
|
|
259
220
|
const propertyName = arrayStructure.options.cliDisplayPropertyName ?? "index";
|
|
260
|
-
|
|
261
|
-
|
|
221
|
+
renderHeader(this.opts, path);
|
|
222
|
+
terminal(ansis.bold.green("Please select the " + propertyName + " you would like to delete.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
262
223
|
const longestDataListName = Math.max(...data.map((d, i) => this.getArrayPreviewStructureNameLength(structure, d, data, i)));
|
|
263
224
|
const dataList = data.map((d, i) => (i + 1) + ". " + this.getArrayPreviewFromStructure(structure, d, data, i, longestDataListName));
|
|
264
|
-
const dataAnswer = await
|
|
225
|
+
const dataAnswer = await terminal.singleColumnMenu(dataList, {
|
|
265
226
|
leftPadding: "> ",
|
|
266
|
-
style:
|
|
267
|
-
selectedStyle:
|
|
268
|
-
submittedStyle:
|
|
227
|
+
style: terminal.cyan,
|
|
228
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
229
|
+
submittedStyle: terminal.bgBlue,
|
|
269
230
|
extraLines: 2,
|
|
270
231
|
cancelable: true
|
|
271
232
|
}).promise;
|
|
@@ -273,21 +234,21 @@ class ODCliEditConfigInstance {
|
|
|
273
234
|
return await backFn();
|
|
274
235
|
data.splice(dataAnswer.selectedIndex, 1);
|
|
275
236
|
await checker.config.save();
|
|
276
|
-
|
|
237
|
+
terminal.bold.blue("\n\n✅ Property deleted succesfully!");
|
|
277
238
|
await utilities.timer(400);
|
|
278
239
|
await backFn();
|
|
279
240
|
}
|
|
280
241
|
async renderConfigArrayStructureDuplicateSelector(checker, backFn, arrayStructure, structure, data, parent, parentIndex, path) {
|
|
281
242
|
const propertyName = arrayStructure.options.cliDisplayPropertyName ?? "index";
|
|
282
|
-
|
|
283
|
-
|
|
243
|
+
renderHeader(this.opts, path);
|
|
244
|
+
terminal(ansis.bold.green("Please select the " + propertyName + " you would like to duplicate.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
284
245
|
const longestDataListName = Math.max(...data.map((d, i) => this.getArrayPreviewStructureNameLength(structure, d, data, i)));
|
|
285
246
|
const dataList = data.map((d, i) => (i + 1) + ". " + this.getArrayPreviewFromStructure(structure, d, data, i, longestDataListName));
|
|
286
|
-
const dataAnswer = await
|
|
247
|
+
const dataAnswer = await terminal.singleColumnMenu(dataList, {
|
|
287
248
|
leftPadding: "> ",
|
|
288
|
-
style:
|
|
289
|
-
selectedStyle:
|
|
290
|
-
submittedStyle:
|
|
249
|
+
style: terminal.cyan,
|
|
250
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
251
|
+
submittedStyle: terminal.bgBlue,
|
|
291
252
|
extraLines: 2,
|
|
292
253
|
cancelable: true
|
|
293
254
|
}).promise;
|
|
@@ -295,22 +256,22 @@ class ODCliEditConfigInstance {
|
|
|
295
256
|
return await backFn();
|
|
296
257
|
data.push(JSON.parse(JSON.stringify(data[dataAnswer.selectedIndex])));
|
|
297
258
|
await checker.config.save();
|
|
298
|
-
|
|
259
|
+
terminal.bold.blue("\n\n✅ Property duplicated succesfully!");
|
|
299
260
|
await utilities.timer(400);
|
|
300
261
|
await backFn();
|
|
301
262
|
}
|
|
302
263
|
async renderConfigBooleanStructureEditor(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
303
264
|
if (typeof data != "boolean")
|
|
304
265
|
throw new api.ODSystemError("OD CLI => Property is not of the type 'boolean'. Please check your config for possible errors. (index: " + parentIndex + ", path: " + path.join(".") + ")");
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const answer = await
|
|
266
|
+
renderHeader(this.opts, path);
|
|
267
|
+
terminal(ansis.bold.green("You are now editing " + (typeof parentIndex == "string" ? "the boolean property " + ansis.blue("\"" + parentIndex + "\"") : "boolean property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
268
|
+
terminal.gray("\nCurrent value: " + ansis.bold[data ? "green" : "red"](data.toString()) + "\n");
|
|
269
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
270
|
+
const answer = await terminal.singleColumnMenu(["false (Disabled)", "true (Enabled)"], {
|
|
310
271
|
leftPadding: "> ",
|
|
311
|
-
style:
|
|
312
|
-
selectedStyle:
|
|
313
|
-
submittedStyle:
|
|
272
|
+
style: terminal.cyan,
|
|
273
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
274
|
+
submittedStyle: terminal.bgBlue,
|
|
314
275
|
extraLines: 2,
|
|
315
276
|
cancelable: true
|
|
316
277
|
}).promise;
|
|
@@ -325,14 +286,14 @@ class ODCliEditConfigInstance {
|
|
|
325
286
|
if (isDataValid) {
|
|
326
287
|
parent[parentIndex] = newValue;
|
|
327
288
|
await checker.config.save();
|
|
328
|
-
|
|
289
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
329
290
|
await utilities.timer(400);
|
|
330
291
|
await backFn();
|
|
331
292
|
}
|
|
332
293
|
else {
|
|
333
294
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
334
|
-
|
|
335
|
-
|
|
295
|
+
terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
296
|
+
terminal.gray("\n" + messages);
|
|
336
297
|
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
337
298
|
await this.renderConfigBooleanStructureEditor(checker, backFn, structure, data, parent, parentIndex, path);
|
|
338
299
|
}
|
|
@@ -340,13 +301,13 @@ class ODCliEditConfigInstance {
|
|
|
340
301
|
async renderConfigNumberStructureEditor(checker, backFn, structure, data, parent, parentIndex, path, prefillValue) {
|
|
341
302
|
if (typeof data != "number")
|
|
342
303
|
throw new api.ODSystemError("OD CLI => Property is not of the type 'number'. Please check your config for possible errors. (index: " + parentIndex + ", path: " + path.join(".") + ")");
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
const answer = await
|
|
304
|
+
renderHeader(this.opts, path);
|
|
305
|
+
terminal(ansis.bold.green("You are now editing " + (typeof parentIndex == "string" ? "the number property " + ansis.blue("\"" + parentIndex + "\"") : "number property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(insert a new value and press enter, go back using escape)\n"));
|
|
306
|
+
terminal.gray("\nCurrent value: " + ansis.bold.blue(data.toString()) + "\n");
|
|
307
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
308
|
+
const answer = await terminal.inputField({
|
|
348
309
|
default: prefillValue,
|
|
349
|
-
style:
|
|
310
|
+
style: terminal.cyan,
|
|
350
311
|
cancelable: true
|
|
351
312
|
}).promise;
|
|
352
313
|
if (typeof answer != "string")
|
|
@@ -360,14 +321,14 @@ class ODCliEditConfigInstance {
|
|
|
360
321
|
if (isDataValid) {
|
|
361
322
|
parent[parentIndex] = newValue;
|
|
362
323
|
await checker.config.save();
|
|
363
|
-
|
|
324
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
364
325
|
await utilities.timer(400);
|
|
365
326
|
await backFn();
|
|
366
327
|
}
|
|
367
328
|
else {
|
|
368
329
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
369
|
-
|
|
370
|
-
|
|
330
|
+
terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
331
|
+
terminal.red("\n" + messages);
|
|
371
332
|
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
372
333
|
await this.renderConfigNumberStructureEditor(checker, backFn, structure, data, parent, parentIndex, path, answer);
|
|
373
334
|
}
|
|
@@ -375,35 +336,35 @@ class ODCliEditConfigInstance {
|
|
|
375
336
|
async renderConfigStringStructureEditor(checker, backFn, structure, data, parent, parentIndex, path, prefillValue) {
|
|
376
337
|
if (typeof data != "string")
|
|
377
338
|
throw new api.ODSystemError("OD CLI => Property is not of the type 'string'. Please check your config for possible errors. (index: " + parentIndex + ", path: " + path.join(".") + ")");
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
339
|
+
renderHeader(this.opts, path);
|
|
340
|
+
terminal(ansis.bold.green("You are now editing " + (typeof parentIndex == "string" ? "the string property " + ansis.blue("\"" + parentIndex + "\"") : "string property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(insert a new value and press enter, go back using escape)\n"));
|
|
341
|
+
terminal.gray("\nCurrent value:" + (data.includes("\n") ? "\n" : " \"") + ansis.bold.blue(data) + ansis.gray(!data.includes("\n") ? "\"\n" : "\n"));
|
|
342
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
382
343
|
const customExtraOptions = (structure instanceof api.ODCheckerCustomStructure_DiscordId) ? structure.extraOptions : undefined;
|
|
383
344
|
const customAutocompleteFunc = structure.options.cliAutocompleteFunc ? await structure.options.cliAutocompleteFunc() : null;
|
|
384
345
|
const autocompleteList = ((customAutocompleteFunc ?? structure.options.cliAutocompleteList) ?? customExtraOptions) ?? structure.options.choices;
|
|
385
346
|
const autoCompleteMenuOpts = {
|
|
386
|
-
style:
|
|
387
|
-
selectedStyle:
|
|
347
|
+
style: terminal.white,
|
|
348
|
+
selectedStyle: terminal.bgBlue.white
|
|
388
349
|
};
|
|
389
|
-
const input =
|
|
350
|
+
const input = terminal.inputField({
|
|
390
351
|
default: prefillValue,
|
|
391
|
-
style:
|
|
392
|
-
hintStyle:
|
|
352
|
+
style: terminal.cyan,
|
|
353
|
+
hintStyle: terminal.gray,
|
|
393
354
|
cancelable: false,
|
|
394
355
|
autoComplete: autocompleteList,
|
|
395
356
|
autoCompleteHint: (!!autocompleteList),
|
|
396
357
|
autoCompleteMenu: (autocompleteList) ? autoCompleteMenuOpts : false
|
|
397
358
|
});
|
|
398
|
-
|
|
359
|
+
terminal.on("key", async (name, matches, data) => {
|
|
399
360
|
if (name == "ESCAPE") {
|
|
400
|
-
|
|
361
|
+
terminal.removeListener("key", "cli-render-string-structure-edit");
|
|
401
362
|
input.abort();
|
|
402
363
|
await backFn();
|
|
403
364
|
}
|
|
404
365
|
}, { id: "cli-render-string-structure-edit" });
|
|
405
366
|
const answer = await input.promise;
|
|
406
|
-
|
|
367
|
+
terminal.removeListener("key", "cli-render-string-structure-edit");
|
|
407
368
|
if (typeof answer != "string")
|
|
408
369
|
return;
|
|
409
370
|
//run config checker
|
|
@@ -415,14 +376,14 @@ class ODCliEditConfigInstance {
|
|
|
415
376
|
if (isDataValid) {
|
|
416
377
|
parent[parentIndex] = newValue;
|
|
417
378
|
await checker.config.save();
|
|
418
|
-
|
|
379
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
419
380
|
await utilities.timer(400);
|
|
420
381
|
await backFn();
|
|
421
382
|
}
|
|
422
383
|
else {
|
|
423
384
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
424
|
-
|
|
425
|
-
|
|
385
|
+
terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
386
|
+
terminal.red("\n" + messages);
|
|
426
387
|
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
427
388
|
await this.renderConfigStringStructureEditor(checker, backFn, structure, data, parent, parentIndex, path, answer);
|
|
428
389
|
}
|
|
@@ -430,15 +391,15 @@ class ODCliEditConfigInstance {
|
|
|
430
391
|
async renderConfigNullStructureEditor(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
431
392
|
if (data !== null)
|
|
432
393
|
throw new api.ODSystemError("OD CLI => Property is not of the type 'null'. Please check your config for possible errors. (index: " + parentIndex + ", path: " + path.join(".") + ")");
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
const answer = await
|
|
394
|
+
renderHeader(this.opts, path);
|
|
395
|
+
terminal(ansis.bold.green("You are now editing " + (typeof parentIndex == "string" ? "the null property " + ansis.blue("\"" + parentIndex + "\"") : "null property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
396
|
+
terminal.gray("\nCurrent value: " + ansis.bold.blue("null") + "\n");
|
|
397
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
398
|
+
const answer = await terminal.singleColumnMenu(["null"], {
|
|
438
399
|
leftPadding: "> ",
|
|
439
|
-
style:
|
|
440
|
-
selectedStyle:
|
|
441
|
-
submittedStyle:
|
|
400
|
+
style: terminal.cyan,
|
|
401
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
402
|
+
submittedStyle: terminal.bgBlue,
|
|
442
403
|
extraLines: 2,
|
|
443
404
|
cancelable: true
|
|
444
405
|
}).promise;
|
|
@@ -453,23 +414,23 @@ class ODCliEditConfigInstance {
|
|
|
453
414
|
if (isDataValid) {
|
|
454
415
|
parent[parentIndex] = newValue;
|
|
455
416
|
await checker.config.save();
|
|
456
|
-
|
|
417
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
457
418
|
await utilities.timer(400);
|
|
458
419
|
await backFn();
|
|
459
420
|
}
|
|
460
421
|
else {
|
|
461
422
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
462
|
-
|
|
463
|
-
|
|
423
|
+
terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
424
|
+
terminal.red("\n" + messages);
|
|
464
425
|
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
465
426
|
await this.renderConfigNullStructureEditor(checker, backFn, structure, data, parent, parentIndex, path);
|
|
466
427
|
}
|
|
467
428
|
}
|
|
468
429
|
async renderConfigTypeSwitchStructureEditor(checker, backFn, structure, data, parent, parentIndex, path) {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
430
|
+
renderHeader(this.opts, path);
|
|
431
|
+
terminal(ansis.bold.green("You are now editing " + (typeof parentIndex == "string" ? "the property " + ansis.blue("\"" + parentIndex + "\"") : "property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
432
|
+
terminal.gray("\nCurrent value: " + ansis.bold.blue(data.toString()) + "\n");
|
|
433
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
473
434
|
const actionsList = [];
|
|
474
435
|
if (structure.options.boolean)
|
|
475
436
|
actionsList.push("Edit as boolean");
|
|
@@ -483,11 +444,11 @@ class ODCliEditConfigInstance {
|
|
|
483
444
|
actionsList.push("Edit as array/list");
|
|
484
445
|
if (structure.options.null)
|
|
485
446
|
actionsList.push("Edit as null");
|
|
486
|
-
const answer = await
|
|
447
|
+
const answer = await terminal.singleColumnMenu(actionsList, {
|
|
487
448
|
leftPadding: "> ",
|
|
488
|
-
style:
|
|
489
|
-
selectedStyle:
|
|
490
|
-
submittedStyle:
|
|
449
|
+
style: terminal.cyan,
|
|
450
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
451
|
+
submittedStyle: terminal.bgBlue,
|
|
491
452
|
extraLines: 2,
|
|
492
453
|
cancelable: true
|
|
493
454
|
}).promise;
|
|
@@ -522,7 +483,7 @@ class ODCliEditConfigInstance {
|
|
|
522
483
|
if (!structure.options.cliDisplayKeyInParentArray)
|
|
523
484
|
return "Object".length;
|
|
524
485
|
else
|
|
525
|
-
return data[structure.options.cliDisplayKeyInParentArray]
|
|
486
|
+
return data[structure.options.cliDisplayKeyInParentArray]?.toString().length ?? 0;
|
|
526
487
|
}
|
|
527
488
|
else if (structure instanceof api.ODCheckerEnabledObjectStructure && typeof data == "object" && !Array.isArray(data) && data) {
|
|
528
489
|
const subStructure = structure.options.checker;
|
|
@@ -571,11 +532,11 @@ class ODCliEditConfigInstance {
|
|
|
571
532
|
else if (structure instanceof api.ODCheckerArrayStructure && Array.isArray(data))
|
|
572
533
|
return "Array";
|
|
573
534
|
else if (structure instanceof api.ODCheckerObjectStructure && typeof data == "object" && !Array.isArray(data) && data) {
|
|
574
|
-
const additionalKeys = (structure.options.cliDisplayAdditionalKeysInParentArray ?? []).map((key) => key + ": " + data[key]
|
|
535
|
+
const additionalKeys = (structure.options.cliDisplayAdditionalKeysInParentArray ?? []).map((key) => key + ": " + data[key]?.toString()).join(", ");
|
|
575
536
|
if (!structure.options.cliDisplayKeyInParentArray)
|
|
576
537
|
return "Object";
|
|
577
538
|
else
|
|
578
|
-
return data[structure.options.cliDisplayKeyInParentArray]
|
|
539
|
+
return data[structure.options.cliDisplayKeyInParentArray]?.toString().padEnd(nameLength + 5, " ") + ansis.gray(additionalKeys.length > 0 ? "(" + additionalKeys + ")" : "");
|
|
579
540
|
}
|
|
580
541
|
else if (structure instanceof api.ODCheckerEnabledObjectStructure && typeof data == "object" && !Array.isArray(data) && data) {
|
|
581
542
|
const subStructure = structure.options.checker;
|
|
@@ -671,7 +632,7 @@ class ODCliEditConfigInstance {
|
|
|
671
632
|
await backFn();
|
|
672
633
|
}, async () => {
|
|
673
634
|
//finish setup
|
|
674
|
-
|
|
635
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
675
636
|
await utilities.timer(400);
|
|
676
637
|
await nextFn(localData);
|
|
677
638
|
});
|
|
@@ -715,28 +676,21 @@ class ODCliEditConfigInstance {
|
|
|
715
676
|
else {
|
|
716
677
|
localData[enabledProperty] = data;
|
|
717
678
|
//copy old object checker to new object checker => all options get de-referenced (this is needed for the new object skip keys are temporary)
|
|
718
|
-
const newStructure = new api.ODCheckerObjectStructure(subStructure.id,
|
|
719
|
-
//
|
|
720
|
-
newStructure.options.children = [...subStructure.options.children];
|
|
721
|
-
newStructure.options.cliInitSkipKeys = subStructure.options.children.map((child) => child.key);
|
|
722
|
-
for (const key of Object.keys(subStructure.options)) {
|
|
723
|
-
if (key != "children" && key != "cliInitSkipKeys")
|
|
724
|
-
newStructure.options[key] = subStructure.options[key];
|
|
725
|
-
}
|
|
726
|
-
//adds all properties to object as "skipKeys", then continues to next function
|
|
679
|
+
const newStructure = new api.ODCheckerObjectStructure(subStructure.id, structuredClone(subStructure.options));
|
|
680
|
+
//continues to next function
|
|
727
681
|
await this.renderAdditionConfigObjectStructure(checker, async () => { await this.renderAdditionConfigEnabledObjectStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath); }, nextFn, newStructure, parent, parentIndex, path, localPath, localData);
|
|
728
682
|
await nextFn(localData);
|
|
729
683
|
}
|
|
730
684
|
}, propertyStructure, localData, enabledProperty, [...path, parentIndex], [...localPath, parentIndex]);
|
|
731
685
|
}
|
|
732
686
|
async renderAdditionConfigObjectSwitchStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath) {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
const answer = await
|
|
687
|
+
renderHeader(this.opts, [...path, parentIndex]);
|
|
688
|
+
terminal(ansis.bold.green("What type of object would you like to add?\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
689
|
+
const answer = await terminal.singleColumnMenu(structure.options.objects.map((obj) => obj.name), {
|
|
736
690
|
leftPadding: "> ",
|
|
737
|
-
style:
|
|
738
|
-
selectedStyle:
|
|
739
|
-
submittedStyle:
|
|
691
|
+
style: terminal.cyan,
|
|
692
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
693
|
+
submittedStyle: terminal.bgBlue,
|
|
740
694
|
extraLines: 2,
|
|
741
695
|
cancelable: true
|
|
742
696
|
}).promise;
|
|
@@ -745,14 +699,7 @@ class ODCliEditConfigInstance {
|
|
|
745
699
|
const objectTemplate = structure.options.objects[answer.selectedIndex];
|
|
746
700
|
//copy old object checker to new object checker => all options get de-referenced (this is needed for the new object switch properties which are temporary)
|
|
747
701
|
const oldStructure = objectTemplate.checker;
|
|
748
|
-
const newStructure = new api.ODCheckerObjectStructure(oldStructure.id,
|
|
749
|
-
//copy all options over to the new checker
|
|
750
|
-
newStructure.options.children = [...oldStructure.options.children];
|
|
751
|
-
newStructure.options.cliInitSkipKeys = [...(oldStructure.options.cliInitSkipKeys ?? [])];
|
|
752
|
-
for (const key of Object.keys(oldStructure.options)) {
|
|
753
|
-
if (key != "children" && key != "cliInitSkipKeys")
|
|
754
|
-
newStructure.options[key] = oldStructure.options[key];
|
|
755
|
-
}
|
|
702
|
+
const newStructure = new api.ODCheckerObjectStructure(oldStructure.id, structuredClone(oldStructure.options));
|
|
756
703
|
//add the keys of the object switch properties to the 'cliInitSkipKeys' because they need to be skipped.
|
|
757
704
|
objectTemplate.properties.map((p) => p.key).forEach((p) => {
|
|
758
705
|
if (!newStructure.options.cliInitSkipKeys)
|
|
@@ -774,15 +721,15 @@ class ODCliEditConfigInstance {
|
|
|
774
721
|
await this.chooseAdditionConfigStructure(checker, backFn, nextFn, newStructure, parent, parentIndex, path, localPath);
|
|
775
722
|
}
|
|
776
723
|
async renderAdditionConfigBooleanStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath) {
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
const answer = await
|
|
724
|
+
renderHeader(this.opts, [...path, parentIndex]);
|
|
725
|
+
terminal(ansis.bold.green("You are now creating " + (typeof parentIndex == "string" ? "the boolean property " + ansis.blue("\"" + parentIndex + "\"") : "boolean property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
726
|
+
terminal.gray("\nProperty: " + ansis.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
727
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
728
|
+
const answer = await terminal.singleColumnMenu(["false (Disabled)", "true (Enabled)"], {
|
|
782
729
|
leftPadding: "> ",
|
|
783
|
-
style:
|
|
784
|
-
selectedStyle:
|
|
785
|
-
submittedStyle:
|
|
730
|
+
style: terminal.cyan,
|
|
731
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
732
|
+
submittedStyle: terminal.bgBlue,
|
|
786
733
|
extraLines: 2,
|
|
787
734
|
cancelable: true
|
|
788
735
|
}).promise;
|
|
@@ -795,26 +742,26 @@ class ODCliEditConfigInstance {
|
|
|
795
742
|
checker.messages = []; //manually clear previous messages
|
|
796
743
|
const isDataValid = structure.check(checker, newValue, newPath);
|
|
797
744
|
if (isDataValid) {
|
|
798
|
-
|
|
745
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
799
746
|
await utilities.timer(400);
|
|
800
747
|
await nextFn(newValue);
|
|
801
748
|
}
|
|
802
749
|
else {
|
|
803
750
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
804
|
-
|
|
805
|
-
|
|
751
|
+
terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
752
|
+
terminal.gray("\n" + messages);
|
|
806
753
|
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
807
754
|
await this.renderAdditionConfigBooleanStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath);
|
|
808
755
|
}
|
|
809
756
|
}
|
|
810
757
|
async renderAdditionConfigNumberStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath, prefillValue) {
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
const answer = await
|
|
758
|
+
renderHeader(this.opts, [...path, parentIndex]);
|
|
759
|
+
terminal(ansis.bold.green("You are now creating " + (typeof parentIndex == "string" ? "the number property " + ansis.blue("\"" + parentIndex + "\"") : "number property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(insert a new value and press enter, go back using escape)\n"));
|
|
760
|
+
terminal.gray("\nProperty: " + ansis.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
761
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
762
|
+
const answer = await terminal.inputField({
|
|
816
763
|
default: prefillValue,
|
|
817
|
-
style:
|
|
764
|
+
style: terminal.cyan,
|
|
818
765
|
cancelable: true
|
|
819
766
|
}).promise;
|
|
820
767
|
if (typeof answer != "string")
|
|
@@ -826,48 +773,48 @@ class ODCliEditConfigInstance {
|
|
|
826
773
|
checker.messages = []; //manually clear previous messages
|
|
827
774
|
const isDataValid = structure.check(checker, newValue, newPath);
|
|
828
775
|
if (isDataValid) {
|
|
829
|
-
|
|
776
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
830
777
|
await utilities.timer(400);
|
|
831
778
|
await nextFn(newValue);
|
|
832
779
|
}
|
|
833
780
|
else {
|
|
834
781
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
835
|
-
|
|
836
|
-
|
|
782
|
+
terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
783
|
+
terminal.red("\n" + messages);
|
|
837
784
|
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
838
785
|
await this.renderAdditionConfigNumberStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath, answer);
|
|
839
786
|
}
|
|
840
787
|
}
|
|
841
788
|
async renderAdditionConfigStringStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath, prefillValue) {
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
789
|
+
renderHeader(this.opts, [...path, parentIndex]);
|
|
790
|
+
terminal(ansis.bold.green("You are now creating " + (typeof parentIndex == "string" ? "the string property " + ansis.blue("\"" + parentIndex + "\"") : "string property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(insert a new value and press enter, go back using escape)\n"));
|
|
791
|
+
terminal.gray("\nProperty: " + ansis.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
792
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
846
793
|
const customExtraOptions = (structure instanceof api.ODCheckerCustomStructure_DiscordId) ? structure.extraOptions : undefined;
|
|
847
794
|
const customAutocompleteFunc = structure.options.cliAutocompleteFunc ? await structure.options.cliAutocompleteFunc() : null;
|
|
848
795
|
const autocompleteList = ((customAutocompleteFunc ?? structure.options.cliAutocompleteList) ?? customExtraOptions) ?? structure.options.choices;
|
|
849
796
|
const autoCompleteMenuOpts = {
|
|
850
|
-
style:
|
|
851
|
-
selectedStyle:
|
|
797
|
+
style: terminal.white,
|
|
798
|
+
selectedStyle: terminal.bgBlue.white
|
|
852
799
|
};
|
|
853
|
-
const input =
|
|
800
|
+
const input = terminal.inputField({
|
|
854
801
|
default: prefillValue,
|
|
855
|
-
style:
|
|
856
|
-
hintStyle:
|
|
802
|
+
style: terminal.cyan,
|
|
803
|
+
hintStyle: terminal.gray,
|
|
857
804
|
cancelable: false,
|
|
858
805
|
autoComplete: autocompleteList,
|
|
859
806
|
autoCompleteHint: (!!autocompleteList),
|
|
860
807
|
autoCompleteMenu: (autocompleteList) ? autoCompleteMenuOpts : false
|
|
861
808
|
});
|
|
862
|
-
|
|
809
|
+
terminal.on("key", async (name, matches, data) => {
|
|
863
810
|
if (name == "ESCAPE") {
|
|
864
|
-
|
|
811
|
+
terminal.removeListener("key", "cli-render-string-structure-add");
|
|
865
812
|
input.abort();
|
|
866
813
|
await backFn();
|
|
867
814
|
}
|
|
868
815
|
}, { id: "cli-render-string-structure-add" });
|
|
869
816
|
const answer = await input.promise;
|
|
870
|
-
|
|
817
|
+
terminal.removeListener("key", "cli-render-string-structure-add");
|
|
871
818
|
if (typeof answer != "string")
|
|
872
819
|
return;
|
|
873
820
|
//run config checker
|
|
@@ -877,28 +824,28 @@ class ODCliEditConfigInstance {
|
|
|
877
824
|
checker.messages = []; //manually clear previous messages
|
|
878
825
|
const isDataValid = structure.check(checker, newValue, newPath);
|
|
879
826
|
if (isDataValid) {
|
|
880
|
-
|
|
827
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
881
828
|
await utilities.timer(400);
|
|
882
829
|
await nextFn(newValue);
|
|
883
830
|
}
|
|
884
831
|
else {
|
|
885
832
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
886
|
-
|
|
887
|
-
|
|
833
|
+
terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
834
|
+
terminal.red("\n" + messages);
|
|
888
835
|
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
889
836
|
await this.renderAdditionConfigStringStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath, answer);
|
|
890
837
|
}
|
|
891
838
|
}
|
|
892
839
|
async renderAdditionConfigNullStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath) {
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
const answer = await
|
|
840
|
+
renderHeader(this.opts, [...path, parentIndex]);
|
|
841
|
+
terminal(ansis.bold.green("You are now creating " + (typeof parentIndex == "string" ? "the null property " + ansis.blue("\"" + parentIndex + "\"") : "null property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
842
|
+
terminal.gray("\nProperty: " + ansis.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
843
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
844
|
+
const answer = await terminal.singleColumnMenu(["null"], {
|
|
898
845
|
leftPadding: "> ",
|
|
899
|
-
style:
|
|
900
|
-
selectedStyle:
|
|
901
|
-
submittedStyle:
|
|
846
|
+
style: terminal.cyan,
|
|
847
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
848
|
+
submittedStyle: terminal.bgBlue,
|
|
902
849
|
extraLines: 2,
|
|
903
850
|
cancelable: true
|
|
904
851
|
}).promise;
|
|
@@ -911,28 +858,28 @@ class ODCliEditConfigInstance {
|
|
|
911
858
|
checker.messages = []; //manually clear previous messages
|
|
912
859
|
const isDataValid = structure.check(checker, newValue, newPath);
|
|
913
860
|
if (isDataValid) {
|
|
914
|
-
|
|
861
|
+
terminal.bold.blue("\n\n✅ Variable saved succesfully!");
|
|
915
862
|
await utilities.timer(400);
|
|
916
863
|
await nextFn(newValue);
|
|
917
864
|
}
|
|
918
865
|
else {
|
|
919
866
|
const messages = checker.messages.map((msg) => "=> [" + msg.type.toUpperCase() + "] " + msg.message).join("\n");
|
|
920
|
-
|
|
921
|
-
|
|
867
|
+
terminal.bold.blue("\n\n❌ Variable is invalid! Please try again!");
|
|
868
|
+
terminal.red("\n" + messages);
|
|
922
869
|
await utilities.timer(1000 + (2000 * checker.messages.length));
|
|
923
870
|
await this.renderAdditionConfigNullStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath);
|
|
924
871
|
}
|
|
925
872
|
}
|
|
926
873
|
async renderAdditionConfigArrayStructureSelector(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath, localData = []) {
|
|
927
|
-
|
|
928
|
-
|
|
874
|
+
renderHeader(this.opts, [...path, parentIndex]);
|
|
875
|
+
terminal(ansis.bold.green("Please select what you would like to do with the new array.\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
929
876
|
if (!structure.options.propertyChecker)
|
|
930
877
|
return await backFn();
|
|
931
|
-
|
|
932
|
-
|
|
878
|
+
terminal.gray("\nProperty: " + ansis.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
879
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
933
880
|
const propertyName = structure.options.cliDisplayPropertyName ?? "index";
|
|
934
|
-
const answer = await
|
|
935
|
-
|
|
881
|
+
const answer = await terminal.singleColumnMenu(localData.length < 1 ? [ansis.magenta("-> Continue to next variable"), "Add " + propertyName] : [
|
|
882
|
+
ansis.magenta("-> Continue to next variable"),
|
|
936
883
|
"Add " + propertyName,
|
|
937
884
|
"Edit " + propertyName,
|
|
938
885
|
"Move " + propertyName,
|
|
@@ -940,9 +887,9 @@ class ODCliEditConfigInstance {
|
|
|
940
887
|
"Duplicate " + propertyName,
|
|
941
888
|
], {
|
|
942
889
|
leftPadding: "> ",
|
|
943
|
-
style:
|
|
944
|
-
selectedStyle:
|
|
945
|
-
submittedStyle:
|
|
890
|
+
style: terminal.cyan,
|
|
891
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
892
|
+
submittedStyle: terminal.bgBlue,
|
|
946
893
|
extraLines: 2,
|
|
947
894
|
cancelable: true
|
|
948
895
|
}).promise;
|
|
@@ -966,10 +913,10 @@ class ODCliEditConfigInstance {
|
|
|
966
913
|
await this.renderConfigArrayStructureDuplicateSelector(checker, backFnFunc, structure, structure.options.propertyChecker, localData, parent, parentIndex, path);
|
|
967
914
|
}
|
|
968
915
|
async renderAdditionConfigTypeSwitchStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath) {
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
916
|
+
renderHeader(this.opts, path);
|
|
917
|
+
terminal(ansis.bold.green("You are now creating " + (typeof parentIndex == "string" ? "the property " + ansis.blue("\"" + parentIndex + "\"") : "property " + ansis.blue("#" + (parentIndex + 1))) + ".\n") + ansis.italic.gray("(use arrow keys to navigate, go back using escape)\n"));
|
|
918
|
+
terminal.gray("\nProperty: " + ansis.bold.blue(structure.options.cliDisplayName ?? [...localPath, parentIndex].join(".")) + "\n");
|
|
919
|
+
terminal.gray("Description: " + ansis.bold(structure.options.cliDisplayDescription ?? "/") + "\n");
|
|
973
920
|
const actionsList = [];
|
|
974
921
|
if (structure.options.boolean)
|
|
975
922
|
actionsList.push("Create as boolean");
|
|
@@ -983,11 +930,11 @@ class ODCliEditConfigInstance {
|
|
|
983
930
|
actionsList.push("Create as array/list");
|
|
984
931
|
if (structure.options.null)
|
|
985
932
|
actionsList.push("Create as null");
|
|
986
|
-
const answer = await
|
|
933
|
+
const answer = await terminal.singleColumnMenu(actionsList, {
|
|
987
934
|
leftPadding: "> ",
|
|
988
|
-
style:
|
|
989
|
-
selectedStyle:
|
|
990
|
-
submittedStyle:
|
|
935
|
+
style: terminal.cyan,
|
|
936
|
+
selectedStyle: terminal.bgDefaultColor.bold,
|
|
937
|
+
submittedStyle: terminal.bgBlue,
|
|
991
938
|
extraLines: 2,
|
|
992
939
|
cancelable: true
|
|
993
940
|
}).promise;
|
|
@@ -1008,4 +955,3 @@ class ODCliEditConfigInstance {
|
|
|
1008
955
|
await this.renderAdditionConfigNullStructure(checker, async () => { await this.renderAdditionConfigTypeSwitchStructure(checker, backFn, nextFn, structure, parent, parentIndex, path, localPath); }, nextFn, structure.options.null, parent, parentIndex, path, localPath);
|
|
1009
956
|
}
|
|
1010
957
|
}
|
|
1011
|
-
exports.ODCliEditConfigInstance = ODCliEditConfigInstance;
|