diff --git a/apps/fun.js b/apps/fun.js index b9f9f48..0576589 100644 --- a/apps/fun.js +++ b/apps/fun.js @@ -64,7 +64,7 @@ export class Fun extends plugin { }, { reg: '^#?半次元话题$', - fnc: 'bcy_topic' + fnc: 'bcyTopic' }, { reg: apiReg, @@ -195,21 +195,9 @@ export class Fun extends plugin { } e.reply(START_EXECUTION) - - const api = 'https://ovooa.caonm.net/API/cosplay/api.php' - - let res - try { - res = await fetch(api).then((res) => res.json()) - } catch (err) { - logger.error(err) - return e.reply(API_ERROR) - } - - const { Title, data } = res.data - const items = _.take(data, 20).map((i) => segment.image(i)) - const msg = [Title, ...items] - common.recallSendForwardMsg(e, msg) + await funApi.coser() + .then(res => common.recallSendForwardMsg(e, res)) + .catch(err => e.reply(err.message)) } // cos/acg搜索 @@ -272,7 +260,7 @@ export class Fun extends plugin { } /** 半次元话题 */ - async bcy_topic (e) { + async bcyTopic (e) { let api = 'https://xiaobai.klizi.cn/API/other/bcy_topic.php' let res = await fetch(api).then(res => res.json()).catch(err => console.log(err)) if (!res) return e.reply(API_ERROR) @@ -284,7 +272,7 @@ export class Fun extends plugin { msg.push(i.title) msg.push(i.image.map(item => segment.image(item))) } - if (_.isEmpty(msg)) return this.bcy_topic(e) + if (_.isEmpty(msg)) return this.bcyTopic(e) common.getforwardMsg(e, msg) } diff --git a/constants/fun.js b/constants/fun.js index 0cd51eb..a91e9cc 100644 --- a/constants/fun.js +++ b/constants/fun.js @@ -1,14 +1,12 @@ /** 点赞成功回复的图片 */ export const successImgs = [ - 'https://api.caonm.net/api/zan/z.php?qq=', - 'http://api.caonm.net/api/bix/b.php?qq=', - 'http://api.caonm.net/api/kan/kan_3.php?qq=', - 'https://api.caonm.net/api/kan/kan.php?qq=' + 'https://xiaobai.klizi.cn/API/ce/xin.php?qq=', + 'https://xiaobai.klizi.cn/API/ce/zan.php?qq=' ] /** 点赞失败回复的图片 */ export const faildsImgs = [ - 'https://ovooa.caonm.net/API/pa/api.php?QQ=' + 'https://xiaobai.klizi.cn/API/ce/paa.php?qq=' ] export const heisiType = { diff --git a/model/api/funApi.js b/model/api/funApi.js index d67b402..144265c 100644 --- a/model/api/funApi.js +++ b/model/api/funApi.js @@ -315,4 +315,28 @@ export default new class { segment.image(gameimg) ] } + + async coser () { + await this._importDependency() + const domain = 'https://t2cy.com' + const homeUrl = `${domain}/acg/cos/index_${_.random(1, 30)}.html` + const home = await request.get(homeUrl).then(res => res.text()) + const $ = cheerio.load(home) + const href = _.sample( + _.map( + $('body > div > div.content.hidden > ul.cy2-coslist.clr > li > div.showImg > a'), + (item) => item.attribs.href + ) + ) + if (!href) throw Error('未知错误') + const imgPage = await request.get(domain + href).then(res => res.text()) + const $1 = cheerio.load(imgPage) + const imgList = _.map( + $1( + 'body > div > div.content.pb20.clr > div.cy_cosCon > div.w.maxImg.tc > p > img' + ), item => segment.image(domain + item.attribs['data-loadsrc'] || item.attribs.src) + ) + const title = $1('h1').text().trim() + return [title, ..._.take(imgList, 20)] + } }()