From af754fc631126c883a3aad356ce9c8ca01e0835b Mon Sep 17 00:00:00 2001 From: Qian23333 <119576779+Qian23333@users.noreply.github.com> Date: Sat, 16 Aug 2025 15:53:03 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E6=8F=90=E5=8F=96=E8=BE=85=E5=8A=A9?= =?UTF-8?q?=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/remind.js | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/apps/remind.js b/apps/remind.js index 0d0edea..bcba109 100644 --- a/apps/remind.js +++ b/apps/remind.js @@ -91,6 +91,18 @@ export class Remind extends ZZZPlugin { await redis.hSet(USER_CONFIGS_KEY, String(userId), JSON.stringify(config)); } + parseRemindTimeMessage(message) { + const pattern = /提醒时间\s*(每日\d+时(?:(\d+)分)?|每周.\d+时(?:(\d+)分)?)/; + const match = message.match(pattern); + if (!match) return { remindTime: null, error: '时间格式错误' }; + const remindTime = match[1]; + const minute = Number(match[2]) || Number(match[3]) || 0; + if (!(minute % 10 === 0 && minute >= 0 && minute < 60)) { + return { remindTime: null, error: '分钟必须为整十分钟' }; + } + return { remindTime, error: null }; + } + isTimeMatch(remindTime, date) { if (!remindTime) return false; @@ -323,16 +335,8 @@ export class Remind extends ZZZPlugin { } async setMyRemindTime() { - const match = this.e.msg.match(/设置个人提醒时间\s*(每日\d+时(?:(\d+)分)?|每周.\d+时(?:(\d+)分)?)/); - if (!match) return; - const remindTime = match[1]; - const minute = Number(match[2]) || Number(match[3]) || 0; - - // 验证分钟格式 - if (minute % 10 !== 0 || minute < 0 || minute >= 60) { - await this.reply('分钟必须为整十分钟'); - return; - } + const { remindTime, error } = this.parseRemindTimeMessage(this.e.msg); + if (!remindTime) return await this.reply(error); let userConfig = await this.getUserConfig(this.e.user_id); if (!userConfig) { @@ -376,17 +380,9 @@ export class Remind extends ZZZPlugin { this.reply('仅限主人设置', false, { at: true, recallMsg: 100 }); return false; } - const match = this.e.msg.match(/设置全局提醒时间\s*(每日\d+时(?:(\d+)分)?|每周.\d+时(?:(\d+)分)?)/); - if (!match) return; - const globalRemindTime = match[1]; - const minute = Number(match[2]) || Number(match[3]) || 0; - - // 验证分钟格式 - if (minute % 10 !== 0 || minute < 0 || minute >= 60) { - await this.reply('分钟必须为整十分钟'); - return; - } + const { remindTime: globalRemindTime, error } = this.parseRemindTimeMessage(this.e.msg); + if (!globalRemindTime) return await this.reply(error); settings.setSingleConfig('remind', 'globalRemindTime', globalRemindTime); await this.reply(`全局提醒时间已更新为: ${globalRemindTime}。`); }