updated !list command

This commit is contained in:
liyunze 2024-10-16 22:07:00 +11:00
parent 80b541552b
commit 574fbf3760
2 changed files with 64 additions and 9 deletions

View file

@ -367,6 +367,8 @@ async function processCommand(user, command, message, flags, extra) {
await clearAllTasks(); await clearAllTasks();
respond(getResponse("clearedTasks"), params); respond(getResponse("clearedTasks"), params);
} else if (getCommand("listCommands").includes(command)) { } else if (getCommand("listCommands").includes(command)) {
const interval = 100;
if (message === "") {
let listTaskResponse = await listTasks(user); let listTaskResponse = await listTasks(user);
if (listTaskResponse.status !== 200) { if (listTaskResponse.status !== 200) {
@ -375,7 +377,60 @@ async function processCommand(user, command, message, flags, extra) {
return; return;
} }
respond(listTaskResponse.body.reply, params); for (reply of listTaskResponse.body.replies) {
params.tasks = reply;
await respond("{tasks}", params);
await sleep(interval);
}
} else {
let separator = ",";
let args = message.split(" ");
let anotherUser = true;
// separate separator from mentioned user
if (args[0].length === 1) {
// args[0] is separator
separator = args[0];
args.shift();
} else if (args[1] && args[1].length === 1) {
// args[1] is separator
separator = args[1];
args.splice(1, 1);
} else {
// default, no separator specified
}
let mentioned = args.join(" ").replace("@", "");
if (args.length === 0) {
// no user specified
mentioned = user;
anotherUser = false;
// noTaskA
}
if (mentioned.toLowerCase() === "id") {
await respond(getResponse("noTaskA"), params);
return;
}
let listTaskResponse = await listTasks(mentioned, separator);
if (listTaskResponse.status !== 200 && anotherUser) {
// no tasks
respond(getResponse("noTaskA"), params);
return;
} else if (listTaskResponse.status !== 200 && !anotherUser) {
respond(getResponse("noTask"), params);
return;
}
for (reply of listTaskResponse.body.replies) {
params.tasks = reply;
await respond("{tasks}", params);
await sleep(interval);
}
}
} else if (getCommand("checkCountCommands").includes(command)) { } else if (getCommand("checkCountCommands").includes(command)) {
if (message === "") { if (message === "") {
let count = await completedTasksCount(user); let count = await completedTasksCount(user);

View file

@ -2608,8 +2608,8 @@ async function tests() {
`task 1, task 2, task 3, task 4, task 5` `task 1, task 2, task 3, task 4, task 5`
); );
await sleep(1000); await sleep(1000);
markTaskDone(listOfStreamers[i], `1, 2, 3, 4, 5`); // markTaskDone(listOfStreamers[i], `1, 2, 3, 4, 5`);
await sleep(1000); // await sleep(1000);
} }
} }