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
436ecd1d5c
commit
67c0bf7a0b
3 changed files with 127 additions and 0 deletions
19
apps/help.js
19
apps/help.js
|
|
@ -256,6 +256,25 @@ export class Help extends ZZZPlugin {
|
|||
'添加+角色名+角色图',
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '查看角色面板图',
|
||||
desc: '查看自定义角色面板图,在添加或者删除角色图后,会导致角色图的ID发生变化,此时需要重新获取图片列表来查看ID,否则可能会删除错误的图片',
|
||||
needCK: false,
|
||||
needSK: false,
|
||||
commands: [
|
||||
'查看+角色名+面板图[+页码]',
|
||||
'查看+角色名+角色图[+页码]',
|
||||
'获取+角色名+面板图[+页码]',
|
||||
'获取+角色名+角色图[+页码]',
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '删除角色面板图',
|
||||
desc: '删除自定义角色面板图,在添加或者删除角色图后,会导致角色图的ID发生变化,此时需要重新获取图片列表来查看ID,否则可能会删除错误的图片',
|
||||
needCK: false,
|
||||
needSK: false,
|
||||
commands: ['删除+角色名+面板图', '删除+角色名+角色图'],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -52,6 +52,14 @@ export class Panel extends ZZZPlugin {
|
|||
reg: `${rulePrefix}(上传|添加)(\\S+)(角色|面板)图$`,
|
||||
fnc: 'uploadCharacterImg',
|
||||
},
|
||||
{
|
||||
reg: `${rulePrefix}(获取|查看)(\\S+)(角色|面板)图(\\d+)?$`,
|
||||
fnc: 'getCharacterImages',
|
||||
},
|
||||
{
|
||||
reg: `${rulePrefix}删除(\\S+)(角色|面板)图(.+)$`,
|
||||
fnc: 'deleteCharacterImg',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
|
|
@ -65,5 +73,7 @@ export class Panel extends ZZZPlugin {
|
|||
this.addAlias = manage.alias.addAlias;
|
||||
this.deleteAlias = manage.alias.deleteAlias;
|
||||
this.uploadCharacterImg = manage.panel.uploadCharacterImg;
|
||||
this.getCharacterImages = manage.panel.getCharacterImages;
|
||||
this.deleteCharacterImg = manage.panel.deleteCharacterImg;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import { char } from '../../lib/convert.js';
|
||||
import { downloadFile } from '../../lib/download.js';
|
||||
import { imageResourcesPath } from '../../lib/path.js';
|
||||
import common from '../../../../lib/common/common.js';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
export async function uploadCharacterImg() {
|
||||
if (!this.e.isMaster) {
|
||||
|
|
@ -95,3 +97,99 @@ export async function uploadCharacterImg() {
|
|||
this.reply(`成功上传${success}张图片,失败${failed}张图片。`);
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function getCharacterImages() {
|
||||
const reg = /(获取|查看)(.+)(角色|面板)图(\d+)?$/;
|
||||
const match = this.e.msg.match(reg);
|
||||
if (!match) {
|
||||
return false;
|
||||
}
|
||||
const charName = match[2].trim();
|
||||
const name = char.aliasToName(charName);
|
||||
let page = match[4];
|
||||
if (!name) {
|
||||
this.reply('未找到对应角色');
|
||||
return false;
|
||||
}
|
||||
const pageSize = 5;
|
||||
const resourcesImagesPath = imageResourcesPath;
|
||||
const panelImagesPath = path.join(resourcesImagesPath, `panel/${name}`);
|
||||
const files = fs.readdirSync(panelImagesPath);
|
||||
const images = [];
|
||||
for (const file of files) {
|
||||
images.push(path.join(panelImagesPath, file));
|
||||
}
|
||||
page = Number(page);
|
||||
if (!page || page < 1) {
|
||||
page = 1;
|
||||
}
|
||||
const start = (page - 1) * pageSize;
|
||||
const end = page * pageSize;
|
||||
if (start >= images.length) {
|
||||
this.reply('哪有这么多图片');
|
||||
return false;
|
||||
}
|
||||
const imagePaths = images.slice(start, end);
|
||||
const imageMsg = imagePaths.map(imagePath => {
|
||||
const id = String(images.findIndex(value => value === imagePath) + 1);
|
||||
const msg = [`ID:${id}`, segment.image(imagePath)];
|
||||
return msg;
|
||||
});
|
||||
imageMsg.unshift(
|
||||
`当前页数:${page},总页数:${Math.ceil(
|
||||
images.length / pageSize
|
||||
)},查询指定页数请在指令后面加上页码。`
|
||||
);
|
||||
imageMsg.push(
|
||||
'删除或者添加后会重新排序ID,此时若想删除,请重新获取图片列表,否则可能会删除错误的图片。'
|
||||
);
|
||||
if (imageMsg.length)
|
||||
await this.reply(await common.makeForwardMsg(this.e, imageMsg));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function deleteCharacterImg() {
|
||||
if (!this.e.isMaster) {
|
||||
this.reply('只有主人才能删除');
|
||||
return false;
|
||||
}
|
||||
const reg = /(删除)(.+)(角色|面板)图(.+)$/;
|
||||
const match = this.e.msg.match(reg);
|
||||
if (!match) {
|
||||
return false;
|
||||
}
|
||||
const charName = match[2].trim();
|
||||
const name = char.aliasToName(charName);
|
||||
if (!name) {
|
||||
this.reply('未找到对应角色');
|
||||
return false;
|
||||
}
|
||||
const ids = match[4].split(/[,,、\s]+/);
|
||||
const resourcesImagesPath = imageResourcesPath;
|
||||
const panelImagesPath = path.join(resourcesImagesPath, `panel/${name}`);
|
||||
const files = fs.readdirSync(panelImagesPath);
|
||||
const images = [];
|
||||
for (const file of files) {
|
||||
images.push(path.join(panelImagesPath, file));
|
||||
}
|
||||
const success = [];
|
||||
const failed = [];
|
||||
for (const id of ids) {
|
||||
const index = Number(id) - 1;
|
||||
if (index < 0 || index >= images.length) {
|
||||
failed.push(id);
|
||||
continue;
|
||||
}
|
||||
const imagePath = images[index];
|
||||
fs.unlinkSync(imagePath);
|
||||
success.push(id);
|
||||
}
|
||||
const msgs = [
|
||||
`成功删除ID为${success.join(',')}的图片`,
|
||||
failed ? `删除失败ID为${failed.join(',')}` : '无失败ID',
|
||||
'删除后会重新排序ID,若想要再次删除,请重新获取图片列表,否则可能会删除错误的图片。',
|
||||
];
|
||||
this.reply(common.makeForwardMsg(this.e, msgs));
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue