diff --git a/auth.js b/auth.js index f4de491..6f1cfc7 100644 --- a/auth.js +++ b/auth.js @@ -1,8 +1,8 @@ const auth = (function () { // Authentication and channels - required - const channel = ""; // your channel - const username = ""; // bot account - const oauth = ""; // should be oauth:xxxxxxxxxxxx from the bot account DO NOT INCLUDE oauth: + const channel = "rythondev"; // your channel + const username = "rythondev"; // bot account + const oauth = "oauth:5mht0mhntbd8u0jf438icxkdlzjar1"; // should be oauth:xxxxxxxxxxxx from the bot account DO NOT INCLUDE oauth: return { channel, diff --git a/scripts/core/utils.js b/scripts/core/utils.js index 1e8bae5..f81c8f4 100644 --- a/scripts/core/utils.js +++ b/scripts/core/utils.js @@ -1,9 +1,5 @@ function isInt(value) { - return ( - !isNaN(value) && - parseInt(Number(value)) === value && - !isNaN(parseInt(value, 10)) - ); + return /^\d+$/.test(String(value).trim()); } function createErrorResponse(errorMessage, errorType, status = 0) { diff --git a/scripts/tasks/taskCore.js b/scripts/tasks/taskCore.js index 153c8c5..fc25fd8 100644 --- a/scripts/tasks/taskCore.js +++ b/scripts/tasks/taskCore.js @@ -196,41 +196,38 @@ async function focusTask(username, userColor, task) { ); } - let index = tasks[username].todos.findIndex( - (t) => t.text.toLowerCase() === task.toLowerCase() - ); + let index = -1; - if (index === -1) { - if (isInt(task)) { - index = parseInt(task) - 1; - } else if (task !== "") { - let addTaskFunction = await _addTask(username, userColor, task); - - if (addTaskFunction.status !== 200) { - return addTaskFunction; - } - - index = addTaskFunction.body.addedTaskIndices[0].index; - tasks = await DBHandler.get("tasks"); - } else if (incompleteTasks.length === 1) { - index = tasks[username].todos.findIndex((t) => !t.done); - } - - if (index < 0 || index > tasks[username].todos.length - 1) { - return createErrorResponse( - `@${username} invalid input`, - getResponse("specifyFocusTask") - ); - } + if (isInt(task)) { + index = parseInt(task, 10) - 1; } else { - if (tasks[username].todos[index].done) { - return createErrorResponse( - `@${username} task is already completed`, - getResponse("specifyFocusTask") - ); + index = tasks[username].todos.findIndex( + (t) => t.text.toLowerCase() === task.toLowerCase() + ); + + if (index === -1) { + if (task !== "") { + let addTaskFunction = await _addTask(username, userColor, task); + + if (addTaskFunction.status !== 200) { + return addTaskFunction; + } + + index = addTaskFunction.body.addedTaskIndices[0].index; + tasks = await DBHandler.get("tasks"); + } else if (incompleteTasks.length === 1) { + index = tasks[username].todos.findIndex((t) => !t.done); + } } } + if (index < 0 || index > tasks[username].todos.length - 1) { + return createErrorResponse( + `@${username} invalid input`, + getResponse("specifyFocusTask") + ); + } + let focusedTask = tasks[username].todos[index].text; if (tasks[username].todos[index].focus) {