add multiple tasks in the same command
This commit is contained in:
parent
1eb7611d5c
commit
b5b2d9d7e2
3 changed files with 16 additions and 4 deletions
|
|
@ -175,7 +175,7 @@ const configs = (function () {
|
||||||
];
|
];
|
||||||
|
|
||||||
// Responses
|
// Responses
|
||||||
const taskAdded = 'The task "{message}" has been added, {user}!';
|
const taskAdded = 'The task(s) "{task}" has been added, {user}!';
|
||||||
const noTaskAdded =
|
const noTaskAdded =
|
||||||
"Looks like you already hit the limit of incomplete tasks, {user}";
|
"Looks like you already hit the limit of incomplete tasks, {user}";
|
||||||
const noTaskContent = "Try using !task the-task-you-are-working-on {user}";
|
const noTaskContent = "Try using !task the-task-you-are-working-on {user}";
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,8 @@ ComfyJS.onCommand = (user, command, message, flags, extra) => {
|
||||||
} else if (addStatus === 2) {
|
} else if (addStatus === 2) {
|
||||||
// task has no content
|
// task has no content
|
||||||
respond(responses.noTaskContent, params);
|
respond(responses.noTaskContent, params);
|
||||||
} else if (addStatus === 3) {
|
} else {
|
||||||
|
params.task = addStatus;
|
||||||
// task added
|
// task added
|
||||||
respond(responses.taskAdded, params);
|
respond(responses.taskAdded, params);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ function setupDB() {
|
||||||
// 0: limit has reached
|
// 0: limit has reached
|
||||||
// 1: duplicate task
|
// 1: duplicate task
|
||||||
// 2: invalid input
|
// 2: invalid input
|
||||||
// 3: success
|
// string (single or multiple tasks): success
|
||||||
function addTask(username, userColor, task) {
|
function addTask(username, userColor, task) {
|
||||||
const tasks = JSON.parse(localStorage.tasks);
|
const tasks = JSON.parse(localStorage.tasks);
|
||||||
if (!tasks[username]) {
|
if (!tasks[username]) {
|
||||||
|
|
@ -183,11 +183,22 @@ function addTask(username, userColor, task) {
|
||||||
return 2;
|
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 });
|
tasks[username].todos.push({ text: task, done: false });
|
||||||
localStorage.setItem(`tasks`, JSON.stringify(tasks));
|
localStorage.setItem(`tasks`, JSON.stringify(tasks));
|
||||||
renderTaskListToDOM();
|
renderTaskListToDOM();
|
||||||
|
|
||||||
return 3;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0: user has no tasks
|
// 0: user has no tasks
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue