Files
ts3gotify/src/main.ts
Timo Behrendt 8e425b4f12
All checks were successful
CD / Test (push) Successful in 23s
CD / Build and push (amd64) (push) Successful in 1m0s
CD / Build and push (arm64) (push) Successful in 1m42s
CD / Create manifest (push) Successful in 20s
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>
2025-01-08 19:07:16 +01:00

65 lines
1.3 KiB
TypeScript

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();