(messageData: MessageData[])
| 605 | // Url 类型:消息中的纯文本 URL |
| 606 | if (entity.className === "MessageEntityUrl" && message.message) { |
| 607 | const url = message.message.substring( |
| 608 | entity.offset, |
| 609 | entity.offset + entity.length, |
| 610 | ); |
| 611 | urls.push(url); |
| 612 | } |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | return urls; |
| 617 | } |
| 618 | |
| 619 | // 提取文本中的 URL |
| 620 | function extractUrlsFromText(text: string): string[] { |
| 621 | const urlRegex = /https?:\/\/[^\s\])】>]+/g; |
| 622 | return text.match(urlRegex) || []; |
| 623 | } |
| 624 | |
| 625 | // 检查是否为贴纸/表情包 |
| 626 | function isStickerOrEmoji(message: any): boolean { |
| 627 | if (!message.media?.document) return false; |
| 628 | |
| 629 | const doc = message.media.document; |
| 630 | |
| 631 | // 检查 MIME 类型 |
| 632 | const stickerMimeTypes = [ |
| 633 | "application/x-tgsticker", // TGS 动画贴纸 |
| 634 | "video/webm", // 视频贴纸 |
| 635 | ]; |
| 636 | if (doc.mimeType && stickerMimeTypes.includes(doc.mimeType)) { |
| 637 | return true; |
| 638 | } |
| 639 | |
| 640 | // 检查 attributes 中是否有贴纸/表情包标识 |
| 641 | if (doc.attributes && Array.isArray(doc.attributes)) { |
| 642 | for (const attr of doc.attributes) { |
| 643 | if ( |
| 644 | attr.className === "DocumentAttributeSticker" || |
| 645 | attr.className === "DocumentAttributeCustomEmoji" |
| 646 | ) { |
| 647 | return true; |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | return false; |
| 653 | } |
no test coverage detected