feat: 增加百科功能

This commit is contained in:
zhiyu1998 2022-11-27 00:21:07 +08:00
parent 5963cbad89
commit e244248b9f
2 changed files with 47 additions and 13 deletions

View File

@ -18,6 +18,7 @@ export class hotSearch extends plugin {
async hotSearch (e) { async hotSearch (e) {
let keyword = e.msg.replace(/#|热搜/g, '').trim() let keyword = e.msg.replace(/#|热搜/g, '').trim()
console.log(keyword)
// 虎扑/知乎/36氪/百度/哔哩哔哩/贴吧/微博/抖音/豆瓣/少数派/IT资讯/微信 // 虎扑/知乎/36氪/百度/哔哩哔哩/贴吧/微博/抖音/豆瓣/少数派/IT资讯/微信
let url = 'https://api.vvhan.com/api/hotlist?type=' let url = 'https://api.vvhan.com/api/hotlist?type='
switch (keyword) { switch (keyword) {
@ -61,22 +62,30 @@ export class hotSearch extends plugin {
url += 'history' url += 'history'
break break
} }
let sendTemplate = {
nickname: this.e.sender.card || this.e.user_id, user_id: this.e.user_id
}
let msg = [] let msg = []
let res = await fetch(url) await fetch(url)
.then((resp) => resp.json()) .then((resp) => resp.json())
.then((resp) => resp.data) .then((resp) => {
.catch((err) => logger.error(err)) for (let element of resp.data) {
res.forEach((element) => { if (_.isUndefined(element)) {
const template = ` continue
标题${ element.title }\n }
简介${ _.isNull(element.desc) ? '' : element.desc }\n const template = `
热度${ element.hot }\n 标题${ _.isNull(element.title) ? '暂无' : element.title}\n
访问详情${ element.url }\n 简介${ _.isNull(element.desc) ? '暂无' : element.desc }\n
` 热度${ _.isNull(element.hot) ? '暂无' : element.hot}\n
msg.push({ 访问详情${ _.isNull(element.url) ? '暂无' : element.url}\n
message: { type: 'text', text: `${ template }` }, nickname: Bot.nickname, user_id: Bot.uin `;
msg.push({
message: { type: 'text', text: `${ template }` },
...sendTemplate
})
}
}) })
}) .catch((err) => logger.error(err))
return !!this.reply(await Bot.makeForwardMsg(msg)) return !!this.reply(await Bot.makeForwardMsg(msg))
} }
} }

View File

@ -33,6 +33,10 @@ export class tools extends plugin {
reg: "(.*)(bilibili.com|b23.tv)", reg: "(.*)(bilibili.com|b23.tv)",
fnc: "bili", fnc: "bili",
}, },
{
reg: "^#(wiki|百科)(.*)$",
fnc: "wiki",
},
], ],
}); });
this.defaultPath = `./data/rcmp4/` this.defaultPath = `./data/rcmp4/`
@ -133,6 +137,27 @@ export class tools extends plugin {
return true return true
} }
async wiki (e) {
const key = e.msg.replace(/#|百科|wiki/g, "").trim();
const url = `https://xiaoapi.cn/API/bk.php?m=json&type=bd&msg=${ encodeURI(key) }`
await axios.get(url, {
headers: {
"User-Agent":
"Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Mobile Safari/537.36",
},
timeout: 10000,
})
.then(resp => {
const data = resp.data
const template = `
解释${ _.isUndefined(data.msg) ? '暂无' : data.msg }\n
详情${ _.isUndefined(data.more) ? '暂无' : data.more }\n
`;
e.reply(template)
})
return true
}
// 请求参数 // 请求参数
async douyinRequest (url) { async douyinRequest (url) {
const params = { const params = {