added "!done all" command

This commit is contained in:
liyunze 2023-08-26 23:18:58 +08:00
parent 2a6aa38563
commit 2323839e75
3 changed files with 38 additions and 0 deletions

View file

@ -213,6 +213,7 @@ const configs = (function () {
const adminDeleteTasks = "All of {mentioned}'s tasks have been deleted"; const adminDeleteTasks = "All of {mentioned}'s tasks have been deleted";
const taskFinished = 'Good job on finishing the task "{task}", {user}!'; const taskFinished = 'Good job on finishing the task "{task}", {user}!';
const allTasksFinished = "Good job on finishing all your tasks, {user}!";
const taskUnfinished = const taskUnfinished =
'Task(s) "{task}" has been unmarked as done, {user}!'; 'Task(s) "{task}" has been unmarked as done, {user}!';
const taskEdited = const taskEdited =
@ -326,6 +327,7 @@ const configs = (function () {
specifyTaskIndex, specifyTaskIndex,
duplicateTask, duplicateTask,
taskFinished, taskFinished,
allTasksFinished,
taskUnfinished, taskUnfinished,
taskEdited, taskEdited,
noTaskEdit, noTaskEdit,

View file

@ -87,6 +87,22 @@ ComfyJS.onCommand = (user, command, message, flags, extra) => {
respond(deletedResponse, params); respond(deletedResponse, params);
} }
} else if (commands.finishTaskCommands.includes(command)) { } else if (commands.finishTaskCommands.includes(command)) {
if (message === "all") {
let finishAllStatus = markAllTasksAsDone(user);
if (finishAllStatus === 0) {
// user has no tasks
respond(responses.noTask, params);
} else {
// all tasks finished
let finishedResponse = responses.allTasksFinished;
respond(finishedResponse, params);
}
return;
}
let finishStatus = markTaskDone(user, message); let finishStatus = markTaskDone(user, message);
if (finishStatus === 0) { if (finishStatus === 0) {

View file

@ -467,6 +467,26 @@ function markTaskDone(username, task) {
} }
} }
function markAllTasksAsDone(username) {
const tasks = JSON.parse(localStorage.tasks);
// user does not have any tasks
if (!tasks[username] || tasks[username].todos.length === 0) {
return 0;
}
for (const task of tasks[username].todos) {
task.done = true;
}
localStorage.setItem(`tasks`, JSON.stringify(tasks));
if (!scrolling) {
renderTaskListToDOM();
}
return 1;
}
function markTaskUndone(username, task) { function markTaskUndone(username, task) {
const tasks = JSON.parse(localStorage.tasks); const tasks = JSON.parse(localStorage.tasks);