From 20af0deb68b06795f1532bacbd8bd03c6c91fbd2 Mon Sep 17 00:00:00 2001 From: UCPr <2032385471@qq.com> Date: Mon, 8 Sep 2025 18:05:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A5=BD=E5=8F=8B=E3=80=81=E5=90=AF=E7=94=A8?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=88=A4=E6=96=AD=EF=BC=9B=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=85=A8=E5=B1=80=E5=BC=8F=E8=88=86/?= =?UTF-8?q?=E5=8D=B1=E5=B1=80=E9=98=88=E5=80=BC=EF=BC=9B=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E9=83=A8=E5=88=86return=20false=EF=BC=9B=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=B8=AE=E5=8A=A9=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/help.js | 60 +++++++++++++-------- apps/remind.js | 142 +++++++++++++++++++++++++++++++------------------ 2 files changed, 127 insertions(+), 75 deletions(-) diff --git a/apps/help.js b/apps/help.js index a83ec2a..70aa309 100644 --- a/apps/help.js +++ b/apps/help.js @@ -188,32 +188,39 @@ const helpData = [ icon: 'dungeon', items: [ { - title: '开启/关闭挑战提醒', + title: '开关挑战提醒', desc: '开启或关闭式舆防卫战/危局强袭战未完成提醒功能', needCK: true, needSK: false, commands: ['开启挑战提醒', '关闭挑战提醒'], }, + { + title: '开关全局挑战提醒', + desc: '开启或关闭全局式舆防卫战/危局强袭战未完成提醒功能', + needCK: true, + needSK: false, + commands: ['开启全局挑战提醒', '关闭全局挑战提醒'], + }, + { + title: '设置全局提醒时间', + desc: '设置全局提醒时间,所有未单独设置个人提醒时间的用户将使用此时间。格式同上,仅限主人可用。', + needCK: true, + needSK: false, + commands: ['设置全局提醒时间+时间'], + }, + { + title: '设置全局提醒阈值', + desc: '设置全局默认防卫战检查层数阈值(1~7),或全局默认危局强袭战星星阈值(1~9)', + needCK: true, + needSK: false, + commands: ['设置全局式舆阈值+数字', '设置全局危局阈值+数字'], + }, { title: '设置提醒阈值', - desc: '设置式舆防卫战检查层数阈值(1~7),或危局强袭战星星阈值。例如:设置式舆阈值7', + desc: '设置防卫战检查层数阈值(1~7),或危局强袭战星星阈值(1~9)。例如:设置危局阈值6', needCK: true, needSK: false, - commands: ['设置式舆阈值+数字', '设置防卫战阈值+数字', '设置强袭阈值+数字', '设置危局强袭战阈值+数字'], - }, - { - title: '查询挑战状态', - desc: '主动查询当前式舆防卫战/危局强袭战完成情况', - needCK: true, - needSK: false, - commands: ['查询挑战状态'], - }, - { - title: '查看提醒时间', - desc: '查看个人提醒时间或全局提醒时间', - needCK: true, - needSK: false, - commands: ['个人提醒时间', '全局提醒时间'] + commands: ['设置防卫战阈值+数字', '设置危局阈值+数字'], }, { title: '设置个人提醒时间', @@ -223,18 +230,25 @@ const helpData = [ commands: ['设置个人提醒时间+时间'], }, { - title: '取消个人提醒时间', - desc: '取消已设置的个人提醒时间', + title: '查看提醒时间', + desc: '查看个人或全局提醒时间', needCK: true, needSK: false, - commands: ['取消个人提醒时间'], + commands: ['个人提醒时间', '全局提醒时间'] }, { - title: '设置全局提醒时间', - desc: '设置全局提醒时间,所有未单独设置个人提醒时间的用户将使用此时间。格式同上,仅限主人可用。', + title: '重置个人提醒时间', + desc: '重置已设置的个人提醒时间为全局默认时间', needCK: true, needSK: false, - commands: ['设置全局提醒时间+时间'], + commands: ['重置个人提醒时间'], + }, + { + title: '查询挑战状态', + desc: '主动查询当前式舆防卫战/危局强袭战完成情况', + needCK: true, + needSK: false, + commands: ['查询挑战状态'], }, ], }, diff --git a/apps/remind.js b/apps/remind.js index 52677b8..e2c9e97 100644 --- a/apps/remind.js +++ b/apps/remind.js @@ -33,17 +33,17 @@ export class Remind extends ZZZPlugin { fnc: 'setSubscribeEnable', }, { - reg: `${rulePrefix}(开启|关闭)全局挑战提醒$`, + reg: `${rulePrefix}(开启|启用|关闭|禁用)全局挑战提醒$`, fnc: 'setGlobalRemindEnable', permission: 'master', }, { - reg: `${rulePrefix}设置式舆阈值\\s*(\\d+)`, - fnc: 'setMyAbyssThreshold', + reg: `${rulePrefix}设置(全局)?式舆阈值\\s*(\\d+)`, + fnc: 'setAbyssThreshold', }, { - reg: `${rulePrefix}设置危局阈值\\s*(\\d+)`, - fnc: 'setMyDeadlyThreshold', + reg: `${rulePrefix}设置(全局)?危局阈值\\s*(\\d+)`, + fnc: 'setDeadlyThreshold', }, { reg: `${rulePrefix}查询挑战状态$`, @@ -58,7 +58,7 @@ export class Remind extends ZZZPlugin { fnc: 'viewMyRemindTime', }, { - reg: `${rulePrefix}取消个人提醒时间`, + reg: `${rulePrefix}(重置|删除|取消)个人提醒时间`, fnc: 'deleteMyRemindTime', }, { @@ -132,16 +132,28 @@ export class Remind extends ZZZPlugin { return false; } + checkEnableAndFriend() { + if (!settings.getConfig('remind').enable) { + this.reply('当前未启用防卫战/危局挑战提醒功能'); + return false; + } + if (!(this.e.bot ?? Bot).fl.get(this.e.user_id)) { + this.reply('请添加好友后重试'); + return false; + }; + return true; + } + async setSubscribeEnable() { + if (!this.checkEnableAndFriend()) return; const enable = /开启挑战提醒$/.test(this.e.msg); const uid = await this.getUID(); if (enable && !uid) { - await this.reply('未绑定UID,请先绑定'); - return false; + return this.reply('未绑定UID,请先绑定'); } let userConfig = await this.getUserConfig(this.e.user_id); + const defaultConfig = settings.getConfig('remind'); if (!userConfig) { - const defaultConfig = settings.getConfig('remind'); userConfig = { enable: false, abyssCheckLevel: defaultConfig.abyssCheckLevel, @@ -149,67 +161,89 @@ export class Remind extends ZZZPlugin { }; } if (userConfig.enable === enable) { - await this.reply(enable ? '提醒已开启,请勿重复操作' : '提醒功能尚未开启'); - return false; + return this.reply(enable ? '提醒已开启,请勿重复操作' : '提醒功能尚未开启'); } userConfig.enable = enable; await this.setUserConfig(this.e.user_id, userConfig); - await this.reply(`提醒功能已${enable ? '开启' : '关闭'}`); + await this.reply(`提醒功能已${enable ? '开启' : '关闭'}${enable ? `,将在${userConfig.remindTime || defaultConfig.globalRemindTime}对防卫战<${userConfig.abyssCheckLevel}层或危局<${userConfig.deadlyStars}星进行提醒` : ''}`); } async setGlobalRemindEnable() { if (!this.e.isMaster) { - this.reply('仅限主人设置', false, { at: true, recallMsg: 100 }); - return false; + return this.reply('仅限主人设置', false, { at: true, recallMsg: 100 }); + } + const enable = /(开启|启用)全局挑战提醒$/.test(this.e.msg); + if (settings.getConfig('remind').enable === enable) { + return this.reply(enable ? '全局防卫战/危局挑战提醒功能已启用,请勿重复操作' : '全局防卫战/危局挑战提醒功能已禁用,请勿重复操作'); } - const enable = /开启全局挑战提醒$/.test(this.e.msg); settings.setSingleConfig('remind', 'enable', enable); - await this.reply(`全局提醒功能已${enable ? '开启' : '关闭'}`); + await this.reply(`全局防卫战/危局挑战提醒功能已${enable ? '启用' : '禁用'}`); } - async setMyAbyssThreshold() { - const match = this.e.msg.match(/设置(?:式舆防卫战|式舆|深渊|防卫战|防卫)阈值\s*(\d+)/); + async setAbyssThreshold() { + const isGlobal = this.e.msg.includes('全局'); + if (isGlobal && !this.e.isMaster) { + return this.reply('仅限主人设置', false, { at: true, recallMsg: 100 }); + } + if (!isGlobal && !this.checkEnableAndFriend()) return; + const match = this.e.msg.match(/设置(?:全局)?(?:式舆防卫战|式舆|深渊|防卫战|防卫)阈值\s*(\d+)/); if (!match) return; const threshold = Number(match[1]); if (threshold < 1 || threshold > 7) { - await this.reply('阈值必须在1到7之间'); - return false; + return this.reply('防卫战阈值必须在1到7之间'); } + + if (isGlobal) { + settings.setSingleConfig('remind', 'abyssCheckLevel', threshold); + } else { + 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.abyssCheckLevel = threshold; + await this.setUserConfig(this.e.user_id, userConfig); + }; - 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.abyssCheckLevel = threshold; - await this.setUserConfig(this.e.user_id, userConfig); - await this.reply(`式舆防卫战提醒阈值已设为: 检查前 ${threshold} 层`); + await this.reply(`${isGlobal ? '全局默认' : ''}式舆防卫战阈值已设为: <${threshold}层时提醒`); } - async setMyDeadlyThreshold() { - const match = this.e.msg.match(/设置(?:危局强袭战|危局|强袭|强袭战)阈值\s*(\d+)/); + async setDeadlyThreshold() { + const isGlobal = this.e.msg.includes('全局'); + if (isGlobal && !this.e.isMaster) { + return this.reply('仅限主人设置', false, { at: true, recallMsg: 100 }); + } + if (!isGlobal && !this.checkEnableAndFriend()) return; + const match = this.e.msg.match(/设置(?:全局)?(?:危局强袭战|危局|强袭|强袭战)阈值\s*(\d+)/); if (!match) return; const threshold = Number(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, - }; + if (threshold < 1 || threshold > 9) { + return this.reply('危局阈值必须在1到9之间'); } - userConfig.deadlyStars = threshold; - await this.setUserConfig(this.e.user_id, userConfig); - await this.reply(`危局强袭战星星阈值已设为: ${threshold}`); + if (isGlobal) { + settings.setSingleConfig('remind', 'deadlyStars', threshold); + } else { + 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.deadlyStars = threshold; + await this.setUserConfig(this.e.user_id, userConfig); + } + await this.reply(`${isGlobal ? '全局默认' : ''}危局强袭战阈值已设为: <${threshold}星时提醒`); } async checkNow() { @@ -311,6 +345,7 @@ export class Remind extends ZZZPlugin { for (const userId in allUserConfigs) { const userConfig = JSON.parse(allUserConfigs[userId]); if (!userConfig.enable) continue; + if (!Bot.fl.get(userId)) continue; const remindTime = userConfig.remindTime || globalRemindTime; @@ -324,7 +359,9 @@ export class Remind extends ZZZPlugin { const messages = await this.checkUser(userId, userConfig, false, mockE); if (messages.length > 0) { - await Bot.pickFriend(userId).sendMsg(messages.join('\n')); + await Bot.pickFriend(userId).sendMsg('【式舆/危局挑战提醒】\n' + messages.join('\n')).catch(err => { + logger.error(`[ZZZ-Plugin] 式舆/危局挑战推送用户 ${userId} 失败`, err); + }); } } } @@ -332,6 +369,7 @@ export class Remind extends ZZZPlugin { } async setMyRemindTime() { + if (!this.checkEnableAndFriend()) return; const { remindTime, error } = this.parseRemindTimeMessage(this.e.msg); if (!remindTime) return await this.reply(error); @@ -353,7 +391,7 @@ export class Remind extends ZZZPlugin { async viewMyRemindTime() { const userConfig = await this.getUserConfig(this.e.user_id); if (userConfig && userConfig.remindTime) { - await this.reply(`当前提醒时间: ${userConfig.remindTime}`); + await this.reply(`当前个人提醒时间: ${userConfig.remindTime}`); } else { const remindConfig = settings.getConfig('remind'); const globalRemindTime = remindConfig.globalRemindTime || '每日20时'; @@ -362,11 +400,12 @@ export class Remind extends ZZZPlugin { } async deleteMyRemindTime() { + if (!this.checkEnableAndFriend()) return; 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('个人提醒时间已取消'); + await this.reply('个人提醒时间已重置为全局默认时间'); } else { await this.reply('个人提醒时间尚未设置'); } @@ -374,14 +413,13 @@ export class Remind extends ZZZPlugin { async setGlobalRemindTime() { if (!this.e.isMaster) { - this.reply('仅限主人设置', false, { at: true, recallMsg: 100 }); - return false; + return this.reply('仅限主人设置', false, { at: true, recallMsg: 100 }); } 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}。`); + await this.reply(`全局提醒时间已更新为: ${globalRemindTime}`); } async viewGlobalRemindTime() {