From 6a963d028c4fb2f21117278ca6c1b75a0a7ea509 Mon Sep 17 00:00:00 2001 From: liyunze <50455574+liyunze-coding@users.noreply.github.com> Date: Sat, 11 May 2024 14:36:07 +0800 Subject: [PATCH] bug fixes --- scripts/defaultConfigs.js | 1 + scripts/processCommand.js | 30 ++++++++++++++++++++++++------ scripts/taskList.js | 9 +++++++-- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/scripts/defaultConfigs.js b/scripts/defaultConfigs.js index 2943b47..151a7a9 100644 --- a/scripts/defaultConfigs.js +++ b/scripts/defaultConfigs.js @@ -335,6 +335,7 @@ const defaultConfigs = (function () { clearedTasks: "All {taskName}s have been cleared, {user}!", adminDeleteTasks: "All of {mentioned}'s {taskName}s have been deleted", clearedAll: "All {taskName}s and points have been cleared, {user}!", + clearedDone: "All completed {taskName}s have been cleared, {user}!", // Grouped by task completion responses taskFinished: diff --git a/scripts/processCommand.js b/scripts/processCommand.js index 3e4bda5..9e2d7de 100644 --- a/scripts/processCommand.js +++ b/scripts/processCommand.js @@ -80,16 +80,25 @@ async function processCommand(user, command, message, flags, extra) { } let finishedResponse = getResponse("taskFinished"); - params.task = finishRequest.body.markedTasks; params.doneCount = await completedTasksCount(user); params.pointCount = finishRequest.body.markedTasksCount * getSetting("pointsPerTask"); if (finishRequest.body.failedTasks !== "") { - finishedResponse += ` | Failed to finish task(s): "${finishRequest.body.failedTasks}"`; + finishedResponse += ` | Failed to finish {taskName}(s): "${finishRequest.body.failedTasks}"`; } + finishedResponse = finishedResponse.replaceAll( + "{pointName}", + getSetting("pointsName") + ); + + finishedResponse = finishedResponse.replaceAll( + "{taskName}", + getSetting("taskName") + ); + respond(finishedResponse, params); } else if (getCommand("unfinishTaskCommands").includes(command)) { let unfinishRequest = await markTaskUndone(user, message); @@ -165,6 +174,7 @@ async function processCommand(user, command, message, flags, extra) { respond(unfocusedResponse, params); } else if (getCommand("checkCommands").includes(command)) { + var checkingUser = user; if (message === "") { let checkRequest = await checkTasks(user); if (checkRequest.status !== 200) { @@ -183,7 +193,10 @@ async function processCommand(user, command, message, flags, extra) { .join(" | ") .replaceAll("{taskName}", getSetting("taskName")); - await respond(`{user} {tasks}`, params); + params.checkingUser = checkingUser; + + await respond(`{checkingUser} {tasks}`, params); + await sleep(200); } // return respond(checkRequest.body.reply, params); @@ -203,9 +216,14 @@ async function processCommand(user, command, message, flags, extra) { // respond every 10 tasks for (let i = 0; i < incompleteTasks.length; i += 10) { let tasks = incompleteTasks.slice(i, i + 10); - params.tasks = tasks.join(" | "); + params.tasks = tasks + .join(" | ") + .replaceAll("{taskName}", getSetting("taskName")); - await respond(`{user} {tasks}`, params); + params.checkingUser = checkingUser; + + await respond(`{checkingUser} {tasks}`, params); + await sleep(200); } } } else if (getCommand("adminDeleteCommands").includes(command)) { @@ -484,7 +502,7 @@ async function processCommand(user, command, message, flags, extra) { let leaderboard = leaderboardResponse.body.leaderboard; - respond(leaderboard, params); + await respond(leaderboard, params); } else if (getCommand("adminSetBoardCountCommands").includes(command)) { if (!isStreamer(flags)) { respond(getResponse("notStreamer"), params); diff --git a/scripts/taskList.js b/scripts/taskList.js index bc3e32a..0265880 100644 --- a/scripts/taskList.js +++ b/scripts/taskList.js @@ -721,9 +721,11 @@ async function leaderboardTaskCount(limit) { let leaderboardArray = []; for (const user in counts.users) { + let userTaskCount = await completedTasksCount(user); + leaderboardArray.push({ username: user, - taskCount: getUserTotalTaskCount(user), + taskCount: userTaskCount, }); } @@ -2134,6 +2136,8 @@ async function clearUserTasks(username) { async function clearAllDoneTasks() { const tasks = await DBHandler.get("tasks"); for (const user in tasks) { + if (!tasks[user].todos) continue; + if (user.toLowerCase() === "id") continue; tasks[user].todos = tasks[user].todos.filter((t) => !t.done); } cancelAnimation(); @@ -2147,6 +2151,7 @@ async function clearAllDoneTasks() { async function clearAllTasks() { await DBHandler.set("tasks", {}); + await setupDB(); cancelAnimation(); await renderTaskListToDOM(); @@ -2156,7 +2161,7 @@ async function clearAllTasks() { } async function clearAll() { - resetDB(); + await resetDB(); cancelAnimation(); checkToAnimate(); await renderTaskListToDOM();