Skip to content

Commit

Permalink
refactor(src): 启用 test.handler 中的 reject 调用
Browse files Browse the repository at this point in the history
- 在 test.handler 函数中取消注释并启用 reject 调用
- 此修改旨在测试或使用下一个处理器的功能
  • Loading branch information
MapleLeaf2007 committed Nov 22, 2024
1 parent 791fa98 commit da87752
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 1 deletion.
65 changes: 65 additions & 0 deletions src/apps/TheFilmAndTelevision.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { karin, common, segment } from 'node-karin'
export const magnetSearch = karin.command(/^#?搜影视\\s*(\\S+)$/,
async (e) => await TheFilmAndTelevision(e), {
priority: 9999,
log: true,
name: '搜影视',
permission: 'all',
})
async function TheFilmAndTelevision(e:any) {
const match = e.msg.match(/^#?搜影视\s*(\S+)$/)
const keyword = match ? match[1] : null

if (!keyword) {
return await e.reply('请输入关键词进行搜索!', true)
}

try {
const results = await searchResources(keyword)
if (results.length > 0) {
const forward = results.map((row:any) =>
segment.text(`名称: ${row.title}\n文件大小: ${row.size}\n下载链接: ${row.link}`)
);
const msg = common.makeForward(forward, e.self_id, e.bot.account.name)
await e.bot.sendForwardMessage(e.contact, msg);
} else {
await e.reply('未找到匹配的结果。', true)
}
} catch (error) {
await e.reply(`搜索过程中发生错误:${(error as Error).message}`, true)
}
}

async function searchResources(keyword: string) {
const apiUrl = `https://ysxjjkl.souyisou.top/api_searchtxt.php?name=${encodeURIComponent(keyword)}`

try {
const response = await fetch(apiUrl)
const text = await response.text()

if (text.includes('[可怜]对不起,本资源暂未收录')) {
return []
}

const results = []
const items = text.split('\n名称:').slice(1)

for (const item of items) {
const nameMatch = item.match(/^(.*?)\s*链接:/)
const linkMatch = item.match(/链接:(https:\/\/.+?)(?=\s|$)/)

if (nameMatch && linkMatch) {
results.push({
name: nameMatch[1].trim(),
category: '影视资源',
link: linkMatch[1]
})
}
}

return results
} catch (error) {
console.error('请求出错:', error)
throw new Error('资源搜索失败')
}
}
2 changes: 1 addition & 1 deletion src/apps/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { karin, handler } from 'node-karin'

export const test = karin.handler('test.image', async (args: any, reject: (msg?: string) => void) => {
/** 取消注释告知karin继续使用下一个处理器 */
// reject('继续循环下一个handler')
reject('继续循环下一个handler')
return 'Handler处理完成'
})

Expand Down

0 comments on commit da87752

Please sign in to comment.