experimental (#1)

Reviewed-on: https://git.t000-n.de/tbehrendt/ts3gotify/pulls/1
This commit is contained in:
2022-11-28 15:10:13 +00:00
parent 2aa6bbeb58
commit 1605ad7c96
9 changed files with 1640 additions and 5 deletions

51
src/app.ts Normal file
View File

@@ -0,0 +1,51 @@
import { Gotify } from "gotify";
import { QueryProtocol, TeamSpeak } from "ts3-nodejs-library"
import { createLogger, transports, format } from "winston";
const logger = createLogger({
level: process.env.LOG_LEVEL,
transports: [new transports.Console()],
format: format.combine(
format.colorize(),
format.timestamp(),
),
})
const gotify = new Gotify({
server: process.env.GOTIFY_URL,
})
TeamSpeak.connect({
host: process.env.TS3_HOST || "info",
queryport: process.env.TS3_QUERY_PORT || 10011,
serverport: process.env.TS3_SERVER_PORT || 9987,
protocol: QueryProtocol.RAW,
username: process.env.TS3_USERNAME,
password: process.env.TS3_PASSWORD,
nickname: process.env.TS3_NICKNAME || "ts3gotify",
}).then((teamspeak) => {
logger.info("connected to TS3")
teamspeak.on("clientconnect", (event) => {
logger.debug(`${event.client.nickname} connected`)
gotify.send({
app: process.env.GOTIFY_TOKEN,
title: process.env.GOTIFY_TITLE || "ts3gotify",
message: `${event.client.nickname} connected`,
}).catch((error: Error) => {
console.error(`Error sending message to gotify: ${error.message}`)
})
})
teamspeak.on("close", async () => {
console.debug("disconnected, trying to reconnect...")
await teamspeak.reconnect(5, 1000)
logger.info("reconnected!")
})
teamspeak.on("error", (error: Error) => {
logger.error(`Error connecting to TS3 server: ${error.message}`)
process.exit(1)
})
})

18
src/environment.d.ts vendored Normal file
View File

@@ -0,0 +1,18 @@
export { };
declare global {
namespace NodeJS {
interface ProcessEnv {
LOG_LEVEL?: "error" | "info" | "debug"
TS3_HOST: string;
TS3_QUERY_PORT?: number;
TS3_SERVER_PORT?: number;
TS3_USERNAME: string;
TS3_PASSWORD: string;
TS3_NICKNAME?: string;
GOTIFY_URL: string;
GOTIFY_TOKEN: string;
GOTIFY_TITLE?: string;
}
}
}