taskmaster feature

This commit is contained in:
liyunze 2024-05-04 22:35:04 +08:00
parent 36ca7ad5c0
commit a5ea077f88
5 changed files with 40 additions and 23 deletions

View file

@ -12,6 +12,7 @@ const configs = (function () {
headerGoogleFont: true, // true: use google font, false: use system font headerGoogleFont: true, // true: use google font, false: use system font
taskGoogleFont: true, // true: use google font, false: use system font taskGoogleFont: true, // true: use google font, false: use system font
displayTaskCount: true, // true or false displayTaskCount: true, // true or false
enableTaskMaster: false, // true or false
}; };
const animation = { const animation = {

View file

@ -12,6 +12,7 @@ const defaultConfigs = (function () {
headerGoogleFont: true, // true: use google font, false: use system font headerGoogleFont: true, // true: use google font, false: use system font
taskGoogleFont: true, // true: use google font, false: use system font taskGoogleFont: true, // true: use google font, false: use system font
displayTaskCount: true, // true or false displayTaskCount: true, // true or false
enableTaskMaster: false, // true or false
}; };
const animation = { const animation = {

View file

@ -6,9 +6,13 @@ function getResponse(responseName) {
} }
function getCommand(commandName) { function getCommand(commandName) {
console.log(configs.commands[commandName]);
console.log(defaultConfigs.commands[commandName]);
return ( return (
configs.commands[commandName] ?? defaultConfigs.commands[commandName] configs.commands[commandName] ?? defaultConfigs.commands[commandName]
); );
} }
function getSetting(settingName) {
return (
configs.settings[settingName] ?? defaultConfigs.settings[settingName]
);
}

View file

@ -2,7 +2,7 @@ async function processCommand(user, command, message, flags, extra) {
params = { params = {
user: user, user: user,
message: message, message: message,
pointName: configs.settings.pointsName, pointName: getSetting("pointsName"),
}; };
if (getCommand("addTaskCommands").includes(command)) { if (getCommand("addTaskCommands").includes(command)) {
@ -83,8 +83,7 @@ async function processCommand(user, command, message, flags, extra) {
params.task = finishRequest.body.markedTasks; params.task = finishRequest.body.markedTasks;
params.doneCount = await completedTasksCount(user); params.doneCount = await completedTasksCount(user);
params.pointCount = params.pointCount =
finishRequest.body.markedTasksCount * finishRequest.body.markedTasksCount * getSetting("pointsPerTask");
configs.settings.pointsPerTask;
if (finishRequest.body.failedTasks !== "") { if (finishRequest.body.failedTasks !== "") {
finishedResponse += ` | Failed to finish task(s): "${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(); await resetUsersCount();
respond(getResponse("clearedUsersCount"), params); respond(getResponse("clearedUsersCount"), params);
} else if (getCommand("taskMasterCommands").includes(command)) { } else if (getCommand("taskMasterCommands").includes(command)) {
if (!getSetting("enableTaskMaster")) {
return;
}
let champion = await getTaskMasterChampion(); let champion = await getTaskMasterChampion();
if (champion === null) { if (champion === null) {
@ -506,6 +509,9 @@ async function processCommand(user, command, message, flags, extra) {
respond(getResponse("taskMaster"), params); respond(getResponse("taskMaster"), params);
} else if (getCommand("resetTaskMasterCommands").includes(command)) { } else if (getCommand("resetTaskMasterCommands").includes(command)) {
if (!getSetting("enableTaskMaster")) {
return;
}
if (!isStreamer(flags)) { if (!isStreamer(flags)) {
respond(getResponse("notStreamer"), params); respond(getResponse("notStreamer"), params);
return; return;

View file

@ -21,13 +21,12 @@ DB structure:
- startDate - startDate
*/ */
const settings = configs.settings;
const styles = configs.styles; const styles = configs.styles;
const scrollSpeed = configs.animation.scrollSpeed; const scrollSpeed = configs.animation.scrollSpeed;
const responses = configs.responses; const responses = configs.responses;
let scrolling = false; let scrolling = false;
let primaryAnimation, secondaryAnimation; let primaryAnimation, secondaryAnimation;
const taskSeparator = configs.settings.taskSeparator; const taskSeparator = getSetting("taskSeparator");
const DBHandler = { const DBHandler = {
db: null, db: null,
@ -272,10 +271,10 @@ function importStyles() {
const styles = configs.styles; const styles = configs.styles;
// fonts // fonts
if (configs.settings.headerGoogleFont) { if (getSetting("headerGoogleFont")) {
loadGoogleFont(styles.headerFontFamily); loadGoogleFont(styles.headerFontFamily);
} }
if (configs.settings.taskGoogleFont) { if (getSetting("taskGoogleFont")) {
loadGoogleFont(styles.taskFontFamily); loadGoogleFont(styles.taskFontFamily);
} }
@ -314,7 +313,7 @@ function importStyles() {
); );
}); });
if (!settings.displayTaskCount) { if (!getSetting("displayTaskCount")) {
document.querySelector(".task-count").style.display = "none"; document.querySelector(".task-count").style.display = "none";
} }
@ -420,7 +419,7 @@ async function calculatePoints(username) {
return ( return (
counts.users[username.toLowerCase()].completeCount * counts.users[username.toLowerCase()].completeCount *
settings.pointsPerTask getSetting("pointsPerTask")
); );
} }
@ -470,7 +469,7 @@ async function addDoneCount(username, value) {
// add to points // add to points
counts.users[username.toLowerCase()].points += counts.users[username.toLowerCase()].points +=
value * settings.pointsPerTask; value * getSetting("pointsPerTask");
// add to taskmaster // add to taskmaster
addCountToTaskMasterUser(username, value); addCountToTaskMasterUser(username, value);
@ -788,8 +787,8 @@ async function addTask(username, userColor, task) {
); );
const taskIsInvalid = !task || !task.trim() || task.toLowerCase() === "all"; const taskIsInvalid = !task || !task.trim() || task.toLowerCase() === "all";
const userHasReachedTaskLimit = const userHasReachedTaskLimit =
incompleteTasksCount(username) >= settings.limit && incompleteTasksCount(username) >= getSetting("limit") &&
settings.enableLimit; getSetting("enableLimit");
if (taskExists) { if (taskExists) {
return createErrorResponse( return createErrorResponse(
@ -807,7 +806,9 @@ async function addTask(username, userColor, task) {
if (userHasReachedTaskLimit) { if (userHasReachedTaskLimit) {
return createErrorResponse( return createErrorResponse(
`@${username} has reached the limit of ${settings.limit} tasks`, `@${username} has reached the limit of ${getSetting(
"limit"
)} tasks`,
responses.noTaskAdded responses.noTaskAdded
); );
} }
@ -875,8 +876,8 @@ async function nowTask(username, userColor, task) {
); );
const taskIsInvalid = !task || !task.trim() || task.toLowerCase() === "all"; const taskIsInvalid = !task || !task.trim() || task.toLowerCase() === "all";
const userHasReachedTaskLimit = const userHasReachedTaskLimit =
incompleteTasksCount(username) >= settings.limit && incompleteTasksCount(username) >= getSetting("limit") &&
settings.enableLimit; getSetting("enableLimit");
const taskHasSeparators = taskSeparator.some((char) => task.includes(char)); const taskHasSeparators = taskSeparator.some((char) => task.includes(char));
if (taskExists) { if (taskExists) {
@ -895,7 +896,9 @@ async function nowTask(username, userColor, task) {
if (userHasReachedTaskLimit) { if (userHasReachedTaskLimit) {
return createErrorResponse( return createErrorResponse(
`@${username} has reached the limit of ${settings.limit} tasks`, `@${username} has reached the limit of ${getSetting(
"limit"
)} tasks`,
responses.noTaskAdded responses.noTaskAdded
); );
} }
@ -951,8 +954,8 @@ async function nowTask(username, userColor, task) {
); );
const taskIsInvalid = !task || !task.trim() || task.toLowerCase() === "all"; const taskIsInvalid = !task || !task.trim() || task.toLowerCase() === "all";
const userHasReachedTaskLimit = const userHasReachedTaskLimit =
incompleteTasksCount(username) >= settings.limit && incompleteTasksCount(username) >= getSetting("limit") &&
settings.enableLimit; getSetting("enableLimit");
const taskHasSeparators = taskSeparator.some((char) => task.includes(char)); const taskHasSeparators = taskSeparator.some((char) => task.includes(char));
if (taskExists) { if (taskExists) {
@ -971,7 +974,9 @@ async function nowTask(username, userColor, task) {
if (userHasReachedTaskLimit) { if (userHasReachedTaskLimit) {
return createErrorResponse( return createErrorResponse(
`@${username} has reached the limit of ${settings.limit} tasks`, `@${username} has reached the limit of ${getSetting(
"limit"
)} tasks`,
responses.noTaskAdded responses.noTaskAdded
); );
} }
@ -1603,7 +1608,7 @@ async function markTaskDone(username, task) {
(t) => (t) =>
t.text.toLowerCase() === focusedTask.text.toLowerCase() t.text.toLowerCase() === focusedTask.text.toLowerCase()
); );
} else if (settings.automaticDoneIndex) { } else if (getSetting("automaticDoneIndex")) {
// index is the first incomplete task // index is the first incomplete task
index = tasks[username].todos.findIndex((t) => !t.done); index = tasks[username].todos.findIndex((t) => !t.done);
} else { } else {
@ -2368,7 +2373,7 @@ function cancelAnimation() {
DBHandler.open() DBHandler.open()
.then(() => { .then(() => {
setupDB(); setupDB();
if (settings.testTasks) { if (getSetting("testTasks")) {
resetDB(); resetDB();
tests(); tests();
} }