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

Method parseTask

keyword/keyword.ts:228–300  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

226 console.error("Process keyword error:", error);
227 }
228 }
229
230 parseTask(text: string): void {
231 const data = text.split("\n+++\n");
232 if (data.length < 2) {
233 throw new Error("任务格式无效");
234 }
235
236 for (const part of data) {
237 if (part === "") {
238 throw new Error("任务格式无效");
239 }
240 }
241
242 this.key = data[0];
243 this.msg = data[1];
244
245 if (data.length > 2) {
246 const options = data[2].split(" ");
247 for (const option of options) {
248 if (option.startsWith("include")) {
249 this.include = true;
250 } else if (option.startsWith("exact")) {
251 this.include = false;
252 this.exact = true;
253 } else if (option.startsWith("regexp")) {
254 this.regexp = true;
255 } else if (option.startsWith("case")) {
256 this.case = true;
257 } else if (option.startsWith("ignore_forward")) {
258 this.ignore_forward = true;
259 } else if (option.trim() !== "") {
260 throw new Error("任务格式无效");
261 }
262 }
263
264 if (this.include && this.exact) {
265 throw new Error("不能同时设置include和exact选项");
266 }
267 }
268
269 if (data.length > 3) {
270 const actions = data[3].split(" ");
271 for (const action of actions) {
272 if (action.startsWith("reply")) {
273 this.reply = true;
274 } else if (action.startsWith("delete")) {
275 this.delete = true;
276 } else if (action.startsWith("ban")) {
277 this.ban = parseInt(action.replace("ban", "")) || 0;
278 } else if (action.startsWith("restrict")) {
279 this.restrict = parseInt(action.replace("restrict", "")) || 0;
280 } else if (action.trim() !== "") {
281 throw new Error("任务格式无效");
282 }
283 }
284 }
285

Callers 1

keywordFunction · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected