fix lint
This commit is contained in:
parent
d32ed657a1
commit
69695e265a
5 changed files with 15 additions and 15 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue