mirror of
https://github.com/Jerryplusy/rc-plugin.git
synced 2025-10-14 16:19:18 +00:00
✨ feat: 增加百科功能
This commit is contained in:
parent
5963cbad89
commit
e244248b9f
@ -18,6 +18,7 @@ export class hotSearch extends plugin {
|
||||
|
||||
async hotSearch (e) {
|
||||
let keyword = e.msg.replace(/#|热搜/g, '').trim()
|
||||
console.log(keyword)
|
||||
// 虎扑/知乎/36氪/百度/哔哩哔哩/贴吧/微博/抖音/豆瓣/少数派/IT资讯/微信
|
||||
let url = 'https://api.vvhan.com/api/hotlist?type='
|
||||
switch (keyword) {
|
||||
@ -61,22 +62,30 @@ export class hotSearch extends plugin {
|
||||
url += 'history'
|
||||
break
|
||||
}
|
||||
let sendTemplate = {
|
||||
nickname: this.e.sender.card || this.e.user_id, user_id: this.e.user_id
|
||||
}
|
||||
let msg = []
|
||||
let res = await fetch(url)
|
||||
await fetch(url)
|
||||
.then((resp) => resp.json())
|
||||
.then((resp) => resp.data)
|
||||
.catch((err) => logger.error(err))
|
||||
res.forEach((element) => {
|
||||
const template = `
|
||||
标题:${ element.title }\n
|
||||
简介:${ _.isNull(element.desc) ? '' : element.desc }\n
|
||||
热度:${ element.hot }\n
|
||||
访问详情:${ element.url }\n
|
||||
`
|
||||
msg.push({
|
||||
message: { type: 'text', text: `${ template }` }, nickname: Bot.nickname, user_id: Bot.uin
|
||||
.then((resp) => {
|
||||
for (let element of resp.data) {
|
||||
if (_.isUndefined(element)) {
|
||||
continue
|
||||
}
|
||||
const template = `
|
||||
标题:${ _.isNull(element.title) ? '暂无' : element.title}\n
|
||||
简介:${ _.isNull(element.desc) ? '暂无' : element.desc }\n
|
||||
热度:${ _.isNull(element.hot) ? '暂无' : element.hot}\n
|
||||
访问详情:${ _.isNull(element.url) ? '暂无' : element.url}\n
|
||||
`;
|
||||
msg.push({
|
||||
message: { type: 'text', text: `${ template }` },
|
||||
...sendTemplate
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
.catch((err) => logger.error(err))
|
||||
return !!this.reply(await Bot.makeForwardMsg(msg))
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,10 @@ export class tools extends plugin {
|
||||
reg: "(.*)(bilibili.com|b23.tv)",
|
||||
fnc: "bili",
|
||||
},
|
||||
{
|
||||
reg: "^#(wiki|百科)(.*)$",
|
||||
fnc: "wiki",
|
||||
},
|
||||
],
|
||||
});
|
||||
this.defaultPath = `./data/rcmp4/`
|
||||
@ -133,6 +137,27 @@ export class tools extends plugin {
|
||||
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) {
|
||||
const params = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user