fix: 修复管理函数位置

This commit is contained in:
Qian23333 2025-08-16 07:15:55 +08:00
parent 94aefc1f0b
commit a34c2835e4
3 changed files with 70 additions and 91 deletions

View file

@ -88,6 +88,11 @@ export class Manage extends ZZZPlugin {
reg: `${rulePrefix}设置检查更新时间(.+)$`, reg: `${rulePrefix}设置检查更新时间(.+)$`,
fnc: 'setCheckUpdateCron', 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.setCheckUpdateCron = manage.version.setCheckUpdateCron;
this.setDefaultDevice = manage.device.setDefaultDevice; this.setDefaultDevice = manage.device.setDefaultDevice;
this.toSetDefaultDevice = manage.device.toSetDefaultDevice; this.toSetDefaultDevice = manage.device.toSetDefaultDevice;
this.setGlobalRemind = manage.remind.setGlobalRemind;
} }
} }

View file

@ -1,96 +1,16 @@
import _ from 'lodash';
import settings from '../../lib/settings.js'; 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 async function setGlobalRemind() {
export class RemindManage extends ZZZPlugin { if (!this.e.isMaster) {
constructor() { this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
super({ return false;
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',
},
],
});
} }
const match = this.e.msg.match(/设置全局提醒时间\s*(每日\d+时|每周.\d+时)/);
if (!match) return;
const remindTime = match[1];
async getUserConfig(userId) { // 将全局提醒时间写入yaml配置
const userConfigJson = await redis.hGet(USER_CONFIGS_KEY, String(userId)); settings.setConfig('remind.globalRemindTime', remindTime);
return userConfigJson ? JSON.parse(userConfigJson) : null; await this.reply(`全局提醒时间已更新为: ${remindTime}`);
}
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('个人提醒时间尚未设置');
}
}
} }

View file

@ -35,6 +35,18 @@ export class Remind extends ZZZPlugin {
reg: `${rulePrefix}查询挑战状态$`, reg: `${rulePrefix}查询挑战状态$`,
fnc: 'checkNow', 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] 式舆防卫战/危局强袭战提醒任务执行完毕'); 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('个人提醒时间尚未设置');
}
}
} }