fix: replace winston with pino (#6)
All checks were successful
CD / Test (push) Successful in 25s
CD / Build and push (amd64) (push) Successful in 59s
CD / Build and push (arm64) (push) Successful in 1m42s
CD / Create manifest (push) Successful in 10s

Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
2025-01-08 14:01:02 +01:00
parent 3eca1f5516
commit e9bcaf153c
4 changed files with 32 additions and 26 deletions

BIN
bun.lockb

Binary file not shown.

View File

@@ -2,7 +2,8 @@
"scripts": {
"build": "bun build --minify --target bun --outdir dist --sourcemap src/app.ts",
"check:code": "eslint src/ --ext .ts",
"check:spell": "cspell --config cspell.code.json **/*.ts"
"check:spell": "cspell --config cspell.code.json **/*.ts",
"start": "bun run src/app.ts"
},
"devDependencies": {
"@types/ts3-nodejs-library": "^2.0.1",
@@ -16,8 +17,9 @@
"dependencies": {
"env-var": "^7.5.0",
"gotify": "^1.1.0",
"ts3-nodejs-library": "^3.4.1",
"winston": "^3.8.2"
"pino": "^9.6.0",
"pino-pretty": "^13.0.0",
"ts3-nodejs-library": "^3.4.1"
},
"name": "ts3gotify",
"module": "src/app.ts",

View File

@@ -4,7 +4,8 @@ import {
TeamSpeak,
TextMessageTargetMode,
} from "ts3-nodejs-library";
import { createLogger, transports, format } from "winston";
import { pino } from "pino";
import {
GOTIFY_TITLE,
@@ -21,10 +22,9 @@ import {
} from "./env";
import type { Mode } from "./types";
const logger = createLogger({
const logger = pino({
level: LOG_LEVEL,
transports: [new transports.Console()],
format: format.combine(format.colorize(), format.timestamp()),
name: "ts3gotify",
});
const gotify = new Gotify({
@@ -43,15 +43,13 @@ function getModes(): {
return { [mode]: true };
});
return Object.assign(
{
connect: false,
disconnect: false,
moved: false,
message: false,
},
...modes
);
return {
connect: false,
disconnect: false,
moved: false,
message: false,
...modes,
};
}
function sendNotification(message: string) {
@@ -91,6 +89,13 @@ TeamSpeak.connect({
}).then((teamspeak) => {
const mode = getModes();
logger.info(
`connected to TS3 in modes: ${Object.entries(mode)
.filter(([_, value]) => value)
.map(([key]) => key)
.join(", ")}`
);
logger.info("connected to TS3");
if (mode.connect) {

View File

@@ -11,13 +11,16 @@ const envVar = from(process.env, {
throw new Error("Invalid log level");
}
},
asTs3GotifyMode: (value): Mode => {
asTs3GotifyMode: (value): Mode[] => {
const parsedValue: string[] = envVar.accessors.asJsonArray(value);
const modes = ["connect", "disconnect", "moved", "message"];
if (modes.includes(value)) {
return value as Mode;
} else {
throw new Error("Invalid mode");
for (const mode of parsedValue) {
if (!modes.includes(mode)) {
throw new Error("Invalid mode");
}
}
return parsedValue as Mode[];
},
});
@@ -46,8 +49,4 @@ export const GOTIFY_TITLE = envVar
.default("ts3gotify")
.asString();
export const MODE = envVar
.get("MODE")
.default("['connect']")
.asJsonArray()
.map((value) => value.asTs3GotifyMode());
export const MODE = envVar.get("MODE").default('["connect"]').asTs3GotifyMode();