bug fixes

This commit is contained in:
liyunze 2024-05-11 14:36:07 +08:00
parent deb9344950
commit 6a963d028c
3 changed files with 32 additions and 8 deletions

View file

@ -335,6 +335,7 @@ const defaultConfigs = (function () {
clearedTasks: "All {taskName}s have been cleared, {user}!", clearedTasks: "All {taskName}s have been cleared, {user}!",
adminDeleteTasks: "All of {mentioned}'s {taskName}s have been deleted", adminDeleteTasks: "All of {mentioned}'s {taskName}s have been deleted",
clearedAll: "All {taskName}s and points have been cleared, {user}!", clearedAll: "All {taskName}s and points have been cleared, {user}!",
clearedDone: "All completed {taskName}s have been cleared, {user}!",
// Grouped by task completion responses // Grouped by task completion responses
taskFinished: taskFinished:

View file

@ -80,16 +80,25 @@ async function processCommand(user, command, message, flags, extra) {
} }
let finishedResponse = getResponse("taskFinished"); let finishedResponse = getResponse("taskFinished");
params.task = finishRequest.body.markedTasks; params.task = finishRequest.body.markedTasks;
params.doneCount = await completedTasksCount(user); params.doneCount = await completedTasksCount(user);
params.pointCount = params.pointCount =
finishRequest.body.markedTasksCount * getSetting("pointsPerTask"); finishRequest.body.markedTasksCount * getSetting("pointsPerTask");
if (finishRequest.body.failedTasks !== "") { 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); respond(finishedResponse, params);
} else if (getCommand("unfinishTaskCommands").includes(command)) { } else if (getCommand("unfinishTaskCommands").includes(command)) {
let unfinishRequest = await markTaskUndone(user, message); let unfinishRequest = await markTaskUndone(user, message);
@ -165,6 +174,7 @@ async function processCommand(user, command, message, flags, extra) {
respond(unfocusedResponse, params); respond(unfocusedResponse, params);
} else if (getCommand("checkCommands").includes(command)) { } else if (getCommand("checkCommands").includes(command)) {
var checkingUser = user;
if (message === "") { if (message === "") {
let checkRequest = await checkTasks(user); let checkRequest = await checkTasks(user);
if (checkRequest.status !== 200) { if (checkRequest.status !== 200) {
@ -183,7 +193,10 @@ async function processCommand(user, command, message, flags, extra) {
.join(" | ") .join(" | ")
.replaceAll("{taskName}", getSetting("taskName")); .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); // return respond(checkRequest.body.reply, params);
@ -203,9 +216,14 @@ async function processCommand(user, command, message, flags, extra) {
// respond every 10 tasks // respond every 10 tasks
for (let i = 0; i < incompleteTasks.length; i += 10) { for (let i = 0; i < incompleteTasks.length; i += 10) {
let tasks = incompleteTasks.slice(i, 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)) { } else if (getCommand("adminDeleteCommands").includes(command)) {
@ -484,7 +502,7 @@ async function processCommand(user, command, message, flags, extra) {
let leaderboard = leaderboardResponse.body.leaderboard; let leaderboard = leaderboardResponse.body.leaderboard;
respond(leaderboard, params); await respond(leaderboard, params);
} else if (getCommand("adminSetBoardCountCommands").includes(command)) { } else if (getCommand("adminSetBoardCountCommands").includes(command)) {
if (!isStreamer(flags)) { if (!isStreamer(flags)) {
respond(getResponse("notStreamer"), params); respond(getResponse("notStreamer"), params);

View file

@ -721,9 +721,11 @@ async function leaderboardTaskCount(limit) {
let leaderboardArray = []; let leaderboardArray = [];
for (const user in counts.users) { for (const user in counts.users) {
let userTaskCount = await completedTasksCount(user);
leaderboardArray.push({ leaderboardArray.push({
username: user, username: user,
taskCount: getUserTotalTaskCount(user), taskCount: userTaskCount,
}); });
} }
@ -2134,6 +2136,8 @@ async function clearUserTasks(username) {
async function clearAllDoneTasks() { async function clearAllDoneTasks() {
const tasks = await DBHandler.get("tasks"); const tasks = await DBHandler.get("tasks");
for (const user in 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); tasks[user].todos = tasks[user].todos.filter((t) => !t.done);
} }
cancelAnimation(); cancelAnimation();
@ -2147,6 +2151,7 @@ async function clearAllDoneTasks() {
async function clearAllTasks() { async function clearAllTasks() {
await DBHandler.set("tasks", {}); await DBHandler.set("tasks", {});
await setupDB();
cancelAnimation(); cancelAnimation();
await renderTaskListToDOM(); await renderTaskListToDOM();
@ -2156,7 +2161,7 @@ async function clearAllTasks() {
} }
async function clearAll() { async function clearAll() {
resetDB(); await resetDB();
cancelAnimation(); cancelAnimation();
checkToAnimate(); checkToAnimate();
await renderTaskListToDOM(); await renderTaskListToDOM();