增加pixiv图片直连设置
This commit is contained in:
38
apps/set.js
38
apps/set.js
@@ -2,7 +2,7 @@ import plugin from '../../../lib/plugins/plugin.js'
|
||||
import fs from 'fs'
|
||||
import lodash from 'lodash'
|
||||
import { Config } from '../components/index.js'
|
||||
import { setu, puppeteer } from '../model/index.js'
|
||||
import { setu, puppeteer, Pixiv } from '../model/index.js'
|
||||
const configs = {
|
||||
好友消息: 'privateMessage',
|
||||
群消息: 'groupMessage',
|
||||
@@ -66,6 +66,11 @@ export class NewConfig extends plugin {
|
||||
fnc: 'proxy',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#(开启|关闭)(p站|pixiv)直连$',
|
||||
fnc: 'proxy',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#(增加|减少|查看)头衔屏蔽词.*$',
|
||||
fnc: 'NoTitle',
|
||||
@@ -83,20 +88,6 @@ export class NewConfig extends plugin {
|
||||
}
|
||||
]
|
||||
})
|
||||
this.proxykey = 'yenai:proxy'
|
||||
this.proxydef = [
|
||||
'i.pixiv.re',
|
||||
'proxy.pixivel.moe',
|
||||
'px2.rainchan.win',
|
||||
'sex.nyan.xyz'
|
||||
]
|
||||
}
|
||||
|
||||
// 初始化
|
||||
async init () {
|
||||
if (!await redis.get(this.proxykey)) {
|
||||
await redis.set(this.proxykey, 'i.pixiv.re')
|
||||
}
|
||||
}
|
||||
|
||||
// 更改配置
|
||||
@@ -216,14 +207,25 @@ export class NewConfig extends plugin {
|
||||
|
||||
// 更换代理
|
||||
async proxy (e) {
|
||||
if (/查看/.test(e.msg)) return e.reply(await redis.get(this.proxykey))
|
||||
let proxykey = 'yenai:proxy'
|
||||
let proxydef = [
|
||||
'i.pixiv.re',
|
||||
'proxy.pixivel.moe',
|
||||
'px2.rainchan.win',
|
||||
'sex.nyan.xyz'
|
||||
]
|
||||
if (/查看/.test(e.msg)) return e.reply(await redis.get(proxykey))
|
||||
let proxy = e.msg.replace(/#|椰奶更换代理/g, '').trim()
|
||||
if (/^[1234]$/.test(proxy)) proxy = this.proxydef[proxy - 1]
|
||||
if (/直连/.test(e.msg)) {
|
||||
proxy = /开启/.test(e.msg) ? 'i.pximg.net' : proxydef[0]
|
||||
}
|
||||
if (/^[1234]$/.test(proxy)) proxy = proxydef[proxy - 1]
|
||||
if (!/([\w\d]+\.){2}[\w\d]+/.test(proxy)) return e.reply('请检查代理地址是否正确')
|
||||
logger.mark(`${e.logFnc}切换为${proxy}`)
|
||||
await redis.set(this.proxykey, proxy)
|
||||
await redis.set(proxykey, proxy)
|
||||
.then(() => e.reply(`✅ 已经切换代理为「${proxy}」`))
|
||||
.catch(err => console.log(err))
|
||||
Pixiv.init()
|
||||
}
|
||||
|
||||
// 查看涩涩设置
|
||||
|
||||
@@ -7,7 +7,8 @@ import moment from 'moment'
|
||||
const API_ERROR = '❎ 出错辣,请稍后重试'
|
||||
export default new class Pixiv {
|
||||
constructor () {
|
||||
this.proxy = 'yenai:proxy'
|
||||
this.proxy = 'i.pixiv.re'
|
||||
this.headers = {}
|
||||
this.ranktype = {
|
||||
日: {
|
||||
type: 'day',
|
||||
@@ -68,6 +69,23 @@ export default new class Pixiv {
|
||||
|
||||
}
|
||||
this.domain = 'http://api.liaobiao.top/api/pixiv'
|
||||
this.init()
|
||||
}
|
||||
|
||||
async init () {
|
||||
this.proxy = await redis.get('yenai:proxy')
|
||||
if (!this.proxy) {
|
||||
await redis.set('yenai:proxy', 'i.pixiv.re')
|
||||
this.proxy = 'i.pixiv.re'
|
||||
}
|
||||
if (this.proxy == 'i.pximg.net') {
|
||||
this.headers = {
|
||||
host: 'i.pximg.net',
|
||||
referer: 'https://www.pixiv.net/'
|
||||
}
|
||||
} else {
|
||||
delete this.headers
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,8 +101,7 @@ export default new class Pixiv {
|
||||
if (res.error) {
|
||||
return { error: res.error?.user_message || '无法获取数据' }
|
||||
}
|
||||
let proxy = await redis.get(this.proxy)
|
||||
let illust = this.format(res.illust, proxy)
|
||||
let illust = this.format(res.illust, this.proxy)
|
||||
let { id, title, user, tags, total_bookmarks, total_view, url, create_date, x_restrict, illust_ai_type } = illust
|
||||
let msg = [
|
||||
`标题:${title}\n`,
|
||||
@@ -112,7 +129,7 @@ export default new class Pixiv {
|
||||
return { error: linkmsg }
|
||||
}
|
||||
|
||||
let img = url.map(item => segment.image(item))
|
||||
let img = url.map(item => segment.image(item, undefined, undefined, this.headers))
|
||||
return { msg, img }
|
||||
}
|
||||
|
||||
@@ -163,10 +180,8 @@ export default new class Pixiv {
|
||||
if (res.error) return { error: res.error.message }
|
||||
if (lodash.isEmpty(res.illusts)) return { error: '暂无数据,请等待榜单更新哦(。-ω-)zzz' }
|
||||
|
||||
let proxy = await redis.get(this.proxy)
|
||||
|
||||
let illusts = res.illusts.map((item, index) => {
|
||||
let list = this.format(item, proxy)
|
||||
let list = this.format(item)
|
||||
let { id, title, user, tags, total_bookmarks, image_urls } = list
|
||||
return [
|
||||
`标题:${title}\n`,
|
||||
@@ -176,7 +191,7 @@ export default new class Pixiv {
|
||||
`点赞:${total_bookmarks}\n`,
|
||||
`排名:${(page - 1) * 30 + (index + 1)}\n`,
|
||||
`Tag:${lodash.truncate(tags)}\n`,
|
||||
segment.image(image_urls.large)
|
||||
segment.image(image_urls.large, undefined, undefined, this.headers)
|
||||
]
|
||||
})
|
||||
let formatDate = res.next_url.match(/date=(\d{4}-\d{1,2}-\d{1,2})/)[1]
|
||||
@@ -226,12 +241,12 @@ export default new class Pixiv {
|
||||
}
|
||||
res.data.rows.sort((a, b) => b.like_total - a.like_total)
|
||||
for (let i of res.data.rows) {
|
||||
let { picture_id, title, regular_url, tags } = i
|
||||
let { picture_id, title, original_url, tags } = i
|
||||
list.push([
|
||||
`标题:${title}\n`,
|
||||
`PID:${picture_id}\n`,
|
||||
`Tag:${lodash.truncate(tags)}\n`,
|
||||
segment.image(regular_url)
|
||||
segment.image(original_url)
|
||||
])
|
||||
}
|
||||
return list
|
||||
@@ -260,12 +275,11 @@ export default new class Pixiv {
|
||||
if (res.error) return { error: res.message }
|
||||
if (lodash.isEmpty(res.illusts)) return { error: '宝~没有数据了哦(๑>︶<)و' }
|
||||
|
||||
let proxy = await redis.get(this.proxy)
|
||||
let illusts = []
|
||||
let filter = 0
|
||||
let NowNum = res.illusts.length
|
||||
for (let i of res.illusts) {
|
||||
let { id, title, user, tags, total_bookmarks, image_urls, x_restrict } = this.format(i, proxy)
|
||||
let { id, title, user, tags, total_bookmarks, image_urls, x_restrict } = this.format(i)
|
||||
if (isfilter && x_restrict) {
|
||||
filter++
|
||||
continue
|
||||
@@ -277,7 +291,7 @@ export default new class Pixiv {
|
||||
`UID:${user.id}\n`,
|
||||
`点赞:${total_bookmarks}\n`,
|
||||
`Tag:${lodash.truncate(tags)}\n`,
|
||||
segment.image(image_urls.large)
|
||||
segment.image(image_urls.large, undefined, undefined, this.headers)
|
||||
])
|
||||
}
|
||||
if (lodash.isEmpty(illusts)) return { error: '该页全为涩涩内容已全部过滤(#/。\#)' }
|
||||
@@ -300,16 +314,15 @@ export default new class Pixiv {
|
||||
if (!res.trend_tags) return { error: '呜呜呜,没有获取到数据(๑ १д१)' }
|
||||
|
||||
let list = []
|
||||
let proxy = await redis.get('yenai:proxy')
|
||||
for (let i of res.trend_tags) {
|
||||
let { tag, translated_name } = i
|
||||
let url = i.illust.image_urls.large.replace('i.pximg.net', proxy)
|
||||
let url = i.illust.image_urls.large.replace('i.pximg.net', this.proxy)
|
||||
list.push(
|
||||
[
|
||||
`Tag:${tag}\n`,
|
||||
`Translated:${translated_name}\n`,
|
||||
`Pid:${i.illust.id}\n`,
|
||||
segment.image(url)
|
||||
segment.image(url, undefined, undefined, this.headers)
|
||||
]
|
||||
)
|
||||
}
|
||||
@@ -333,7 +346,6 @@ export default new class Pixiv {
|
||||
|
||||
keyword = wordlist.data.rows[0].user.id
|
||||
}
|
||||
let proxy = await redis.get(this.proxy)
|
||||
// let userapi = `https://api.obfs.dev/api/pixiv/member?id=${keyword}`
|
||||
// let user = await fetch(userapi).then(res => res.json()).catch(err => console.log(err))
|
||||
// if (!user) return { error: API_ERROR }
|
||||
@@ -367,7 +379,7 @@ export default new class Pixiv {
|
||||
let filter = 0
|
||||
let NowNum = res.illusts.length
|
||||
for (let i of res.illusts) {
|
||||
let { id: pid, title, tags, total_bookmarks, total_view, url, x_restrict } = this.format(i, proxy)
|
||||
let { id: pid, title, tags, total_bookmarks, total_view, url, x_restrict } = this.format(i)
|
||||
if (isfilter && x_restrict) {
|
||||
filter++
|
||||
continue
|
||||
@@ -378,7 +390,7 @@ export default new class Pixiv {
|
||||
`点赞:${total_bookmarks}\n`,
|
||||
`访问:${total_view}\n`,
|
||||
`Tag:${lodash.truncate(tags)}\n`,
|
||||
segment.image(url[0])
|
||||
segment.image(url[0], undefined, undefined, this.headers)
|
||||
])
|
||||
}
|
||||
if (lodash.isEmpty(illusts)) return { error: '该页全为涩涩内容已全部过滤(#/。\#)' }
|
||||
@@ -390,7 +402,7 @@ export default new class Pixiv {
|
||||
// list.push(...illusts)
|
||||
return [
|
||||
[
|
||||
segment.image(profile_image_urls.medium.replace('i.pximg.net', proxy)),
|
||||
segment.image(profile_image_urls.medium.replace('i.pximg.net', this.proxy), undefined, undefined, this.headers),
|
||||
`\nUid:${uid}\n`,
|
||||
`画师:${name}\n`
|
||||
],
|
||||
@@ -417,7 +429,7 @@ export default new class Pixiv {
|
||||
`点赞: ${like_total}\n`,
|
||||
`插画ID:${picture_id}\n`,
|
||||
`Tag:${lodash.truncate(tags)}\n`,
|
||||
segment.image(regular_url)
|
||||
segment.image(regular_url, undefined, undefined, this.headers)
|
||||
])
|
||||
}
|
||||
return list
|
||||
@@ -435,11 +447,10 @@ export default new class Pixiv {
|
||||
if (res.error) return { error: res.error.user_message }
|
||||
if (lodash.isEmpty(res.illusts)) return { error: '呃...没有数据(•ิ_•ิ)' }
|
||||
|
||||
let proxy = await redis.get(this.proxy)
|
||||
let illusts = []
|
||||
let filter = 0
|
||||
for (let i of res.illusts) {
|
||||
let { id, title, user, tags, total_bookmarks, image_urls, x_restrict } = this.format(i, proxy)
|
||||
let { id, title, user, tags, total_bookmarks, image_urls, x_restrict } = this.format(i)
|
||||
if (isfilter && x_restrict) {
|
||||
filter++
|
||||
continue
|
||||
@@ -451,7 +462,7 @@ export default new class Pixiv {
|
||||
`UID:${user.id}\n`,
|
||||
`点赞:${total_bookmarks}\n`,
|
||||
`Tag:${lodash.truncate(tags)}\n`,
|
||||
segment.image(image_urls.large)
|
||||
segment.image(image_urls.large, undefined, undefined, this.headers)
|
||||
])
|
||||
}
|
||||
if (lodash.isEmpty(illusts)) return { error: '啊啊啊!!!居然全是瑟瑟哒不给你看(*/ω\*)' }
|
||||
@@ -478,7 +489,7 @@ export default new class Pixiv {
|
||||
`标题:${title}\n`,
|
||||
`画师:${author}\n`,
|
||||
`Tag:${tags.join(',')}\n`,
|
||||
segment.image(urls.original.replace('i.der.ink', await redis.get('yenai:proxy')))
|
||||
segment.image(urls.original.replace('i.der.ink', this.proxy), undefined, undefined, this.headers)
|
||||
]
|
||||
return msg
|
||||
}
|
||||
@@ -496,19 +507,18 @@ export default new class Pixiv {
|
||||
/**
|
||||
* @description: 格式化
|
||||
* @param {Object} illusts 处理对象
|
||||
* @param {Object} proxy 代理
|
||||
* @return {Object}
|
||||
*/
|
||||
format (illusts, proxy) {
|
||||
format (illusts) {
|
||||
let url = []
|
||||
let { id, title, tags, total_bookmarks, total_view, meta_single_page, meta_pages, user, image_urls, x_restrict, create_date, illust_ai_type, visible } = illusts
|
||||
tags = lodash.uniq(lodash.compact(lodash.flattenDeep(tags?.map(item => Object.values(item)))))
|
||||
if (!lodash.isEmpty(meta_single_page)) {
|
||||
url.push(meta_single_page.original_image_url.replace('i.pximg.net', proxy))
|
||||
url.push(meta_single_page.original_image_url.replace('i.pximg.net', this.proxy))
|
||||
} else {
|
||||
url = meta_pages.map(item => item.image_urls.original.replace('i.pximg.net', proxy))
|
||||
url = meta_pages.map(item => item.image_urls.original.replace('i.pximg.net', this.proxy))
|
||||
}
|
||||
image_urls = lodash.mapValues(image_urls, (item) => item.replace('i.pximg.net', proxy))
|
||||
image_urls = lodash.mapValues(image_urls, (item) => item.replace('i.pximg.net', this.proxy))
|
||||
|
||||
return {
|
||||
title, // 标题
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { segment } from 'oicq'
|
||||
import fetch from 'node-fetch'
|
||||
import { common } from './index.js'
|
||||
import { common, Pixiv } from './index.js'
|
||||
import { Data } from '../components/index.js'
|
||||
import lodash from 'lodash'
|
||||
|
||||
@@ -38,11 +38,10 @@ export default new class setu {
|
||||
if (apicfg.api) api = apicfg.api
|
||||
|
||||
let size = 'original'
|
||||
let proxy = await redis.get('yenai:proxy')
|
||||
if (num > 6) {
|
||||
size = 'regular'
|
||||
}
|
||||
let url = `${api}?r18=${r18}&num=${num}${tag}&proxy=${proxy}&size=${size}`
|
||||
let url = `${api}?r18=${r18}&num=${num}${tag}&proxy=${Pixiv.proxy}&size=${size}`
|
||||
let result = await fetch(url).then(res => res.json()).catch(err => console.log(err))
|
||||
if (!result) {
|
||||
logger.warn(`${e.logFnc}使用备用接口`)
|
||||
@@ -67,7 +66,7 @@ export default new class setu {
|
||||
`pid:${pid}\n`,
|
||||
r18 !== undefined ? `r18:${r18}\n` : '',
|
||||
`tag:${lodash.truncate(tags.join(','))}\n`,
|
||||
segment.image(url || urls?.original || urls?.regular || urls?.small)
|
||||
segment.image(url || urls?.original || urls?.regular || urls?.small, undefined, undefined, Pixiv.headers)
|
||||
]
|
||||
})
|
||||
return msg
|
||||
|
||||
Reference in New Issue
Block a user