Compare commits

...

1 commit

Author SHA1 Message Date
liyunze
0599700c5b fixed focus task 2026-09-14 12:53:53 +08:00
3 changed files with 29 additions and 36 deletions

View file

@ -2,7 +2,7 @@ const auth = (function () {
// Authentication and channels - required // Authentication and channels - required
const channel = ""; // your channel const channel = ""; // your channel
const username = ""; // bot account const username = ""; // bot account
const oauth = ""; // should be oauth:xxxxxxxxxxxx from the bot account DO NOT INCLUDE oauth: const oauth = ""; // should be oauth:xxxxxxxxxxxx from the bot account
return { return {
channel, channel,

View file

@ -1,9 +1,5 @@
function isInt(value) { function isInt(value) {
return ( return /^\d+$/.test(String(value).trim());
!isNaN(value) &&
parseInt(Number(value)) === value &&
!isNaN(parseInt(value, 10))
);
} }
function createErrorResponse(errorMessage, errorType, status = 0) { function createErrorResponse(errorMessage, errorType, status = 0) {

View file

@ -196,14 +196,17 @@ async function focusTask(username, userColor, task) {
); );
} }
let index = tasks[username].todos.findIndex( let index = -1;
if (isInt(task)) {
index = parseInt(task, 10) - 1;
} else {
index = tasks[username].todos.findIndex(
(t) => t.text.toLowerCase() === task.toLowerCase() (t) => t.text.toLowerCase() === task.toLowerCase()
); );
if (index === -1) { if (index === -1) {
if (isInt(task)) { if (task !== "") {
index = parseInt(task) - 1;
} else if (task !== "") {
let addTaskFunction = await _addTask(username, userColor, task); let addTaskFunction = await _addTask(username, userColor, task);
if (addTaskFunction.status !== 200) { if (addTaskFunction.status !== 200) {
@ -215,6 +218,8 @@ async function focusTask(username, userColor, task) {
} else if (incompleteTasks.length === 1) { } else if (incompleteTasks.length === 1) {
index = tasks[username].todos.findIndex((t) => !t.done); index = tasks[username].todos.findIndex((t) => !t.done);
} }
}
}
if (index < 0 || index > tasks[username].todos.length - 1) { if (index < 0 || index > tasks[username].todos.length - 1) {
return createErrorResponse( return createErrorResponse(
@ -222,14 +227,6 @@ async function focusTask(username, userColor, task) {
getResponse("specifyFocusTask") getResponse("specifyFocusTask")
); );
} }
} else {
if (tasks[username].todos[index].done) {
return createErrorResponse(
`@${username} task is already completed`,
getResponse("specifyFocusTask")
);
}
}
let focusedTask = tasks[username].todos[index].text; let focusedTask = tasks[username].todos[index].text;