ver 3.3
This commit is contained in:
parent
33cb61b10f
commit
81e3b5f5ba
4 changed files with 67 additions and 55 deletions
|
|
@ -11,7 +11,7 @@ const configs = (function () {
|
||||||
taskSeparator: [";", ","], // array of strings
|
taskSeparator: [";", ","], // array of strings
|
||||||
openQuote: '"', // string
|
openQuote: '"', // string
|
||||||
closeQuote: '"', // string
|
closeQuote: '"', // string
|
||||||
testTasks: true, // true or false
|
testTasks: false, // true or false
|
||||||
headerGoogleFont: true, // true: use google font, false: use system font
|
headerGoogleFont: true, // true: use google font, false: use system font
|
||||||
taskGoogleFont: true, // true: use google font, false: use system font
|
taskGoogleFont: true, // true: use google font, false: use system font
|
||||||
displayTaskCount: true, // true or false
|
displayTaskCount: true, // true or false
|
||||||
|
|
@ -334,6 +334,8 @@ const configs = (function () {
|
||||||
nowTask:
|
nowTask:
|
||||||
"{taskName} {task} is now the task you are working on, {user}!",
|
"{taskName} {task} is now the task you are working on, {user}!",
|
||||||
taskLogged: "Task(s) {task} has been logged, {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
|
// Grouped by task progression responses
|
||||||
taskNext:
|
taskNext:
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,6 @@ const defaultConfigs = (function () {
|
||||||
"!task",
|
"!task",
|
||||||
"!add",
|
"!add",
|
||||||
"!todo",
|
"!todo",
|
||||||
"!tasks",
|
|
||||||
"!a",
|
"!a",
|
||||||
],
|
],
|
||||||
|
|
||||||
|
|
@ -197,7 +196,6 @@ const defaultConfigs = (function () {
|
||||||
"!next",
|
"!next",
|
||||||
"!n",
|
"!n",
|
||||||
],
|
],
|
||||||
|
|
||||||
logTaskCommands: ["!log", "!tasklog", "!logtask", "!logtasks"],
|
logTaskCommands: ["!log", "!tasklog", "!logtask", "!logtasks"],
|
||||||
|
|
||||||
// focus task commands - please add commands in the exact format
|
// focus task commands - please add commands in the exact format
|
||||||
|
|
@ -279,7 +277,14 @@ const defaultConfigs = (function () {
|
||||||
resetTaskMasterCommands: ["!resettaskmaster"],
|
resetTaskMasterCommands: ["!resettaskmaster"],
|
||||||
|
|
||||||
// Help commands - please add commands in the exact format
|
// 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
|
// Admin clear all except streamer - please add commands following the exact format
|
||||||
adminClearNotStreamerCommands: [
|
adminClearNotStreamerCommands: [
|
||||||
|
|
@ -329,6 +334,8 @@ const defaultConfigs = (function () {
|
||||||
nowTask:
|
nowTask:
|
||||||
"{taskName} {task} is now the task you are working on, {user}!",
|
"{taskName} {task} is now the task you are working on, {user}!",
|
||||||
taskLogged: "Task(s) {task} has been logged, {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
|
// Grouped by task progression responses
|
||||||
taskNext:
|
taskNext:
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ async function processCommand(user, command, message, flags, extra) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// task logged
|
// task logged
|
||||||
let loggedResponse = getResponse("taskLogged");
|
let loggedResponse = await getResponse("taskLogged");
|
||||||
|
|
||||||
params.task = `${openQuote}${logRequest.body.task}${closeQuote}`;
|
params.task = `${openQuote}${logRequest.body.task}${closeQuote}`;
|
||||||
|
|
||||||
|
|
@ -179,18 +179,6 @@ async function processCommand(user, command, message, flags, extra) {
|
||||||
}
|
}
|
||||||
|
|
||||||
await respond(loggedResponse, params);
|
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)) {
|
} else if (getCommand("focusTaskCommands").includes(command)) {
|
||||||
let focusRequest = await focusTask(user, message);
|
let focusRequest = await focusTask(user, message);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -851,13 +851,16 @@ async function _addTask(username, userColor, task, oneTaskOnly = false) {
|
||||||
.split(taskSeparator.find((char) => task.includes(char)))
|
.split(taskSeparator.find((char) => task.includes(char)))
|
||||||
.map((t) => t.trim());
|
.map((t) => t.trim());
|
||||||
|
|
||||||
tasksToAdd.forEach((t) => {
|
for (const t of tasksToAdd) {
|
||||||
if (
|
if (
|
||||||
(t &&
|
t &&
|
||||||
!tasks[username].todos.find((task) => task.text === t) &&
|
!tasks[username].todos.find(
|
||||||
!isInt(t) &&
|
(task) => task.text === t && !task.completed
|
||||||
!getSetting("taskCharacterLimitEnabled")) ||
|
) &&
|
||||||
t.length <= getSetting("taskCharacterLimit")
|
!isInt(t) &&
|
||||||
|
t.trim() !== "" &&
|
||||||
|
(!getSetting("taskCharacterLimitEnabled") ||
|
||||||
|
t.length <= getSetting("taskCharacterLimit"))
|
||||||
) {
|
) {
|
||||||
tasks[username].todos.push({
|
tasks[username].todos.push({
|
||||||
text: t,
|
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
|
addedTaskIndices.push({ index: index, task: t }); // store index of added task
|
||||||
taskListMemory.totalTaskCount++;
|
taskListMemory.totalTaskCount++;
|
||||||
} else {
|
} 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);
|
tasksFailedToAdd.push(t);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
await DBHandler.set("tasks", tasks);
|
await DBHandler.set("tasks", tasks);
|
||||||
} else {
|
} else {
|
||||||
const taskExists = tasks[username].todos.find(
|
const taskExistsAndIncomplete = tasks[username].todos.find(
|
||||||
(t) => t.text.toLowerCase() === task.toLowerCase()
|
(t) => t.text.toLowerCase() === task.toLowerCase() && !t.done
|
||||||
);
|
);
|
||||||
|
|
||||||
const taskIsInvalid =
|
const taskIsInvalid =
|
||||||
!task ||
|
!task ||
|
||||||
!task.trim() ||
|
!task.trim() ||
|
||||||
|
|
@ -898,7 +896,7 @@ async function _addTask(username, userColor, task, oneTaskOnly = false) {
|
||||||
(await incompleteTasksCount(username)) >= getSetting("limit") &&
|
(await incompleteTasksCount(username)) >= getSetting("limit") &&
|
||||||
getSetting("enableLimit");
|
getSetting("enableLimit");
|
||||||
|
|
||||||
if (taskExists) {
|
if (taskExistsAndIncomplete) {
|
||||||
return createErrorResponse(
|
return createErrorResponse(
|
||||||
`@${username} already has this task`,
|
`@${username} already has this task`,
|
||||||
getResponse("duplicateTask")
|
getResponse("duplicateTask")
|
||||||
|
|
@ -1676,15 +1674,10 @@ async function markTaskDone(username, task) {
|
||||||
|
|
||||||
for (const t of tasksToMarkDone) {
|
for (const t of tasksToMarkDone) {
|
||||||
let index = tasks[username].todos.findIndex(
|
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 (index === -1) {
|
||||||
if (isInt(t)) {
|
if (isInt(t)) {
|
||||||
index = parseInt(t) - 1; // ACTUAL INDEX
|
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)
|
// if there's no comma in the task (single task)
|
||||||
|
|
||||||
let index = tasks[username].todos.findIndex(
|
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?
|
// 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) {
|
if (index < 0 || index > tasks[username].todos.length - 1) {
|
||||||
return {
|
return {
|
||||||
status: 1,
|
status: 1,
|
||||||
|
|
@ -2175,19 +2169,30 @@ async function logTask(username, userColor, task) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const taskExists = tasks[username].todos.find(
|
const taskExistsAndIncomplete = tasks[username].todos.find(
|
||||||
(t) => t.text.toLowerCase() === task.toLowerCase()
|
(t) => t.text.toLowerCase() === task.toLowerCase() && !t.done
|
||||||
|
);
|
||||||
|
|
||||||
|
const taskExistsAndCompleted = tasks[username].todos.find(
|
||||||
|
(t) => t.text.toLowerCase() === task.toLowerCase() && t.done
|
||||||
);
|
);
|
||||||
const taskIsInvalid =
|
const taskIsInvalid =
|
||||||
!task || !task.trim() || task.toLowerCase() === "all" || isInt(task);
|
!task || !task.trim() || task.toLowerCase() === "all" || isInt(task);
|
||||||
|
|
||||||
if (taskExists) {
|
if (taskExistsAndIncomplete) {
|
||||||
return createErrorResponse(
|
return createErrorResponse(
|
||||||
`@${username} already has this task`,
|
`@${username} already has this task`,
|
||||||
getResponse("duplicateTask")
|
getResponse("duplicateTask")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (taskExistsAndCompleted) {
|
||||||
|
return createErrorResponse(
|
||||||
|
`@${username} already has this task completed`,
|
||||||
|
getResponse("taskAlreadyCompleted")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (taskIsInvalid) {
|
if (taskIsInvalid) {
|
||||||
return createErrorResponse(
|
return createErrorResponse(
|
||||||
`@${username} empty task or reserved keyword used`,
|
`@${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
|
? task
|
||||||
.split(taskSeparator.find((char) => task.includes(char)))
|
.split(taskSeparator.find((char) => task.includes(char)))
|
||||||
.map((t) => t.trim())
|
.map((t) => t.trim())
|
||||||
: [task];
|
: [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 (
|
if (
|
||||||
t &&
|
t &&
|
||||||
!tasks[username].todos.find((task) => task.text === 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 });
|
tasks[username].todos.push({ text: t, done: true, focus: false });
|
||||||
|
|
||||||
|
// increment count
|
||||||
|
await addDoneCount(username, 1);
|
||||||
|
|
||||||
let index = tasks[username].todos.length - 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++;
|
taskListMemory.totalTaskCount++;
|
||||||
} else {
|
} else {
|
||||||
tasksFailedToAdd.push(t);
|
tasksFailedToLog.push(t);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
await DBHandler.set("tasks", tasks);
|
await DBHandler.set("tasks", tasks);
|
||||||
if (!scrolling) {
|
if (!scrolling) {
|
||||||
await renderTaskListToDOM();
|
await renderTaskListToDOM();
|
||||||
}
|
}
|
||||||
|
|
||||||
let displayedTasksAdded = addedTaskIndices.map((t) => {
|
let displayedTasksLogged = loggedTaskIndices.map((t) => {
|
||||||
return `(${t.index + 1}) ${t.task}`;
|
return `(${t.index + 1}) ${t.task}`;
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
status: 200,
|
status: 200,
|
||||||
body: {
|
body: {
|
||||||
task: displayedTasksAdded.join(`${closeQuote}, ${openQuote}`),
|
task: displayedTasksLogged.join(`${closeQuote}, ${openQuote}`),
|
||||||
tasksFailedToLog:
|
tasksFailedToLog:
|
||||||
tasksFailedToAdd.join(`${closeQuote}, ${openQuote}`) || "",
|
tasksFailedToLog.join(`${closeQuote}, ${openQuote}`) || "",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue