fix: replace winston with pino #6
@@ -2,7 +2,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "bun build --minify --target bun --outdir dist --sourcemap src/app.ts",
|
"build": "bun build --minify --target bun --outdir dist --sourcemap src/app.ts",
|
||||||
"check:code": "eslint src/ --ext .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": {
|
"devDependencies": {
|
||||||
"@types/ts3-nodejs-library": "^2.0.1",
|
"@types/ts3-nodejs-library": "^2.0.1",
|
||||||
@@ -16,8 +17,9 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"env-var": "^7.5.0",
|
"env-var": "^7.5.0",
|
||||||
"gotify": "^1.1.0",
|
"gotify": "^1.1.0",
|
||||||
"ts3-nodejs-library": "^3.4.1",
|
"pino": "^9.6.0",
|
||||||
"winston": "^3.8.2"
|
"pino-pretty": "^13.0.0",
|
||||||
|
"ts3-nodejs-library": "^3.4.1"
|
||||||
},
|
},
|
||||||
"name": "ts3gotify",
|
"name": "ts3gotify",
|
||||||
"module": "src/app.ts",
|
"module": "src/app.ts",
|
||||||
|
|||||||
23
src/app.ts
23
src/app.ts
@@ -4,7 +4,8 @@ import {
|
|||||||
TeamSpeak,
|
TeamSpeak,
|
||||||
TextMessageTargetMode,
|
TextMessageTargetMode,
|
||||||
} from "ts3-nodejs-library";
|
} from "ts3-nodejs-library";
|
||||||
import { createLogger, transports, format } from "winston";
|
|
||||||
|
import { pino } from "pino";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
GOTIFY_TITLE,
|
GOTIFY_TITLE,
|
||||||
@@ -21,10 +22,9 @@ import {
|
|||||||
} from "./env";
|
} from "./env";
|
||||||
import type { Mode } from "./types";
|
import type { Mode } from "./types";
|
||||||
|
|
||||||
const logger = createLogger({
|
const logger = pino({
|
||||||
level: LOG_LEVEL,
|
level: LOG_LEVEL,
|
||||||
transports: [new transports.Console()],
|
name: "ts3gotify",
|
||||||
format: format.combine(format.colorize(), format.timestamp()),
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const gotify = new Gotify({
|
const gotify = new Gotify({
|
||||||
@@ -43,15 +43,13 @@ function getModes(): {
|
|||||||
return { [mode]: true };
|
return { [mode]: true };
|
||||||
});
|
});
|
||||||
|
|
||||||
return Object.assign(
|
return {
|
||||||
{
|
|
||||||
connect: false,
|
connect: false,
|
||||||
disconnect: false,
|
disconnect: false,
|
||||||
moved: false,
|
moved: false,
|
||||||
message: false,
|
message: false,
|
||||||
},
|
...modes,
|
||||||
...modes
|
};
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendNotification(message: string) {
|
function sendNotification(message: string) {
|
||||||
@@ -91,6 +89,13 @@ TeamSpeak.connect({
|
|||||||
}).then((teamspeak) => {
|
}).then((teamspeak) => {
|
||||||
const mode = getModes();
|
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");
|
logger.info("connected to TS3");
|
||||||
|
|
||||||
if (mode.connect) {
|
if (mode.connect) {
|
||||||
|
|||||||
17
src/env.ts
17
src/env.ts
@@ -11,13 +11,16 @@ const envVar = from(process.env, {
|
|||||||
throw new Error("Invalid log level");
|
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"];
|
const modes = ["connect", "disconnect", "moved", "message"];
|
||||||
if (modes.includes(value)) {
|
for (const mode of parsedValue) {
|
||||||
return value as Mode;
|
if (!modes.includes(mode)) {
|
||||||
} else {
|
|
||||||
throw new Error("Invalid mode");
|
throw new Error("Invalid mode");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return parsedValue as Mode[];
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -46,8 +49,4 @@ export const GOTIFY_TITLE = envVar
|
|||||||
.default("ts3gotify")
|
.default("ts3gotify")
|
||||||
.asString();
|
.asString();
|
||||||
|
|
||||||
export const MODE = envVar
|
export const MODE = envVar.get("MODE").default('["connect"]').asTs3GotifyMode();
|
||||||
.get("MODE")
|
|
||||||
.default("['connect']")
|
|
||||||
.asJsonArray()
|
|
||||||
.map((value) => value.asTs3GotifyMode());
|
|
||||||
|
|||||||
Reference in New Issue
Block a user