Compare commits
2 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4f81a40f6b | |||
|
|
3ef3ddf1ba |
4 changed files with 30 additions and 37 deletions
|
|
@ -1,3 +1,3 @@
|
||||||
# Multi-Task widget Infinity (PRIVATE)
|
# Multi-Task widget Infinity
|
||||||
|
|
||||||

|

|
||||||
|
|
|
||||||
2
auth.js
2
auth.js
|
|
@ -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,
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
|
|
|
||||||
|
|
@ -196,41 +196,38 @@ async function focusTask(username, userColor, task) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let index = tasks[username].todos.findIndex(
|
let index = -1;
|
||||||
(t) => t.text.toLowerCase() === task.toLowerCase()
|
|
||||||
);
|
|
||||||
|
|
||||||
if (index === -1) {
|
if (isInt(task)) {
|
||||||
if (isInt(task)) {
|
index = parseInt(task, 10) - 1;
|
||||||
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")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if (tasks[username].todos[index].done) {
|
index = tasks[username].todos.findIndex(
|
||||||
return createErrorResponse(
|
(t) => t.text.toLowerCase() === task.toLowerCase()
|
||||||
`@${username} task is already completed`,
|
);
|
||||||
getResponse("specifyFocusTask")
|
|
||||||
);
|
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;
|
let focusedTask = tasks[username].todos[index].text;
|
||||||
|
|
||||||
if (tasks[username].todos[index].focus) {
|
if (tasks[username].todos[index].focus) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue