@open-discord-bots/framework 0.0.1 → 0.0.2
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/LICENSE.md +713 -0
- package/README.md +104 -0
- package/dist/api/api.d.ts +26 -0
- package/dist/api/api.js +44 -0
- package/dist/api/main.d.ts +133 -0
- package/dist/api/main.js +87 -0
- package/dist/api/modules/action.d.ts +34 -0
- package/dist/api/modules/action.js +58 -0
- package/dist/api/modules/base.d.ts +329 -0
- package/dist/api/modules/base.js +804 -0
- package/dist/api/modules/builder.d.ts +647 -0
- package/dist/api/modules/builder.js +1441 -0
- package/dist/api/modules/checker.d.ts +648 -0
- package/dist/api/modules/checker.js +1324 -0
- package/dist/api/modules/client.d.ts +768 -0
- package/dist/api/modules/client.js +1859 -0
- package/dist/api/modules/code.d.ts +33 -0
- package/dist/api/modules/code.js +57 -0
- package/dist/api/modules/config.d.ts +70 -0
- package/dist/api/modules/config.js +206 -0
- package/dist/api/modules/console.d.ts +305 -0
- package/dist/api/modules/console.js +598 -0
- package/dist/api/modules/cooldown.d.ts +138 -0
- package/dist/api/modules/cooldown.js +359 -0
- package/dist/api/modules/database.d.ts +135 -0
- package/dist/api/modules/database.js +271 -0
- package/dist/api/modules/event.d.ts +43 -0
- package/dist/api/modules/event.js +100 -0
- package/dist/api/modules/flag.d.ts +40 -0
- package/dist/api/modules/flag.js +72 -0
- package/dist/api/modules/fuse.d.ts +218 -0
- package/dist/api/modules/fuse.js +123 -0
- package/dist/api/modules/helpmenu.d.ts +106 -0
- package/dist/api/modules/helpmenu.js +167 -0
- package/dist/api/modules/language.d.ts +85 -0
- package/dist/api/modules/language.js +195 -0
- package/dist/api/modules/permission.d.ts +121 -0
- package/dist/api/modules/permission.js +314 -0
- package/dist/api/modules/plugin.d.ts +128 -0
- package/dist/api/modules/plugin.js +168 -0
- package/dist/api/modules/post.d.ts +44 -0
- package/dist/api/modules/post.js +92 -0
- package/dist/api/modules/progressbar.d.ts +108 -0
- package/dist/api/modules/progressbar.js +233 -0
- package/dist/api/modules/responder.d.ts +506 -0
- package/dist/api/modules/responder.js +1468 -0
- package/dist/api/modules/session.d.ts +58 -0
- package/dist/api/modules/session.js +171 -0
- package/dist/api/modules/startscreen.d.ts +165 -0
- package/dist/api/modules/startscreen.js +293 -0
- package/dist/api/modules/stat.d.ts +142 -0
- package/dist/api/modules/stat.js +293 -0
- package/dist/api/modules/verifybar.d.ts +54 -0
- package/dist/api/modules/verifybar.js +60 -0
- package/dist/api/modules/worker.d.ts +41 -0
- package/dist/api/modules/worker.js +93 -0
- package/dist/api/utils.d.ts +61 -0
- package/dist/api/utils.js +254 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +40 -0
- package/dist/startup/dump.d.ts +14 -0
- package/dist/startup/dump.js +79 -0
- package/dist/startup/errorHandling.d.ts +2 -0
- package/dist/startup/errorHandling.js +43 -0
- package/dist/startup/pluginLauncher.d.ts +2 -0
- package/dist/startup/pluginLauncher.js +202 -0
- package/package.json +9 -3
- package/src/api/api.ts +29 -0
- package/src/api/main.ts +189 -0
- package/src/api/modules/action.ts +58 -0
- package/src/api/modules/base.ts +811 -0
- package/src/api/modules/builder.ts +1554 -0
- package/src/api/modules/checker.ts +1549 -0
- package/src/api/modules/client.ts +2247 -0
- package/src/api/modules/code.ts +58 -0
- package/src/api/modules/config.ts +159 -0
- package/src/api/modules/console.ts +665 -0
- package/src/api/modules/cooldown.ts +348 -0
- package/src/api/modules/database.ts +278 -0
- package/src/api/modules/event.ts +99 -0
- package/src/api/modules/flag.ts +73 -0
- package/src/api/modules/fuse.ts +348 -0
- package/src/api/modules/helpmenu.ts +216 -0
- package/src/api/modules/language.ts +201 -0
- package/src/api/modules/permission.ts +340 -0
- package/src/api/modules/plugin.ts +242 -0
- package/src/api/modules/post.ts +90 -0
- package/src/api/modules/progressbar.ts +232 -0
- package/src/api/modules/responder.ts +1420 -0
- package/src/api/modules/session.ts +155 -0
- package/src/api/modules/startscreen.ts +320 -0
- package/src/api/modules/stat.ts +313 -0
- package/src/api/modules/verifybar.ts +61 -0
- package/src/api/modules/worker.ts +93 -0
- package/src/api/utils.ts +206 -0
- package/src/cli/cli.ts +151 -0
- package/src/cli/editConfig.ts +943 -0
- package/src/index.ts +6 -1
- package/src/startup/compilation.ts +186 -0
- package/src/startup/dump.ts +45 -0
- package/src/startup/errorHandling.ts +38 -0
- package/src/startup/pluginLauncher.ts +261 -0
- package/LICENSE +0 -21
package/src/cli/cli.ts
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import {api, utilities} from "../index"
|
|
2
|
+
import {Terminal, terminal} from "terminal-kit"
|
|
3
|
+
import * as discord from "discord.js"
|
|
4
|
+
import ansis from "ansis"
|
|
5
|
+
import crypto from "crypto"
|
|
6
|
+
|
|
7
|
+
export * from "./editConfig"
|
|
8
|
+
|
|
9
|
+
/**## ODCliHeaderOpts `interface`
|
|
10
|
+
* All metadata required for rendering the Interactive Setup CLI header.
|
|
11
|
+
*/
|
|
12
|
+
export interface ODCliHeaderOpts {
|
|
13
|
+
/**The main logo to display (multiple lines splitted in string array). */
|
|
14
|
+
logo:string[],
|
|
15
|
+
/**The main color of the project. */
|
|
16
|
+
projectColor:discord.HexColorString,
|
|
17
|
+
/**The version of the project. */
|
|
18
|
+
projectVersion:api.ODVersion,
|
|
19
|
+
/**The name of the project in display style (e.g. `Open Ticket`) */
|
|
20
|
+
projectName:string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**## ODCliStartFunction `type`
|
|
24
|
+
* A function used to start a sub-system of the interactive setup CLI.
|
|
25
|
+
*/
|
|
26
|
+
export type ODCliStartFunction = (backFn:() => api.ODPromiseVoid) => Promise<void>
|
|
27
|
+
|
|
28
|
+
/**A utility function to center text to a certain width. */
|
|
29
|
+
export function centerText(text:string,width:number){
|
|
30
|
+
if (width < text.length) return text
|
|
31
|
+
let newWidth = width-ansis.strip(text).length+1
|
|
32
|
+
let final = " ".repeat(newWidth/2)+text
|
|
33
|
+
return final
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**A utility function to terminate the interactive CLI. */
|
|
37
|
+
export async function terminate(opts:ODCliHeaderOpts){
|
|
38
|
+
terminal.grabInput(false)
|
|
39
|
+
terminal.clear()
|
|
40
|
+
terminal.green("👋 Exited the "+opts.projectName+" Interactive Setup CLI.\n")
|
|
41
|
+
process.exit(0)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**A utility function generate a unique config ID based on a user-named input. */
|
|
45
|
+
export function generateUniqueIdFromName(name:string){
|
|
46
|
+
//id only allows a-z, 0-9 & dash characters (& replace spaces with dashes)
|
|
47
|
+
const filteredChars = name.toLowerCase().replaceAll(" ","-").split("").filter((ch) => /^[a-zA-Z0-9-]{1}$/.test(ch))
|
|
48
|
+
const randomSuffix = "-"+crypto.randomBytes(4).toString("hex")
|
|
49
|
+
return filteredChars.join("")+randomSuffix
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**Render the header of the interactive setup CLI. */
|
|
53
|
+
export function renderHeader(opts:ODCliHeaderOpts,path:(string|number)[]|string){
|
|
54
|
+
terminal.grabInput(true)
|
|
55
|
+
terminal.clear().moveTo(1,1)
|
|
56
|
+
terminal(ansis.hex("#f8ba00")(opts.logo.join("\n")+"\n"))
|
|
57
|
+
terminal.bold(centerText("Interactive Setup CLI - Version: "+opts.projectVersion.toString()+" - Support: https://discord.dj-dj.be\n",88))
|
|
58
|
+
if (typeof path == "string") terminal.cyan(centerText(path+"\n\n",88))
|
|
59
|
+
else if (path.length < 1) terminal.cyan(centerText("👋 Hi! Welcome to the "+opts.projectName+" Interactive Setup CLI! 👋\n\n",88))
|
|
60
|
+
else terminal.cyan(centerText("🌐 Current Location: "+path.map((v,i) => {
|
|
61
|
+
if (i == 0) return v.toString()
|
|
62
|
+
else if (typeof v == "string") return ".\""+v+"\""
|
|
63
|
+
else if (typeof v == "number") return "."+v
|
|
64
|
+
}).join("")+"\n\n",88))
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**Render the mode selector for the interactive setup CLI */
|
|
68
|
+
async function renderCliModeSelector(opts:ODCliHeaderOpts,backFn:(() => api.ODPromiseVoid),renderEditConfig:ODCliStartFunction|null,renderQuickSetup:ODCliStartFunction|null){
|
|
69
|
+
renderHeader(opts,[])
|
|
70
|
+
terminal(ansis.bold.green("Please select what CLI module you want to use.\n")+ansis.italic.gray("(use arrow keys to navigate, exit using escape)\n"))
|
|
71
|
+
|
|
72
|
+
const answer = await terminal.singleColumnMenu([
|
|
73
|
+
"✏️ Edit Config "+ansis.gray("=> Edit the current config, add/remove settings & more!"),
|
|
74
|
+
"⏱️ Quick Setup "+ansis.gray("=> A quick and easy way of setting up the bot in your Discord server."),
|
|
75
|
+
],{
|
|
76
|
+
leftPadding:"> ",
|
|
77
|
+
style:terminal.cyan,
|
|
78
|
+
selectedStyle:terminal.bgDefaultColor.bold,
|
|
79
|
+
submittedStyle:terminal.bgBlue,
|
|
80
|
+
extraLines:2,
|
|
81
|
+
cancelable:true
|
|
82
|
+
}).promise
|
|
83
|
+
|
|
84
|
+
if (answer.canceled) return await backFn()
|
|
85
|
+
else if (answer.selectedIndex == 0 && renderEditConfig) await renderEditConfig(async () => {await renderCliModeSelector(opts,backFn,renderEditConfig,renderQuickSetup)})
|
|
86
|
+
else if (answer.selectedIndex == 1 && renderQuickSetup) await renderQuickSetup(async () => {await renderCliModeSelector(opts,backFn,renderEditConfig,renderQuickSetup)})
|
|
87
|
+
else return await backFn()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**Execute/start the Interactive Setup CLI. Make sure no other processes disturb the flow. */
|
|
91
|
+
export async function execute(opts:ODCliHeaderOpts,renderEditConfig:ODCliStartFunction|null,renderQuickSetup:ODCliStartFunction|null){
|
|
92
|
+
terminal.on("key",(name:string) => {
|
|
93
|
+
if (name == "CTRL_C") terminate(opts)
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
if (terminal.width < 100 || terminal.height < 35){
|
|
97
|
+
terminal(ansis.red.bold("\n\nMake sure your console, terminal or CMD window has a "+ansis.cyan("minimum width & height")+" of "+ansis.cyan("100x35")+" characters."))
|
|
98
|
+
terminal(ansis.red.bold("\nOtherwise the "+opts.projectName+" Interactive Setup CLI will be rendered incorrectly."))
|
|
99
|
+
terminal(ansis.red.bold("\nThe current terminal dimensions are: "+ansis.cyan(terminal.width+"x"+terminal.height)+"."))
|
|
100
|
+
}else await renderCliModeSelector(opts,async () => {await terminate(opts)},renderEditConfig,renderQuickSetup)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**A basic style template for select menu's in the interactive setup CLI. */
|
|
104
|
+
export const autoCompleteMenuOpts: Terminal.SingleLineMenuOptions = {
|
|
105
|
+
style:terminal.white,
|
|
106
|
+
selectedStyle:terminal.bgBlue.white
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**A set of preset colors to be used when auto-filling colors in the interactive setup CLI. */
|
|
110
|
+
export const presetColors = new Map<string,string>([
|
|
111
|
+
["dark red","#992d22"],
|
|
112
|
+
["red","#ff0000"],
|
|
113
|
+
["light red","#f06c6c"],
|
|
114
|
+
["dark orange","#ed510e"],
|
|
115
|
+
["orange","#ed6f0e"],
|
|
116
|
+
["light orange","#f0b06c"],
|
|
117
|
+
["openticket","#f8ba00"],
|
|
118
|
+
["dark yellow","#deb100"],
|
|
119
|
+
["yellow","#ffff00"],
|
|
120
|
+
["light yellow","#ffff8c"],
|
|
121
|
+
["banana","#ffe896"],
|
|
122
|
+
["lime","#a8e312"],
|
|
123
|
+
["dark green","#009600"],
|
|
124
|
+
["green","#00ff00"],
|
|
125
|
+
["light green","#76f266"],
|
|
126
|
+
["dark cyan","#00abab"],
|
|
127
|
+
["cyan","#00ffff"],
|
|
128
|
+
["light cyan","#63ffff"],
|
|
129
|
+
["aquamarine","#7fffd4"],
|
|
130
|
+
["dark skyblue","#006bc9"],
|
|
131
|
+
["skyblue","#0095ff"],
|
|
132
|
+
["light skyblue","#40bfff"],
|
|
133
|
+
["dark blue","#00006e"],
|
|
134
|
+
["blue","#0000ff"],
|
|
135
|
+
["light blue","#5353fc"],
|
|
136
|
+
["blurple","#5865F2"],
|
|
137
|
+
["dark purple","#3f009e"],
|
|
138
|
+
["purple","#8000ff"],
|
|
139
|
+
["light purple","#9257eb"],
|
|
140
|
+
["dark pink","#b82ab0"],
|
|
141
|
+
["pink","#ff6bf8"],
|
|
142
|
+
["light pink","#ff9cfa"],
|
|
143
|
+
["magenta","#ff00ff"],
|
|
144
|
+
["black","#000000"],
|
|
145
|
+
["brown","#806050"],
|
|
146
|
+
["dark gray","#4f4f4f"],
|
|
147
|
+
["gray","#808080"],
|
|
148
|
+
["light gray","#b3b3b3"],
|
|
149
|
+
["white","#ffffff"],
|
|
150
|
+
["invisible","#393A41"]
|
|
151
|
+
])
|