Skip to content

Commit 7b4fec7

Browse files
committed
Update file loading to try and prevent some issues
1 parent 3e5c521 commit 7b4fec7

File tree

12 files changed

+20
-69
lines changed

12 files changed

+20
-69
lines changed

build/example.d.ts

-1
This file was deleted.

build/example.js

-50
This file was deleted.

build/example/main.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ class ExampleModule {
4141
},
4242
},
4343
];
44-
load(bot) {
44+
async load(bot) {
4545
main_1.Logger.info("Hello wold, example module has been loaded");
4646
this.commands.push(new TestCommand_1.default(bot));
4747
}
48-
unload() {
48+
async unload() {
4949
main_1.Logger.info("Example module has been unloaded");
5050
}
5151
}

build/libs/Config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class Config {
5252
}
5353
if ((0, fs_1.existsSync)(this.getPath())) {
5454
try {
55-
this.data = require(this.getPath());
55+
const fileData = (0, fs_1.readFileSync)(this.getPath(), "utf8");
56+
this.data = JSON.parse(fileData);
5657
}
5758
catch (error) {
5859
logger_1.Logger.warn(`Failed to load file ${this.name}.json. ${error}`);

build/libs/ModuleManager/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ class ModuleManager {
516516
try {
517517
if (module.unload) {
518518
logger_1.Logger.debug(`Unloading module ${module.name} from ${id}`);
519-
module.unload(this.client);
519+
await module.unload(this.client);
520520
}
521521
}
522522
catch (err) {

build/libs/ModuleManager/types/Module.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ export default abstract class ModuleBase {
4747
* Loads the module's resources into the main system
4848
* @param bot The discord bot client
4949
*/
50-
abstract load?: (client: BotClient) => Promise<void> | void;
50+
abstract load?: (client: BotClient) => Promise<void>;
5151
/**
5252
* UnLoads the module's resources into the main system
5353
* @param bot The discord bot client
5454
*/
55-
unload?: (client: BotClient) => Promise<void> | void;
55+
unload?: (client: BotClient) => Promise<void>;
5656
}
5757
export interface BotCommand {
5858
cmd_data: ApplicationCommandData | RESTPostAPIApplicationCommandsJSONBody;

package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "skelton-bot",
3-
"version": "1.5.0",
3+
"version": "1.5.1",
44
"description": "A simple bot library with advanced capabilities",
55
"main": "./build/main.js",
66
"types": "./build/main.d.ts",

src/example/main.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ class ExampleModule implements ModuleBase {
4545
},
4646
]
4747

48-
load(bot: Client): void {
48+
async load(bot: Client) {
4949
Logger.info("Hello wold, example module has been loaded")
5050
this.commands.push(new TestCommand(bot))
5151
}
5252

53-
unload(): void {
53+
async unload() {
5454
Logger.info("Example module has been unloaded")
5555
}
5656

src/libs/Config.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { existsSync, mkdirSync, writeFile } from "fs"
1+
import { existsSync, mkdirSync, readFileSync, writeFile } from "fs"
22
import { join } from "path"
33
import { Logger } from "./logger"
44

@@ -56,7 +56,8 @@ export default class Config<T> {
5656

5757
if (existsSync(this.getPath())) {
5858
try {
59-
this.data = require(this.getPath())
59+
const fileData = readFileSync(this.getPath(), "utf8")
60+
this.data = JSON.parse(fileData)
6061
} catch (error) {
6162
Logger.warn(`Failed to load file ${this.name}.json. ${error}`)
6263
this.data = this.default

src/libs/ModuleManager/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ export default class ModuleManager {
587587
try {
588588
if (module.unload) {
589589
Logger.debug(`Unloading module ${module.name} from ${id}`)
590-
module.unload(this.client)
590+
await module.unload(this.client)
591591
}
592592
} catch (err) {
593593
Logger.severe(`Failed run module unload ${id}: ${err}`)

src/libs/ModuleManager/types/Module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ export default abstract class ModuleBase {
6262
* @param bot The discord bot client
6363
*/
6464
// load(bot: Client): void {}
65-
abstract load?: (client: BotClient) => Promise<void> | void
65+
abstract load?: (client: BotClient) => Promise<void>
6666

6767
/**
6868
* UnLoads the module's resources into the main system
6969
* @param bot The discord bot client
7070
*/
7171
// unload(bot: Client): void {}
72-
unload?: (client: BotClient) => Promise<void> | void
72+
unload?: (client: BotClient) => Promise<void>
7373
}
7474

7575
export interface BotCommand {

0 commit comments

Comments
 (0)