From b5b2d9d7e23febf5fedbe9b12c38747b504cd885 Mon Sep 17 00:00:00 2001 From: liyunze <50455574+liyunze-coding@users.noreply.github.com> Date: Mon, 7 Aug 2023 22:19:08 +0800 Subject: [PATCH] add multiple tasks in the same command --- configs.js | 2 +- scripts/index.js | 3 ++- scripts/taskList.js | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/configs.js b/configs.js index fa1aafb..6907e60 100644 --- a/configs.js +++ b/configs.js @@ -175,7 +175,7 @@ const configs = (function () { ]; // Responses - const taskAdded = 'The task "{message}" has been added, {user}!'; + const taskAdded = 'The task(s) "{task}" has been added, {user}!'; const noTaskAdded = "Looks like you already hit the limit of incomplete tasks, {user}"; const noTaskContent = "Try using !task the-task-you-are-working-on {user}"; diff --git a/scripts/index.js b/scripts/index.js index 92317a5..8ec2427 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -41,7 +41,8 @@ ComfyJS.onCommand = (user, command, message, flags, extra) => { } else if (addStatus === 2) { // task has no content respond(responses.noTaskContent, params); - } else if (addStatus === 3) { + } else { + params.task = addStatus; // task added respond(responses.taskAdded, params); } diff --git a/scripts/taskList.js b/scripts/taskList.js index 6911923..46566c3 100644 --- a/scripts/taskList.js +++ b/scripts/taskList.js @@ -152,7 +152,7 @@ function setupDB() { // 0: limit has reached // 1: duplicate task // 2: invalid input -// 3: success +// string (single or multiple tasks): success function addTask(username, userColor, task) { const tasks = JSON.parse(localStorage.tasks); if (!tasks[username]) { @@ -183,11 +183,22 @@ function addTask(username, userColor, task) { return 2; } + // if task has commas + if (task.includes(",")) { + let tasksToAdd = task.split(",").map((t) => t.trim()); + for (const t of tasksToAdd) { + tasks[username].todos.push({ text: t, done: false }); + } + localStorage.setItem(`tasks`, JSON.stringify(tasks)); + renderTaskListToDOM(); + return tasksToAdd.join('", "'); + } + tasks[username].todos.push({ text: task, done: false }); localStorage.setItem(`tasks`, JSON.stringify(tasks)); renderTaskListToDOM(); - return 3; + return task; } // 0: user has no tasks