This commit is contained in:
liyunze 2024-10-25 19:47:40 +11:00
parent 33cb61b10f
commit 81e3b5f5ba
4 changed files with 67 additions and 55 deletions

View file

@ -11,7 +11,7 @@ const configs = (function () {
taskSeparator: [";", ","], // array of strings
openQuote: '"', // string
closeQuote: '"', // string
testTasks: true, // true or false
testTasks: false, // true or false
headerGoogleFont: true, // true: use google font, false: use system font
taskGoogleFont: true, // true: use google font, false: use system font
displayTaskCount: true, // true or false
@ -334,6 +334,8 @@ const configs = (function () {
nowTask:
"{taskName} {task} is now the task you are working on, {user}!",
taskLogged: "Task(s) {task} has been logged, {user}!",
taskAlreadyCompleted:
"Looks like you already completed that {taskName} {task} up there {user}!",
// Grouped by task progression responses
taskNext:

View file

@ -129,7 +129,6 @@ const defaultConfigs = (function () {
"!task",
"!add",
"!todo",
"!tasks",
"!a",
],
@ -197,7 +196,6 @@ const defaultConfigs = (function () {
"!next",
"!n",
],
logTaskCommands: ["!log", "!tasklog", "!logtask", "!logtasks"],
// focus task commands - please add commands in the exact format
@ -279,7 +277,14 @@ const defaultConfigs = (function () {
resetTaskMasterCommands: ["!resettaskmaster"],
// Help commands - please add commands in the exact format
helpCommands: ["!taskh", "!taskhelp", "!htask", "!helptask", "!help"],
helpCommands: [
"!taskh",
"!taskhelp",
"!htask",
"!helptask",
"!tasks",
"!help",
],
// Admin clear all except streamer - please add commands following the exact format
adminClearNotStreamerCommands: [
@ -329,6 +334,8 @@ const defaultConfigs = (function () {
nowTask:
"{taskName} {task} is now the task you are working on, {user}!",
taskLogged: "Task(s) {task} has been logged, {user}!",
taskAlreadyCompleted:
"Looks like you already completed that {taskName} {task} up there {user}!",
// Grouped by task progression responses
taskNext:

View file

@ -170,7 +170,7 @@ async function processCommand(user, command, message, flags, extra) {
}
// task logged
let loggedResponse = getResponse("taskLogged");
let loggedResponse = await getResponse("taskLogged");
params.task = `${openQuote}${logRequest.body.task}${closeQuote}`;
@ -179,18 +179,6 @@ async function processCommand(user, command, message, flags, extra) {
}
await respond(loggedResponse, params);
// let addRequest = await addTask(user, extra.userColor, message);
// if (addRequest.status !== 200) {
// respond(addRequest.body.error, params);
// return;
// }
// let addedResponse = getResponse("taskAdded");
// params.task = `${openQuote}${addRequest.body.task}${closeQuote}`;
// respond(addedResponse, params);
} else if (getCommand("focusTaskCommands").includes(command)) {
let focusRequest = await focusTask(user, message);

View file

@ -851,13 +851,16 @@ async function _addTask(username, userColor, task, oneTaskOnly = false) {
.split(taskSeparator.find((char) => task.includes(char)))
.map((t) => t.trim());
tasksToAdd.forEach((t) => {
for (const t of tasksToAdd) {
if (
(t &&
!tasks[username].todos.find((task) => task.text === t) &&
t &&
!tasks[username].todos.find(
(task) => task.text === t && !task.completed
) &&
!isInt(t) &&
!getSetting("taskCharacterLimitEnabled")) ||
t.length <= getSetting("taskCharacterLimit")
t.trim() !== "" &&
(!getSetting("taskCharacterLimitEnabled") ||
t.length <= getSetting("taskCharacterLimit"))
) {
tasks[username].todos.push({
text: t,
@ -869,21 +872,16 @@ async function _addTask(username, userColor, task, oneTaskOnly = false) {
addedTaskIndices.push({ index: index, task: t }); // store index of added task
taskListMemory.totalTaskCount++;
} else {
console.log(
!tasks[username].todos.find((task) => task.text === t)
);
console.log(!isInt(t));
console.log(!getSetting("taskCharacterLimitEnabled"));
console.log(task.length <= getSetting("taskCharacterLimit"));
tasksFailedToAdd.push(t);
}
});
}
await DBHandler.set("tasks", tasks);
} else {
const taskExists = tasks[username].todos.find(
(t) => t.text.toLowerCase() === task.toLowerCase()
const taskExistsAndIncomplete = tasks[username].todos.find(
(t) => t.text.toLowerCase() === task.toLowerCase() && !t.done
);
const taskIsInvalid =
!task ||
!task.trim() ||
@ -898,7 +896,7 @@ async function _addTask(username, userColor, task, oneTaskOnly = false) {
(await incompleteTasksCount(username)) >= getSetting("limit") &&
getSetting("enableLimit");
if (taskExists) {
if (taskExistsAndIncomplete) {
return createErrorResponse(
`@${username} already has this task`,
getResponse("duplicateTask")
@ -1676,15 +1674,10 @@ async function markTaskDone(username, task) {
for (const t of tasksToMarkDone) {
let index = tasks[username].todos.findIndex(
(task) => task.text.toLowerCase() === t.toLowerCase()
(task) =>
task.text.toLowerCase() === t.toLowerCase() && !task.done
);
// check if task is already marked done
if (index !== -1 && tasks[username].todos[index].done) {
tasksFailedToComplete.push(t);
continue;
}
if (index === -1) {
if (isInt(t)) {
index = parseInt(t) - 1; // ACTUAL INDEX
@ -1748,7 +1741,7 @@ async function markTaskDone(username, task) {
// if there's no comma in the task (single task)
let index = tasks[username].todos.findIndex(
(t) => t.text.toLowerCase() === task.toLowerCase()
(t) => t.text.toLowerCase() === task.toLowerCase() && !task.done
);
// is there a task with focus on?
@ -1777,6 +1770,7 @@ async function markTaskDone(username, task) {
};
}
// index out of range
if (index < 0 || index > tasks[username].todos.length - 1) {
return {
status: 1,
@ -2175,19 +2169,30 @@ async function logTask(username, userColor, task) {
};
}
const taskExists = tasks[username].todos.find(
(t) => t.text.toLowerCase() === task.toLowerCase()
const taskExistsAndIncomplete = tasks[username].todos.find(
(t) => t.text.toLowerCase() === task.toLowerCase() && !t.done
);
const taskExistsAndCompleted = tasks[username].todos.find(
(t) => t.text.toLowerCase() === task.toLowerCase() && t.done
);
const taskIsInvalid =
!task || !task.trim() || task.toLowerCase() === "all" || isInt(task);
if (taskExists) {
if (taskExistsAndIncomplete) {
return createErrorResponse(
`@${username} already has this task`,
getResponse("duplicateTask")
);
}
if (taskExistsAndCompleted) {
return createErrorResponse(
`@${username} already has this task completed`,
getResponse("taskAlreadyCompleted")
);
}
if (taskIsInvalid) {
return createErrorResponse(
`@${username} empty task or reserved keyword used`,
@ -2195,45 +2200,55 @@ async function logTask(username, userColor, task) {
);
}
const tasksToAdd = taskSeparator.some((char) => task.includes(char))
const tasksToLog = taskSeparator.some((char) => task.includes(char))
? task
.split(taskSeparator.find((char) => task.includes(char)))
.map((t) => t.trim())
: [task];
let tasksFailedToAdd = [];
let addedTaskIndices = []; // new array to store indices of added tasks
tasksToAdd.forEach((t) => {
let tasksFailedToLog = [];
let loggedTaskIndices = []; // new array to store indices of added tasks
for (const t of tasksToLog) {
if (
t &&
!tasks[username].todos.find((task) => task.text === t) &&
!isInt(t)
!isInt(t) &&
t.trim() !== "" &&
(!getSetting("taskCharacterLimitEnabled") ||
t.length <= getSetting("taskCharacterLimit"))
) {
tasks[username].todos.push({ text: t, done: true, focus: false });
// increment count
await addDoneCount(username, 1);
let index = tasks[username].todos.length - 1;
addedTaskIndices.push({ index: index, task: t }); // store index of added task
console.log({ index: index, task: t });
loggedTaskIndices.push({ index: index, task: t }); // store index of added task
console.log(loggedTaskIndices);
taskListMemory.totalTaskCount++;
} else {
tasksFailedToAdd.push(t);
tasksFailedToLog.push(t);
}
}
});
await DBHandler.set("tasks", tasks);
if (!scrolling) {
await renderTaskListToDOM();
}
let displayedTasksAdded = addedTaskIndices.map((t) => {
let displayedTasksLogged = loggedTaskIndices.map((t) => {
return `(${t.index + 1}) ${t.task}`;
});
return {
status: 200,
body: {
task: displayedTasksAdded.join(`${closeQuote}, ${openQuote}`),
task: displayedTasksLogged.join(`${closeQuote}, ${openQuote}`),
tasksFailedToLog:
tasksFailedToAdd.join(`${closeQuote}, ${openQuote}`) || "",
tasksFailedToLog.join(`${closeQuote}, ${openQuote}`) || "",
},
};
}