@nexint/lumina 0.0.0-stage → 0.7.7
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/.env.example +22 -0
- package/.gitattributes +2 -0
- package/LICENSE +85 -0
- package/README.md +298 -2
- package/boot.js +227 -0
- package/config/core/core.js +25 -0
- package/config/core/framework.js +12 -0
- package/config/core/log.js +6 -0
- package/config/cosmetic/config.js +4 -0
- package/console/Restart.js +128 -0
- package/console/about.js +81 -0
- package/console/tests.js +57 -0
- package/databases/README.md +3 -0
- package/functions/README.md +3 -0
- package/functions/core/clearCache.js +34 -0
- package/functions/core/date.js +4 -0
- package/functions/core/delay.js +4 -0
- package/functions/core/dirs.js +12 -0
- package/functions/core/fatalShutdown.mjs +174 -0
- package/functions/core/getConfig.js +32 -0
- package/functions/core/gradient.js +36 -0
- package/functions/core/load.js +229 -0
- package/functions/core/log.mjs +174 -0
- package/functions/core/powerCycle.js +212 -0
- package/functions/core/update.js +78 -0
- package/index.js +65 -0
- package/package.json +28 -4
- package/plugins/README.md +3 -0
- package/preload/core/fileLog.js +124 -0
- package/preload/readline.js +8 -0
- package/start.bat +2 -0
- package/start.sh +3 -0
- package/test/sample/test.js +74 -0
- package/ver.txt +1 -0
- package/verName.txt +1 -0
package/.env.example
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Discord
|
|
2
|
+
DISCORD_TOKEN=
|
|
3
|
+
DISCORD_CLIENT_ID=
|
|
4
|
+
DEV_ID=
|
|
5
|
+
DEV_GUILD_ID=
|
|
6
|
+
|
|
7
|
+
# External APIs
|
|
8
|
+
TENOR_API_KEY=
|
|
9
|
+
KLIPY_API_KEY=
|
|
10
|
+
SEKAI_TOKEN=
|
|
11
|
+
|
|
12
|
+
# Legacy AutoMod
|
|
13
|
+
AUTOMOD_API_TOKEN=
|
|
14
|
+
|
|
15
|
+
# Web server
|
|
16
|
+
SERVER_URL=
|
|
17
|
+
SERVER_TOKEN=
|
|
18
|
+
SERVER_HEADER=
|
|
19
|
+
|
|
20
|
+
# Misc
|
|
21
|
+
INVITE_CHANNEL_ID=
|
|
22
|
+
REDIS_TOKEN=
|
package/.gitattributes
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Nexint Labs Proprietary Software License
|
|
2
|
+
Version 1.0
|
|
3
|
+
|
|
4
|
+
Copyright © 2026 Nexint. All rights reserved.
|
|
5
|
+
|
|
6
|
+
## 1. Scope and Ownership
|
|
7
|
+
|
|
8
|
+
This license applies to the original source code, object code, documentation, configuration files, and other copyrightable materials accompanying this license, collectively referred to as the "Software," to the extent that the applicable rights are owned or controlled by Nexint (the "Copyright Holder").
|
|
9
|
+
|
|
10
|
+
The Software is proprietary and is not released under an open-source license.
|
|
11
|
+
|
|
12
|
+
All intellectual property rights in the Software remain with their respective owners.
|
|
13
|
+
|
|
14
|
+
## 2. Reservation of Rights
|
|
15
|
+
|
|
16
|
+
Except as expressly authorized by the Copyright Holder, permitted under Section 3, or otherwise permitted by applicable law, no license or permission is granted to:
|
|
17
|
+
|
|
18
|
+
- Download, install, execute, or otherwise use the Software.
|
|
19
|
+
- Copy, reproduce, modify, adapt, translate, or create derivative works of the Software.
|
|
20
|
+
- Distribute, publish, sublicense, sell, rent, or otherwise make copies of the Software available to third parties.
|
|
21
|
+
- Deploy, self-host, or operate instances of the Software.
|
|
22
|
+
- Incorporate protected portions of the Software into other software, products, or services.
|
|
23
|
+
- Commercially or non-commercially exploit the Software in a manner requiring authorization from the Copyright Holder.
|
|
24
|
+
|
|
25
|
+
These restrictions apply to the Software in whole or in part, including modified versions, to the extent protected by applicable law.
|
|
26
|
+
|
|
27
|
+
## 3. Permitted Activities
|
|
28
|
+
|
|
29
|
+
Where the Software is made publicly accessible, individuals may:
|
|
30
|
+
|
|
31
|
+
- View, read, and study the publicly accessible source code and documentation.
|
|
32
|
+
- Exercise viewing, forking, and other rights granted under the applicable hosting platform's terms of service.
|
|
33
|
+
- Access and interact with authorized hosted instances of the Software through their intended user-facing interfaces, subject to any applicable service terms and access requirements.
|
|
34
|
+
|
|
35
|
+
Public availability of the Software does not independently grant permission to execute, deploy, modify, or redistribute it beyond the permissions expressly identified in this license.
|
|
36
|
+
|
|
37
|
+
Nothing in this license restricts activities independently permitted by applicable law, including applicable copyright exceptions.
|
|
38
|
+
|
|
39
|
+
## 4. Additional Authorization
|
|
40
|
+
|
|
41
|
+
The Copyright Holder may grant additional permissions through a separate written authorization or licensing agreement.
|
|
42
|
+
|
|
43
|
+
Such authorization applies only to the persons, entities, purposes, and materials specified therein.
|
|
44
|
+
|
|
45
|
+
An authorization granted to one party does not constitute authorization to any other party.
|
|
46
|
+
|
|
47
|
+
## 5. Third-Party Materials
|
|
48
|
+
|
|
49
|
+
The Software may incorporate, depend upon, or be distributed alongside third-party software and other materials.
|
|
50
|
+
|
|
51
|
+
Those materials remain subject to their respective licenses and copyright notices.
|
|
52
|
+
|
|
53
|
+
Nothing in this license supersedes, restricts, or revokes rights independently granted under applicable third-party licenses.
|
|
54
|
+
|
|
55
|
+
Where a third-party license governs particular materials, that license continues to govern those materials.
|
|
56
|
+
|
|
57
|
+
## 6. Previous Releases
|
|
58
|
+
|
|
59
|
+
This license applies to the version of the Software with which it is provided.
|
|
60
|
+
|
|
61
|
+
Nothing in this license retroactively revokes or restricts rights validly granted under previous licenses.
|
|
62
|
+
|
|
63
|
+
Previously licensed materials remain subject to their applicable licensing terms.
|
|
64
|
+
|
|
65
|
+
## 7. Disclaimer of Warranty
|
|
66
|
+
|
|
67
|
+
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE SOFTWARE IS PROVIDED "AS IS" AND "AS AVAILABLE," WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS, IMPLIED, OR STATUTORY, INCLUDING BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND NON-INFRINGEMENT.
|
|
68
|
+
|
|
69
|
+
THE COPYRIGHT HOLDER MAKES NO WARRANTY REGARDING THE ACCURACY, SECURITY, RELIABILITY, AVAILABILITY, OR CONTINUED MAINTENANCE OF THE SOFTWARE.
|
|
70
|
+
|
|
71
|
+
## 8. Limitation of Liability
|
|
72
|
+
|
|
73
|
+
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE COPYRIGHT HOLDER SHALL NOT BE LIABLE FOR ANY CLAIM, DAMAGES, LOSSES, OR OTHER LIABILITY ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE, ITS AVAILABILITY, OR ITS USE, WHETHER ARISING IN CONTRACT, TORT, OR OTHERWISE.
|
|
74
|
+
|
|
75
|
+
NOTHING IN THIS LICENSE EXCLUDES OR LIMITS LIABILITY OR LEGAL RIGHTS THAT CANNOT LAWFULLY BE EXCLUDED OR LIMITED.
|
|
76
|
+
|
|
77
|
+
## 9. Severability
|
|
78
|
+
|
|
79
|
+
If any provision of this license is held to be invalid or unenforceable, the remaining provisions shall continue to apply to the extent permitted by applicable law.
|
|
80
|
+
|
|
81
|
+
## 10. No Implied License
|
|
82
|
+
|
|
83
|
+
Except as expressly provided herein or otherwise established by applicable law, no license or other intellectual property right is granted by implication, estoppel, public disclosure, or otherwise.
|
|
84
|
+
|
|
85
|
+
All rights not expressly granted are reserved.
|
package/README.md
CHANGED
|
@@ -1,3 +1,299 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Lumina
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Lightweight Node.js Framework
|
|
4
|
+
|
|
5
|
+
## What is Lumina?
|
|
6
|
+
|
|
7
|
+
Lumina is a source-available Node.js framework for developing, hosting and managing modular applications.
|
|
8
|
+
|
|
9
|
+
We offer several ways for developers to integrate their applications into Lumina without having to implement their own application lifecycle, module loader, logging system or console interface.
|
|
10
|
+
|
|
11
|
+
Lumina is designed to be flexible and is not restricted to any particular application type or external library. Developers can use Lumina to host REST APIs, Discord bots, WebSocket clients and servers, background services, or other Node.js applications.
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- Modular application architecture.
|
|
16
|
+
- Automatic and recursive module discovery.
|
|
17
|
+
- Application lifecycle management.
|
|
18
|
+
- Graceful shutdown, restarting and reloading.
|
|
19
|
+
- Configurable error handling policies.
|
|
20
|
+
- Integrated logging utilities.
|
|
21
|
+
- Extensible console commands.
|
|
22
|
+
- Environment variable and configuration management.
|
|
23
|
+
- Support for CommonJS and compatible ECMAScript modules.
|
|
24
|
+
|
|
25
|
+
## Deployments
|
|
26
|
+
|
|
27
|
+
Lumina is currently deployed on multiple Discord bots!
|
|
28
|
+
|
|
29
|
+
- Miku#0100 (Discord Bot)
|
|
30
|
+
- Teto#4311 (Discord Bot)
|
|
31
|
+
- Neru#7016 (Discord Bot)
|
|
32
|
+
- NexAPI Manager#4213 (API Management)
|
|
33
|
+
- Prism#8911 (Development Bot)
|
|
34
|
+
|
|
35
|
+
Additionally, Lumina powers both the production and development environments of the Nexint API.
|
|
36
|
+
|
|
37
|
+
- api.nexint.org (Production API)
|
|
38
|
+
- dev.nexint.org (Development version of Nexint API)
|
|
39
|
+
|
|
40
|
+
Finally, Lumina also powers the Nexint Sonolus Server, used by thousands of people!
|
|
41
|
+
|
|
42
|
+
- sono.nexint.ca (Sonolus Server)
|
|
43
|
+
|
|
44
|
+
## Disclosures
|
|
45
|
+
|
|
46
|
+
The vast majority of code in this project is my own, however AI assisted with pen-testing this program.
|
|
47
|
+
|
|
48
|
+
This readme was primarily generated with AI.
|
|
49
|
+
|
|
50
|
+
Node.js 24 or later is recommended. Earlier versions may work but have not been tested.
|
|
51
|
+
|
|
52
|
+
### Security
|
|
53
|
+
|
|
54
|
+
Lumina executes discovered modules within the host Node.js process. Applications, plugins, preloads and console commands are not sandboxed.
|
|
55
|
+
|
|
56
|
+
Only install and execute modules from trusted sources. Developers are responsible for securing their applications, dependencies, credentials and deployment environments.
|
|
57
|
+
|
|
58
|
+
## Getting Started
|
|
59
|
+
|
|
60
|
+
Install the required dependencies:
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
npm install
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Create and configure your `.env` file, and review the framework configuration under `config/core/`.
|
|
67
|
+
|
|
68
|
+
To start Lumina:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
npm start
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Integrating with Lumina
|
|
75
|
+
|
|
76
|
+
Lumina offers four primary integration mechanisms: applications, plugins, preloads and console commands.
|
|
77
|
+
|
|
78
|
+
### 1. Applications
|
|
79
|
+
|
|
80
|
+
The `apps/` directory contains applications managed by Lumina.
|
|
81
|
+
|
|
82
|
+
Applications can expose lifecycle methods that Lumina invokes during startup, reloading and shutdown.
|
|
83
|
+
|
|
84
|
+
Create a file under `apps/`, such as `apps/example.js`:
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
const { log } = require("#functions/core/log.mjs");
|
|
88
|
+
|
|
89
|
+
module.exports = {
|
|
90
|
+
async execute() {
|
|
91
|
+
log.info("Application started.");
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
async reload() {
|
|
95
|
+
log.info("Application reloaded.");
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
async close() {
|
|
99
|
+
log.info("Application closed.");
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The following lifecycle methods are supported:
|
|
105
|
+
|
|
106
|
+
| Method | Description |
|
|
107
|
+
|---|---|
|
|
108
|
+
| `execute()` | Initializes the application. |
|
|
109
|
+
| `reload()` | Executes application-specific reload logic. |
|
|
110
|
+
| `close()` | Releases resources and shuts down the application. |
|
|
111
|
+
|
|
112
|
+
Developers are responsible for implementing the behaviour of each lifecycle method. For example, a web server should stop accepting connections and close its server instance when `close()` is called.
|
|
113
|
+
|
|
114
|
+
Lumina awaits asynchronous lifecycle methods before proceeding with the corresponding lifecycle operation.
|
|
115
|
+
|
|
116
|
+
### 2. Plugins
|
|
117
|
+
|
|
118
|
+
The `plugins/` directory allows developers to extend Lumina with additional functionality.
|
|
119
|
+
|
|
120
|
+
Plugins can be used to initialize services, register handlers, prepare application logic or perform other startup operations.
|
|
121
|
+
|
|
122
|
+
Create a file under `plugins/`:
|
|
123
|
+
|
|
124
|
+
```js
|
|
125
|
+
const { log } = require("#functions/core/log.mjs");
|
|
126
|
+
|
|
127
|
+
module.exports = {
|
|
128
|
+
async execute() {
|
|
129
|
+
log.info("Plugin successfully loaded.");
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Plugins are loaded recursively, allowing developers to organize their plugins into separate categories and subdirectories.
|
|
135
|
+
|
|
136
|
+
Plugins are loaded before applications.
|
|
137
|
+
|
|
138
|
+
### 3. Preloads
|
|
139
|
+
|
|
140
|
+
The `preload/` directory contains modules that must be initialized before plugins and applications.
|
|
141
|
+
|
|
142
|
+
Preloads are particularly useful for:
|
|
143
|
+
|
|
144
|
+
- Initializing database connections.
|
|
145
|
+
- Preparing shared resources.
|
|
146
|
+
- Validating configuration.
|
|
147
|
+
- Initializing shared services.
|
|
148
|
+
- Performing startup checks.
|
|
149
|
+
|
|
150
|
+
Create a file under `preload/`:
|
|
151
|
+
|
|
152
|
+
```js
|
|
153
|
+
module.exports = {
|
|
154
|
+
async execute() {
|
|
155
|
+
// Initialize shared resources here.
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
Lumina initializes preloads before proceeding to plugins and applications.
|
|
161
|
+
|
|
162
|
+
### 4. Console Commands
|
|
163
|
+
|
|
164
|
+
Developers can extend Lumina's console interface by creating modules under `console/`.
|
|
165
|
+
|
|
166
|
+
Each console command exposes a `command()` method that receives the input entered into the console.
|
|
167
|
+
|
|
168
|
+
```js
|
|
169
|
+
const { log } = require("#functions/core/log.mjs");
|
|
170
|
+
|
|
171
|
+
module.exports = {
|
|
172
|
+
async command(input) {
|
|
173
|
+
if (input !== "hello") return false;
|
|
174
|
+
|
|
175
|
+
log.info("Hello from Lumina!");
|
|
176
|
+
return true;
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
async help() {
|
|
180
|
+
return ["hello - Displays a greeting."];
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
The `command()` method should return `true` if the command was handled, or `false` if the input does not match the command.
|
|
186
|
+
|
|
187
|
+
The optional `help()` method provides information about the available command.
|
|
188
|
+
|
|
189
|
+
## Directory Structure
|
|
190
|
+
|
|
191
|
+
Lumina separates application logic from framework functionality.
|
|
192
|
+
|
|
193
|
+
```text
|
|
194
|
+
Lumina/
|
|
195
|
+
├── apps/
|
|
196
|
+
├── appHelpers/
|
|
197
|
+
├── config/
|
|
198
|
+
│ └── core/
|
|
199
|
+
├── console/
|
|
200
|
+
├── databases/
|
|
201
|
+
├── functions/
|
|
202
|
+
│ └── core/
|
|
203
|
+
├── logs/
|
|
204
|
+
├── plugins/
|
|
205
|
+
├── preload/
|
|
206
|
+
├── test/
|
|
207
|
+
├── .env
|
|
208
|
+
├── boot.js
|
|
209
|
+
├── index.js
|
|
210
|
+
└── package.json
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
| Directory | Purpose |
|
|
214
|
+
|---|---|
|
|
215
|
+
| `apps/` | Managed applications and services. |
|
|
216
|
+
| `appHelpers/` | Application-specific helper modules. |
|
|
217
|
+
| `config/` | Framework and application configuration. |
|
|
218
|
+
| `console/` | Custom console commands. |
|
|
219
|
+
| `databases/` | Database-related files. |
|
|
220
|
+
| `functions/` | Shared functions and utilities. |
|
|
221
|
+
| `logs/` | Application and framework logs. |
|
|
222
|
+
| `plugins/` | Extensible application functionality. |
|
|
223
|
+
| `preload/` | Early initialization modules. |
|
|
224
|
+
| `test/` | Automated tests. |
|
|
225
|
+
|
|
226
|
+
## Initialization Order
|
|
227
|
+
|
|
228
|
+
Lumina initializes its components in the following order:
|
|
229
|
+
|
|
230
|
+
1. Framework bootstrap and configuration.
|
|
231
|
+
2. Environment and directory preparation.
|
|
232
|
+
3. Preload initialization.
|
|
233
|
+
4. Plugin initialization.
|
|
234
|
+
5. Application initialization.
|
|
235
|
+
6. Console interface and periodic update checking, when enabled.
|
|
236
|
+
|
|
237
|
+
Modules within the same directory should not assume a particular loading order. Explicit dependencies should be imported directly where necessary.
|
|
238
|
+
|
|
239
|
+
## Module Discovery
|
|
240
|
+
|
|
241
|
+
Lumina recursively discovers JavaScript modules with the following extensions:
|
|
242
|
+
|
|
243
|
+
- `.js`
|
|
244
|
+
- `.cjs`
|
|
245
|
+
- `.mjs`
|
|
246
|
+
|
|
247
|
+
CommonJS modules can expose their integration methods through `module.exports`.
|
|
248
|
+
|
|
249
|
+
ECMAScript modules may also be used, provided they are compatible with the Node.js runtime's synchronous `require()` support.
|
|
250
|
+
|
|
251
|
+
Modules intended for automatic startup must expose an `execute()` method and must not expose a `data` property.
|
|
252
|
+
|
|
253
|
+
## Import Aliases
|
|
254
|
+
|
|
255
|
+
Lumina provides import aliases to simplify accessing shared resources without long relative paths.
|
|
256
|
+
|
|
257
|
+
```js
|
|
258
|
+
const { log } = require("#functions/core/log.mjs");
|
|
259
|
+
const config = require("#config/core/core");
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
Available aliases include:
|
|
263
|
+
|
|
264
|
+
| Alias | Directory |
|
|
265
|
+
|---|---|
|
|
266
|
+
| `#config/*` | `config/` |
|
|
267
|
+
| `#functions/*` | `functions/` |
|
|
268
|
+
| `#preload/*` | `preload/` |
|
|
269
|
+
| `#console/*` | `console/` |
|
|
270
|
+
| `#apps/*` | `apps/` |
|
|
271
|
+
| `#appHelpers/*` | `appHelpers/` |
|
|
272
|
+
|
|
273
|
+
## Error Handling
|
|
274
|
+
|
|
275
|
+
Lumina provides configurable error handling policies through its core configuration.
|
|
276
|
+
|
|
277
|
+
| Policy | Behaviour |
|
|
278
|
+
|---|---|
|
|
279
|
+
| `warn` | Logs the error and attempts to continue. |
|
|
280
|
+
| `continue` | Suppresses the affected framework error and attempts to continue. |
|
|
281
|
+
| `shutdown` | Initiates framework shutdown for errors where this policy applies. |
|
|
282
|
+
|
|
283
|
+
Developers should still implement appropriate application-specific error handling.
|
|
284
|
+
|
|
285
|
+
## Extending Lumina
|
|
286
|
+
|
|
287
|
+
Lumina is designed to serve as the foundation of an application rather than dictate how an application must be built.
|
|
288
|
+
|
|
289
|
+
Developers are free to integrate external libraries such as Express, Discord.js, Sequelize and WebSocket libraries into their applications.
|
|
290
|
+
|
|
291
|
+
Lumina manages initialization and lifecycle coordination, while developers retain control over their application logic, dependencies and architecture.
|
|
292
|
+
|
|
293
|
+
Multiple applications can operate within the same Lumina instance, allowing developers to share configuration, utilities and services across their projects.
|
|
294
|
+
|
|
295
|
+
## Licensing
|
|
296
|
+
|
|
297
|
+
Lumina is source-available software developed by Nexint Labs.
|
|
298
|
+
|
|
299
|
+
Usage, modification and distribution are subject to the terms provided in the accompanying `LICENSE` file.
|
package/boot.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// Configure root directories
|
|
2
|
+
const { root, frameworkDir, standalone } = require("#functions/core/dirs")
|
|
3
|
+
|
|
4
|
+
// Import the .env lol
|
|
5
|
+
const { loadEnvFile } = require("node:process");
|
|
6
|
+
const { parseEnv } = require("node:util");
|
|
7
|
+
const fs = require('node:fs');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
|
|
10
|
+
let envCount;
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
loadEnvFile(path.join(root, ".env"));
|
|
14
|
+
envCount = Object.keys(
|
|
15
|
+
parseEnv(fs.readFileSync(path.join(root, ".env"), "utf8"))
|
|
16
|
+
).length;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
if (error.code !== "ENOENT") throw error;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Load configs (that actually matter)
|
|
22
|
+
const { getConfig } = require("#functions/core/getConfig");
|
|
23
|
+
const { logFormat } = getConfig("core/log");
|
|
24
|
+
|
|
25
|
+
if (!process.env.PRISM_LOG_FORMAT) {
|
|
26
|
+
process.env.PRISM_LOG_FORMAT = logFormat
|
|
27
|
+
}
|
|
28
|
+
const { log } = require('#functions/core/log.mjs');
|
|
29
|
+
|
|
30
|
+
log.event(`Loading configs...`)
|
|
31
|
+
const { autoUpdate, errorPolicy } = getConfig("core/core");
|
|
32
|
+
const { frameVer, frameName } = require('#config/core/framework');
|
|
33
|
+
const { load, loadConsole } = require('#functions/core/load');
|
|
34
|
+
const delay = require("#functions/core/delay");
|
|
35
|
+
|
|
36
|
+
// Other cool stuff :)
|
|
37
|
+
const { date } = require('#functions/core/date');
|
|
38
|
+
const { updateCheck } = require('#functions/core/update');
|
|
39
|
+
const { gracefulShutdown } = require('#functions/core/powerCycle');
|
|
40
|
+
|
|
41
|
+
// Prepare the console
|
|
42
|
+
const readline = require('node:readline');
|
|
43
|
+
const { gradient } = require("#functions/core/gradient");
|
|
44
|
+
const rl = readline.createInterface({
|
|
45
|
+
input: process.stdin,
|
|
46
|
+
output: process.stdout
|
|
47
|
+
});
|
|
48
|
+
const prompt = (query) => new Promise((resolve) => rl.question(query, resolve));
|
|
49
|
+
|
|
50
|
+
// Start loading
|
|
51
|
+
const startLoad = Date.now();
|
|
52
|
+
const start = performance.now();
|
|
53
|
+
|
|
54
|
+
// Is the console open?
|
|
55
|
+
let consoleOpen = true;
|
|
56
|
+
|
|
57
|
+
// Export some weird stuff idk
|
|
58
|
+
module.exports = {
|
|
59
|
+
consoleOpen,
|
|
60
|
+
startLoad,
|
|
61
|
+
readline: rl,
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Process.on random unhandled stuff
|
|
65
|
+
process.on('uncaughtException', async (error, origin) => {
|
|
66
|
+
try {
|
|
67
|
+
if (errorPolicy.uncaughtException === "warn") {
|
|
68
|
+
log.error("An uncaught exception has happened", error)
|
|
69
|
+
log.error(origin)
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (errorPolicy.uncaughtException !== "continue") {
|
|
73
|
+
log.error(origin)
|
|
74
|
+
await log.fatal("An uncaught exception has happened.", error, 0x0000, true);
|
|
75
|
+
process.exit(1); // this shouldnt run but i have it
|
|
76
|
+
}
|
|
77
|
+
} catch {
|
|
78
|
+
process.exit(2); // this shouldnt run but i have it
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
process.on("unhandledRejection", async (error, origin) => {
|
|
82
|
+
try {
|
|
83
|
+
if (errorPolicy.unhandledRejection === "warn") {
|
|
84
|
+
log.error("An uncaught promised rejection has happened", error)
|
|
85
|
+
log.error(origin)
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (errorPolicy.unhandledRejection !== "continue") {
|
|
89
|
+
log.error(origin)
|
|
90
|
+
await log.fatal("An uncaught promised rejection has happened.", error, 0x0000, true);
|
|
91
|
+
process.exit(1); // this shouldnt run but i have it
|
|
92
|
+
}
|
|
93
|
+
} catch {
|
|
94
|
+
process.exit(2); // this shouldnt run but i have it
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
const init = async function () {
|
|
99
|
+
|
|
100
|
+
log.event("Loading directories...")
|
|
101
|
+
if (envCount === undefined) {
|
|
102
|
+
log.warn("No .env file exists. You should probably make one! (Non-Fatal)");
|
|
103
|
+
} else {
|
|
104
|
+
log.event(`${envCount} envs loaded!`)
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// Make sure directories exist lol
|
|
108
|
+
const dirs = ["plugins", "preload", "console", "databases", "apps", "functions", "test", "config"];
|
|
109
|
+
dirs.forEach((dir) => {
|
|
110
|
+
const dirPath = path.join(root, dir);
|
|
111
|
+
|
|
112
|
+
if (!fs.existsSync(dirPath)) {
|
|
113
|
+
log.event(`Creating directory: ${dir}`);
|
|
114
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Windows specific patch im ticked off bro
|
|
119
|
+
// Screw you microsoft :sob:
|
|
120
|
+
if (process.platform === "win32") {
|
|
121
|
+
rl.on("SIGINT", function () {
|
|
122
|
+
process.emit("SIGINT");
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Sigint / Sigterm (real)
|
|
127
|
+
process.on('SIGINT', async () => {
|
|
128
|
+
await gracefulShutdown("Ctrl-C", true)
|
|
129
|
+
})
|
|
130
|
+
process.on('SIGTERM', async () => {
|
|
131
|
+
await gracefulShutdown("OS Termination", true)
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
main().catch(async error => {
|
|
135
|
+
await log.fatal(`${frameName} failed to initialize external files.`, error, 0x0001, true);
|
|
136
|
+
process.exit(1)
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Main function
|
|
142
|
+
* This is the main function that runs the entire backend.
|
|
143
|
+
* what am i doing bro :sob:
|
|
144
|
+
*/
|
|
145
|
+
const main = async () => {
|
|
146
|
+
|
|
147
|
+
log.event("Loading files...")
|
|
148
|
+
|
|
149
|
+
// Load framework preloads + plugins
|
|
150
|
+
await load("preload", frameworkDir);
|
|
151
|
+
await load("plugins", frameworkDir);
|
|
152
|
+
|
|
153
|
+
// Load application preloads + plugins
|
|
154
|
+
if (!standalone) {
|
|
155
|
+
await load("preload", root);
|
|
156
|
+
await load("plugins", root);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Load the apps (FINALLY?)
|
|
160
|
+
// This makes my API super modular :)
|
|
161
|
+
await load("apps", root);
|
|
162
|
+
|
|
163
|
+
log.info(`\x1b[36m--------------------- Nex ${date.getFullYear()} ---------------------\x1b[0m`)
|
|
164
|
+
log.info(` ${gradient(`Welcome to ${frameName}!`, "#FF66CC", "#66CCFF")} `);
|
|
165
|
+
log.info(` You're running version: ${frameVer} `);
|
|
166
|
+
log.info(" Stay up to date for the best features. ");
|
|
167
|
+
log.info('\x1b[36m----------------------------------------------------\x1b[0m');
|
|
168
|
+
const elapsed = performance.now() - start;
|
|
169
|
+
|
|
170
|
+
if (elapsed < 1000) {
|
|
171
|
+
log.success(`Done in ${elapsed.toFixed(3)}ms!`);
|
|
172
|
+
} else {
|
|
173
|
+
log.success(`Done in ${(elapsed / 1000).toFixed(3)} seconds!`);
|
|
174
|
+
}
|
|
175
|
+
console.log("Server is running.")
|
|
176
|
+
|
|
177
|
+
await updateCheck(true)
|
|
178
|
+
|
|
179
|
+
// real?
|
|
180
|
+
await asyncFunctions();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
init().catch(async error => {
|
|
184
|
+
await log.fatal(`${frameName} failed to start initializing.`, error, 0x0000, true);
|
|
185
|
+
process.exit(1)
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Async Functions
|
|
190
|
+
* These functions are deliberately async'd
|
|
191
|
+
*/
|
|
192
|
+
const asyncFunctions = async function () {
|
|
193
|
+
commandParser();
|
|
194
|
+
if (autoUpdate) {
|
|
195
|
+
autoUpdateCheck();
|
|
196
|
+
} else {
|
|
197
|
+
log.info("Automatic update checking disabled.")
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Command Parser
|
|
203
|
+
* Parses commands
|
|
204
|
+
*/
|
|
205
|
+
const commandParser = async () => {
|
|
206
|
+
while (consoleOpen) {
|
|
207
|
+
const command = await prompt('> ');
|
|
208
|
+
|
|
209
|
+
// why am i doing this
|
|
210
|
+
if (!(await loadConsole("console", command, frameworkDir))) {
|
|
211
|
+
if (standalone || !(await loadConsole("console", command, root))) {
|
|
212
|
+
log.info("This command is not valid.")
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Update Checker
|
|
220
|
+
* Checks updates lol
|
|
221
|
+
*/
|
|
222
|
+
const autoUpdateCheck = async () => {
|
|
223
|
+
while (consoleOpen) {
|
|
224
|
+
await delay(3600000); // artificial delay to ensure host's CPU doesn't die
|
|
225
|
+
updateCheck(false);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
devMode: false, // Determines dev mode?
|
|
3
|
+
devMsg: "This bot is running in dev mode. Developer functions are enabled.",
|
|
4
|
+
devName: "Nexint",
|
|
5
|
+
dateOptions: {
|
|
6
|
+
hour: "numeric",
|
|
7
|
+
minute: "numeric",
|
|
8
|
+
second: "numeric",
|
|
9
|
+
},
|
|
10
|
+
verbose: false, // Extra Logging Info
|
|
11
|
+
autoUpdate: true,
|
|
12
|
+
|
|
13
|
+
restart: "start start.bat", // Restart command. This would be different on a linux based system. It would be "sh start.sh".
|
|
14
|
+
// args: ['--', 'bash', '-c', "./start.sh"],
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
It's in your best interest to not change this unless you know what you're doing.
|
|
18
|
+
Please don't change this :sob:
|
|
19
|
+
Types: warn, shutdown, continue
|
|
20
|
+
*/
|
|
21
|
+
errorPolicy: {
|
|
22
|
+
uncaughtException: "shutdown",
|
|
23
|
+
unhandledRejection: "warn",
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Framework level code lol
|
|
3
|
+
*/
|
|
4
|
+
const { version } = require("../../package.json");
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
frameName: "Lumina ☆", // Framework Name
|
|
8
|
+
frameVer: `${version}-dev`, // Version of the bot
|
|
9
|
+
frameID: 24, // Framework version ID
|
|
10
|
+
updateURL: "https://github.com/Nexint-Labs/Lumina/",
|
|
11
|
+
updateSource: "https://raw.githubusercontent.com/Nexint-Labs/Lumina/refs/heads/main", // prolly dont change this unless you know what ur doing
|
|
12
|
+
}
|