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} 别名删除成功`);
}
}