(msg: Api.Message, client: TelegramClient, config: Config)
| 488 | break; |
| 489 | } |
| 490 | } catch (error: any) { |
| 491 | console.error(`[${PLUGIN_NAME}] Command failed:`, error); |
| 492 | await MessageManager.edit(msg, `❌ 命令执行失败: ${htmlEscape(error.message)}`); |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | private async handleNewMessage(event: NewMessageEvent): Promise<void> { |
| 497 | const config = await ConfigManager.getConfig(); |
| 498 | if (!config.enabled || !event.message.peerId) return; |
| 499 | |
| 500 | const client = await getGlobalClient(); |
| 501 | if (!client) return; |
| 502 | |
| 503 | const msg = event.message; |
| 504 | const chatId = await getPeerId(client, msg); |
| 505 | |
| 506 | if (chatId && config.monitoredChats.some(c => c.id === chatId)) { |
| 507 | console.log(`[${PLUGIN_NAME}] Processing new message ${msg.id} in chat ${chatId}`); |
| 508 | await this.processImageMessage(msg, client, config); |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | private async handleEditedMessage(event: EditedMessageEvent): Promise<void> { |
| 513 | const config = await ConfigManager.getConfig(); |
| 514 | if (!config.enabled || !event.message.peerId) return; |
| 515 | |
| 516 | const client = await getGlobalClient(); |
| 517 | if (!client) return; |
| 518 | |
| 519 | const msg = event.message; |
| 520 | const chatId = await getPeerId(client, msg); |
| 521 | |
| 522 | if (chatId && config.monitoredChats.some(c => c.id === chatId)) { |
| 523 | console.log(`[${PLUGIN_NAME}] Processing edited message ${msg.id} in chat ${chatId}`); |
| 524 | await this.processImageMessage(msg, client, config); |
| 525 | } |
| 526 | } |
| 527 | |
| 528 | private async processImageMessage(msg: Api.Message, client: TelegramClient, config: Config): Promise<void> { |
| 529 | let media: Api.MessageMediaPhoto | Api.MessageMediaDocument | undefined; |
| 530 | let fileSize: number | undefined; |
| 531 | |
| 532 | if (!msg.media) return; |
| 533 | |
| 534 | if (msg.media instanceof Api.MessageMediaDocument) { |
| 535 | const docRaw = msg.media.document; |
| 536 | if (docRaw instanceof Api.Document) { |
| 537 | const isSticker = Array.isArray(docRaw.attributes) && docRaw.attributes.some(a => a instanceof Api.DocumentAttributeSticker); |
| 538 | if (isSticker) { |
| 539 | const stickerId = String(docRaw.id); |
| 540 | const action = config.bannedStickerIds?.[stickerId]; |
| 541 | if (action) { |
| 542 | try { |
| 543 | if (action === 'delete') { |
| 544 | await msg.delete({ revoke: true }); |
| 545 | } else if (action === 'ban') { |
| 546 | const senderId = msg.senderId; |
| 547 | if (senderId) { |
no test coverage detected