Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 21 additions & 3 deletions src/modules/moderation/ban-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -96,9 +97,13 @@ export class BanAllQueue extends Module<ModuleShared> {
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([
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")
Expand Down Expand Up @@ -170,6 +175,19 @@ export class BanAllQueue extends Module<ModuleShared> {
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,
})
.catch(() => {
logger.warn("[BanAllQueue] Failed to create audit log for ban all command")
})

const job = await this.flowProducer.add({
name: `${banType}_all`,
queueName: CONFIG.ORCHESTRATOR_QUEUE,
Expand Down
8 changes: 4 additions & 4 deletions src/modules/moderation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function deduceModerationAction(oldMember: ChatMember, newMember: ChatMember): M
}

const MAP_ACTIONS: Record<
Exclude<ModerationAction["action"], "SILENT" | "MULTI_CHAT_SPAM"> | "BAN_ALL" | "MUTE_ALL",
Exclude<ModerationAction["action"], "SILENT" | "MULTI_CHAT_SPAM"> | "BAN_ALL" | "UNBAN_ALL",
ApiInput["tg"]["auditLog"]["create"]["type"]
> = {
MUTE: "mute",
Expand All @@ -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<C extends Context> implements MiddlewareObj<C> {
Expand Down Expand Up @@ -148,7 +148,7 @@ class ModerationClass<C extends Context> implements MiddlewareObj<C> {
*
* Used when banning a user to delete all their messages in the chat
*/
private async deleteLastMessages(userId: number, chatId: number): Promise<void> {
public async deleteAllLastMessages(userId: number, chatId: number): Promise<void> {
await MessageUserStorage.getInstance()
.sync()
.catch(() => {})
Expand Down Expand Up @@ -183,7 +183,7 @@ class ModerationClass<C extends Context> implements MiddlewareObj<C> {
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
}
Expand Down
Loading