fix: 主人权限,消息撤回

This commit is contained in:
bietiaop 2024-08-20 15:06:57 +08:00
parent eacea6e902
commit 18f24f87bb
7 changed files with 107 additions and 35 deletions

View file

@ -3,7 +3,7 @@ import settings from '../../lib/settings.js';
export async function addAlias() { export async function addAlias() {
if (!this.e.isMaster) { if (!this.e.isMaster) {
this.reply('仅限主人设置'); this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
return false; return false;
} }
const match = /添加(\S+)别名(\S+)$/g.exec(this.e.msg); const match = /添加(\S+)别名(\S+)$/g.exec(this.e.msg);
@ -12,15 +12,24 @@ export async function addAlias() {
const oriName = char.aliasToName(key); const oriName = char.aliasToName(key);
const isExist = char.aliasToName(value); const isExist = char.aliasToName(value);
if (!oriName) { if (!oriName) {
await this.e.reply(`未找到 ${value} 的对应角色`); await this.e.reply(`未找到 ${value} 的对应角色`, false, {
at: true,
recallMsg: 100,
});
return; return;
} }
if (isExist) { if (isExist) {
await this.e.reply(`别名 ${value} 已存在`); await this.e.reply(`别名 ${value} 已存在`, false, {
at: true,
recallMsg: 100,
});
return; return;
} }
settings.addArrayleConfig('alias', oriName, value); settings.addArrayleConfig('alias', oriName, value);
await this.e.reply(`角色 ${key} 别名 ${value} 成功`); await this.e.reply(`角色 ${key} 别名 ${value} 成功`, false, {
at: true,
recallMsg: 100,
});
} }
export async function deleteAlias() { export async function deleteAlias() {
@ -32,13 +41,22 @@ export async function deleteAlias() {
const key = match[1]; const key = match[1];
const oriName = char.aliasToName(key); const oriName = char.aliasToName(key);
if (!oriName) { if (!oriName) {
await this.e.reply(`未找到 ${key} 的对应角色`); await this.e.reply(`未找到 ${key} 的对应角色`, false, {
at: true,
recallMsg: 100,
});
return; return;
} }
if (key === oriName) { if (key === oriName) {
await this.e.reply(`别名 ${key} 为角色本名,无法删除`); await this.e.reply(`别名 ${key} 为角色本名,无法删除`, false, {
at: true,
recallMsg: 100,
});
return; return;
} }
settings.removeArrayleConfig('alias', oriName, key); settings.removeArrayleConfig('alias', oriName, key);
await this.e.reply(`角色 ${key} 别名删除成功`); await this.e.reply(`角色 ${key} 别名删除成功`, false, {
at: true,
recallMsg: 100,
});
} }

View file

@ -44,7 +44,9 @@ export async function downloadAll() {
}, },
}; };
await this.reply( await this.reply(
'开始下载资源,注意,仅支持下载面板的角色图、武器图、套装图,以及角色卡片的角色头像图。暂不支持下载邦布头像。' '开始下载资源,注意,仅支持下载面板的角色图、武器图、套装图,以及角色卡片的角色头像图。暂不支持下载邦布头像。',
false,
{ at: true, recallMsg: 100 }
); );
for (const id of charIDs) { for (const id of charIDs) {
try { try {
@ -122,9 +124,13 @@ export async function downloadAll() {
} }
export async function deleteAll() { export async function deleteAll() {
if (!this.e.isMaster) return false; if (!this.e.isMaster) return false;
await this.reply('【注意】正在删除所有资源图片,后续使用需要重新下载!'); await this.reply(
'【注意】正在删除所有资源图片,后续使用需要重新下载!',
false,
{ at: true, recallMsg: 100 }
);
if (fs.existsSync(imageResourcesPath)) { if (fs.existsSync(imageResourcesPath)) {
fs.rmSync(imageResourcesPath, { recursive: true }); fs.rmSync(imageResourcesPath, { recursive: true });
} }
await this.reply('资源图片已删除!'); await this.reply('资源图片已删除!', false, { at: true, recallMsg: 100 });
} }

View file

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

View file

@ -1,6 +1,10 @@
import settings from '../../lib/settings.js'; import settings from '../../lib/settings.js';
export async function setDefaultDevice() { export async function setDefaultDevice() {
if (!this.e.isMaster) {
this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
return false;
}
this.setContext('toSetDefaultDevice'); this.setContext('toSetDefaultDevice');
await this.reply( await this.reply(
`请发送默认设备信息,或者发送“取消”取消设置默认设备信息`, `请发送默认设备信息,或者发送“取消”取消设置默认设备信息`,

View file

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

View file

@ -6,7 +6,7 @@ import fs from 'fs';
import path from 'path'; import path from 'path';
export async function uploadCharacterImg() { export async function uploadCharacterImg() {
if (!this.e.isMaster) { if (!this.e.isMaster) {
this.reply('只有主人才能添加'); this.reply('只有主人才能添加', false, { at: true, recallMsg: 100 });
return false; return false;
} }
const reg = /(上传|添加)(.+)(角色|面板)图$/; const reg = /(上传|添加)(.+)(角色|面板)图$/;
@ -17,7 +17,7 @@ export async function uploadCharacterImg() {
const charName = match[2].trim(); const charName = match[2].trim();
const name = char.aliasToName(charName); const name = char.aliasToName(charName);
if (!name) { if (!name) {
this.reply('未找到对应角色'); this.reply('未找到对应角色', false, { at: true, recallMsg: 100 });
return false; return false;
} }
const images = []; const images = [];
@ -71,7 +71,9 @@ export async function uploadCharacterImg() {
} }
if (images.length <= 0) { if (images.length <= 0) {
this.reply( this.reply(
'消息中未找到图片,请将要发送的图片与消息一同发送或引用要添加的图像。' '消息中未找到图片,请将要发送的图片与消息一同发送或引用要添加的图像。',
false,
{ at: true, recallMsg: 100 }
); );
return false; return false;
} }
@ -94,7 +96,10 @@ export async function uploadCharacterImg() {
failed++; failed++;
} }
} }
this.reply(`成功上传${success}张图片,失败${failed}张图片。`); this.reply(`成功上传${success}张图片,失败${failed}张图片。`, false, {
at: true,
recallMsg: 100,
});
return false; return false;
} }
@ -108,7 +113,7 @@ export async function getCharacterImages() {
const name = char.aliasToName(charName); const name = char.aliasToName(charName);
let page = match[4]; let page = match[4];
if (!name) { if (!name) {
this.reply('未找到对应角色'); this.reply('未找到对应角色', false, { at: true, recallMsg: 100 });
return false; return false;
} }
const pageSize = 5; const pageSize = 5;
@ -126,7 +131,7 @@ export async function getCharacterImages() {
const start = (page - 1) * pageSize; const start = (page - 1) * pageSize;
const end = page * pageSize; const end = page * pageSize;
if (start >= images.length) { if (start >= images.length) {
this.reply('哪有这么多图片'); this.reply('哪有这么多图片', false, { at: true, recallMsg: 100 });
return false; return false;
} }
const imagePaths = images.slice(start, end); const imagePaths = images.slice(start, end);
@ -151,7 +156,7 @@ export async function getCharacterImages() {
export async function deleteCharacterImg() { export async function deleteCharacterImg() {
if (!this.e.isMaster) { if (!this.e.isMaster) {
this.reply('只有主人才能删除'); this.reply('只有主人才能删除', false, { at: true, recallMsg: 100 });
return false; return false;
} }
const reg = /(删除)(.+)(角色|面板)图(.+)$/; const reg = /(删除)(.+)(角色|面板)图(.+)$/;
@ -162,7 +167,7 @@ export async function deleteCharacterImg() {
const charName = match[2].trim(); const charName = match[2].trim();
const name = char.aliasToName(charName); const name = char.aliasToName(charName);
if (!name) { if (!name) {
this.reply('未找到对应角色'); this.reply('未找到对应角色', false, { at: true, recallMsg: 100 });
return false; return false;
} }
const ids = match[4].split(/[,,、\s]+/); const ids = match[4].split(/[,,、\s]+/);

View file

@ -23,7 +23,10 @@ export async function getCommitLog() {
commitData, commitData,
}); });
} catch (error) { } catch (error) {
this.reply(`[${pluginName}]获取更新日志失败\n${error.message}`); this.reply(`[${pluginName}]获取更新日志失败\n${error.message}`, false, {
at: true,
recallMsg: 100,
});
} }
} }
return true; return true;