2024-06-14 10:44:18 +08:00
|
|
|
import { Plugin } from 'yunzai/core'
|
|
|
|
import { gsCfg } from 'yunzai/mys'
|
|
|
|
import fs from 'node:fs'
|
|
|
|
import fetch from 'node-fetch'
|
|
|
|
import { downFile } from 'yunzai/utils'
|
|
|
|
export class material extends Plugin {
|
|
|
|
constructor() {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
name: "角色素材",
|
|
|
|
dsc: "角色养成突破素材",
|
|
|
|
*/
|
|
|
|
super({
|
|
|
|
priority: 500,
|
|
|
|
rule: [
|
|
|
|
{
|
2024-06-17 23:04:18 +08:00
|
|
|
reg: '^#?(星铁)?(.*)(突破|材料|素材|培养)$',
|
|
|
|
fnc: 'material'
|
2024-06-14 10:44:18 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-06-17 23:04:18 +08:00
|
|
|
path = './temp/material/gs/友人A'
|
|
|
|
pathOther = './temp/material/gs/other'
|
|
|
|
srPath = './temp/material/sr/小橙子啊'
|
|
|
|
srPathOther = './temp/material/sr/other'
|
2024-06-14 10:44:18 +08:00
|
|
|
|
2024-06-17 23:04:18 +08:00
|
|
|
url =
|
|
|
|
'https://bbs-api.mihoyo.com/post/wapi/getPostFullInCollection?&gids=2&order_type=2&collection_id='
|
2024-06-14 10:44:18 +08:00
|
|
|
|
|
|
|
collection_id = [428421, 1164644, 1362644]
|
|
|
|
srCollection_id = [1998643, 2146693, 2279356]
|
|
|
|
|
2024-06-17 23:04:18 +08:00
|
|
|
special = [
|
|
|
|
'雷电将军',
|
|
|
|
'珊瑚宫心海',
|
|
|
|
'菲谢尔',
|
|
|
|
'托马',
|
|
|
|
'八重神子',
|
|
|
|
'九条裟罗',
|
|
|
|
'辛焱',
|
|
|
|
'神里绫华'
|
|
|
|
]
|
2024-06-14 10:44:18 +08:00
|
|
|
|
2024-06-17 23:04:18 +08:00
|
|
|
oss =
|
|
|
|
'?x-oss-process=image//resize,s_1000/quality,q_80/auto-orient,0/interlace,1/format,jpg'
|
2024-06-14 10:44:18 +08:00
|
|
|
|
|
|
|
/** 初始化创建配置文件 */
|
|
|
|
async init() {
|
2024-06-17 23:04:18 +08:00
|
|
|
for (let dir of [
|
|
|
|
'./temp',
|
|
|
|
'./temp/material',
|
|
|
|
'./temp/material/gs',
|
|
|
|
'./temp/material/sr',
|
|
|
|
this.path,
|
|
|
|
this.pathOther,
|
|
|
|
this.srPath,
|
|
|
|
this.srPathOther
|
|
|
|
]) {
|
2024-06-14 10:44:18 +08:00
|
|
|
if (!fs.existsSync(dir)) {
|
|
|
|
fs.mkdirSync(dir)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** #刻晴素材 *符玄素材 */
|
|
|
|
async material() {
|
2024-06-17 23:04:18 +08:00
|
|
|
let isUpdate = this.e.msg.includes('更新')
|
|
|
|
let role = gsCfg.getRole(this.e.msg, '星铁|突破|材料|素材|更新')
|
2024-06-14 10:44:18 +08:00
|
|
|
if (!role) return false
|
|
|
|
|
2024-06-17 23:04:18 +08:00
|
|
|
if (
|
|
|
|
['10000005', '10000007', '20000000', '8003', '8001'].includes(
|
|
|
|
String(role.roleId)
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
await this.e.reply('暂无主角素材')
|
2024-06-14 10:44:18 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-17 23:04:18 +08:00
|
|
|
let pathSuffix = this.e.msg.includes('星铁') ? 'sr' : ''
|
|
|
|
this.imgPath = `${this[pathSuffix + 'Path']}/${role.name}.jpg`
|
2024-06-14 10:44:18 +08:00
|
|
|
|
|
|
|
if (fs.existsSync(this.imgPath) && !isUpdate) {
|
|
|
|
await this.e.reply(segment.image(`file://${this.imgPath}`))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-17 23:04:18 +08:00
|
|
|
if (await this[`getImg${pathSuffix ? 'Sr' : ''}`](role.name)) {
|
2024-06-14 10:44:18 +08:00
|
|
|
return await this.e.reply(segment.image(`file://${this.imgPath}`))
|
|
|
|
}
|
|
|
|
|
2024-06-17 23:04:18 +08:00
|
|
|
this.imgPath = `${this[pathSuffix + 'PathOther']}/${role.name}.jpg`
|
2024-06-14 10:44:18 +08:00
|
|
|
|
|
|
|
if (fs.existsSync(this.imgPath) && !isUpdate) {
|
|
|
|
await this.e.reply(segment.image(`file://${this.imgPath}`))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-06-17 23:04:18 +08:00
|
|
|
if (await this[`getImg${pathSuffix ? 'OtherSr' : 'Other'}`](role.name)) {
|
2024-06-14 10:44:18 +08:00
|
|
|
return await this.e.reply(segment.image(`file://${this.imgPath}`))
|
|
|
|
}
|
|
|
|
|
2024-06-17 23:04:18 +08:00
|
|
|
if (await this[`getImg${pathSuffix ? 'Other2Sr' : 'Other2'}`](role.name)) {
|
2024-06-14 10:44:18 +08:00
|
|
|
return await this.e.reply(segment.image(`file://${this.imgPath}`))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 下载攻略图 */
|
|
|
|
async getImg(name) {
|
|
|
|
this.imgPath = `${this.path}/${name}.jpg`
|
|
|
|
|
|
|
|
let ret = await this.getData(this.collection_id[0])
|
|
|
|
|
|
|
|
if (!ret || ret.retcode !== 0) {
|
2024-06-17 23:04:18 +08:00
|
|
|
await this.e.reply('暂无素材数据,请稍后再试')
|
|
|
|
logger.error(`米游社接口报错:${ret.message || '未知错误'}}`)
|
2024-06-14 10:44:18 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
let url
|
|
|
|
for (let val of ret.data.posts) {
|
|
|
|
if (val.post.subject.includes(name)) {
|
|
|
|
url = val.image_list[1].url
|
|
|
|
if (this.special.includes(name)) {
|
|
|
|
url = val.image_list[2].url
|
|
|
|
}
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!url) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.mark(`${this.e.logFnc} 下载${name}素材图`)
|
|
|
|
|
2024-06-17 23:04:18 +08:00
|
|
|
if (!(await downFile(url + this.oss, this.imgPath))) {
|
2024-06-14 10:44:18 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.mark(`${this.e.logFnc} 下载${name}素材成功`)
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
async getImgOther(name) {
|
|
|
|
this.imgPath = `${this.pathOther}/${name}.jpg`
|
|
|
|
|
|
|
|
let ret = await this.getData(this.collection_id[1])
|
|
|
|
|
|
|
|
if (!ret || ret.retcode !== 0) {
|
2024-06-17 23:04:18 +08:00
|
|
|
await this.e.reply('暂无素材数据,请稍后再试')
|
|
|
|
logger.error(`米游社接口报错:${ret.message || '未知错误'}}`)
|
2024-06-14 10:44:18 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
let url
|
|
|
|
for (let val of ret.data.posts) {
|
|
|
|
if (val.post.subject.includes(name)) {
|
|
|
|
url = val.image_list[0].url
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!url) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.mark(`${this.e.logFnc} 下载${name}素材图`)
|
|
|
|
|
2024-06-17 23:04:18 +08:00
|
|
|
if (!(await downFile(url + this.oss, this.imgPath))) {
|
2024-06-14 10:44:18 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.mark(`${this.e.logFnc} 下载${name}素材成功`)
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
async getImgOther2(name) {
|
|
|
|
this.imgPath = `${this.pathOther}/${name}.jpg`
|
|
|
|
|
|
|
|
let ret = await this.getData(this.collection_id[2])
|
|
|
|
|
|
|
|
if (!ret || ret.retcode !== 0) {
|
2024-06-17 23:04:18 +08:00
|
|
|
await this.e.reply('暂无素材数据,请稍后再试')
|
|
|
|
logger.error(`米游社接口报错:${ret.message || '未知错误'}}`)
|
2024-06-14 10:44:18 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
let url
|
|
|
|
for (let val of ret.data.posts) {
|
|
|
|
if (val.post.subject.includes(name)) {
|
|
|
|
url = val.image_list[2].url
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!url) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.mark(`${this.e.logFnc} 下载${name}素材图`)
|
|
|
|
|
2024-06-17 23:04:18 +08:00
|
|
|
if (!(await downFile(url + this.oss, this.imgPath))) {
|
2024-06-14 10:44:18 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.mark(`${this.e.logFnc} 下载${name}素材成功`)
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
async getImgSr(name) {
|
|
|
|
this.imgPath = `${this.srPath}/${name}.jpg`
|
|
|
|
|
|
|
|
let ret = await this.getData(this.srCollection_id[0])
|
|
|
|
|
|
|
|
if (!ret || ret.retcode !== 0) {
|
2024-06-17 23:04:18 +08:00
|
|
|
await this.e.reply('暂无素材数据,请稍后再试')
|
|
|
|
logger.error(`米游社接口报错:${ret.message || '未知错误'}}`)
|
2024-06-14 10:44:18 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
let url
|
|
|
|
for (let val of ret.data.posts) {
|
|
|
|
if (val.post.subject.includes(name)) {
|
|
|
|
url = val.post.images[2]
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!url) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.mark(`${this.e.logFnc} 下载${name}素材图`)
|
|
|
|
|
2024-06-17 23:04:18 +08:00
|
|
|
if (!(await downFile(url + this.oss, this.imgPath))) {
|
2024-06-14 10:44:18 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.mark(`${this.e.logFnc} 下载${name}素材成功`)
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
async getImgOtherSr(name) {
|
|
|
|
this.imgPath = `${this.srPathOther}/${name}.jpg`
|
|
|
|
|
|
|
|
let ret = await this.getData(this.srCollection_id[1])
|
|
|
|
|
|
|
|
if (!ret || ret.retcode !== 0) {
|
2024-06-17 23:04:18 +08:00
|
|
|
await this.e.reply('暂无素材数据,请稍后再试')
|
|
|
|
logger.error(`米游社接口报错:${ret.message || '未知错误'}}`)
|
2024-06-14 10:44:18 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-06-17 23:04:18 +08:00
|
|
|
let url
|
2024-06-14 10:44:18 +08:00
|
|
|
for (let val of ret.data.posts) {
|
|
|
|
if (val.post.subject.includes(name)) {
|
2024-06-17 23:04:18 +08:00
|
|
|
url = val.post.images[0]
|
|
|
|
break
|
2024-06-14 10:44:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!url) {
|
2024-06-17 23:04:18 +08:00
|
|
|
return false
|
2024-06-14 10:44:18 +08:00
|
|
|
}
|
2024-06-17 23:04:18 +08:00
|
|
|
logger.mark(`${this.e.logFnc} 下载${name}素材图`)
|
|
|
|
if (!(await downFile(url + this.oss, this.imgPath))) {
|
|
|
|
return false
|
2024-06-14 10:44:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
logger.mark(`${this.e.logFnc} 下载${name}素材成功`)
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
async getImgOther2Sr(name) {
|
|
|
|
this.imgPath = `${this.srPathOther}/${name}.jpg`
|
|
|
|
|
|
|
|
let ret = await this.getData(this.srCollection_id[2])
|
|
|
|
|
|
|
|
if (!ret || ret.retcode !== 0) {
|
2024-06-17 23:04:18 +08:00
|
|
|
await this.e.reply('暂无素材数据,请稍后再试')
|
|
|
|
logger.error(`米游社接口报错:${ret.message || '未知错误'}}`)
|
2024-06-14 10:44:18 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
let url
|
|
|
|
for (let val of ret.data.posts) {
|
|
|
|
if (val.post.subject.includes(name)) {
|
|
|
|
url = val.image_list[0].url
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!url) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.mark(`${this.e.logFnc} 下载${name}素材图`)
|
|
|
|
|
2024-06-17 23:04:18 +08:00
|
|
|
if (!(await downFile(url + this.oss, this.imgPath))) {
|
2024-06-14 10:44:18 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.mark(`${this.e.logFnc} 下载${name}素材成功`)
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 获取数据 */
|
|
|
|
async getData(collectionId) {
|
2024-06-17 23:04:18 +08:00
|
|
|
let response = await fetch(this.url + collectionId, { method: 'get' })
|
2024-06-14 10:44:18 +08:00
|
|
|
if (!response.ok) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
const res = await response.json()
|
|
|
|
return res
|
|
|
|
}
|
2024-06-17 23:04:18 +08:00
|
|
|
}
|