Merge remote-tracking branch 'origin/main' into main

This commit is contained in:
yysforget 2024-07-11 13:47:32 +08:00
commit 25dd6b012a
4 changed files with 96 additions and 42 deletions

View file

@ -13,6 +13,11 @@
```bash
git clone --depth=1 https://github.com/ZZZure/ZZZ-Plugin.git ./plugins/ZZZ-Plugin
```
> [!tip]
> 如果您的网络环境较差,建议使用代理加速
> ```
> git clone --depth=1 https://mirror.ghproxy.com/https://github.com/ZZZure/ZZZ-Plugin.git ./plugins/ZZZ-Plugin
> ```
安装后重启Yunzai即可使用。

View file

@ -1,13 +1,15 @@
import {ZZZPlugin} from '../lib/plugin.js';
import {rulePrefix} from '../lib/common.js';
import {ZZZPlugin} from '../lib/plugin.js'
import {rulePrefix} from '../lib/common.js'
import {atlasToName} from '../lib/convert/char.js'
import path from 'path';
import fs from 'fs';
import path from 'path'
import fs from 'fs'
import {imageResourcesPath} from '../lib/path.js'
import fetch from 'node-fetch'
import lodash from 'lodash'
const ZZZ_GUIDES_PATH = path.join(imageResourcesPath, 'guides');
const ZZZ_GUIDES_PATH = path.join(imageResourcesPath, 'guides')
// 最大攻略数量
const maxNum = 2
export class Guide extends ZZZPlugin {
constructor() {
@ -18,7 +20,7 @@ export class Guide extends ZZZPlugin {
priority: 100,
rule: [
{
reg: `${rulePrefix}角色攻略\\S+$`,
reg: `${rulePrefix}(更新)?\\S+攻略([0-${maxNum}])?$`,
fnc: 'Guide',
},
],
@ -29,28 +31,73 @@ export class Guide extends ZZZPlugin {
[],
// 来源:新艾利都快讯
[2712859],
[2727116]
]
this.source = [
'新艾利都快讯',
'清茶沐沐Kiyotya'
]
this.source = ['新艾利都快讯']
}
async init () {
for (let group = 1; group <= maxNum; group++) {
let guideFolder = this.getGuideFolder(group)
if (!fs.existsSync(guideFolder)) {
fs.mkdirSync(guideFolder, { recursive: true })
}
}
}
getGuideFolder(groupIndex) {
let guideFolder = path.join(ZZZ_GUIDES_PATH, this.source[groupIndex-1])
return guideFolder
}
getGuidePath(groupIndex, characterName) {
let filename = `role_guide_${characterName}.png`
let guidePath = path.join(this.getGuideFolder(groupIndex), filename)
return guidePath
}
async Guide() {
let reg = new RegExp(`${rulePrefix}角色攻略(\\S+)$`);
let [,,,, name] = this.e.msg.match(reg);
let id = atlasToName(name);
logger.warn('123')
let reg = new RegExp(`${rulePrefix}(更新)?(\\S+)攻略([0-${maxNum}])?$`)
let [,,,, isUpdate, name,
group = 1 // setting.getConfig('mys')?.defaultSource
] = this.e.msg.match(reg)
let id = atlasToName(name)
if (!id) {
await this.reply('该角色不存在');
return;
}
const filename = `role_guide_${id}.png`;
const guidePath = path.join(ZZZ_GUIDES_PATH, filename);
if (fs.existsSync(guidePath)) {
await this.e.reply(segment.image(`file://${guidePath}`));
return;
}
//目前攻略较少,暂为1
if (await this.getImg(id, 1)) {
await this.e.reply(segment.image(`file://${guidePath}`))
await this.reply('该角色不存在')
return
}
if (group === 0) {
// eslint-disable-next-line no-unused-vars
let msg = []
// eslint-disable-next-line no-unused-vars
for (let i = 1; i <= maxNum; i++) {
let guildePath = this.getGuidePath(i, name)
if (fs.existsSync(this.sfPath) && !isUpdate) {
msg.push(segment.image(`file://${guidePath}`))
continue
}
if (i < 4 && await this.getImg(role, i)) {
msg.push(segment.image(`file://${guidePath}`))
}
}
if (msg.length) { await this.reply(await common.makeForwardMsg(this.e, [msg])) }
return false
}
let guidePath = this.getGuidePath(group, name)
if (fs.existsSync(guidePath)) {
await this.e.reply(segment.image(`file://${guidePath}`))
return
}
if (await this.getImg(name, group)) {
await this.e.reply(segment.image(`file://${guidePath}`))
}
}
/** 下载攻略图 */
@ -84,15 +131,11 @@ export class Guide extends ZZZPlugin {
}
console.log(`${this.e.logFnc} 下载${name}攻略图`)
const download = await fetch(url);
const arrayBuffer = await download.arrayBuffer();
const buffer = Buffer.from(arrayBuffer);
const filename = `role_guide_${name}.png`;
const avatarPath = path.join(ZZZ_GUIDES_PATH, filename);
if (!fs.existsSync(ZZZ_GUIDES_PATH)) {
fs.mkdirSync(ZZZ_GUIDES_PATH, { recursive: true });
}
fs.writeFileSync(avatarPath , buffer);
const download = await fetch(url)
const arrayBuffer = await download.arrayBuffer()
const buffer = Buffer.from(arrayBuffer)
let guidePath = this.getGuidePath(group, name)
fs.writeFileSync(guidePath , buffer)
console.log(`${this.e.logFnc} 下载${name}攻略成功`)

View file

@ -7,7 +7,6 @@ import MysApi from '../../genshin/model/mys/mysApi.js';
// const DEVICE_ID = randomString(32).toUpperCase()
const DEVICE_NAME = randomString(_.random(1, 10));
const game_region = [
'prod_gf_cn',
'prod_gf_cn',
'prod_gf_us',
'prod_gf_eu',
@ -38,13 +37,13 @@ export default class MysZZZApi extends MysApi {
}
switch (_uid.slice(0, -8)) {
case '10':
return game_region[2]; // 美服
return game_region[1]; // 美服
case '15':
return game_region[3]; // 欧服
return game_region[2]; // 欧服
case '13':
return game_region[4]; // 亚服
return game_region[3]; // 亚服
case '17':
return game_region[5]; // 港澳台服
return game_region[4]; // 港澳台服
}
}
@ -102,9 +101,9 @@ export default class MysZZZApi extends MysApi {
getDs(q = '', b = '') {
let n = '';
if (['prod_gf_cn', 'prod_qd_cn'].includes(this.server)) {
if (['prod_gf_cn'].includes(this.server)) {
n = 'xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs';
} else if (/prod_gf_/.test(this.server)) {
} else {
n = 'okr4obncj8bw5a65hbnn5oo6ixjc3l9w';
}
let t = Math.round(new Date().getTime() / 1000);
@ -140,10 +139,10 @@ export default class MysZZZApi extends MysApi {
Referer: 'https://act.hoyolab.com/',
};
let client;
if (/official/.test(this.server)) {
client = os;
} else {
if (['prod_gf_cn'].includes(this.server)) {
client = cn;
} else {
client = os;
}
return {
'x-rpc-app_version': client.app_version,

View file

@ -23,7 +23,7 @@ export default class ZZZApiTool {
host = 'https://api-takumi.mihoyo.com/';
hostRecord = 'https://api-takumi-record.mihoyo.com/';
hostPublicData = 'https://public-data-api.mihoyo.com/';
} else if (/prod_gf_/.test(this.server)) {
} else {
host = 'https://sg-public-api.hoyolab.com/';
hostRecord = 'https://bbs-api-os.hoyolab.com/';
hostPublicData = 'https://sg-public-data-api.hoyoverse.com/';
@ -90,6 +90,13 @@ export default class ZZZApiTool {
},
},
};
if (/_us|_eu|_jp|_sg/.test(this.server)) {
urlMap.zzz.zzzNote.url = 'https://sg-act-nap-api.hoyolab.com/event/game_record_zzz/api/zzz/note'
urlMap.zzz.zzzNote.query = `role_id=${this.uid}&server=${this.server}`
urlMap.zzz.zzzIndex.url = 'https://sg-act-nap-api.hoyolab.com/event/game_record_zzz/api/zzz/index'
urlMap.zzz.zzzIndex.query = `lang=zh-cn&role_id=${this.uid}&server=${this.server}`
};
return urlMap[this.game];
};
}