diff --git a/README.md b/README.md index 9198a8d..9fa496a 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,7 @@ Tip:具体可使用 **#椰奶群管帮助** 查看 - [SauceNAO](https://saucenao.com/) - [Ascii2D](https://ascii2d.net/) - [trace.moe](https://trace.moe) ([GitHub](https://github.com/soruly/trace.moe)) +- [vilipix](https://www.vilipix.com/) ### 贡献者 ✨ @@ -252,6 +253,7 @@ Tip:具体可使用 **#椰奶群管帮助** 查看 - [Yunzai-Bot插件索引](https://gitee.com/Hikari666/Yunzai-Bot-plugins-index) - [码云镜像库](https://gitee.com/yeyang52/yenai-plugin) +- [Miao-Yunzai](https://gitee.com/yoimiya-kokomi/miao-plugin) ## 免责声明 ❗ diff --git a/apps/pixiv.js b/apps/pixiv.js index 223deab..ee31850 100644 --- a/apps/pixiv.js +++ b/apps/pixiv.js @@ -2,6 +2,7 @@ import plugin from '../../../lib/plugins/plugin.js' import { Config } from '../components/index.js' import { Pixiv, common, setu } from '../model/index.js' import { Setting } from './setting.js' +import { ImageRPSS } from '../tools/pixiv.js' // 文案 const SWITCH_ERROR = '主人没有开放这个功能哦(*/ω\*)' // 汉字数字匹配正则 @@ -28,7 +29,7 @@ export class NewPixiv extends plugin { }, { reg: rankingrReg, - fnc: 'pixivRanking' + fnc: 'pixivRank' }, { reg: tagReg, @@ -44,15 +45,15 @@ export class NewPixiv extends plugin { }, { reg: randomImgReg, - fnc: 'randomImg' + fnc: 'vilipixRandomImg' }, { reg: '^#?(查看|获取)?热门(t|T)(a|A)(g|G)$', - fnc: 'PopularTags' + fnc: 'popularTags' }, { reg: '^#?看?看?相关作品(\\d+)$', - fnc: 'related' + fnc: 'relatedIllust' }, { reg: '^#来(\\d+)?张推荐图$', @@ -86,7 +87,8 @@ export class NewPixiv extends plugin { if (!await this._Authentication(e, 'sese')) return e.reply(Pixiv.startMsg) let regRet = pidReg.exec(e.msg) - await Pixiv.illust(regRet[1], !e.isMaster && !setu.getR18(e.group_id)) + let filter = !e.isMaster && !setu.getR18(e.group_id) + await Pixiv.illust(regRet[1], filter) .then(async res => { await e.reply(res.msg) res.img.length == 1 ? common.recallsendMsg(e, res.img) : common.getRecallsendMsg(e, res.img, false) @@ -95,10 +97,12 @@ export class NewPixiv extends plugin { } // p站排行榜 - async pixivRanking (e) { - if (!await this._Authentication(e, 'sese')) return + async pixivRank (e) { let regRet = rankingrReg.exec(e.msg) - if ((regRet[4] && !setu.getR18(e.group_id)) && !e.isMaster) return e.reply(SWITCH_ERROR) + if (!await this._Authentication(e, 'sese')) return + if ((regRet[4] && !setu.getR18(e.group_id)) && !e.isMaster) { + return e.reply(SWITCH_ERROR) + } e.reply(Pixiv.startMsg) @@ -117,13 +121,13 @@ export class NewPixiv extends plugin { e.reply(Pixiv.startMsg) let page = common.translateChinaNum(regRet[4]) - await Pixiv[`searchTags${regRet[1] ? 'pro' : ''}`](regRet[2], page, !setu.getR18(e.group_id)) + await Pixiv[`${regRet[1] ? 's' : 'vilipixS'}earchTags`](regRet[2], page, !setu.getR18(e.group_id)) .then(res => common.getRecallsendMsg(e, res)) .catch(err => e.reply(err.message)) } /** 获取热门tag */ - async PopularTags (e) { + async popularTags (e) { if (!await this._Authentication(e, 'sese')) return e.reply(Pixiv.startMsg) await Pixiv.PopularTags() @@ -146,7 +150,7 @@ export class NewPixiv extends plugin { } // 随机原创插画 - async randomImg (e) { + async vilipixRandomImg (e) { if (!await this._Authentication(e, 'sese')) return e.reply(Pixiv.startMsg) let regRet = randomImgReg.exec(e.msg) @@ -157,19 +161,19 @@ export class NewPixiv extends plugin { num = 1 } num = common.translateChinaNum(num) - await Pixiv.randomImg(num) + await Pixiv.vilipixRandomImg(num) .then(res => common.getRecallsendMsg(e, res)) .catch(err => e.reply(err.message)) } // 相关作品 - async related (e) { + async relatedIllust (e) { if (!await this._Authentication(e, 'sese')) return e.reply(Pixiv.startMsg) let regRet = e.msg.match(/\d+/) - await Pixiv.related(regRet[0], !setu.getR18(e.group_id)) + await Pixiv.relatedIllust(regRet[0], !setu.getR18(e.group_id)) .then(res => common.getRecallsendMsg(e, res)) .catch(err => e.reply(err.message)) } @@ -212,16 +216,14 @@ export class NewPixiv extends plugin { // 更换代理 async setProxy (e) { - let proxydef = [ - 'i.pixiv.re', - 'proxy.pixivel.moe', - 'px2.rainchan.win', - 'sex.nyan.xyz' - ] if (/查看/.test(e.msg)) return e.reply(await redis.get('yenai:proxy')) let proxy = e.msg.replace(/#|(p站|pixiv)更换代理/g, '').trim() - if (/^[1234]$/.test(proxy)) proxy = proxydef[proxy - 1] - if (!/([\w\d]+\.){2}[\w\d]+/.test(proxy)) return e.reply('请检查代理地址是否正确') + if (new RegExp(`^[1-${ImageRPSS.length}]$`).test(proxy)) { + proxy = ImageRPSS[proxy - 1] + } + if (!/([\w\d]+\.){2}[\w\d]+/.test(proxy)) { + return e.reply('请检查代理地址是否正确') + } logger.mark(`${e.logFnc}切换为${proxy}`) Config.modify('pixiv', 'pixivImageProxy', proxy) new Setting().SeSe_Settings(e) diff --git a/model/Pixiv.js b/model/Pixiv.js index 6da35c8..8d169d6 100644 --- a/model/Pixiv.js +++ b/model/Pixiv.js @@ -180,7 +180,7 @@ export default new class Pixiv { * @param {String} page 页数 * @return {Array} */ - async searchTags (tag, page = 1) { + async vilipixSearchTags (tag, page = 1) { const api = 'https://www.vilipix.com/api/v1/picture/public' const params = { limit: 30, @@ -220,7 +220,7 @@ export default new class Pixiv { * @param {String} page 页数 * @return {*} */ - async searchTagspro (tag, page = 1, isfilter = true) { + async searchTags (tag, page = 1, isfilter = true) { const params = { word: tag, page, @@ -405,26 +405,23 @@ export default new class Pixiv { } /** - * @description: 随机图片 + * @description: vilipix随机图片 * @return {Array} */ - async randomImg (limit) { + async vilipixRandomImg (limit) { let api = `https://www.vilipix.com/api/v1/picture/recommand?limit=${limit}&offset=${_.random(1, 700)}` let res = await request.get(api).then(res => res.json()) if (!res.data || !res.data.rows) throw Error('呜呜呜,没拿到瑟瑟的图片(˃ ⌑ ˂ഃ )') - - let list = [] - for (let i of res.data.rows) { - let { picture_id, title, regular_url, tags, like_total } = i - list.push([ + return res.data.rows.map(item => { + let { picture_id, title, regular_url, tags, like_total } = item + return [ `标题:${title}\n`, `点赞: ${like_total}\n`, `插画ID:${picture_id}\n`, `Tag:${_.truncate(tags)}\n`, - await this._requestPixivImg(regular_url) - ]) - } - return list + segment.image(regular_url) + ] + }) } /** @@ -432,7 +429,7 @@ export default new class Pixiv { * @param {String} pid * @return {*} */ - async related (pid, isfilter = true) { + async relatedIllust (pid, isfilter = true) { let params = { id: pid } let res = null if (this.PixivClient) { diff --git a/tools/pixiv.js b/tools/pixiv.js index 78fc3cf..814b196 100644 --- a/tools/pixiv.js +++ b/tools/pixiv.js @@ -81,3 +81,9 @@ export const rankType = { r18: false } } +export const ImageRPSS = [ + 'i.pixiv.re', + 'proxy.pixivel.moe', + 'px2.rainchan.win', + 'sex.nyan.xyz' +]