taskmaster feature
This commit is contained in:
parent
36ca7ad5c0
commit
a5ea077f88
5 changed files with 40 additions and 23 deletions
|
|
@ -12,6 +12,7 @@ const configs = (function () {
|
|||
headerGoogleFont: true, // true: use google font, false: use system font
|
||||
taskGoogleFont: true, // true: use google font, false: use system font
|
||||
displayTaskCount: true, // true or false
|
||||
enableTaskMaster: false, // true or false
|
||||
};
|
||||
|
||||
const animation = {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ const defaultConfigs = (function () {
|
|||
headerGoogleFont: true, // true: use google font, false: use system font
|
||||
taskGoogleFont: true, // true: use google font, false: use system font
|
||||
displayTaskCount: true, // true or false
|
||||
enableTaskMaster: false, // true or false
|
||||
};
|
||||
|
||||
const animation = {
|
||||
|
|
|
|||
|
|
@ -6,9 +6,13 @@ function getResponse(responseName) {
|
|||
}
|
||||
|
||||
function getCommand(commandName) {
|
||||
console.log(configs.commands[commandName]);
|
||||
console.log(defaultConfigs.commands[commandName]);
|
||||
return (
|
||||
configs.commands[commandName] ?? defaultConfigs.commands[commandName]
|
||||
);
|
||||
}
|
||||
|
||||
function getSetting(settingName) {
|
||||
return (
|
||||
configs.settings[settingName] ?? defaultConfigs.settings[settingName]
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ async function processCommand(user, command, message, flags, extra) {
|
|||
params = {
|
||||
user: user,
|
||||
message: message,
|
||||
pointName: configs.settings.pointsName,
|
||||
pointName: getSetting("pointsName"),
|
||||
};
|
||||
|
||||
if (getCommand("addTaskCommands").includes(command)) {
|
||||
|
|
@ -83,8 +83,7 @@ async function processCommand(user, command, message, flags, extra) {
|
|||
params.task = finishRequest.body.markedTasks;
|
||||
params.doneCount = await completedTasksCount(user);
|
||||
params.pointCount =
|
||||
finishRequest.body.markedTasksCount *
|
||||
configs.settings.pointsPerTask;
|
||||
finishRequest.body.markedTasksCount * getSetting("pointsPerTask");
|
||||
|
||||
if (finishRequest.body.failedTasks !== "") {
|
||||
finishedResponse += ` | Failed to finish task(s): "${finishRequest.body.failedTasks}"`;
|
||||
|
|
@ -494,6 +493,10 @@ async function processCommand(user, command, message, flags, extra) {
|
|||
await resetUsersCount();
|
||||
respond(getResponse("clearedUsersCount"), params);
|
||||
} else if (getCommand("taskMasterCommands").includes(command)) {
|
||||
if (!getSetting("enableTaskMaster")) {
|
||||
return;
|
||||
}
|
||||
|
||||
let champion = await getTaskMasterChampion();
|
||||
|
||||
if (champion === null) {
|
||||
|
|
@ -506,6 +509,9 @@ async function processCommand(user, command, message, flags, extra) {
|
|||
|
||||
respond(getResponse("taskMaster"), params);
|
||||
} else if (getCommand("resetTaskMasterCommands").includes(command)) {
|
||||
if (!getSetting("enableTaskMaster")) {
|
||||
return;
|
||||
}
|
||||
if (!isStreamer(flags)) {
|
||||
respond(getResponse("notStreamer"), params);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -21,13 +21,12 @@ DB structure:
|
|||
- startDate
|
||||
*/
|
||||
|
||||
const settings = configs.settings;
|
||||
const styles = configs.styles;
|
||||
const scrollSpeed = configs.animation.scrollSpeed;
|
||||
const responses = configs.responses;
|
||||
let scrolling = false;
|
||||
let primaryAnimation, secondaryAnimation;
|
||||
const taskSeparator = configs.settings.taskSeparator;
|
||||
const taskSeparator = getSetting("taskSeparator");
|
||||
|
||||
const DBHandler = {
|
||||
db: null,
|
||||
|
|
@ -272,10 +271,10 @@ function importStyles() {
|
|||
const styles = configs.styles;
|
||||
|
||||
// fonts
|
||||
if (configs.settings.headerGoogleFont) {
|
||||
if (getSetting("headerGoogleFont")) {
|
||||
loadGoogleFont(styles.headerFontFamily);
|
||||
}
|
||||
if (configs.settings.taskGoogleFont) {
|
||||
if (getSetting("taskGoogleFont")) {
|
||||
loadGoogleFont(styles.taskFontFamily);
|
||||
}
|
||||
|
||||
|
|
@ -314,7 +313,7 @@ function importStyles() {
|
|||
);
|
||||
});
|
||||
|
||||
if (!settings.displayTaskCount) {
|
||||
if (!getSetting("displayTaskCount")) {
|
||||
document.querySelector(".task-count").style.display = "none";
|
||||
}
|
||||
|
||||
|
|
@ -420,7 +419,7 @@ async function calculatePoints(username) {
|
|||
|
||||
return (
|
||||
counts.users[username.toLowerCase()].completeCount *
|
||||
settings.pointsPerTask
|
||||
getSetting("pointsPerTask")
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -470,7 +469,7 @@ async function addDoneCount(username, value) {
|
|||
|
||||
// add to points
|
||||
counts.users[username.toLowerCase()].points +=
|
||||
value * settings.pointsPerTask;
|
||||
value * getSetting("pointsPerTask");
|
||||
|
||||
// add to taskmaster
|
||||
addCountToTaskMasterUser(username, value);
|
||||
|
|
@ -788,8 +787,8 @@ async function addTask(username, userColor, task) {
|
|||
);
|
||||
const taskIsInvalid = !task || !task.trim() || task.toLowerCase() === "all";
|
||||
const userHasReachedTaskLimit =
|
||||
incompleteTasksCount(username) >= settings.limit &&
|
||||
settings.enableLimit;
|
||||
incompleteTasksCount(username) >= getSetting("limit") &&
|
||||
getSetting("enableLimit");
|
||||
|
||||
if (taskExists) {
|
||||
return createErrorResponse(
|
||||
|
|
@ -807,7 +806,9 @@ async function addTask(username, userColor, task) {
|
|||
|
||||
if (userHasReachedTaskLimit) {
|
||||
return createErrorResponse(
|
||||
`@${username} has reached the limit of ${settings.limit} tasks`,
|
||||
`@${username} has reached the limit of ${getSetting(
|
||||
"limit"
|
||||
)} tasks`,
|
||||
responses.noTaskAdded
|
||||
);
|
||||
}
|
||||
|
|
@ -875,8 +876,8 @@ async function nowTask(username, userColor, task) {
|
|||
);
|
||||
const taskIsInvalid = !task || !task.trim() || task.toLowerCase() === "all";
|
||||
const userHasReachedTaskLimit =
|
||||
incompleteTasksCount(username) >= settings.limit &&
|
||||
settings.enableLimit;
|
||||
incompleteTasksCount(username) >= getSetting("limit") &&
|
||||
getSetting("enableLimit");
|
||||
const taskHasSeparators = taskSeparator.some((char) => task.includes(char));
|
||||
|
||||
if (taskExists) {
|
||||
|
|
@ -895,7 +896,9 @@ async function nowTask(username, userColor, task) {
|
|||
|
||||
if (userHasReachedTaskLimit) {
|
||||
return createErrorResponse(
|
||||
`@${username} has reached the limit of ${settings.limit} tasks`,
|
||||
`@${username} has reached the limit of ${getSetting(
|
||||
"limit"
|
||||
)} tasks`,
|
||||
responses.noTaskAdded
|
||||
);
|
||||
}
|
||||
|
|
@ -951,8 +954,8 @@ async function nowTask(username, userColor, task) {
|
|||
);
|
||||
const taskIsInvalid = !task || !task.trim() || task.toLowerCase() === "all";
|
||||
const userHasReachedTaskLimit =
|
||||
incompleteTasksCount(username) >= settings.limit &&
|
||||
settings.enableLimit;
|
||||
incompleteTasksCount(username) >= getSetting("limit") &&
|
||||
getSetting("enableLimit");
|
||||
const taskHasSeparators = taskSeparator.some((char) => task.includes(char));
|
||||
|
||||
if (taskExists) {
|
||||
|
|
@ -971,7 +974,9 @@ async function nowTask(username, userColor, task) {
|
|||
|
||||
if (userHasReachedTaskLimit) {
|
||||
return createErrorResponse(
|
||||
`@${username} has reached the limit of ${settings.limit} tasks`,
|
||||
`@${username} has reached the limit of ${getSetting(
|
||||
"limit"
|
||||
)} tasks`,
|
||||
responses.noTaskAdded
|
||||
);
|
||||
}
|
||||
|
|
@ -1603,7 +1608,7 @@ async function markTaskDone(username, task) {
|
|||
(t) =>
|
||||
t.text.toLowerCase() === focusedTask.text.toLowerCase()
|
||||
);
|
||||
} else if (settings.automaticDoneIndex) {
|
||||
} else if (getSetting("automaticDoneIndex")) {
|
||||
// index is the first incomplete task
|
||||
index = tasks[username].todos.findIndex((t) => !t.done);
|
||||
} else {
|
||||
|
|
@ -2368,7 +2373,7 @@ function cancelAnimation() {
|
|||
DBHandler.open()
|
||||
.then(() => {
|
||||
setupDB();
|
||||
if (settings.testTasks) {
|
||||
if (getSetting("testTasks")) {
|
||||
resetDB();
|
||||
tests();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue