forked from ubiquity/ubiquibot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.ts
More file actions
37 lines (33 loc) · 1.3 KB
/
Copy pathconfig.ts
File metadata and controls
37 lines (33 loc) · 1.3 KB
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
import { BotConfig, BotConfigSchema } from "../types";
import fs from "fs";
import path from "path";
import { DefaultPriceConfig, DEFAULT_BOT_DELAY } from "../configs";
import { ajv } from "../utils";
export const loadConfig = async (): Promise<BotConfig> => {
let configFile: any = {};
const configFilePath = path.join(__dirname, "./config.json");
if (fs.existsSync(configFilePath)) {
configFile = await import(configFilePath);
}
const botConfig: BotConfig = {
price: {
baseMultiplier: process.env.BASE_MULTIPLIER ? Number(process.env.BASE_MULTIPLIER) : configFile.baseMultiplier ?? DefaultPriceConfig.baseMultiplier,
timeLabels: configFile.timeLabels ?? DefaultPriceConfig.timeLabels,
priorityLabels: configFile.priorityLabels ?? DefaultPriceConfig.priorityLabels,
},
supabase: {
url: process.env.SUPABASE_PROJECT_URL ?? "",
key: process.env.SUPABASE_PROJECT_KEY ?? "",
},
telegram: {
token: process.env.TELEGRAM_BOT_TOKEN ?? "",
delay: process.env.TELEGRAM_BOT_DELAY ? Number(process.env.TELEGRAM_BOT_DELAY) : DEFAULT_BOT_DELAY,
},
};
const validate = ajv.compile(BotConfigSchema);
const valid = validate(botConfig);
if (!valid) {
throw new Error(`Config schema validation failed!!!, config: ${botConfig}`);
}
return botConfig;
};