Compare commits
2 Commits
bump-bun
...
01a8b10c57
| Author | SHA1 | Date | |
|---|---|---|---|
| 01a8b10c57 | |||
| 203eb0e3ec |
@@ -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",
|
||||
|
||||
31
src/app.ts
31
src/app.ts
@@ -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) {
|
||||
|
||||
19
src/env.ts
19
src/env.ts
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user