Fixed dynamic loading of discord classes / commands

This commit is contained in:
Alec LaLonde
2021-05-04 16:28:50 -06:00
committed by Alec LaLonde
parent d0bf595126
commit ef6c2ef545
5 changed files with 22 additions and 14 deletions

View File

@@ -3,7 +3,8 @@ import * as Path from 'path';
@Discord('!', {
import: [
Path.join(__dirname, "commands", "*.ts"),
// We are using tsc, so we want to load the compiled files
Path.join(__dirname, "commands", "*.js"),
],
})
export abstract class AppDiscord {

View File

@@ -6,8 +6,8 @@ import { CONFIG } from './config';
async function createDiscordClient(): Promise<Client> {
const client = new Client({
classes: [
`${__dirname}/Discord/**/*.ts`, // glob string to load the classes
`${__dirname}/Discord/**/*.js`, // If you compile using "tsc" the file extension change to .js
// We are using tsc, so we want to load the compiled files
`${__dirname}/discord/**/*.js`, // glob string to load the classes
],
silent: false,
variablesChar: ':',

View File

@@ -16,14 +16,16 @@ let loading = false;
let ledgerLoadedPromise: Promise<ReloadResult>;
export const loadSourceCredLedger = (): Promise<ReloadResult> => {
if (!loading) {
loading = true;
ledgerLoadedPromise = manager.reloadLedger();
ledgerLoadedPromise.then(() => {
loading = false;
});
if (ledgerLoadedPromise == null) {
if (!loading) {
loading = true;
console.log('reloading ledger...')
ledgerLoadedPromise = manager.reloadLedger();
ledgerLoadedPromise.then(() => {
loading = false;
});
}
}
return ledgerLoadedPromise;
}
console.log('created ledger manager');

View File

@@ -3,6 +3,8 @@ import express from 'express';
import { createDiscordClient } from ".";
import { CONFIG } from './config';
createDiscordClient();
const app = express();
app.get('/healthz', (_, res) => {
@@ -12,5 +14,3 @@ app.get('/healthz', (_, res) => {
app.listen(CONFIG.port, () => {
console.log(`Discord bot started on port ${CONFIG.port}`);
});
createDiscordClient();

View File

@@ -5,7 +5,12 @@
"module": "commonjs",
"rootDir": "src",
"outDir": "dist",
"tsBuildInfoFile": "dist/.tsbuildinfo"
"tsBuildInfoFile": "dist/.tsbuildinfo",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
},
"references": [
{