mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-17 13:47:44 +00:00
feat: 支持整十分钟
This commit is contained in:
parent
7359981c19
commit
fcb78f2426
2 changed files with 31 additions and 13 deletions
|
|
@ -6,9 +6,17 @@ export async function setGlobalRemind() {
|
||||||
this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
|
this.reply('仅限主人设置', false, { at: true, recallMsg: 100 });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const match = this.e.msg.match(/设置全局提醒时间\s*(每日\d+时|每周.\d+时)/);
|
const match = this.e.msg.match(/设置全局提醒时间\s*(每日\d+时(?:(\d+)分)?)|每周.\d+时(?:(\d+)分)?))/);
|
||||||
if (!match) return;
|
if (!match) return;
|
||||||
const remindTime = match[1];
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
settings.setSingleConfig('remind', 'globalRemindTime', remindTime);
|
settings.setSingleConfig('remind', 'globalRemindTime', remindTime);
|
||||||
await this.reply(`全局提醒时间已更新为: ${remindTime}。`);
|
await this.reply(`全局提醒时间已更新为: ${remindTime}。`);
|
||||||
}
|
}
|
||||||
|
|
@ -36,7 +36,7 @@ export class Remind extends ZZZPlugin {
|
||||||
fnc: 'checkNow',
|
fnc: 'checkNow',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
reg: `${rulePrefix}设置个人提醒时间\\s*(每日\\d+时|每周.\\d+时)`,
|
reg: `${rulePrefix}设置个人提醒时间\\s*(每日\\d+时(?:(\\d+)分)?|每周.\\d+时(?:(\\d+)分)?)`,
|
||||||
fnc: 'setMyRemindTime',
|
fnc: 'setMyRemindTime',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -54,7 +54,7 @@ export class Remind extends ZZZPlugin {
|
||||||
if (globalRemindConfig.enable) {
|
if (globalRemindConfig.enable) {
|
||||||
this.task = {
|
this.task = {
|
||||||
name: 'ZZZ-Plugin式舆防卫战/危局强袭战提醒任务',
|
name: 'ZZZ-Plugin式舆防卫战/危局强袭战提醒任务',
|
||||||
cron: '0 * * * * ?', // 每小时的第0分钟执行
|
cron: '0 0/10 * * * *',
|
||||||
fnc: () => this.runTask(),
|
fnc: () => this.runTask(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -72,23 +72,26 @@ export class Remind extends ZZZPlugin {
|
||||||
isTimeMatch(remindTime, date) {
|
isTimeMatch(remindTime, date) {
|
||||||
if (!remindTime) return false;
|
if (!remindTime) return false;
|
||||||
|
|
||||||
const currentHour = date.getHours();
|
|
||||||
const currentDay = date.getDay(); // 0 = 周日, 1 = 周一, ..., 6 = 周六
|
const currentDay = date.getDay(); // 0 = 周日, 1 = 周一, ..., 6 = 周六
|
||||||
|
const currentHour = date.getHours();
|
||||||
|
const currentMinute = date.getMinutes();
|
||||||
|
|
||||||
if (remindTime.includes('每日')) {
|
if (remindTime.includes('每日')) {
|
||||||
const match = remindTime.match(/每日(\d+)时/);
|
const match = remindTime.match(/每日(\d+)时(?:(\d+)分)?/);
|
||||||
if (match) {
|
if (match) {
|
||||||
const hour = parseInt(match[1], 10);
|
const hour = parseInt(match[1]);
|
||||||
return currentHour === hour;
|
const minute = match[2] ? parseInt(match[2]) : 0;
|
||||||
|
return currentHour === hour && currentMinute === minute;
|
||||||
}
|
}
|
||||||
} else if (remindTime.includes('每周')) {
|
} else if (remindTime.includes('每周')) {
|
||||||
const dayMap = { '日': 0, '一': 1, '二': 2, '三': 3, '四': 4, '五': 5, '六': 6 };
|
const dayMap = { '日': 0, '天': 0, '一': 1, '二': 2, '三': 3, '四': 4, '五': 5, '六': 6 };
|
||||||
const match = remindTime.match(/每周(.)(\d+)时/);
|
const match = remindTime.match(/每周(.)(\d+)时(?:(\d+)分)?/);
|
||||||
if (match) {
|
if (match) {
|
||||||
const dayChar = match[1];
|
const dayChar = match[1];
|
||||||
const hour = parseInt(match[2], 10);
|
const day = dayMap[dayChar];
|
||||||
const day = dayMap[dayChar] || parseInt(dayChar, 10);
|
const hour = parseInt(match[2]);
|
||||||
return currentDay === day && currentHour === hour;
|
const minute = match[3] ? parseInt(match[3]) : 0;
|
||||||
|
return currentDay === day && currentHour === hour && currentMinute === minute;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -300,9 +303,16 @@ export class Remind extends ZZZPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
async setMyRemindTime() {
|
async setMyRemindTime() {
|
||||||
const match = this.e.msg.match(/设置个人提醒时间\s*(每日\d+时|每周.\d+时)/);
|
const match = this.e.msg.match(/设置个人提醒时间\s*(每日\d+时(?:(\d+)分)?|每周.\d+时(?:(\d+)分)?)/);
|
||||||
if (!match) return;
|
if (!match) return;
|
||||||
const remindTime = match[1];
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
let userConfig = await this.getUserConfig(this.e.user_id);
|
let userConfig = await this.getUserConfig(this.e.user_id);
|
||||||
if (!userConfig) {
|
if (!userConfig) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue