mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-04-24 03:00:09 -04:00
Fixed dynamic loading of discord classes / commands
This commit is contained in:
committed by
Alec LaLonde
parent
d0bf595126
commit
ef6c2ef545
@@ -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 {
|
||||
|
||||
@@ -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: ':',
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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": [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user