From 791fa9867724e75fb08e8cbcca8d9938e816b0de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E6=AE=87?= <197728340@qq.com> Date: Fri, 22 Nov 2024 14:05:50 +0800 Subject: [PATCH] =?UTF-8?q?refactor(Cili):=20=E9=87=8D=E6=9E=84=E7=A3=81?= =?UTF-8?q?=E5=8A=9B=E6=90=9C=E7=B4=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 优化代码结构,提高可读性和可维护性 - 添加错误日志记录,便于调试和排查问题 - 使用 forward 消息格式,提升用户体验 - 引入 common 和 segment 模块,丰富功能 - 添加 logger 模块,用于错误日志输出 --- src/apps/Cili.ts | 52 +++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/src/apps/Cili.ts b/src/apps/Cili.ts index 52144f7..62bfabf 100644 --- a/src/apps/Cili.ts +++ b/src/apps/Cili.ts @@ -1,52 +1,50 @@ -import { karin } from 'node-karin' - +import { karin, common,segment,logger } from 'node-karin' export const magnetSearch = karin.command(/^#?磁力搜索\s*(.+)/, async (e) => { - const searchQuery = e.msg.match(/^#?磁力搜索\s*(.+)$/)?.[1] + const searchQuery = e.msg.match(/^#?磁力搜索\s*(.+)$/)?.[1]; if (!searchQuery) { - await e.reply('请输入有效的搜索关键词!', { at: true, recallMsg: 0, reply: true }) - return true + await e.reply('请输入有效的搜索关键词!', { at: true, recallMsg: 0, reply: true }); + return true; } - const url = `https://cili.site/search?q=${encodeURIComponent(searchQuery)}` + const url = `https://cili.site/search?q=${encodeURIComponent(searchQuery)}`; try { - const response = await fetch(url) + const response = await fetch(url); if (!response.ok) { - throw new Error(`请求失败,状态码:${response.status}`) + throw new Error(`请求失败,状态码:${response.status}`); } - const data = await response.text() - const results: { title: string; size: string; link: string }[] = [] + const data = await response.text(); + const results: { title: string; size: string; link: string }[] = []; const regex = - /
([^<]+)<\/p>[\s\S]*?<\/a>[\s\S]*?<\/td>[\s\S]*?
([^<]+)<\/p>[\s\S]*?<\/a>[\s\S]*?<\/td>[\s\S]*?