From a34c2835e44028b459c610a5895e58684a7a3b23 Mon Sep 17 00:00:00 2001 From: Qian23333 <119576779+Qian23333@users.noreply.github.com> Date: Sat, 16 Aug 2025 07:15:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/manage.js | 6 +++ apps/manage/remind.js | 102 +++++------------------------------------- apps/remind.js | 53 ++++++++++++++++++++++ 3 files changed, 70 insertions(+), 91 deletions(-) diff --git a/apps/manage.js b/apps/manage.js index 4cd078a..6f8eb55 100644 --- a/apps/manage.js +++ b/apps/manage.js @@ -88,6 +88,11 @@ export class Manage extends ZZZPlugin { reg: `${rulePrefix}设置检查更新时间(.+)$`, fnc: 'setCheckUpdateCron', }, + { + reg: `${rulePrefix}设置全局提醒时间\\s*(每日\\d+时|每周.\\d+时)`, + fnc: 'setGlobalRemind', + permission: 'master', + }, ], }); @@ -111,5 +116,6 @@ export class Manage extends ZZZPlugin { this.setCheckUpdateCron = manage.version.setCheckUpdateCron; this.setDefaultDevice = manage.device.setDefaultDevice; this.toSetDefaultDevice = manage.device.toSetDefaultDevice; + this.setGlobalRemind = manage.remind.setGlobalRemind; } } diff --git a/apps/manage/remind.js b/apps/manage/remind.js index dafeb38..c34923d 100644 --- a/apps/manage/remind.js +++ b/apps/manage/remind.js @@ -1,96 +1,16 @@ -import _ from 'lodash'; import settings from '../../lib/settings.js'; -import { rulePrefix } from '../../lib/common.js'; -import { ZZZPlugin } from '../../lib/plugin.js'; -const USER_CONFIGS_KEY = 'ZZZ:REMIND:USER_CONFIGS'; - -export class RemindManage extends ZZZPlugin { - constructor() { - super({ - name: '[ZZZ-Plugin]RemindManage', - dsc: '提醒功能管理', - event: 'message', - priority: _.get(settings.getConfig('priority'), 'remind', 70), - rule: [ - { - reg: `${rulePrefix}设置全局提醒时间\\s*(每日\\d+时|每周.\\d+时)`, - fnc: 'setGlobalRemind', - permission: 'master', - }, - { - reg: `${rulePrefix}设置个人提醒时间\\s*(每日\\d+时|每周.\\d+时)`, - fnc: 'setMyRemindTime', - }, - { - reg: `${rulePrefix}个人提醒时间$`, - fnc: 'viewMyRemindTime', - }, - { - reg: `${rulePrefix}取消个人提醒时间`, - fnc: 'deleteMyRemindTime', - }, - ], - }); +/** 设置全局提醒时间 */ +export async function setGlobalRemind() { + if (!this.e.isMaster) { + this.reply('仅限主人设置', false, { at: true, recallMsg: 100 }); + return false; } + const match = this.e.msg.match(/设置全局提醒时间\s*(每日\d+时|每周.\d+时)/); + if (!match) return; + const remindTime = match[1]; - async getUserConfig(userId) { - const userConfigJson = await redis.hGet(USER_CONFIGS_KEY, String(userId)); - return userConfigJson ? JSON.parse(userConfigJson) : null; - } - - async setUserConfig(userId, config) { - await redis.hSet(USER_CONFIGS_KEY, String(userId), JSON.stringify(config)); - } - - async setGlobalRemind() { - const match = this.e.msg.match(/设置全局提醒时间\s*(每日\d+时|每周.\d+时)/); - if (!match) return; - const remindTime = match[1]; - - // 将全局提醒时间写入yaml配置 - settings.setConfig('remind.globalRemindTime', remindTime); - await this.reply(`全局提醒时间已更新为: ${remindTime}。`); - } - - async setMyRemindTime() { - const match = this.e.msg.match(/设置个人提醒时间\s*(每日\d+时|每周.\d+时)/); - if (!match) return; - const remindTime = match[1]; - - let userConfig = await this.getUserConfig(this.e.user_id); - if (!userConfig) { - const defaultConfig = settings.getConfig('remind'); - userConfig = { - enable: false, - abyssCheckLevel: defaultConfig.abyssCheckLevel, - deadlyStars: defaultConfig.deadlyStars, - }; - } - - userConfig.remindTime = remindTime; - await this.setUserConfig(this.e.user_id, userConfig); - await this.reply(`您的个人提醒时间已设置为: ${remindTime}`); - } - - async viewMyRemindTime() { - const userConfig = await this.getUserConfig(this.e.user_id); - if (userConfig && userConfig.remindTime) { - await this.reply(`当前提醒时间: ${userConfig.remindTime}`); - } else { - const globalRemindTime = settings.getConfig('remind.globalRemindTime') || '每日20时'; - await this.reply(`个人提醒时间未设置,默认使用全局时间: ${globalRemindTime}`); - } - } - - async deleteMyRemindTime() { - let userConfig = await this.getUserConfig(this.e.user_id); - if (userConfig && userConfig.remindTime) { - delete userConfig.remindTime; - await this.setUserConfig(this.e.user_id, userConfig); - await this.reply('个人提醒时间已取消'); - } else { - await this.reply('个人提醒时间尚未设置'); - } - } + // 将全局提醒时间写入yaml配置 + settings.setConfig('remind.globalRemindTime', remindTime); + await this.reply(`全局提醒时间已更新为: ${remindTime}。`); } \ No newline at end of file diff --git a/apps/remind.js b/apps/remind.js index 3fdfd10..d924b9e 100644 --- a/apps/remind.js +++ b/apps/remind.js @@ -35,6 +35,18 @@ export class Remind extends ZZZPlugin { reg: `${rulePrefix}查询挑战状态$`, fnc: 'checkNow', }, + { + reg: `${rulePrefix}设置个人提醒时间\\s*(每日\\d+时|每周.\\d+时)`, + fnc: 'setMyRemindTime', + }, + { + reg: `${rulePrefix}个人提醒时间$`, + fnc: 'viewMyRemindTime', + }, + { + reg: `${rulePrefix}取消个人提醒时间`, + fnc: 'deleteMyRemindTime', + }, ], }); @@ -263,4 +275,45 @@ export class Remind extends ZZZPlugin { } logger.info('[ZZZ-Plugin] 式舆防卫战/危局强袭战提醒任务执行完毕'); } + + async setMyRemindTime() { + const match = this.e.msg.match(/设置个人提醒时间\s*(每日\d+时|每周.\d+时)/); + if (!match) return; + const remindTime = match[1]; + + let userConfig = await this.getUserConfig(this.e.user_id); + if (!userConfig) { + const defaultConfig = settings.getConfig('remind'); + userConfig = { + enable: false, + abyssCheckLevel: defaultConfig.abyssCheckLevel, + deadlyStars: defaultConfig.deadlyStars, + }; + } + + userConfig.remindTime = remindTime; + await this.setUserConfig(this.e.user_id, userConfig); + await this.reply(`您的个人提醒时间已设置为: ${remindTime}`); + } + + async viewMyRemindTime() { + const userConfig = await this.getUserConfig(this.e.user_id); + if (userConfig && userConfig.remindTime) { + await this.reply(`当前提醒时间: ${userConfig.remindTime}`); + } else { + const globalRemindTime = settings.getConfig('remind.globalRemindTime') || '每日20时'; + await this.reply(`个人提醒时间未设置,默认使用全局时间: ${globalRemindTime}`); + } + } + + async deleteMyRemindTime() { + let userConfig = await this.getUserConfig(this.e.user_id); + if (userConfig && userConfig.remindTime) { + delete userConfig.remindTime; + await this.setUserConfig(this.e.user_id, userConfig); + await this.reply('个人提醒时间已取消'); + } else { + await this.reply('个人提醒时间尚未设置'); + } + } } \ No newline at end of file