list tasks command, fixed gapbetweenscrolls
This commit is contained in:
parent
740230840c
commit
44ab279ab3
3 changed files with 55 additions and 7 deletions
10
configs.js
10
configs.js
|
|
@ -6,9 +6,8 @@ const configs = (function () {
|
||||||
const limit = 5; // integer
|
const limit = 5; // integer
|
||||||
|
|
||||||
// animation
|
// animation
|
||||||
const scrollSpeed = 30; // milliseconds
|
const scrollSpeed = 40; // milliseconds
|
||||||
const pauseBetweenScrolls = 2000; // milliseconds
|
const gapBetweenScrolls = 100; // px
|
||||||
const gapBetweenScrolls = "50px"; // px
|
|
||||||
|
|
||||||
// STYLES
|
// STYLES
|
||||||
// task list
|
// task list
|
||||||
|
|
@ -150,6 +149,9 @@ const configs = (function () {
|
||||||
"!check",
|
"!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
|
// Clear my done commands - please add commands in the exact format
|
||||||
const clearMyDoneCommands = ["!clearmydone"];
|
const clearMyDoneCommands = ["!clearmydone"];
|
||||||
|
|
||||||
|
|
@ -298,7 +300,6 @@ const configs = (function () {
|
||||||
|
|
||||||
const animation = {
|
const animation = {
|
||||||
scrollSpeed,
|
scrollSpeed,
|
||||||
pauseBetweenScrolls,
|
|
||||||
gapBetweenScrolls,
|
gapBetweenScrolls,
|
||||||
titles,
|
titles,
|
||||||
};
|
};
|
||||||
|
|
@ -311,6 +312,7 @@ const configs = (function () {
|
||||||
unfinishTaskCommands,
|
unfinishTaskCommands,
|
||||||
helpCommands,
|
helpCommands,
|
||||||
checkCommands,
|
checkCommands,
|
||||||
|
listCommands,
|
||||||
clearMyDoneCommands,
|
clearMyDoneCommands,
|
||||||
adminDeleteCommands,
|
adminDeleteCommands,
|
||||||
adminClearNotStreamerCommands,
|
adminClearNotStreamerCommands,
|
||||||
|
|
|
||||||
|
|
@ -173,6 +173,7 @@ ComfyJS.onCommand = (user, command, message, flags, extra) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
clearUserTasks(mentioned);
|
clearUserTasks(mentioned);
|
||||||
|
|
||||||
params.mentioned = mentioned;
|
params.mentioned = mentioned;
|
||||||
respond(responses.adminDeleteTasks, params);
|
respond(responses.adminDeleteTasks, params);
|
||||||
return mentioned;
|
return mentioned;
|
||||||
|
|
@ -207,6 +208,13 @@ ComfyJS.onCommand = (user, command, message, flags, extra) => {
|
||||||
respond(responses.clearTasksExceptBroadcaster, params);
|
respond(responses.clearTasksExceptBroadcaster, params);
|
||||||
} else if (commands.helpCommands.includes(command)) {
|
} else if (commands.helpCommands.includes(command)) {
|
||||||
respond(responses.help, params);
|
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]) {
|
} else if (commands.additionalCommands[command]) {
|
||||||
respond(commands.additionalCommands[command], params);
|
respond(commands.additionalCommands[command], params);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -678,6 +678,36 @@ function checkTasks(username) {
|
||||||
return reply;
|
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) {
|
function incompleteTasksCount(username) {
|
||||||
const tasks = JSON.parse(localStorage.tasks);
|
const tasks = JSON.parse(localStorage.tasks);
|
||||||
if (!tasks[username]) {
|
if (!tasks[username]) {
|
||||||
|
|
@ -686,11 +716,18 @@ function incompleteTasksCount(username) {
|
||||||
return tasks[username].todos.filter((t) => !t.done).length;
|
return tasks[username].todos.filter((t) => !t.done).length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 0: user has no tasks
|
||||||
function clearUserTasks(username) {
|
function clearUserTasks(username) {
|
||||||
const tasks = JSON.parse(localStorage.tasks);
|
const tasks = JSON.parse(localStorage.tasks);
|
||||||
if (!tasks[username]) {
|
// find username where lowercase matches username
|
||||||
return;
|
username = Object.keys(tasks).find(
|
||||||
|
(user) => user.toLowerCase() === username.toLowerCase()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!username) {
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks[username].todos = [];
|
tasks[username].todos = [];
|
||||||
|
|
||||||
localStorage.setItem(`tasks`, JSON.stringify(tasks));
|
localStorage.setItem(`tasks`, JSON.stringify(tasks));
|
||||||
|
|
@ -842,7 +879,8 @@ async function checkToAnimate() {
|
||||||
if (!scrolling) {
|
if (!scrolling) {
|
||||||
document.querySelector(".secondary").style.display = "flex";
|
document.querySelector(".secondary").style.display = "flex";
|
||||||
|
|
||||||
let finalHeight = taskContainerHeight + 100;
|
let finalHeight =
|
||||||
|
taskContainerHeight + configs.animation.gapBetweenScrolls;
|
||||||
|
|
||||||
let primaryKeyFrames = [
|
let primaryKeyFrames = [
|
||||||
{ transform: `translateY(0)` },
|
{ transform: `translateY(0)` },
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue