feat: 管理指令

This commit is contained in:
bietiaop 2024-08-01 16:52:48 +08:00
parent f08f149fa6
commit be1c00db59
8 changed files with 283 additions and 31 deletions

View file

@ -5,11 +5,11 @@ import lodash from 'lodash';
import common from '../../../lib/common/common.js';
import { ZZZPlugin } from '../lib/plugin.js';
import { rulePrefix } from '../lib/common.js';
import { atlasToName } from '../lib/convert/char.js';
import { imageResourcesPath } from '../lib/path.js';
import _ from 'lodash';
import settings from '../lib/settings.js';
import { downloadFile } from '../lib/download.js';
import { char } from '../lib/convert.js';
const ZZZ_GUIDES_PATH = path.join(imageResourcesPath, 'guides');
@ -85,7 +85,7 @@ export class Guide extends ZZZPlugin {
,
,
isUpdate,
atlas,
alias,
group = _.get(settings.getConfig('guide'), 'default_guide', 1).toString(),
] = this.e.msg.match(reg);
// all -> 0
@ -97,7 +97,7 @@ export class Guide extends ZZZPlugin {
await this.reply(`超过攻略数量(${this.maxNum}`);
return false;
}
const name = atlasToName(atlas);
const name = char.aliasToName(alias);
if (!name) {
await this.reply('该角色不存在');

View file

@ -209,6 +209,41 @@ export class Help extends ZZZPlugin {
needSK: false,
commands: ['设置所有攻略显示个数+1~7'],
},
{
title: '设置渲染精度',
desc: '设置插件的渲染精度可选值50~200建议100',
needCK: false,
needSK: false,
commands: ['设置渲染精度+50~200'],
},
{
title: '刷新抽卡间隔',
desc: '设置刷新抽卡记录的冷却时间单位为秒取值范围为01000',
needCK: false,
needSK: false,
commands: ['刷新抽卡间隔+0~1000'],
},
{
title: '刷新面板间隔',
desc: '设置刷新面板的冷却时间单位为秒取值范围为01000',
needCK: false,
needSK: false,
commands: ['刷新面板间隔+0~1000'],
},
{
title: '添加角色别名',
desc: '添加角色别名,方便查询角色信息',
needCK: false,
needSK: false,
commands: ['添加+角色名+别名+角色别名'],
},
{
title: '删除角色别名',
desc: '删除角色别名',
needCK: false,
needSK: false,
commands: ['删除别名+角色别名'],
},
],
},
];

View file

@ -1,6 +1,5 @@
import { ZZZPlugin } from '../lib/plugin.js';
import { rulePrefix } from '../lib/common.js';
import { getAllCharactersID } from '../lib/convert/char.js';
import { getAllEquipID } from '../lib/convert/equip.js';
import { getAllWeaponID } from '../lib/convert/weapon.js';
import { imageResourcesPath } from '../lib/path.js';
@ -14,6 +13,7 @@ import {
getWeaponImage,
} from '../lib/download.js';
import _ from 'lodash';
import { char } from '../lib/convert.js';
export class Panel extends ZZZPlugin {
constructor() {
@ -39,12 +39,32 @@ export class Panel extends ZZZPlugin {
reg: `^${rulePrefix}设置所有攻略显示个数(\\d+)$`,
fnc: 'setMaxForwardGuide',
},
{
reg: `^${rulePrefix}设置渲染精度(\\d+)$`,
fnc: 'setRenderPrecision',
},
{
reg: `^${rulePrefix}刷新抽卡间隔(\\d+)$`,
fnc: 'setRefreshGachaInterval',
},
{
reg: `^${rulePrefix}刷新面板间隔(\\d+)$`,
fnc: 'setRefreshPanelInterval',
},
{
reg: `^${rulePrefix}添加(\\S+)别名(\\S+)$`,
fnc: 'addAlias',
},
{
reg: `^${rulePrefix}删除别名(\\S+)$`,
fnc: 'deleteAlias',
},
],
});
}
async downloadAll() {
if (!this.e.isMaster) return false;
const charIDs = getAllCharactersID();
const charIDs = char.getAllCharactersID();
const equipSprites = getAllEquipID();
const weaponSprites = getAllWeaponID();
const result = {
@ -166,14 +186,14 @@ export class Panel extends ZZZPlugin {
this.reply('仅限主人设置');
return false;
}
let match = /设置默认攻略(\d+|all)$/g.exec(this.e.msg);
const match = /设置默认攻略(\d+|all)$/g.exec(this.e.msg);
let guide_id = match[1];
if (guide_id == 'all') {
guide_id = 0;
}
guide_id = Number(guide_id);
if (guide_id > this.maxNum) {
let reply_msg = [
const reply_msg = [
'绝区零默认攻略设置方式为:',
'%设置默认攻略[0123...]',
`请增加数字0-${this.maxNum}其中一个,或者增加 all 以显示所有攻略`,
@ -184,7 +204,7 @@ export class Panel extends ZZZPlugin {
}
settings.setSingleConfig('guide', 'default_guide', guide_id);
let source_name = guide_id == 0 ? 'all' : this.source[guide_id - 1];
const source_name = guide_id == 0 ? 'all' : this.source[guide_id - 1];
await this.e.reply(`绝区零默认攻略已设置为: ${guide_id} (${source_name})`);
}
@ -194,9 +214,113 @@ export class Panel extends ZZZPlugin {
this.reply('仅限主人设置');
return false;
}
let match = /设置所有攻略显示个数(\d+)$/g.exec(this.e.msg);
let max_forward_guide = Number(match[1]);
this.setSingleConfig('max_forward_guides', max_forward_guide);
const match = /设置所有攻略显示个数(\d+)$/g.exec(this.e.msg);
const max_forward_guide = Number(match[1]);
settings.setSingleConfig('guide', 'max_forward_guides', max_forward_guide);
await this.e.reply(`绝区零所有攻略显示个数已设置为: ${max_forward_guide}`);
}
/** 设置渲染精度 */
async setRenderPrecision() {
if (!this.e.isMaster) {
this.reply('仅限主人设置');
return false;
}
const match = /渲染精度(\d+)$/g.exec(this.e.msg);
const render_precision = Number(match[1]);
if (render_precision < 50) {
await this.e.reply('渲染精度不能小于50');
return false;
}
if (render_precision > 200) {
await this.e.reply('渲染精度不能大于200');
return false;
}
settings.setSingleConfig('config', 'render', {
scale: render_precision,
});
await this.e.reply(`绝区零渲染精度已设置为: ${render_precision}`);
}
/** 设置刷新抽卡间隔 */
async setRefreshGachaInterval() {
if (!this.e.isMaster) {
this.reply('仅限主人设置');
return false;
}
const match = /刷新抽卡间隔(\d+)$/g.exec(this.e.msg);
const refresh_gacha_interval = Number(match[1]);
if (refresh_gacha_interval < 0) {
await this.e.reply('刷新抽卡间隔不能小于0秒');
return false;
}
if (refresh_gacha_interval > 1000) {
await this.e.reply('刷新抽卡间隔不能大于1000秒');
return false;
}
settings.setSingleConfig('gacha', 'interval', refresh_gacha_interval);
await this.e.reply(`绝区零刷新抽卡间隔已设置为: ${refresh_gacha_interval}`);
}
/** 设置刷新面板间隔 */
async setRefreshPanelInterval() {
if (!this.e.isMaster) {
this.reply('仅限主人设置');
return false;
}
const match = /刷新面板间隔(\d+)$/g.exec(this.e.msg);
const refresh_panel_interval = Number(match[1]);
if (refresh_panel_interval < 0) {
await this.e.reply('刷新面板间隔不能小于0秒');
return false;
}
if (refresh_panel_interval > 1000) {
await this.e.reply('刷新面板间隔不能大于1000秒');
return false;
}
settings.setSingleConfig('panel', 'interval', refresh_panel_interval);
await this.e.reply(`绝区零刷新面板间隔已设置为: ${refresh_panel_interval}`);
}
async addAlias() {
if (!this.e.isMaster) {
this.reply('仅限主人设置');
return false;
}
const match = /添加(\S+)别名(\S+)$/g.exec(this.e.msg);
const key = match[1];
const value = match[2];
const oriName = char.aliasToName(key);
const isExist = char.aliasToName(value);
if (!oriName) {
await this.e.reply(`未找到 ${value} 的对应角色`);
return;
}
if (isExist) {
await this.e.reply(`别名 ${value} 已存在`);
return;
}
settings.addArrayleConfig('alias', oriName, value);
await this.e.reply(`角色 ${key} 别名 ${value} 成功`);
}
async deleteAlias() {
if (!this.e.isMaster) {
this.reply('仅限主人设置');
return false;
}
const match = /删除别名(\S+)$/g.exec(this.e.msg);
const key = match[1];
const oriName = char.aliasToName(key);
if (!oriName) {
await this.e.reply(`未找到 ${key} 的对应角色`);
return;
}
if (key === oriName) {
await this.e.reply(`别名 ${key} 为角色本名,无法删除`);
return;
}
settings.removeArrayleConfig('alias', oriName, key);
await this.e.reply(`角色 ${key} 别名删除成功`);
}
}

View file

@ -46,17 +46,17 @@ export function supportGuoba() {
},
{
field: 'config.query.others',
label: '允许查询他人信息',
label: '查询他人信息',
bottomHelpMessage: '是否允许查询他人信息',
component: 'Switch',
},
{
component: 'Divider',
label: '抽卡设置',
label: '抽卡分析设置',
},
{
field: 'gacha.interval',
label: '冷却时间(单位:秒)',
label: '冷却时间',
bottomHelpMessage:
'设置刷新抽卡记录的冷却时间单位为秒取值范围为01000',
component: 'InputNumber',
@ -73,7 +73,7 @@ export function supportGuoba() {
},
{
field: 'panel.interval',
label: '冷却时间(单位:秒)',
label: '冷却时间',
bottomHelpMessage:
'设置刷新面板的冷却时间单位为秒取值范围为01000',
component: 'InputNumber',
@ -84,6 +84,65 @@ export function supportGuoba() {
placeholder: '请输入数字',
},
},
{
component: 'Divider',
label: '攻略设置',
},
{
field: 'guide.default_guide',
label: '默认攻略',
bottomHelpMessage: '设置默认攻略,攻略合集即为多个攻略的合集',
component: 'Select',
required: true,
componentProps: {
options: [
{
value: 0,
label: '攻略合集',
},
{
value: 1,
label: '新艾利都快讯',
},
{
value: 2,
label: '清茶沐沐Kiyotya',
},
{
value: 3,
label: '小橙子阿',
},
{
value: 4,
label: '猫冬',
},
{
value: 5,
label: '月光中心',
},
{
value: 6,
label: '苦雪的清心花凉糕Suki',
},
{
value: 7,
label: 'HoYo青枫',
},
],
},
},
{
field: 'guide.max_forward_guides',
label: '合集最大数量',
bottomHelpMessage: '当查询攻略合集时,返回攻略的最大数量',
component: 'InputNumber',
required: true,
componentProps: {
min: 1,
max: 7,
placeholder: '请输入数字17',
},
},
{
component: 'Divider',
label: '优先级设置(-10001000',

View file

@ -116,7 +116,7 @@ export const getPanel = (uid, name) => {
// 获取所有面板数据
const data = _data.map(item => new ZZZAvatarInfo(item));
// 通过名称(包括别名)获取角色 ID
const id = char.atlasToID(name);
const id = char.aliasToID(name);
if (!id) return null;
// 通过 ID 获取角色数据
const result = data.find(item => item.id === id);

View file

@ -53,24 +53,24 @@ export const charNameToSprite = name => {
};
/**
* @param {string} atlas
* @param {string} alias
* @returns string | null
*/
export const atlasToName = _atlas => {
const atlas = settings.getConfig('atlas');
for (const [id, data] of Object.entries(atlas)) {
if (id === _atlas) return id;
if (data.includes(_atlas)) return id;
export const aliasToName = _alias => {
const alias = settings.getConfig('alias');
for (const [id, data] of Object.entries(alias)) {
if (id === _alias) return id;
if (data.includes(_alias)) return id;
}
return null;
};
/**
* @param {string} _atlas
* @param {string} _alias
* @returns string | null
*/
export const atlasToSprite = _atlas => {
const name = atlasToName(name);
export const aliasToSprite = _alias => {
const name = aliasToName(_alias);
return charNameToSprite(name);
};
@ -78,8 +78,8 @@ export const atlasToSprite = _atlas => {
* @param {string} name
* @returns number | null
*/
export const atlasToID = name => {
const _name = atlasToName(name);
export const aliasToID = name => {
const _name = aliasToName(name);
const id = charNameToID(_name);
return id;
};

View file

@ -113,7 +113,7 @@ class Setting {
/**
* 获取对应模块默认配置
* @param {'atlas'|'config'|'gacha'|'panel'} app
* @param {'alias'|'config'|'gacha'|'panel'} app
* @returns {object}
*/
getdefSet(app) {
@ -122,7 +122,7 @@ class Setting {
/**
* 获取对应模块用户配置配置文件名
* @param {'atlas'|'config'|'gacha'|'panel'} app
* @param {'alias'|'config'|'gacha'|'panel'} app
* @returns {object}
*/
getConfig(app) {
@ -153,7 +153,7 @@ class Setting {
/**
* 设置对应模块用户配置
* @param {'atlas'|'config'|'gacha'|'panel'|'guide'} app
* @param {'alias'|'config'|'gacha'|'panel'|'guide'} app
* @param {object} obj
* @returns
*/
@ -167,7 +167,7 @@ class Setting {
/**
* 设置对应模块用户配置
* @param {'atlas'|'config'|'gacha'|'panel'|'guide'} app
* @param {'alias'|'config'|'gacha'|'panel'|'guide'} app
* @param {string} key
* @param {string} value
* @returns {boolean}
@ -180,6 +180,40 @@ class Setting {
return this.setYaml(app, 'config', { ...defSet, ...config });
}
/**
* 向数组中添加元素
* @param {'alias'|'config'|'gacha'|'panel'|'guide'} app
* @param {string} key
* @param {string} value
* @returns {boolean}
*/
addArrayleConfig(app, key, value) {
const defSet = this.getdefSet(app);
const config = this.getConfig(app);
if (!config[key]) {
config[key] = [];
}
config[key].push(value);
return this.setYaml(app, 'config', { ...defSet, ...config });
}
/**
* 从数组中删除元素
* @param {'alias'|'config'|'gacha'|'panel'|'guide'} app
* @param {string} key
* @param {string} value
* @returns {boolean}
*/
removeArrayleConfig(app, key, value) {
const defSet = this.getdefSet(app);
const config = this.getConfig(app);
if (!config[key]) {
return false;
}
config[key] = config[key].filter(item => item !== value);
return this.setYaml(app, 'config', { ...defSet, ...config });
}
// 将对象写入YAML文件
setYaml(app, type, Object) {
let file = this.getFilePath(app, type);