From 399e395f62f1d1a5a7ba283e07a98125efe7d2d9 Mon Sep 17 00:00:00 2001 From: Lorenzo Corallo Date: Sun, 12 Apr 2026 00:12:40 +0200 Subject: [PATCH 1/4] fix: log audit for banall --- package.json | 2 +- pnpm-lock.yaml | 10 +++++----- src/modules/moderation/ban-all.ts | 10 ++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index e4c6c79..5897327 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "@grammyjs/parse-mode": "^1.11.1", "@grammyjs/runner": "^2.0.3", "@influxdata/influxdb-client": "^1.35.0", - "@polinetwork/backend": "^0.15.10", + "@polinetwork/backend": "^0.15.11", "@t3-oss/env-core": "^0.13.4", "@trpc/client": "^11.5.1", "@types/ssdeep.js": "^0.0.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f0621a7..a21db0b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -30,8 +30,8 @@ importers: specifier: ^1.35.0 version: 1.35.0 '@polinetwork/backend': - specifier: ^0.15.10 - version: 0.15.10 + specifier: ^0.15.11 + version: 0.15.11 '@t3-oss/env-core': specifier: ^0.13.4 version: 0.13.4(arktype@2.1.20)(typescript@5.7.3)(zod@4.1.11) @@ -431,8 +431,8 @@ packages: resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} engines: {node: '>=14'} - '@polinetwork/backend@0.15.10': - resolution: {integrity: sha512-9tmz33rVHuQUe1nqybMN5JbB3nxwQsM183jq8dSlOb2z+RfIV2OTiBTzE+g1bYqkek1ASPInj79Zq8R/DA3yMA==} + '@polinetwork/backend@0.15.11': + resolution: {integrity: sha512-bSGJJ/jSLsfMGVo7mCNp8lfYZiCx91MClPP5YaD72oFpXiSv7PaFlAXi+DwO7A3U6E2QPNG5vkvfxVE63A/AWw==} '@redis/bloom@1.2.0': resolution: {integrity: sha512-HG2DFjYKbpNmVXsa0keLHp/3leGJz1mjh09f2RLGGLQZzSHpkmZWuwJbAvo3QcRY8p80m5+ZdXZdYOSBLlp7Cg==} @@ -1831,7 +1831,7 @@ snapshots: '@pkgjs/parseargs@0.11.0': optional: true - '@polinetwork/backend@0.15.10': {} + '@polinetwork/backend@0.15.11': {} '@redis/bloom@1.2.0(@redis/client@1.6.0)': dependencies: diff --git a/src/modules/moderation/ban-all.ts b/src/modules/moderation/ban-all.ts index a789de8..8adf82e 100644 --- a/src/modules/moderation/ban-all.ts +++ b/src/modules/moderation/ban-all.ts @@ -7,6 +7,7 @@ import { throttle } from "@/utils/throttle" import type { ModuleShared } from "@/utils/types" import { modules } from ".." import { type BanAll, type BanAllState, isBanAllState } from "../tg-logger/ban-all" +import { Moderation } from "." /** * Utility type that get the Worker type for a Job @@ -170,6 +171,15 @@ export class BanAllQueue extends Module { const chats = allGroups.map((g) => g.telegramId) const banType = banAll.type === "BAN" ? "ban" : "unban" + await api.tg.auditLog.create.mutate({ + adminId: banAll.reporter.id, + targetId: banAll.target.id, + type: banAll.type === "BAN" ? "ban_all" : "unban_all", + reason: banAll.reason, + groupId: null, + until: null, + }) + const job = await this.flowProducer.add({ name: `${banType}_all`, queueName: CONFIG.ORCHESTRATOR_QUEUE, From 12a9b8e54697c6e74c7d4e91728e1b1acab4298c Mon Sep 17 00:00:00 2001 From: Tommaso Morganti Date: Sun, 12 Apr 2026 00:14:06 +0200 Subject: [PATCH 2/4] feat: also delete last 100 messages with ban_all --- src/modules/moderation/ban-all.ts | 10 +++++++--- src/modules/moderation/index.ts | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/modules/moderation/ban-all.ts b/src/modules/moderation/ban-all.ts index 8adf82e..9487823 100644 --- a/src/modules/moderation/ban-all.ts +++ b/src/modules/moderation/ban-all.ts @@ -97,9 +97,13 @@ export class BanAllQueue extends Module { async (job) => { switch (job.name) { case "ban": { - const success = await this.shared.api.banChatMember(job.data.chatId, job.data.targetId, { - revoke_messages: true, - }) + const [success] = await Promise.all([ + await this.shared.api + .banChatMember(job.data.chatId, job.data.targetId, { revoke_messages: true }) + .catch(() => false), + Moderation.deleteAllLastMessages(job.data.targetId, job.data.chatId), + ]) + logger.debug({ chatId: job.data.chatId, targetId: job.data.targetId, success }, "[BanAllQueue] ban result") if (!success) { throw new Error("Failed to ban user") diff --git a/src/modules/moderation/index.ts b/src/modules/moderation/index.ts index ca3cd9c..8a38089 100644 --- a/src/modules/moderation/index.ts +++ b/src/modules/moderation/index.ts @@ -148,7 +148,7 @@ class ModerationClass implements MiddlewareObj { * * Used when banning a user to delete all their messages in the chat */ - private async deleteLastMessages(userId: number, chatId: number): Promise { + public async deleteAllLastMessages(userId: number, chatId: number): Promise { await MessageUserStorage.getInstance() .sync() .catch(() => {}) @@ -183,7 +183,7 @@ class ModerationClass implements MiddlewareObj { modules.shared.api .banChatMember(p.chat.id, p.target.id, { until_date: p.duration?.timestamp_s }) .catch(() => false), - this.deleteLastMessages(p.target.id, p.chat.id), + this.deleteAllLastMessages(p.target.id, p.chat.id), ]) return success } From 0b0b2dd8e3b73e6c5892d5210cb90b637944220c Mon Sep 17 00:00:00 2001 From: Tommaso Morganti Date: Sun, 12 Apr 2026 00:18:03 +0200 Subject: [PATCH 3/4] fix: rabbit --- src/modules/moderation/ban-all.ts | 20 ++++++++++++-------- src/modules/moderation/index.ts | 4 ++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/modules/moderation/ban-all.ts b/src/modules/moderation/ban-all.ts index 9487823..5c51313 100644 --- a/src/modules/moderation/ban-all.ts +++ b/src/modules/moderation/ban-all.ts @@ -175,14 +175,18 @@ export class BanAllQueue extends Module { const chats = allGroups.map((g) => g.telegramId) const banType = banAll.type === "BAN" ? "ban" : "unban" - await api.tg.auditLog.create.mutate({ - adminId: banAll.reporter.id, - targetId: banAll.target.id, - type: banAll.type === "BAN" ? "ban_all" : "unban_all", - reason: banAll.reason, - groupId: null, - until: null, - }) + await api.tg.auditLog.create + .mutate({ + adminId: banAll.reporter.id, + targetId: banAll.target.id, + type: banAll.type === "BAN" ? "ban_all" : "unban_all", + reason: banAll.reason, + groupId: null, + until: null, + }) + .catch(() => { + logger.warn("[BanAllQueue] Failed to create audit log for ban all command") + }) const job = await this.flowProducer.add({ name: `${banType}_all`, diff --git a/src/modules/moderation/index.ts b/src/modules/moderation/index.ts index 8a38089..c0553c0 100644 --- a/src/modules/moderation/index.ts +++ b/src/modules/moderation/index.ts @@ -34,7 +34,7 @@ function deduceModerationAction(oldMember: ChatMember, newMember: ChatMember): M } const MAP_ACTIONS: Record< - Exclude | "BAN_ALL" | "MUTE_ALL", + Exclude | "BAN_ALL" | "UNBAN_ALL", ApiInput["tg"]["auditLog"]["create"]["type"] > = { MUTE: "mute", @@ -43,7 +43,7 @@ const MAP_ACTIONS: Record< UNBAN: "unban", UNMUTE: "unmute", BAN_ALL: "ban_all", - MUTE_ALL: "mute_all", + UNBAN_ALL: "unban_all", } class ModerationClass implements MiddlewareObj { From 1e90d1799f934cd15bbc6f8c17d709910af06303 Mon Sep 17 00:00:00 2001 From: Tommaso Morganti Date: Sun, 12 Apr 2026 00:25:09 +0200 Subject: [PATCH 4/4] fix: stray await --- src/modules/moderation/ban-all.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/moderation/ban-all.ts b/src/modules/moderation/ban-all.ts index 5c51313..b28dc90 100644 --- a/src/modules/moderation/ban-all.ts +++ b/src/modules/moderation/ban-all.ts @@ -98,7 +98,7 @@ export class BanAllQueue extends Module { switch (job.name) { case "ban": { const [success] = await Promise.all([ - await this.shared.api + this.shared.api .banChatMember(job.data.chatId, job.data.targetId, { revoke_messages: true }) .catch(() => false), Moderation.deleteAllLastMessages(job.data.targetId, job.data.chatId),