MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / parseTask

Method parseTask

sendat/sendat.ts:104–185  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

102 if (parts.length < 2) {
103 throw new Error("任务格式错误,请使用 '时间 | 消息内容' 格式");
104 }
105
106 this.msg = parts.slice(1).join("|").trim();
107 if (!this.msg) {
108 throw new Error("消息内容不能为空");
109 }
110
111 const timePart = parts[0].trim();
112 let hasEvery = false;
113 let timeText = timePart;
114
115 // 检查是否有 every 关键字
116 if (timePart.toLowerCase().includes("every")) {
117 hasEvery = true;
118 this.interval = true;
119 timeText = timePart.toLowerCase().replace("every", "").trim();
120 }
121
122 const timeComponents = timeText.split(/\s+/);
123 if (timeComponents.length % 2 !== 0) {
124 throw new Error("时间格式错误");
125 }
126
127 let hasDate = false;
128 let hasTimeUnit = false;
129
130 for (let i = 0; i < timeComponents.length; i += 2) {
131 const value = timeComponents[i];
132 const unit = timeComponents[i + 1].toLowerCase();
133
134 switch (unit) {
135 case "seconds":
136 hasTimeUnit = true;
137 this.second = SendTask.checkTime(value, 0, 59);
138 break;
139 case "minutes":
140 hasTimeUnit = true;
141 this.minute = SendTask.checkTime(value, 0, 59);
142 break;
143 case "hours":
144 hasTimeUnit = true;
145 this.hour = SendTask.checkTime(value, 0, 23);
146 break;
147 case "times":
148 this.time_limit = parseInt(SendTask.checkTime(value, 1));
149 break;
150 case "date":
151 hasDate = true;
152 hasTimeUnit = true;
153 this.cron = true;
154 // 解析时间格式 HH:MM:SS
155 const timeParts = value.split(":");
156 if (timeParts.length !== 3) {
157 throw new Error("时间格式应为 HH:MM:SS");
158 }
159 this.hour = SendTask.checkTime(timeParts[0], 0, 23);
160 this.minute = SendTask.checkTime(timeParts[1], 0, 59);
161 this.second = SendTask.checkTime(timeParts[2], 0, 59);

Callers 1

handleAddTaskMethod · 0.95

Calls 1

checkTimeMethod · 0.80

Tested by

no test coverage detected