experimental (#1)
Reviewed-on: https://git.t000-n.de/tbehrendt/ts3gotify/pulls/1
This commit is contained in:
51
src/app.ts
Normal file
51
src/app.ts
Normal 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)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user