mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-16 13:17:32 +00:00
feat: 自定义角色图上传
This commit is contained in:
parent
be1c00db59
commit
64275de0e8
11 changed files with 498 additions and 326 deletions
|
|
@ -10,6 +10,7 @@ import _ from 'lodash';
|
|||
import settings from '../lib/settings.js';
|
||||
import { downloadFile } from '../lib/download.js';
|
||||
import { char } from '../lib/convert.js';
|
||||
import guides from '../lib/guides.js';
|
||||
|
||||
const ZZZ_GUIDES_PATH = path.join(imageResourcesPath, 'guides');
|
||||
|
||||
|
|
@ -34,39 +35,13 @@ export class Guide extends ZZZPlugin {
|
|||
|
||||
this.url =
|
||||
'https://bbs-api.mihoyo.com/post/wapi/getPostFullInCollection?&gids=8&collection_id=';
|
||||
this.collection_id = [
|
||||
[],
|
||||
// 来源:新艾利都快讯
|
||||
[2712859],
|
||||
[2727116],
|
||||
[2721968],
|
||||
[2724610],
|
||||
[2722266],
|
||||
[2723586],
|
||||
[2716049],
|
||||
];
|
||||
this.source = [
|
||||
'新艾利都快讯',
|
||||
'清茶沐沐Kiyotya',
|
||||
'小橙子阿',
|
||||
'猫冬',
|
||||
'月光中心',
|
||||
'苦雪的清心花凉糕Suki',
|
||||
'HoYo青枫',
|
||||
];
|
||||
// 最大攻略数量
|
||||
this.maxNum = this.source.length;
|
||||
|
||||
// 最大显示攻略数量
|
||||
this.maxForwardGuides = _.get(
|
||||
settings.getConfig('guide'),
|
||||
'max_forward_guides',
|
||||
4
|
||||
);
|
||||
}
|
||||
|
||||
getGuideFolder(groupIndex) {
|
||||
let guideFolder = path.join(ZZZ_GUIDES_PATH, this.source[groupIndex - 1]);
|
||||
let guideFolder = path.join(
|
||||
ZZZ_GUIDES_PATH,
|
||||
guides.guideSources[groupIndex - 1]
|
||||
);
|
||||
return guideFolder;
|
||||
}
|
||||
|
||||
|
|
@ -93,10 +68,14 @@ export class Guide extends ZZZPlugin {
|
|||
group = '0';
|
||||
}
|
||||
group = Number(group);
|
||||
if (group > this.maxNum) {
|
||||
await this.reply(`超过攻略数量(${this.maxNum})`);
|
||||
if (group > guides.guideMaxNum) {
|
||||
await this.reply(`超过攻略数量(${guides.guideMaxNum})`);
|
||||
return false;
|
||||
}
|
||||
if (alias === '设置默认' || alias === '设置所有') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const name = char.aliasToName(alias);
|
||||
|
||||
if (!name) {
|
||||
|
|
@ -106,13 +85,18 @@ export class Guide extends ZZZPlugin {
|
|||
|
||||
if (group === 0) {
|
||||
const msg = [];
|
||||
for (let i = 1; i <= this.maxNum; i++) {
|
||||
for (
|
||||
let i = 1;
|
||||
i <=
|
||||
Number(_.get(settings.getConfig('guide'), 'max_forward_guides', 4));
|
||||
i++
|
||||
) {
|
||||
const guidePath = await this.getGuidePath(i, name, !!isUpdate);
|
||||
// msg.push(segment.image(`file://${guidePath}`));
|
||||
if (guidePath) {
|
||||
msg.push(segment.image(guidePath));
|
||||
} else {
|
||||
msg.push(`暂无${name}攻略 (${this.source[i - 1]})`);
|
||||
msg.push(`暂无${name}攻略 (${guides.guideSources[i - 1]})`);
|
||||
}
|
||||
}
|
||||
if (msg.length) {
|
||||
|
|
@ -124,7 +108,9 @@ export class Guide extends ZZZPlugin {
|
|||
const guidePath = await this.getGuidePath(group, name, !!isUpdate);
|
||||
if (!guidePath) {
|
||||
this.e.reply(
|
||||
`暂无${name}攻略 (${this.source[group - 1]})\n请尝试其他的攻略来源查询`
|
||||
`暂无${name}攻略 (${
|
||||
guides.guideSources[group - 1]
|
||||
})\n请尝试其他的攻略来源查询`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
|
@ -135,7 +121,7 @@ export class Guide extends ZZZPlugin {
|
|||
/** 下载攻略图 */
|
||||
async getImg(name, group) {
|
||||
let mysRes = [];
|
||||
this.collection_id[group].forEach(id =>
|
||||
guides.collection_id[group].forEach(id =>
|
||||
mysRes.push(this.getData(this.url + id))
|
||||
);
|
||||
|
||||
|
|
@ -150,7 +136,7 @@ export class Guide extends ZZZPlugin {
|
|||
// 搜索时过滤特殊符号,譬如「11号」
|
||||
const filtered_name = name.replace(/[^a-zA-Z0-9\u4e00-\u9fa5]/g, '');
|
||||
let posts = lodash.flatten(lodash.map(mysRes, item => item.data.posts));
|
||||
let url, created_at, updated_at;
|
||||
let url;
|
||||
for (const val of posts) {
|
||||
if (
|
||||
val.post.subject
|
||||
|
|
@ -176,7 +162,7 @@ export class Guide extends ZZZPlugin {
|
|||
return false;
|
||||
}
|
||||
logger.debug(
|
||||
`${this.e.logFnc} 下载${name}攻略图 - ${this.source[group - 1]}`
|
||||
`${this.e.logFnc} 下载${name}攻略图 - ${guides.guideSources[group - 1]}`
|
||||
);
|
||||
|
||||
const filename = `role_guide_${name}.png`;
|
||||
|
|
@ -184,7 +170,7 @@ export class Guide extends ZZZPlugin {
|
|||
const download = await downloadFile(url, guidePath);
|
||||
|
||||
logger.debug(
|
||||
`${this.e.logFnc} 下载${name}攻略成功 - ${this.source[group - 1]}`
|
||||
`${this.e.logFnc} 下载${name}攻略成功 - ${guides.guideSources[group - 1]}`
|
||||
);
|
||||
|
||||
return download;
|
||||
|
|
@ -210,7 +196,9 @@ export class Guide extends ZZZPlugin {
|
|||
'示例: %艾莲攻略2',
|
||||
'',
|
||||
'攻略来源:',
|
||||
].concat(this.source.map((element, index) => `${index + 1}: ${element}`));
|
||||
].concat(
|
||||
guides.guideSources.map((element, index) => `${index + 1}: ${element}`)
|
||||
);
|
||||
await this.e.reply(reply_msg.join('\n'));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue