refactor: introduce env-var

This commit is contained in:
2025-01-07 19:34:36 +01:00
parent 94b03a97d4
commit 23584c0b9c
5 changed files with 68 additions and 33 deletions

View File

@@ -2,8 +2,10 @@ import { Gotify } from "gotify";
import { QueryProtocol, TeamSpeak, TextMessageTargetMode } from "ts3-nodejs-library"
import { createLogger, transports, format } from "winston";
import { GOTIFY_TITLE, GOTIFY_TOKEN, GOTIFY_URL, LOG_LEVEL, MODE, TS3_HOST, TS3_NICKNAME, TS3_PASSWORD, TS3_QUERY_PORT, TS3_SERVER_PORT, TS3_USERNAME } from "./env";
const logger = createLogger({
level: process.env.LOG_LEVEL,
level: LOG_LEVEL,
transports: [new transports.Console()],
format: format.combine(
format.colorize(),
@@ -12,22 +14,22 @@ const logger = createLogger({
})
const gotify = new Gotify({
server: process.env.GOTIFY_URL,
server: GOTIFY_URL,
})
const gotifyConfig = {
app: process.env.GOTIFY_TOKEN,
title: process.env.GOTIFY_TITLE || "ts3gotify"
app: GOTIFY_TOKEN,
title: GOTIFY_TITLE
}
function getModes() {
const modeIsProvided = process.env.MODE != undefined
return {
connect: modeIsProvided ? process.env.MODE?.includes("connect") || false : true,
disconnect: process.env.MODE?.includes("disconnect") || false,
moved: process.env.MODE?.includes("moved") || false,
message: process.env.MODE?.includes("message") || false
connect: MODE?.includes("connect") || false,
disconnect: MODE?.includes("disconnect") || false,
moved: MODE?.includes("moved") || false,
message: MODE?.includes("message") || false
}
}
@@ -56,13 +58,13 @@ function handleMessage(message: string) {
}
TeamSpeak.connect({
host: process.env.TS3_HOST || "info",
queryport: process.env.TS3_QUERY_PORT || 10011,
serverport: process.env.TS3_SERVER_PORT || 9987,
host: TS3_HOST,
queryport: TS3_QUERY_PORT,
serverport: TS3_SERVER_PORT,
protocol: QueryProtocol.RAW,
username: process.env.TS3_USERNAME,
password: process.env.TS3_PASSWORD,
nickname: process.env.TS3_NICKNAME || "ts3gotify",
username: TS3_USERNAME,
password: TS3_PASSWORD,
nickname: TS3_NICKNAME,
}).then((teamspeak) => {
const mode = getModes()