From 44ab279ab31879421d3abe624f60fddb65dcfa6f Mon Sep 17 00:00:00 2001 From: liyunze <50455574+liyunze-coding@users.noreply.github.com> Date: Mon, 4 Sep 2023 23:13:02 +0800 Subject: [PATCH] list tasks command, fixed gapbetweenscrolls --- configs.js | 10 ++++++---- scripts/index.js | 8 ++++++++ scripts/taskList.js | 44 +++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/configs.js b/configs.js index 0dd154a..6cf620d 100644 --- a/configs.js +++ b/configs.js @@ -6,9 +6,8 @@ const configs = (function () { const limit = 5; // integer // animation - const scrollSpeed = 30; // milliseconds - const pauseBetweenScrolls = 2000; // milliseconds - const gapBetweenScrolls = "50px"; // px + const scrollSpeed = 40; // milliseconds + const gapBetweenScrolls = 100; // px // STYLES // task list @@ -150,6 +149,9 @@ const configs = (function () { "!check", ]; + // List tasks commands - please add commands in the exact format + const listCommands = ["!taskl", "!tasklist", "!listtasks", "!list"]; + // Clear my done commands - please add commands in the exact format const clearMyDoneCommands = ["!clearmydone"]; @@ -298,7 +300,6 @@ const configs = (function () { const animation = { scrollSpeed, - pauseBetweenScrolls, gapBetweenScrolls, titles, }; @@ -311,6 +312,7 @@ const configs = (function () { unfinishTaskCommands, helpCommands, checkCommands, + listCommands, clearMyDoneCommands, adminDeleteCommands, adminClearNotStreamerCommands, diff --git a/scripts/index.js b/scripts/index.js index 54e63be..3f2a5f4 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -173,6 +173,7 @@ ComfyJS.onCommand = (user, command, message, flags, extra) => { } clearUserTasks(mentioned); + params.mentioned = mentioned; respond(responses.adminDeleteTasks, params); return mentioned; @@ -207,6 +208,13 @@ ComfyJS.onCommand = (user, command, message, flags, extra) => { respond(responses.clearTasksExceptBroadcaster, params); } else if (commands.helpCommands.includes(command)) { respond(responses.help, params); + } else if (commands.listCommands.includes(command)) { + let response = listTasks(user); + if (response === 0) { + respond(responses.noTask, params); + return; + } + ComfyJS.Say(response); } else if (commands.additionalCommands[command]) { respond(commands.additionalCommands[command], params); } else { diff --git a/scripts/taskList.js b/scripts/taskList.js index ea567fc..9b10105 100644 --- a/scripts/taskList.js +++ b/scripts/taskList.js @@ -678,6 +678,36 @@ function checkTasks(username) { return reply; } +// 0: user has no tasks +function listTasks(username) { + const tasks = JSON.parse(localStorage.tasks); + if (!tasks[username]) { + return 0; + } + // filter completed tasks + const incompleteTasks = tasks[username].todos.filter((t) => !t.done); + + if (incompleteTasks.length === 0) { + return 0; + } + + // format incomplete tasks into string: 1. task 1 | 2. task 2 | 3. task 3... + let reply = `@${username} `; + let taskIndex; + for (let i = 0; i < incompleteTasks.length; i++) { + // get index of task by task name + taskIndex = + tasks[username].todos.findIndex( + (t) => + t.text.toLowerCase() === + incompleteTasks[i].text.toLowerCase() + ) + 1; + reply += `${incompleteTasks[i].text}, `; + } + reply = reply.slice(0, -2); + return reply; +} + function incompleteTasksCount(username) { const tasks = JSON.parse(localStorage.tasks); if (!tasks[username]) { @@ -686,11 +716,18 @@ function incompleteTasksCount(username) { return tasks[username].todos.filter((t) => !t.done).length; } +// 0: user has no tasks function clearUserTasks(username) { const tasks = JSON.parse(localStorage.tasks); - if (!tasks[username]) { - return; + // find username where lowercase matches username + username = Object.keys(tasks).find( + (user) => user.toLowerCase() === username.toLowerCase() + ); + + if (!username) { + return 0; } + tasks[username].todos = []; localStorage.setItem(`tasks`, JSON.stringify(tasks)); @@ -842,7 +879,8 @@ async function checkToAnimate() { if (!scrolling) { document.querySelector(".secondary").style.display = "flex"; - let finalHeight = taskContainerHeight + 100; + let finalHeight = + taskContainerHeight + configs.animation.gapBetweenScrolls; let primaryKeyFrames = [ { transform: `translateY(0)` },