移除apps插件非必要return false,拦截指令向后传递 #138

This commit is contained in:
UCPr 2025-09-09 03:30:27 +08:00
parent 3273f256fc
commit 9d676fa70a
17 changed files with 82 additions and 173 deletions

View file

@ -3,8 +3,7 @@ import settings from '../../lib/settings.js';
export async function addAlias() {
if (!this.e.isMaster) {
this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
return false;
return this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
}
const match = /添加(\S+)别名(\S+)$/g.exec(this.e.msg);
const key = match[1];
@ -34,8 +33,7 @@ export async function addAlias() {
export async function deleteAlias() {
if (!this.e.isMaster) {
this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
return false;
return this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
}
const match = /删除别名(\S+)$/g.exec(this.e.msg);
const key = match[1];

View file

@ -3,24 +3,21 @@ import settings from '../../lib/settings.js';
/** 设置渲染精度 */
export async function setRenderPrecision() {
if (!this.e.isMaster) {
this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
return false;
return this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
}
const match = /渲染精度(\d+)$/g.exec(this.e.msg);
const render_precision = Number(match[1]);
if (render_precision < 50) {
await this.e.reply('渲染精度不能小于50', false, {
return this.e.reply('渲染精度不能小于50', false, {
at: true,
recallMsg: 100,
});
return false;
}
if (render_precision > 200) {
await this.e.reply('渲染精度不能大于200', false, {
return this.e.reply('渲染精度不能大于200', false, {
at: true,
recallMsg: 100,
});
return false;
}
settings.setSingleConfig('config', 'render', {
scale: render_precision,
@ -31,24 +28,21 @@ export async function setRenderPrecision() {
/** 设置刷新抽卡间隔 */
export async function setRefreshGachaInterval() {
if (!this.e.isMaster) {
this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
return false;
return this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
}
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秒', false, {
return this.e.reply('刷新抽卡间隔不能小于0秒', false, {
at: true,
recallMsg: 100,
});
return false;
}
if (refresh_gacha_interval > 1000) {
await this.e.reply('刷新抽卡间隔不能大于1000秒', false, {
return this.e.reply('刷新抽卡间隔不能大于1000秒', false, {
at: true,
recallMsg: 100,
});
return false;
}
settings.setSingleConfig('gacha', 'interval', refresh_gacha_interval);
await this.e.reply(`绝区零刷新抽卡间隔已设置为: ${refresh_gacha_interval}`);
@ -57,24 +51,21 @@ export async function setRefreshGachaInterval() {
/** 设置刷新面板间隔 */
export async function setRefreshPanelInterval() {
if (!this.e.isMaster) {
this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
return false;
return this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
}
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秒', false, {
return this.e.reply('刷新面板间隔不能小于0秒', false, {
at: true,
recallMsg: 100,
});
return false;
}
if (refresh_panel_interval > 1000) {
await this.e.reply('刷新面板间隔不能大于1000秒', false, {
return this.e.reply('刷新面板间隔不能大于1000秒', false, {
at: true,
recallMsg: 100,
});
return false;
}
settings.setSingleConfig('panel', 'interval', refresh_panel_interval);
await this.e.reply(
@ -87,24 +78,21 @@ export async function setRefreshPanelInterval() {
/** 设置角色刷新间隔 */
export async function setRefreshCharInterval() {
if (!this.e.isMaster) {
this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
return false;
return this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
}
const match = /刷新角色间隔(\d+)$/g.exec(this.e.msg);
const refresh_char_interval = Number(match[1]);
if (refresh_char_interval < 0) {
await this.e.reply('刷新角色间隔不能小于0秒', false, {
return this.e.reply('刷新角色间隔不能小于0秒', false, {
at: true,
recallMsg: 100,
});
return false;
}
if (refresh_char_interval > 1000) {
await this.e.reply('刷新角色间隔不能大于1000秒', false, {
return this.e.reply('刷新角色间隔不能大于1000秒', false, {
at: true,
recallMsg: 100,
});
return false;
}
settings.setSingleConfig('panel', 'roleInterval', refresh_char_interval);
await this.e.reply(`绝区零刷新角色间隔已设置为: ${refresh_char_interval}`);

View file

@ -2,8 +2,7 @@ import settings from '../../lib/settings.js';
export async function setDefaultDevice() {
if (!this.e.isMaster) {
this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
return false;
return this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
}
this.setContext('toSetDefaultDevice');
await this.reply(
@ -15,19 +14,16 @@ export async function setDefaultDevice() {
export async function toSetDefaultDevice() {
const msg = this.e.msg.trim();
if (!msg) {
this.reply('请发送设备信息', false, { at: true, recallMsg: 100 });
return false;
return this.reply('请发送设备信息', false, { at: true, recallMsg: 100 });
}
if (msg.includes('取消')) {
await this.reply('已取消', false, { at: true, recallMsg: 100 });
this.finish('toSetDefaultDevice');
return false;
return this.reply('已取消', false, { at: true, recallMsg: 100 });
}
try {
const info = JSON.parse(msg);
if (!info) {
this.reply('设备信息格式错误', false, { at: true, recallMsg: 100 });
return false;
return this.reply('设备信息格式错误', false, { at: true, recallMsg: 100 });
}
if (
!info?.deviceName ||
@ -37,8 +33,7 @@ export async function toSetDefaultDevice() {
!info?.deviceFingerprint ||
!info?.deviceProduct
) {
this.reply('设备信息格式错误', false, { at: true, recallMsg: 100 });
return false;
return this.reply('设备信息格式错误', false, { at: true, recallMsg: 100 });
}
settings.setConfig('device', {
productName: info.deviceProduct,

View file

@ -4,8 +4,7 @@ import settings from '../../lib/settings.js';
/** 设置默认攻略 */
export async function setDefaultGuide() {
if (!this.e.isMaster) {
this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
return false;
return this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
}
const match = /设置默认攻略(\d+|all)$/g.exec(this.e.msg);
let guide_id = match[1];
@ -36,24 +35,21 @@ export async function setDefaultGuide() {
/** 设置所有攻略显示个数 */
export async function setMaxForwardGuide() {
if (!this.e.isMaster) {
this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
return false;
return this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
}
const match = /设置所有攻略显示个数(\d+)$/g.exec(this.e.msg);
const max_forward_guide = Number(match[1]);
if (max_forward_guide < 1) {
await this.e.reply('所有攻略显示个数不能小于1', false, {
return this.e.reply('所有攻略显示个数不能小于1', false, {
at: true,
recallMsg: 100,
});
return false;
}
if (max_forward_guide > guides.guideMaxNum) {
await this.e.reply(`所有攻略显示个数不能大于${guides.guideMaxNum}`, false, {
return this.e.reply(`所有攻略显示个数不能大于${guides.guideMaxNum}`, false, {
at: true,
recallMsg: 100,
});
return false;
}
settings.setSingleConfig('guide', 'max_forward_guides', max_forward_guide);
await this.e.reply(

View file

@ -6,8 +6,7 @@ import fs from 'fs';
import path from 'path';
export async function uploadCharacterImg() {
if (!this.e.isMaster) {
this.reply('只有主人才能添加', false, { at: true, recallMsg: 100 });
return false;
return this.reply('只有主人才能添加', false, { at: true, recallMsg: 100 });
}
const reg = /(上传|添加)(.+)(角色|面板)图$/;
const match = this.e.msg.match(reg);
@ -17,8 +16,7 @@ export async function uploadCharacterImg() {
const charName = match[2].trim();
const name = char.aliasToName(charName);
if (!name) {
this.reply('未找到对应角色', false, { at: true, recallMsg: 100 });
return false;
return this.reply('未找到对应角色', false, { at: true, recallMsg: 100 });
}
const images = [];
// 下面方法来源于miao-plugin/apps/character/ImgUpload.js
@ -70,12 +68,11 @@ export async function uploadCharacterImg() {
}
}
if (images.length <= 0) {
this.reply(
return this.reply(
'消息中未找到图片,请将要发送的图片与消息一同发送或引用要添加的图像。',
false,
{ at: true, recallMsg: 100 }
);
return false;
}
const resourcesImagesPath = imageResourcesPath;
const panelImagesPath = path.join(resourcesImagesPath, `panel/${name}`);
@ -96,11 +93,10 @@ export async function uploadCharacterImg() {
failed++;
}
}
this.reply(`成功上传${success}张图片,失败${failed}张图片。`, false, {
return this.reply(`成功上传${success}张图片,失败${failed}张图片。`, false, {
at: true,
recallMsg: 100,
});
return false;
}
export async function getCharacterImages() {
@ -113,8 +109,7 @@ export async function getCharacterImages() {
const name = char.aliasToName(charName);
let page = match[4];
if (!name) {
this.reply('未找到对应角色', false, { at: true, recallMsg: 100 });
return false;
return this.reply('未找到对应角色', false, { at: true, recallMsg: 100 });
}
const pageSize = 5;
const resourcesImagesPath = imageResourcesPath;
@ -131,8 +126,7 @@ export async function getCharacterImages() {
const start = (page - 1) * pageSize;
const end = page * pageSize;
if (start >= images.length) {
this.reply('哪有这么多图片', false, { at: true, recallMsg: 100 });
return false;
return this.reply('哪有这么多图片', false, { at: true, recallMsg: 100 });
}
const imagePaths = images.slice(start, end);
const imageMsg = imagePaths.map(imagePath => {
@ -150,14 +144,11 @@ export async function getCharacterImages() {
);
if (imageMsg.length)
await this.reply(await common.makeForwardMsg(this.e, imageMsg));
return false;
}
export async function deleteCharacterImg() {
if (!this.e.isMaster) {
this.reply('只有主人才能删除', false, { at: true, recallMsg: 100 });
return false;
return this.reply('只有主人才能删除', false, { at: true, recallMsg: 100 });
}
const reg = /(删除)(.+)(角色|面板)图(.+)$/;
const match = this.e.msg.match(reg);
@ -167,8 +158,7 @@ export async function deleteCharacterImg() {
const charName = match[2].trim();
const name = char.aliasToName(charName);
if (!name) {
this.reply('未找到对应角色', false, { at: true, recallMsg: 100 });
return false;
return this.reply('未找到对应角色', false, { at: true, recallMsg: 100 });
}
const ids = match[4].split(/[,,、\s]+/);
const resourcesImagesPath = imageResourcesPath;
@ -195,6 +185,5 @@ export async function deleteCharacterImg() {
failed ? `删除失败ID为${failed.join(',')}` : '无失败ID',
'删除后会重新排序ID若想要再次删除请重新获取图片列表否则可能会删除错误的图片。',
];
this.reply(common.makeForwardMsg(this.e, msgs));
return false;
return this.reply(common.makeForwardMsg(this.e, msgs));
}

View file

@ -54,8 +54,7 @@ export async function hasUpdate() {
/** 开启/关闭自动更新推送 */
export async function enableAutoUpdatePush() {
if (!this.e.isMaster) {
this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
return false;
return this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
}
let enable = true;
if (this.e.msg.includes('关闭')) {
@ -72,12 +71,11 @@ export async function enableAutoUpdatePush() {
/** 设置自动更新时间 */
export async function setCheckUpdateCron() {
if (!this.e.isMaster) {
this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
return false;
return this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
}
const cron = this.e.msg.split('时间')[1];
if (!cron) {
await this.reply(
return this.reply(
`[${pluginName}]设置自动更新频率失败无cron表达式`,
false,
{
@ -85,7 +83,6 @@ export async function setCheckUpdateCron() {
recallMsg: 100,
}
);
return false;
}
settings.setSingleConfig('config', 'update', { cron });
await this.reply(`[${pluginName}]自动更新频率已设置为${cron}`, false, {