From 69695e265af99e13b7f32fe49bb236ed47e0580f Mon Sep 17 00:00:00 2001 From: soffee Date: Tue, 8 Apr 2025 13:42:47 +0300 Subject: [PATCH] fix lint --- README.md | 8 ++++---- src/config.ts | 4 ++-- src/filters.ts | 10 +++++----- src/keywords.ts | 2 +- src/metrics.ts | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 785c155..967f020 100644 --- a/README.md +++ b/README.md @@ -42,12 +42,12 @@ This metric can be enabled with command line flag `--words-counter` `--watch-file`, `-w` - watch for keywords file updates and reload keywords configuration in runtime -`--include-peers`, `-i` - comma-separated list of `peer.id`s to gather metrics from. -if set, only specified peers will be exposed in metrics. +`--include-peers`, `-i` - comma-separated list of `peer.id`s to gather metrics from. +if set, only specified peers will be exposed in metrics. can be specified multiple times. can not be used along with `--exclude-peers` -`--exclude-peers` `x` - comma-separated list of `peer.id`s to exclude from metrics. -if set, specified peers will not be exposed in metrics. +`--exclude-peers` `x` - comma-separated list of `peer.id`s to exclude from metrics. +if set, specified peers will not be exposed in metrics. can be specified multiple times. can not be used along with `--include-peers` ## Environment Variables diff --git a/src/config.ts b/src/config.ts index f2c93e1..86c02f2 100644 --- a/src/config.ts +++ b/src/config.ts @@ -43,14 +43,14 @@ if (cli["include-peers"] && cli["exclude-peers"]) { if (cli["include-peers"]) { config.includePeers = []; for (const o of cli["include-peers"] as string[]) { - config.includePeers.push(...o.split(",").map(i => parseInt(i)).filter(i => !isNaN(i))); + config.includePeers.push(...o.split(",").map(i => Number.parseInt(i)).filter(i => !Number.isNaN(i))); } } if (cli["exclude-peers"]) { config.excludePeers = []; for (const o of cli["exclude-peers"] as string[]) { - config.excludePeers.push(...o.split(",").map(i => parseInt(i)).filter(i => !isNaN(i))); + config.excludePeers.push(...o.split(",").map(i => Number.parseInt(i)).filter(i => !Number.isNaN(i))); } } diff --git a/src/filters.ts b/src/filters.ts index cef2a82..6cd8c56 100644 --- a/src/filters.ts +++ b/src/filters.ts @@ -1,21 +1,21 @@ +import type { Configuration } from "./config.js"; import { filters } from "@mtcute/dispatcher"; -import { Configuration } from "./config.js"; export function peersConfigBoolFilter(conf: Configuration, peerId: number) { - if(conf.excludePeers && conf.excludePeers.indexOf(peerId) !== -1) { + if (conf.excludePeers && conf.excludePeers.includes(peerId)) { return false; } - if(conf.includePeers && conf.includePeers.indexOf(peerId) === -1) { + if (conf.includePeers && !conf.includePeers.includes(peerId)) { return false; } return true; } export function peersConfigFilter(conf: Configuration) { - if(conf.excludePeers) { + if (conf.excludePeers) { return filters.not(filters.chatId(conf.excludePeers)); } else if (conf.includePeers) { return filters.chatId(conf.includePeers); } return filters.any; -} \ No newline at end of file +} diff --git a/src/keywords.ts b/src/keywords.ts index 3340cf6..fdb0a79 100644 --- a/src/keywords.ts +++ b/src/keywords.ts @@ -1,8 +1,8 @@ import type { Dispatcher } from "@mtcute/dispatcher"; import { PropagationAction } from "@mtcute/dispatcher"; import { Counter } from "prom-client"; -import { peersConfigFilter } from "./filters.js"; import { config } from "./config.js"; +import { peersConfigFilter } from "./filters.js"; interface KeywordPattern { name: string; diff --git a/src/metrics.ts b/src/metrics.ts index 527cb68..9faf0db 100644 --- a/src/metrics.ts +++ b/src/metrics.ts @@ -3,9 +3,9 @@ import type { TelegramClient } from "@mtcute/node"; import { PropagationAction } from "@mtcute/dispatcher"; import { Counter, Gauge } from "prom-client"; -import { KeywordsCounter, newWordsCounter } from "./keywords.js"; import { config } from "./config.js"; import { peersConfigBoolFilter, peersConfigFilter } from "./filters.js"; +import { KeywordsCounter, newWordsCounter } from "./keywords.js"; function newMessagesCounter(dp: Dispatcher) { const counter = new Counter({ @@ -31,7 +31,7 @@ function newStaticPeerInfoGauge(tg: TelegramClient) { collect: async () => { gauge.reset(); for await (const d of tg.iterDialogs()) { - if(!peersConfigBoolFilter(config, d.peer.id)) { + if (!peersConfigBoolFilter(config, d.peer.id)) { continue; } @@ -54,7 +54,7 @@ function newUnreadCountGauge(tg: TelegramClient) { collect: async () => { gauge.reset(); for await (const d of tg.iterDialogs()) { - if(!peersConfigBoolFilter(config, d.peer.id)) { + if (!peersConfigBoolFilter(config, d.peer.id)) { continue; }