Skip to content

Commit 872e2e6

Browse files
author
xyzjesper
committed
Add config env var
1 parent b136040 commit 872e2e6

File tree

3 files changed

+7
-34
lines changed

3 files changed

+7
-34
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
MONGODBURL=your-url-to-database
2+
CONFIG_PATH=/mnt/server/config.yml or /bot/config.yml
23
TWITCH_TOKEN_URL=only-for-scripts-folder
34

45
# Disabled

src/main/config.ts

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import YAML from "yaml";
22
import fs from "fs";
3-
import {Logger} from "./logger.js";
4-
import {LoggingAction} from "../enums/loggingTypes.js";
53
import {botData} from "./version.js";
64
import colors from "colors";
75
import {DisBotConfigData} from "../types/config.js";
@@ -11,10 +9,10 @@ colors.enable();
119
export let Config: DisBotConfigData
1210

1311
export async function configStartup() {
14-
const fileCheck = fs.existsSync(`${process.cwd()}/config.yml`);
12+
const fileCheck = fs.existsSync(process.env.CONFIG_PATH);
1513
let content: string
1614
if (fileCheck) {
17-
const fileContent = fs.readFileSync(`${process.cwd()}/config.yml`);
15+
const fileContent = fs.readFileSync(process.env.CONFIG_PATH);
1816
content = fileContent.toString();
1917
}
2018
if (!fileCheck || !content) {
@@ -76,8 +74,6 @@ export async function configStartup() {
7674
DbName: "",
7775
},
7876
Logging: {
79-
BotLoggingApiPort: 0,
80-
BotLoggingPassword: "",
8177
ErrorWebhook: "",
8278
BotLogger: "",
8379
},
@@ -86,41 +82,19 @@ export async function configStartup() {
8682
};
8783

8884
fs.writeFileSync(
89-
`${process.cwd()}/config.yml`,
85+
process.env.CONFIG_PATH,
9086
YAML.stringify(configData)
9187
);
9288
}
9389

94-
const file = fs.readFileSync(`${process.cwd()}/config.yml`, "utf8");
90+
const file = fs.readFileSync(process.env.CONFIG_PATH, "utf8");
9591
const ymlData = YAML.parse(file);
9692
Config = ymlData;
9793

98-
Logger.info({
99-
guildId: "0",
100-
userId: "0",
101-
channelId: "0",
102-
messageId: "0",
103-
timestamp: new Date().toISOString(),
104-
level: "info",
105-
label: "Config",
106-
message: `DisBot Config is loaded and exported!`,
107-
botType: "Unknown",
108-
action: LoggingAction.Other,
109-
});
94+
console.log("DisBot Config is loaded and exported! (Logger, Startup, Bot)")
11095

11196
if (Config.CONFIG_VERSION != botData.configVersion) {
112-
Logger.error({
113-
guildId: "0",
114-
userId: "0",
115-
channelId: "0",
116-
messageId: "0",
117-
timestamp: new Date().toISOString(),
118-
level: "error",
119-
label: "Config",
120-
message: `Please recreate your Bot Config`.red,
121-
botType: "Unknown",
122-
action: LoggingAction.Other,
123-
});
97+
console.error(`Please recreate your Bot Config`.red)
12498
process.exit(0);
12599
}
126100
}

src/types/config.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ export type DisBotConfigData = {
5959
DbName: string;
6060
};
6161
Logging: {
62-
BotLoggingApiPort: number;
63-
BotLoggingPassword: string;
6462
ErrorWebhook: string;
6563
BotLogger: string;
6664
};

0 commit comments

Comments
 (0)