-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.ts
45 lines (35 loc) · 1.49 KB
/
cli.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import { load } from './src/modules/dynamicModules.js';
import { botFactory } from './libs/util.js';
import { MessageHandler } from './src/modules/messageHandler.js';
import { EntryPoint } from './@types/types.js';
const SUPPORTED_LANGUAGES = ["en-us", "pt-br"];
async function initializeFramework(entrypointFile: string | undefined = undefined): Promise<void> {
const rootPath = process.cwd();
const modulesPath = process.env.DEBUG
? path.join(rootPath, 'test_modules')
: path.join(rootPath, 'modules');
fs.mkdirSync('./temp', { recursive: true });
if (entrypointFile == undefined) {
entrypointFile = path.join(modulesPath, "entrypoint.js");
} else {
entrypointFile = path.resolve(entrypointFile);
}
const entryPoint = path.join(entrypointFile);
const entryPointModule = await load(entryPoint);
const entryPointClass: EntryPoint = new (entryPointModule.Entrypoint as any)();
if (entryPointClass.language) {
if (!SUPPORTED_LANGUAGES.includes(entryPointClass.language)) {
throw new Error("Language is not supported!");
}
} else {
entryPointClass.language = "en-us";
}
const messageHandler = new MessageHandler(entryPointClass);
const bot = botFactory(entryPointClass);
await bot.init(messageHandler);
}
initializeFramework(process.argv[2]);
export { initializeFramework };