@open-discord-bots/framework 0.0.3 → 0.0.5
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 +3 -3
- package/dist/api/modules/plugin.d.ts +11 -2
- package/dist/api/modules/plugin.js +4 -0
- package/dist/cli/cli.d.ts +35 -0
- package/dist/cli/cli.js +157 -0
- package/dist/cli/editConfig.d.ts +35 -0
- package/dist/cli/editConfig.js +977 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +4 -1
- package/dist/startup/compilation.d.ts +2 -0
- package/dist/startup/compilation.js +187 -0
- package/dist/startup/pluginLauncher.js +66 -2
- package/package.json +2 -2
- package/src/startup/compilation.ts +9 -2
package/README.md
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
-
<img src="https://apis.dj-dj.be/cdn/opendiscord/logo.png" alt="Open
|
|
2
|
+
<img src="https://apis.dj-dj.be/cdn/opendiscord/logo.png" alt="Open Discord Logo" width="650px"><br>
|
|
3
3
|
<span align="center"><b>A modular framework for the next-generation of Discord bots</b></span><br><br>
|
|
4
|
-
<a href="https://otgithub.dj-dj.be"><img src="https://apis.dj-dj.be/cdn/openticket/logo.png" alt="Open Ticket" height="55px"></a>
|
|
5
|
-
<a href="https://otgithub.dj-dj.be"><img src="https://apis.dj-dj.be/cdn/openmoderation/logo.png" alt="Open Moderation" height="60px"></a><br><br>
|
|
4
|
+
<a href="https://otgithub.dj-dj.be"><img src="https://apis.dj-dj.be/cdn/openticket/logo.png" alt="Open Ticket Logo" height="55px"></a>
|
|
5
|
+
<a href="https://otgithub.dj-dj.be"><img src="https://apis.dj-dj.be/cdn/openmoderation/logo.png" alt="Open Moderation Logo" height="60px"></a><br><br>
|
|
6
6
|
<a href="https://discord.com/invite/26vT9wt3n3"><img alt="Discord Invite Link" src="https://img.shields.io/badge/discord-support%20server-5865F2.svg?style=flat-square&logo=discord"></img></a>
|
|
7
7
|
<a href="https://github.com/open-discord-bots/plugins/blob/main/LICENSE"><img alt="Open Discord Plugins License" src="https://img.shields.io/badge/license-MIT-important.svg?style=flat-square"></img></a>
|
|
8
8
|
<a href="https://discord.dj-dj.be"><img alt="Open Discord Plugins Stars" src="https://img.shields.io/github/stars/open-discord-bots/framework?color=yellow&label=stars&logo=github&style=flat-square"></img></a>
|
|
@@ -39,6 +39,11 @@ export interface ODPluginData {
|
|
|
39
39
|
version: string;
|
|
40
40
|
/**The location of the start file of the plugin relative to the rootDir of the plugin */
|
|
41
41
|
startFile: string;
|
|
42
|
+
/**A list of compatible versions. (e.g. `["OTv4.0.x", "OMv1.x.x"]`) (optional, will be required in future version)
|
|
43
|
+
* - `OT` --> Open Ticket support
|
|
44
|
+
* - `OM` --> Open Moderation support
|
|
45
|
+
*/
|
|
46
|
+
supportedVersions?: string[];
|
|
42
47
|
/**Is this plugin enabled? */
|
|
43
48
|
enabled: boolean;
|
|
44
49
|
/**The priority of this plugin. Higher priority will load before lower priority. */
|
|
@@ -58,8 +63,10 @@ export interface ODPluginData {
|
|
|
58
63
|
* Additional details in the `plugin.json` file from a plugin.
|
|
59
64
|
*/
|
|
60
65
|
export interface ODPluginDetails {
|
|
61
|
-
/**The author of the plugin. */
|
|
66
|
+
/**The main author of the plugin. Additional contributors can be specified in `contributors`. */
|
|
62
67
|
author: string;
|
|
68
|
+
/**A list of plugin contributors. (optional, will be required in future version) */
|
|
69
|
+
contributors?: string[];
|
|
63
70
|
/**A short description of this plugin. */
|
|
64
71
|
shortDescription: string;
|
|
65
72
|
/**A large description of this plugin. */
|
|
@@ -100,7 +107,7 @@ export declare class ODPlugin extends ODManagerData {
|
|
|
100
107
|
/**Did this plugin crash? (A reason is available in the `crashReason`) */
|
|
101
108
|
crashed: boolean;
|
|
102
109
|
/**The reason which caused this plugin to crash. */
|
|
103
|
-
crashReason: null | "incompatible.plugin" | "missing.plugin" | "missing.dependency" | "executed";
|
|
110
|
+
crashReason: null | "incompatible.plugin" | "missing.plugin" | "missing.dependency" | "incompatible.version" | "executed";
|
|
104
111
|
constructor(dir: string, jsondata: ODPluginData);
|
|
105
112
|
/**Get the startfile location relative to the `./plugins/` directory. (`./dist/plugins/`) when compiled) */
|
|
106
113
|
getStartFile(): string;
|
|
@@ -112,6 +119,8 @@ export declare class ODPlugin extends ODManagerData {
|
|
|
112
119
|
pluginsInstalled(manager: ODPluginManager): string[];
|
|
113
120
|
/**Get a list of all enabled incompatible plugins that interfere with this plugin. */
|
|
114
121
|
pluginsIncompatible(manager: ODPluginManager): string[];
|
|
122
|
+
/**Get a list of all authors & contributors of this plugin. */
|
|
123
|
+
getAuthors(): string[];
|
|
115
124
|
}
|
|
116
125
|
/**## ODPluginClassManager `class`
|
|
117
126
|
* This is an Open Discord plugin class manager.
|
|
@@ -148,6 +148,10 @@ class ODPlugin extends base_1.ODManagerData {
|
|
|
148
148
|
});
|
|
149
149
|
return incompatible;
|
|
150
150
|
}
|
|
151
|
+
/**Get a list of all authors & contributors of this plugin. */
|
|
152
|
+
getAuthors() {
|
|
153
|
+
return [this.details.author, ...(this.details.contributors ?? [])];
|
|
154
|
+
}
|
|
151
155
|
}
|
|
152
156
|
exports.ODPlugin = ODPlugin;
|
|
153
157
|
/**## ODPluginClassManager `class`
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { api } from "../index";
|
|
2
|
+
import { Terminal } from "terminal-kit";
|
|
3
|
+
import * as discord from "discord.js";
|
|
4
|
+
export * from "./editConfig";
|
|
5
|
+
/**## ODCliHeaderOpts `interface`
|
|
6
|
+
* All metadata required for rendering the Interactive Setup CLI header.
|
|
7
|
+
*/
|
|
8
|
+
export interface ODCliHeaderOpts {
|
|
9
|
+
/**The main logo to display (multiple lines splitted in string array). */
|
|
10
|
+
logo: string[];
|
|
11
|
+
/**The main color of the project. */
|
|
12
|
+
projectColor: discord.HexColorString;
|
|
13
|
+
/**The version of the project. */
|
|
14
|
+
projectVersion: api.ODVersion;
|
|
15
|
+
/**The name of the project in display style (e.g. `Open Ticket`) */
|
|
16
|
+
projectName: string;
|
|
17
|
+
}
|
|
18
|
+
/**## ODCliStartFunction `type`
|
|
19
|
+
* A function used to start a sub-system of the interactive setup CLI.
|
|
20
|
+
*/
|
|
21
|
+
export type ODCliStartFunction = (backFn: () => api.ODPromiseVoid) => Promise<void>;
|
|
22
|
+
/**A utility function to center text to a certain width. */
|
|
23
|
+
export declare function centerText(text: string, width: number): string;
|
|
24
|
+
/**A utility function to terminate the interactive CLI. */
|
|
25
|
+
export declare function terminate(opts: ODCliHeaderOpts): Promise<void>;
|
|
26
|
+
/**A utility function generate a unique config ID based on a user-named input. */
|
|
27
|
+
export declare function generateUniqueIdFromName(name: string): string;
|
|
28
|
+
/**Render the header of the interactive setup CLI. */
|
|
29
|
+
export declare function renderHeader(opts: ODCliHeaderOpts, path: (string | number)[] | string): void;
|
|
30
|
+
/**Execute/start the Interactive Setup CLI. Make sure no other processes disturb the flow. */
|
|
31
|
+
export declare function execute(opts: ODCliHeaderOpts, renderEditConfig: ODCliStartFunction | null, renderQuickSetup: ODCliStartFunction | null): Promise<void>;
|
|
32
|
+
/**A basic style template for select menu's in the interactive setup CLI. */
|
|
33
|
+
export declare const autoCompleteMenuOpts: Terminal.SingleLineMenuOptions;
|
|
34
|
+
/**A set of preset colors to be used when auto-filling colors in the interactive setup CLI. */
|
|
35
|
+
export declare const presetColors: Map<string, string>;
|
package/dist/cli/cli.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.presetColors = exports.autoCompleteMenuOpts = void 0;
|
|
21
|
+
exports.centerText = centerText;
|
|
22
|
+
exports.terminate = terminate;
|
|
23
|
+
exports.generateUniqueIdFromName = generateUniqueIdFromName;
|
|
24
|
+
exports.renderHeader = renderHeader;
|
|
25
|
+
exports.execute = execute;
|
|
26
|
+
const terminal_kit_1 = require("terminal-kit");
|
|
27
|
+
const ansis_1 = __importDefault(require("ansis"));
|
|
28
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
29
|
+
__exportStar(require("./editConfig"), exports);
|
|
30
|
+
/**A utility function to center text to a certain width. */
|
|
31
|
+
function centerText(text, width) {
|
|
32
|
+
if (width < text.length)
|
|
33
|
+
return text;
|
|
34
|
+
let newWidth = width - ansis_1.default.strip(text).length + 1;
|
|
35
|
+
let final = " ".repeat(newWidth / 2) + text;
|
|
36
|
+
return final;
|
|
37
|
+
}
|
|
38
|
+
/**A utility function to terminate the interactive CLI. */
|
|
39
|
+
async function terminate(opts) {
|
|
40
|
+
terminal_kit_1.terminal.grabInput(false);
|
|
41
|
+
terminal_kit_1.terminal.clear();
|
|
42
|
+
terminal_kit_1.terminal.green("👋 Exited the " + opts.projectName + " Interactive Setup CLI.\n");
|
|
43
|
+
process.exit(0);
|
|
44
|
+
}
|
|
45
|
+
/**A utility function generate a unique config ID based on a user-named input. */
|
|
46
|
+
function generateUniqueIdFromName(name) {
|
|
47
|
+
//id only allows a-z, 0-9 & dash characters (& replace spaces with dashes)
|
|
48
|
+
const filteredChars = name.toLowerCase().replaceAll(" ", "-").split("").filter((ch) => /^[a-zA-Z0-9-]{1}$/.test(ch));
|
|
49
|
+
const randomSuffix = "-" + crypto_1.default.randomBytes(4).toString("hex");
|
|
50
|
+
return filteredChars.join("") + randomSuffix;
|
|
51
|
+
}
|
|
52
|
+
/**Render the header of the interactive setup CLI. */
|
|
53
|
+
function renderHeader(opts, path) {
|
|
54
|
+
terminal_kit_1.terminal.grabInput(true);
|
|
55
|
+
terminal_kit_1.terminal.clear().moveTo(1, 1);
|
|
56
|
+
(0, terminal_kit_1.terminal)(ansis_1.default.hex("#f8ba00")(opts.logo.join("\n") + "\n"));
|
|
57
|
+
terminal_kit_1.terminal.bold(centerText("Interactive Setup CLI - Version: " + opts.projectVersion.toString() + " - Support: https://discord.dj-dj.be\n", 88));
|
|
58
|
+
if (typeof path == "string")
|
|
59
|
+
terminal_kit_1.terminal.cyan(centerText(path + "\n\n", 88));
|
|
60
|
+
else if (path.length < 1)
|
|
61
|
+
terminal_kit_1.terminal.cyan(centerText("👋 Hi! Welcome to the " + opts.projectName + " Interactive Setup CLI! 👋\n\n", 88));
|
|
62
|
+
else
|
|
63
|
+
terminal_kit_1.terminal.cyan(centerText("🌐 Current Location: " + path.map((v, i) => {
|
|
64
|
+
if (i == 0)
|
|
65
|
+
return v.toString();
|
|
66
|
+
else if (typeof v == "string")
|
|
67
|
+
return ".\"" + v + "\"";
|
|
68
|
+
else if (typeof v == "number")
|
|
69
|
+
return "." + v;
|
|
70
|
+
}).join("") + "\n\n", 88));
|
|
71
|
+
}
|
|
72
|
+
/**Render the mode selector for the interactive setup CLI */
|
|
73
|
+
async function renderCliModeSelector(opts, backFn, renderEditConfig, renderQuickSetup) {
|
|
74
|
+
renderHeader(opts, []);
|
|
75
|
+
(0, terminal_kit_1.terminal)(ansis_1.default.bold.green("Please select what CLI module you want to use.\n") + ansis_1.default.italic.gray("(use arrow keys to navigate, exit using escape)\n"));
|
|
76
|
+
const answer = await terminal_kit_1.terminal.singleColumnMenu([
|
|
77
|
+
"✏️ Edit Config " + ansis_1.default.gray("=> Edit the current config, add/remove settings & more!"),
|
|
78
|
+
"⏱️ Quick Setup " + ansis_1.default.gray("=> A quick and easy way of setting up the bot in your Discord server."),
|
|
79
|
+
], {
|
|
80
|
+
leftPadding: "> ",
|
|
81
|
+
style: terminal_kit_1.terminal.cyan,
|
|
82
|
+
selectedStyle: terminal_kit_1.terminal.bgDefaultColor.bold,
|
|
83
|
+
submittedStyle: terminal_kit_1.terminal.bgBlue,
|
|
84
|
+
extraLines: 2,
|
|
85
|
+
cancelable: true
|
|
86
|
+
}).promise;
|
|
87
|
+
if (answer.canceled)
|
|
88
|
+
return await backFn();
|
|
89
|
+
else if (answer.selectedIndex == 0 && renderEditConfig)
|
|
90
|
+
await renderEditConfig(async () => { await renderCliModeSelector(opts, backFn, renderEditConfig, renderQuickSetup); });
|
|
91
|
+
else if (answer.selectedIndex == 1 && renderQuickSetup)
|
|
92
|
+
await renderQuickSetup(async () => { await renderCliModeSelector(opts, backFn, renderEditConfig, renderQuickSetup); });
|
|
93
|
+
else
|
|
94
|
+
return await backFn();
|
|
95
|
+
}
|
|
96
|
+
/**Execute/start the Interactive Setup CLI. Make sure no other processes disturb the flow. */
|
|
97
|
+
async function execute(opts, renderEditConfig, renderQuickSetup) {
|
|
98
|
+
terminal_kit_1.terminal.on("key", (name) => {
|
|
99
|
+
if (name == "CTRL_C")
|
|
100
|
+
terminate(opts);
|
|
101
|
+
});
|
|
102
|
+
if (terminal_kit_1.terminal.width < 100 || terminal_kit_1.terminal.height < 35) {
|
|
103
|
+
(0, terminal_kit_1.terminal)(ansis_1.default.red.bold("\n\nMake sure your console, terminal or CMD window has a " + ansis_1.default.cyan("minimum width & height") + " of " + ansis_1.default.cyan("100x35") + " characters."));
|
|
104
|
+
(0, terminal_kit_1.terminal)(ansis_1.default.red.bold("\nOtherwise the " + opts.projectName + " Interactive Setup CLI will be rendered incorrectly."));
|
|
105
|
+
(0, terminal_kit_1.terminal)(ansis_1.default.red.bold("\nThe current terminal dimensions are: " + ansis_1.default.cyan(terminal_kit_1.terminal.width + "x" + terminal_kit_1.terminal.height) + "."));
|
|
106
|
+
}
|
|
107
|
+
else
|
|
108
|
+
await renderCliModeSelector(opts, async () => { await terminate(opts); }, renderEditConfig, renderQuickSetup);
|
|
109
|
+
}
|
|
110
|
+
/**A basic style template for select menu's in the interactive setup CLI. */
|
|
111
|
+
exports.autoCompleteMenuOpts = {
|
|
112
|
+
style: terminal_kit_1.terminal.white,
|
|
113
|
+
selectedStyle: terminal_kit_1.terminal.bgBlue.white
|
|
114
|
+
};
|
|
115
|
+
/**A set of preset colors to be used when auto-filling colors in the interactive setup CLI. */
|
|
116
|
+
exports.presetColors = new Map([
|
|
117
|
+
["dark red", "#992d22"],
|
|
118
|
+
["red", "#ff0000"],
|
|
119
|
+
["light red", "#f06c6c"],
|
|
120
|
+
["dark orange", "#ed510e"],
|
|
121
|
+
["orange", "#ed6f0e"],
|
|
122
|
+
["light orange", "#f0b06c"],
|
|
123
|
+
["openticket", "#f8ba00"],
|
|
124
|
+
["dark yellow", "#deb100"],
|
|
125
|
+
["yellow", "#ffff00"],
|
|
126
|
+
["light yellow", "#ffff8c"],
|
|
127
|
+
["banana", "#ffe896"],
|
|
128
|
+
["lime", "#a8e312"],
|
|
129
|
+
["dark green", "#009600"],
|
|
130
|
+
["green", "#00ff00"],
|
|
131
|
+
["light green", "#76f266"],
|
|
132
|
+
["dark cyan", "#00abab"],
|
|
133
|
+
["cyan", "#00ffff"],
|
|
134
|
+
["light cyan", "#63ffff"],
|
|
135
|
+
["aquamarine", "#7fffd4"],
|
|
136
|
+
["dark skyblue", "#006bc9"],
|
|
137
|
+
["skyblue", "#0095ff"],
|
|
138
|
+
["light skyblue", "#40bfff"],
|
|
139
|
+
["dark blue", "#00006e"],
|
|
140
|
+
["blue", "#0000ff"],
|
|
141
|
+
["light blue", "#5353fc"],
|
|
142
|
+
["blurple", "#5865F2"],
|
|
143
|
+
["dark purple", "#3f009e"],
|
|
144
|
+
["purple", "#8000ff"],
|
|
145
|
+
["light purple", "#9257eb"],
|
|
146
|
+
["dark pink", "#b82ab0"],
|
|
147
|
+
["pink", "#ff6bf8"],
|
|
148
|
+
["light pink", "#ff9cfa"],
|
|
149
|
+
["magenta", "#ff00ff"],
|
|
150
|
+
["black", "#000000"],
|
|
151
|
+
["brown", "#806050"],
|
|
152
|
+
["dark gray", "#4f4f4f"],
|
|
153
|
+
["gray", "#808080"],
|
|
154
|
+
["light gray", "#b3b3b3"],
|
|
155
|
+
["white", "#ffffff"],
|
|
156
|
+
["invisible", "#393A41"]
|
|
157
|
+
]);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { api } from "../index";
|
|
2
|
+
import { ODCliHeaderOpts } from "./cli";
|
|
3
|
+
export declare class ODCliEditConfigInstance {
|
|
4
|
+
private readonly opts;
|
|
5
|
+
private readonly opendiscord;
|
|
6
|
+
constructor(opts: ODCliHeaderOpts, opendiscord: api.ODMain);
|
|
7
|
+
renderEditConfig(backFn: (() => api.ODPromiseVoid)): Promise<void>;
|
|
8
|
+
private chooseConfigStructure;
|
|
9
|
+
private renderConfigObjectStructureSelector;
|
|
10
|
+
private renderConfigEnabledObjectStructureSelector;
|
|
11
|
+
private renderConfigObjectSwitchStructureSelector;
|
|
12
|
+
private renderConfigArrayStructureSelector;
|
|
13
|
+
private renderConfigArrayStructureEditSelector;
|
|
14
|
+
private renderConfigArrayStructureMoveSelector;
|
|
15
|
+
private renderConfigArrayStructureRemoveSelector;
|
|
16
|
+
private renderConfigArrayStructureDuplicateSelector;
|
|
17
|
+
private renderConfigBooleanStructureEditor;
|
|
18
|
+
private renderConfigNumberStructureEditor;
|
|
19
|
+
private renderConfigStringStructureEditor;
|
|
20
|
+
private renderConfigNullStructureEditor;
|
|
21
|
+
private renderConfigTypeSwitchStructureEditor;
|
|
22
|
+
private getArrayPreviewStructureNameLength;
|
|
23
|
+
private getArrayPreviewFromStructure;
|
|
24
|
+
private chooseAdditionConfigStructure;
|
|
25
|
+
private renderAdditionConfigObjectStructure;
|
|
26
|
+
private configureAdditionObjectProperties;
|
|
27
|
+
private renderAdditionConfigEnabledObjectStructure;
|
|
28
|
+
private renderAdditionConfigObjectSwitchStructure;
|
|
29
|
+
private renderAdditionConfigBooleanStructure;
|
|
30
|
+
private renderAdditionConfigNumberStructure;
|
|
31
|
+
private renderAdditionConfigStringStructure;
|
|
32
|
+
private renderAdditionConfigNullStructure;
|
|
33
|
+
private renderAdditionConfigArrayStructureSelector;
|
|
34
|
+
private renderAdditionConfigTypeSwitchStructure;
|
|
35
|
+
}
|