refactor: application structure (#11)
Reviewed-on: #11 Co-authored-by: Timo Behrendt <t.behrendt@t00n.de> Co-committed-by: Timo Behrendt <t.behrendt@t00n.de>
This commit was merged in pull request #11.
This commit is contained in:
64
src/main.ts
Normal file
64
src/main.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import { Gotify } from "gotify";
|
||||
import { QueryProtocol, TeamSpeak } from "ts3-nodejs-library";
|
||||
|
||||
import { pino } from "pino";
|
||||
|
||||
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";
|
||||
import type { Mode } from "./types";
|
||||
import { getModes, ts3gotifyFactory } from "./ts3gotify";
|
||||
|
||||
async function main() {
|
||||
const logger = pino({
|
||||
level: LOG_LEVEL,
|
||||
name: "ts3gotify",
|
||||
});
|
||||
|
||||
const gotify = new Gotify({
|
||||
server: GOTIFY_URL,
|
||||
});
|
||||
|
||||
const teamspeak = await TeamSpeak.connect({
|
||||
host: TS3_HOST,
|
||||
queryport: TS3_QUERY_PORT,
|
||||
serverport: TS3_SERVER_PORT,
|
||||
protocol: QueryProtocol.RAW,
|
||||
username: TS3_USERNAME,
|
||||
password: TS3_PASSWORD,
|
||||
nickname: TS3_NICKNAME,
|
||||
});
|
||||
logger.info("connected to TS3");
|
||||
|
||||
const modeList = getModes(MODE);
|
||||
const enabledModeNames = Object.entries(modeList)
|
||||
.filter(([, value]) => value)
|
||||
.map(([key]) => key);
|
||||
|
||||
logger.info(`connected to TS3 in modes: ${enabledModeNames.join(", ")}`);
|
||||
|
||||
const ts3gotify = ts3gotifyFactory(
|
||||
teamspeak,
|
||||
gotify,
|
||||
{
|
||||
app: GOTIFY_TOKEN,
|
||||
title: GOTIFY_TITLE,
|
||||
},
|
||||
logger
|
||||
);
|
||||
|
||||
for (const mode of enabledModeNames)
|
||||
ts3gotify.registerEventListenerForMode(mode as Mode);
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user