NEW FEATURE: clear your own completed tasks

- removed "completed tasks" in check
- removed useless console log
- removed some comments
- added one comment in configs.js
This commit is contained in:
liyunze 2023-08-04 19:57:23 +08:00
parent dae6c59363
commit 507747c5e4
3 changed files with 48 additions and 16 deletions

View file

@ -74,7 +74,7 @@ const configs = (function () {
const taskMarginBottom = "5px"; // px const taskMarginBottom = "5px"; // px
const taskHorizontalPadding = "20px"; // px const taskHorizontalPadding = "20px"; // px
const taskVerticalPadding = "10px"; const taskVerticalPadding = "10px"; // px
// Add task commands - please add commands in the exact format // Add task commands - please add commands in the exact format
const addTaskCommands = [ const addTaskCommands = [
@ -136,6 +136,9 @@ const configs = (function () {
"!check", "!check",
]; ];
// Clear my done commands - please add commands in the exact format
const clearMyDoneCommands = ["!clearmydone"];
// Help commands - please add commands in the exact format // Help commands - please add commands in the exact format
const helpCommands = [ const helpCommands = [
"!taskh", "!taskh",
@ -193,6 +196,7 @@ const configs = (function () {
const notMod = "Permission denied, {user}; Mods only"; const notMod = "Permission denied, {user}; Mods only";
const clearedAll = "All tasks have been cleared!"; const clearedAll = "All tasks have been cleared!";
const clearedDone = "All completed tasks have been cleared!"; const clearedDone = "All completed tasks have been cleared!";
const clearedMyDone = "All your completed tasks have been cleared!";
const specifyUser = "Try specifying a user to delete their tasks {user}"; const specifyUser = "Try specifying a user to delete their tasks {user}";
const help = `{user} Use the following commands to help you out - !task !edit !remove !done. For mods, you can do !adel @user. More commmands here: https://github.com/liyunze-coding/Chat-Task-Tic-Overlay/blob/main/MultiTask.md/`; const help = `{user} Use the following commands to help you out - !task !edit !remove !done. For mods, you can do !adel @user. More commmands here: https://github.com/liyunze-coding/Chat-Task-Tic-Overlay/blob/main/MultiTask.md/`;
// to edit check task command, go to // to edit check task command, go to
@ -277,6 +281,7 @@ const configs = (function () {
finishTaskCommands, finishTaskCommands,
helpCommands, helpCommands,
checkCommands, checkCommands,
clearMyDoneCommands,
adminDeleteCommands, adminDeleteCommands,
adminClearDoneCommands, adminClearDoneCommands,
adminClearAllCommands, adminClearAllCommands,
@ -298,6 +303,7 @@ const configs = (function () {
notMod, notMod,
help, help,
adminDeleteTasks, adminDeleteTasks,
clearedMyDone,
clearedAll, clearedAll,
clearedDone, clearedDone,
specifyUser, specifyUser,

View file

@ -135,6 +135,16 @@ ComfyJS.onCommand = (user, command, message, flags, extra) => {
clearAllTasks(); clearAllTasks();
respond(responses.clearedAll, params); respond(responses.clearedAll, params);
} }
} else if (commands.clearMyDoneCommands.includes(command)) {
let response = markOwnTaskDone(user);
if (response === 0) {
// no tasks
respond(responses.noTask, params);
return;
}
respond(responses.clearedMyDone, params);
} else if (commands.helpCommands.includes(command)) { } else if (commands.helpCommands.includes(command)) {
respond(responses.help, params); respond(responses.help, params);
} else if (commands.additionalCommands[command]) { } else if (commands.additionalCommands[command]) {

View file

@ -232,6 +232,26 @@ function isInt(value) {
); );
} }
// 0: user has no tasks
// 1: success
function markOwnTaskDone(username) {
const tasks = JSON.parse(localStorage.tasks);
if (!tasks[username] || tasks[username].todos.length === 0) {
return 0;
}
let incompleteUserTasks = tasks[username].todos.filter((t) => !t.done);
// replace user's task with incomplete tasks
tasks[username].todos = incompleteUserTasks;
localStorage.setItem(`tasks`, JSON.stringify(tasks));
renderTaskListToDOM();
return 1;
}
// 0: user has no tasks // 0: user has no tasks
// 1: invalid input // 1: invalid input
// task: succcess // task: succcess
@ -354,18 +374,18 @@ function checkTasks(username) {
reply = reply.slice(0, -3); reply = reply.slice(0, -3);
// format completed tasks into string: 1. task 1 | 2. task 2 | 3. task 3... // format completed tasks into string: 1. task 1 | 2. task 2 | 3. task 3...
reply += `\n|| completed tasks (${completedTasks.length}) : `; // reply += `\n|| completed tasks (${completedTasks.length}) : `;
for (let j = 0; j < completedTasks.length; j++) { // for (let j = 0; j < completedTasks.length; j++) {
taskIndex = // taskIndex =
tasks[username].todos.findIndex( // tasks[username].todos.findIndex(
(t) => // (t) =>
t.text.toLowerCase() === // t.text.toLowerCase() ===
completedTasks[j].text.toLowerCase() // completedTasks[j].text.toLowerCase()
) + 1; // ) + 1;
reply += `${taskIndex}. ${completedTasks[j].text} | `; // reply += `${taskIndex}. ${completedTasks[j].text} | `;
} // }
reply = reply.slice(0, -3); // reply = reply.slice(0, -3);
return reply; return reply;
} }
@ -425,8 +445,6 @@ function smutOnly(streamer) {
function renderTaskListToDOM() { function renderTaskListToDOM() {
const tasks = JSON.parse(localStorage.tasks); const tasks = JSON.parse(localStorage.tasks);
// console.log(tasks);
const taskContainers = document.querySelectorAll(".task-container"); const taskContainers = document.querySelectorAll(".task-container");
taskContainers.forEach((taskList) => { taskContainers.forEach((taskList) => {
taskList.innerHTML = ""; taskList.innerHTML = "";
@ -526,8 +544,6 @@ async function checkToAnimate() {
let taskWrapper = document.querySelector(".task-wrapper"); let taskWrapper = document.querySelector(".task-wrapper");
let taskWrapperHeight = taskWrapper.clientHeight; let taskWrapperHeight = taskWrapper.clientHeight;
console.log(taskContainerHeight > taskWrapperHeight);
// scroll task wrapper up and down once // scroll task wrapper up and down once
if (taskContainerHeight > taskWrapperHeight) { if (taskContainerHeight > taskWrapperHeight) {
if (!scrolling) { if (!scrolling) {