leaderboard, sync points, modify points + count
This commit is contained in:
parent
128e6eafe0
commit
1890d9c02d
4 changed files with 507 additions and 41 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
|||
.vscode/*
|
||||
styles/taskList.css.map
|
||||
styles/taskList.scss
|
||||
to-do.md
|
||||
47
configs.js
47
configs.js
|
|
@ -207,6 +207,29 @@ const configs = (function () {
|
|||
"!checkpoints",
|
||||
];
|
||||
|
||||
// sync points with count commands - please add commands in the exact format
|
||||
const syncCountPointsCommands = ["!syncpoints", "!synccount"];
|
||||
|
||||
const addPointsCommands = ["!addpoints", "!givepoints", "!adduserpoints"];
|
||||
|
||||
const reducePointsCommands = ["!reducepoints", "!takepoints"];
|
||||
|
||||
const setUserPointsCommands = [
|
||||
"!setuserpoints",
|
||||
"!setpoints",
|
||||
"!setpointsuser",
|
||||
"!setuserpoint",
|
||||
];
|
||||
|
||||
const setUserTaskCountCommands = [
|
||||
"!setusertaskcount",
|
||||
"!settaskcount",
|
||||
"!settaskcountuser",
|
||||
"!setusertask",
|
||||
];
|
||||
|
||||
const leaderboardCommands = ["!leaderboard", "!lb", "!top", "!toppoints"];
|
||||
|
||||
// Help commands - please add commands in the exact format
|
||||
const helpCommands = [
|
||||
"!taskh",
|
||||
|
|
@ -303,7 +326,7 @@ const configs = (function () {
|
|||
const noTask = "Looks like you don't have a task up there {user}";
|
||||
const noTaskA = "Looks like there is no task from that user there {user}";
|
||||
|
||||
// Responses related to viewing counts
|
||||
// Responses related to viewing counts / points
|
||||
const checkMyPoints = "You have {pointCount} {pointName}, {user}!";
|
||||
const checkUserPoints =
|
||||
"{mentioned} has {pointCount} {pointName}, {user}!";
|
||||
|
|
@ -314,6 +337,15 @@ const configs = (function () {
|
|||
const checkAllCount =
|
||||
"Everyone has completed {doneCount} task(s) so far, {user}!";
|
||||
const noCountAll = "Looks like no one has completed a task yet {user}";
|
||||
const leaderboard = "Leaderboard: {leaderboard}";
|
||||
|
||||
// Responses related to modifying points
|
||||
const syncCountPoints = "Points have been synced with count, {user}!";
|
||||
const addPoints = "{mentioned} has been given {pointCount} {pointName}!";
|
||||
const reducePoints = "{mentioned} has lost {pointCount} {pointName}!";
|
||||
const setUserPoints = "{mentioned} now has {pointCount} {pointName}!";
|
||||
const setUserTaskCount = "{mentioned} now has {taskCount} tasks!";
|
||||
const specifyPoints = "Try specifying a number of points {user}";
|
||||
|
||||
// Responses related to permissions
|
||||
const notMod = "Permission denied, {user}; Mods only";
|
||||
|
|
@ -436,6 +468,12 @@ const configs = (function () {
|
|||
checkCountCommands,
|
||||
checkAllCountCommands,
|
||||
checkMyPointsCommands,
|
||||
syncCountPointsCommands,
|
||||
addPointsCommands,
|
||||
reducePointsCommands,
|
||||
setUserPointsCommands,
|
||||
setUserTaskCountCommands,
|
||||
leaderboardCommands,
|
||||
adminDeleteCommands,
|
||||
adminClearNotStreamerCommands,
|
||||
adminClearDoneCommands,
|
||||
|
|
@ -474,6 +512,13 @@ const configs = (function () {
|
|||
checkUserCount,
|
||||
checkAllCount,
|
||||
noCountAll,
|
||||
leaderboard,
|
||||
syncCountPoints,
|
||||
addPoints,
|
||||
reducePoints,
|
||||
setUserPoints,
|
||||
setUserTaskCount,
|
||||
specifyPoints,
|
||||
notMod,
|
||||
notStreamer,
|
||||
help,
|
||||
|
|
|
|||
178
scripts/index.js
178
scripts/index.js
|
|
@ -3,18 +3,11 @@ const commands = configs.commands;
|
|||
let params = {};
|
||||
|
||||
function respond(template, params) {
|
||||
ComfyJS.Say(
|
||||
template
|
||||
.replace("{user}", `@${params.user}`)
|
||||
.replace("{message}", params.message)
|
||||
.replace("{mentioned}", `@${params.mentioned}`)
|
||||
.replace("{task}", params.task)
|
||||
.replace("{originalTask}", params.originalTask)
|
||||
.replace("{doneCount}", params.doneCount)
|
||||
.replace("{count}", params.count)
|
||||
.replace("{pointName}", params.pointName)
|
||||
.replace("{pointCount}", params.pointCount)
|
||||
);
|
||||
Object.keys(params).forEach((key) => {
|
||||
template = template.replace(`{${key}}`, params[key]);
|
||||
});
|
||||
|
||||
ComfyJS.Say(template);
|
||||
}
|
||||
|
||||
function isMod(flags) {
|
||||
|
|
@ -31,13 +24,7 @@ ComfyJS.onCommand = (user, command, message, flags, extra) => {
|
|||
params = {
|
||||
user: user,
|
||||
message: message,
|
||||
mentioned: "",
|
||||
task: "",
|
||||
originalTask: "",
|
||||
doneCount: "",
|
||||
count: "",
|
||||
pointName: configs.settings.pointsName,
|
||||
pointCount: "",
|
||||
};
|
||||
|
||||
if (commands.addTaskCommands.includes(command)) {
|
||||
|
|
@ -299,20 +286,171 @@ ComfyJS.onCommand = (user, command, message, flags, extra) => {
|
|||
respond(responses.checkAllCount, params);
|
||||
} else if (commands.checkMyPointsCommands.includes(command)) {
|
||||
if (message === "") {
|
||||
let points = calculatePoints(user);
|
||||
let points = getUserPoints(user);
|
||||
|
||||
params.pointCount = points;
|
||||
|
||||
return respond(responses.checkMyPoints, params);
|
||||
} else {
|
||||
let mentioned = message.replace("@", "");
|
||||
let points = calculatePoints(mentioned);
|
||||
let points = getUserPoints(mentioned);
|
||||
|
||||
params.pointCount = points;
|
||||
params.mentioned = mentioned;
|
||||
|
||||
return respond(responses.checkUserPoints, params);
|
||||
}
|
||||
} else if (commands.syncCountPointsCommands.includes(command)) {
|
||||
if (!isStreamer(flags)) {
|
||||
respond(responses.notStreamer, params);
|
||||
return;
|
||||
}
|
||||
|
||||
syncPointsToCount();
|
||||
respond(responses.syncCountPoints, params);
|
||||
} else if (commands.addPointsCommands.includes(command)) {
|
||||
// !addpoints @user 100
|
||||
|
||||
if (!isMod(flags)) {
|
||||
respond(responses.notMod, params);
|
||||
return;
|
||||
}
|
||||
|
||||
let mentioned = message.split(" ")[0].replace("@", "");
|
||||
|
||||
if (mentioned === "") {
|
||||
respond(responses.specifyUser, params);
|
||||
return;
|
||||
}
|
||||
|
||||
let points = message.split(" ")[1];
|
||||
|
||||
if (points === undefined) {
|
||||
respond(responses.specifyPoints, params);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!/^\d+$/.test(points)) {
|
||||
respond(responses.invalidNumber, params);
|
||||
return;
|
||||
}
|
||||
|
||||
points = parseInt(points);
|
||||
|
||||
addPoints(mentioned, points);
|
||||
|
||||
params.mentioned = mentioned;
|
||||
params.pointCount = points;
|
||||
|
||||
respond(responses.addPoints, params);
|
||||
} else if (commands.reducePointsCommands.includes(command)) {
|
||||
if (!isMod(flags)) {
|
||||
respond(responses.notMod, params);
|
||||
return;
|
||||
}
|
||||
|
||||
let mentioned = message.split(" ")[0].replace("@", "");
|
||||
|
||||
if (mentioned === "") {
|
||||
respond(responses.specifyUser, params);
|
||||
return;
|
||||
}
|
||||
|
||||
let points = message.split(" ")[1];
|
||||
|
||||
if (points === undefined) {
|
||||
respond(responses.specifyPoints, params);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!/^\d+$/.test(points)) {
|
||||
respond(responses.invalidNumber, params);
|
||||
return;
|
||||
}
|
||||
|
||||
reducePoints(mentioned, points);
|
||||
|
||||
params.mentioned = mentioned;
|
||||
params.pointCount = points;
|
||||
|
||||
respond(responses.reducePoints, params);
|
||||
} else if (commands.setUserPointsCommands.includes(command)) {
|
||||
if (!isMod(flags)) {
|
||||
respond(responses.notMod, params);
|
||||
return;
|
||||
}
|
||||
|
||||
let mentioned = message.split(" ")[0].replace("@", "");
|
||||
|
||||
if (mentioned === "") {
|
||||
respond(responses.specifyUser, params);
|
||||
return;
|
||||
}
|
||||
|
||||
let points = message.split(" ")[1];
|
||||
|
||||
if (points === undefined) {
|
||||
respond(responses.specifyPoints, params);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!/^\d+$/.test(points)) {
|
||||
respond(responses.invalidNumber, params);
|
||||
return;
|
||||
}
|
||||
|
||||
points = parseInt(points);
|
||||
|
||||
setUserPoints(mentioned, points);
|
||||
|
||||
params.mentioned = mentioned;
|
||||
params.pointCount = points;
|
||||
|
||||
respond(responses.setUserPoints, params);
|
||||
} else if (commands.setUserTaskCountCommands.includes(commands)) {
|
||||
if (!isMod(flags)) {
|
||||
respond(responses.notMod, params);
|
||||
return;
|
||||
}
|
||||
|
||||
let mentioned = message.split(" ")[0].replace("@", "");
|
||||
|
||||
if (mentioned === "") {
|
||||
respond(responses.specifyUser, params);
|
||||
return;
|
||||
}
|
||||
|
||||
let count = message.split(" ")[1];
|
||||
|
||||
if (count === undefined) {
|
||||
respond(responses.specifyCount, params);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!/^\d+$/.test(count)) {
|
||||
respond(responses.invalidNumber, params);
|
||||
return;
|
||||
}
|
||||
|
||||
points = parseInt(points);
|
||||
|
||||
setUserTaskCount(mentioned, count);
|
||||
|
||||
params.mentioned = mentioned;
|
||||
params.pointCount = count;
|
||||
|
||||
respond(responses.setUserTaskCount, params);
|
||||
} else if (commands.leaderboardCommands.includes(command)) {
|
||||
let leaderboardResponse = leaderboardTaskCount(5);
|
||||
|
||||
if (leaderboardResponse.status !== 200) {
|
||||
respond(leaderboardResponse.body.error, params);
|
||||
return;
|
||||
}
|
||||
|
||||
let leaderboard = leaderboardResponse.body.leaderboard;
|
||||
|
||||
respond(leaderboard, params);
|
||||
} else if (commands.adminSetBoardCount.includes(command)) {
|
||||
if (!isStreamer(flags)) {
|
||||
respond(responses.notStreamer, params);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ DB structure:
|
|||
- users
|
||||
- [username]:
|
||||
- completeCount
|
||||
- points
|
||||
- totalCompleteCount
|
||||
*/
|
||||
|
||||
|
|
@ -75,7 +76,9 @@ function hexToRgb(hex) {
|
|||
return `${r}, ${g}, ${b}`;
|
||||
}
|
||||
|
||||
// import styles from configs
|
||||
/**
|
||||
* import styles from configs
|
||||
*/
|
||||
function importStyles() {
|
||||
const styles = configs.styles;
|
||||
|
||||
|
|
@ -151,11 +154,17 @@ function importStyles() {
|
|||
}, 8000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the entire localstorage
|
||||
*/
|
||||
function resetDB() {
|
||||
localStorage.clear();
|
||||
setupDB();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the local storage database.
|
||||
*/
|
||||
function setupDB() {
|
||||
if (!localStorage.tasks) {
|
||||
localStorage.setItem(`tasks`, "{}");
|
||||
|
|
@ -202,6 +211,42 @@ function completedTasksCount(username) {
|
|||
function getUserTotalTaskCount(username) {
|
||||
return incompleteTasksCount(username) + completedTasksCount(username);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the total points for a given user based on the number of completed tasks and the points per task setting.
|
||||
*
|
||||
* @param {string} username - The name of the user whose points are to be calculated.
|
||||
* @returns {number} The total points for the user.
|
||||
*/
|
||||
function calculatePoints(username) {
|
||||
const counts = JSON.parse(localStorage.counts);
|
||||
|
||||
if (!counts.users[username.toLowerCase()]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (
|
||||
counts.users[username.toLowerCase()].completeCount *
|
||||
settings.pointsPerTask
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the points of a specific user from local storage.
|
||||
*
|
||||
* @param {string} username - The name of the user.
|
||||
* @returns {number} The points of the user. If the user does not exist, returns 0.
|
||||
*/
|
||||
function getUserPoints(username) {
|
||||
const counts = JSON.parse(localStorage.counts);
|
||||
|
||||
if (!counts.users[username.toLowerCase()]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return counts.users[username.toLowerCase()].points;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a specified value to the completed task count for a given user and the total completed task count.
|
||||
*
|
||||
|
|
@ -227,31 +272,157 @@ function addDoneCount(username, value) {
|
|||
localStorage.setItem(`counts`, JSON.stringify(counts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the completed task count for a given user.
|
||||
*
|
||||
* @param {string} username
|
||||
* @param {int} value
|
||||
* @returns {Object} An object with a status and body. The status is 200 if successful, and the body contains a success message.
|
||||
*/
|
||||
function setUserCompleteCount(username, value) {
|
||||
const counts = JSON.parse(localStorage.counts);
|
||||
|
||||
if (!counts.users[username.toLowerCase()]) {
|
||||
counts.users[username.toLowerCase()] = {
|
||||
completeCount: 0,
|
||||
};
|
||||
}
|
||||
|
||||
if (!counts.users[username.toLowerCase()].completeCount) {
|
||||
counts.users[username.toLowerCase()].completeCount = 0;
|
||||
}
|
||||
|
||||
counts.users[username.toLowerCase()].completeCount = parseInt(value);
|
||||
|
||||
localStorage.setItem(`counts`, JSON.stringify(counts));
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
message: `Successfully set ${username}'s complete count to ${value}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the total count of completed tasks in local storage.
|
||||
*
|
||||
* @param {number} value - The new total count of completed tasks.
|
||||
* @returns {Object} An object with a status and body. The status is 200 if successful, and the body contains a success message.
|
||||
*/
|
||||
function setTotalCompleteCount(value) {
|
||||
const counts = JSON.parse(localStorage.counts);
|
||||
|
||||
counts.totalCompleteCount = parseInt(value);
|
||||
|
||||
localStorage.setItem(`counts`, JSON.stringify(counts));
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
message: `Successfully set total complete count to ${value}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the total points for a given user based on the number of completed tasks and the points per task setting.
|
||||
* Adds a specified number of points to a user's total in local storage.
|
||||
*
|
||||
* @param {string} username - The name of the user whose points are to be calculated.
|
||||
* @returns {number} The total points for the user.
|
||||
* @param {string} username - The name of the user.
|
||||
* @param {number} value - The number of points to add.
|
||||
* @returns {Object} An object with a status and body. The status is 200 if successful, and the body contains a success message.
|
||||
*/
|
||||
function calculatePoints(username) {
|
||||
function addPoints(username, value) {
|
||||
const counts = JSON.parse(localStorage.counts);
|
||||
|
||||
if (!counts.users[username.toLowerCase()]) {
|
||||
return 0;
|
||||
counts.users[username.toLowerCase()] = {
|
||||
points: 0,
|
||||
};
|
||||
}
|
||||
|
||||
return (
|
||||
counts.users[username.toLowerCase()].completeCount *
|
||||
settings.pointsPerTask
|
||||
);
|
||||
if (!counts.users[username.toLowerCase()].points) {
|
||||
counts.users[username.toLowerCase()].points = 0;
|
||||
}
|
||||
|
||||
console.log(counts.users[username.toLowerCase()].points);
|
||||
|
||||
counts.users[username.toLowerCase()].points += value;
|
||||
|
||||
console.log(counts.users[username.toLowerCase()].points);
|
||||
|
||||
localStorage.setItem(`counts`, JSON.stringify(counts));
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
message: `Successfully added ${value} points to ${username}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the points for a specific user in local storage.
|
||||
*
|
||||
* @param {string} username - The name of the user.
|
||||
* @param {number} pointsCount - The new points count for the user.
|
||||
* @returns {Object} An object with a status and body. The status is 200 if successful, and the body contains a success message.
|
||||
*/
|
||||
function setUserPoints(username, pointsCount) {
|
||||
const counts = JSON.parse(localStorage.counts);
|
||||
|
||||
if (!counts.users[username.toLowerCase()]) {
|
||||
counts.users[username.toLowerCase()] = {
|
||||
points: 0,
|
||||
};
|
||||
}
|
||||
|
||||
if (!counts.users[username.toLowerCase()].points) {
|
||||
counts.users[username.toLowerCase()].points = 0;
|
||||
}
|
||||
|
||||
counts.users[username.toLowerCase()].points = pointsCount;
|
||||
|
||||
localStorage.setItem(`counts`, JSON.stringify(counts));
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
message: `Successfully set ${username}'s points to ${pointsCount}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Reduces the points of a specific user in local storage by a specified value.
|
||||
*
|
||||
* @param {string} username - The name of the user.
|
||||
* @param {number} value - The value by which the user's points are to be reduced.
|
||||
* @returns {Object} An object with a status and body. The status is 200 if successful, and the body contains a success message.
|
||||
*/
|
||||
function reducePoints(username, value) {
|
||||
const counts = JSON.parse(localStorage.counts);
|
||||
|
||||
if (!counts.users[username.toLowerCase()]) {
|
||||
counts.users[username.toLowerCase()] = {
|
||||
points: 0,
|
||||
};
|
||||
}
|
||||
|
||||
if (!counts.users[username.toLowerCase()].points) {
|
||||
counts.users[username.toLowerCase()].points = 0;
|
||||
}
|
||||
|
||||
counts.users[username.toLowerCase()].points -= parseInt(value);
|
||||
|
||||
localStorage.setItem(`counts`, JSON.stringify(counts));
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
message: `Successfully reduced ${username}'s points by ${value}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -269,33 +440,144 @@ function getBoardTotalTaskCount() {
|
|||
return counts.totalCompleteCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the task count for a specific user in local storage and returns a success message.
|
||||
*
|
||||
* @param {string} username - The name of the user.
|
||||
* @param {number} value - The new task count for the user.
|
||||
* @returns {Object} An object with a status and body. The status is 200 if successful, and the body contains a success message.
|
||||
*/
|
||||
function setUserTaskCount(username, value) {
|
||||
const counts = JSON.parse(localStorage.counts);
|
||||
|
||||
if (!counts.users[username.toLowerCase()]) {
|
||||
counts.users[username.toLowerCase()] = {
|
||||
points: 0,
|
||||
};
|
||||
}
|
||||
|
||||
if (!counts.users[username.toLowerCase()].points) {
|
||||
counts.users[username.toLowerCase()].points = 0;
|
||||
}
|
||||
|
||||
counts.users[username.toLowerCase()].taskCount = parseInt(value);
|
||||
|
||||
localStorage.setItem(`counts`, JSON.stringify(counts));
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
message: `Successfully set ${username}'s task count to ${value}`,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronizes the points of each user with their task count in local storage. After the synchronization, the function returns an object with a status of 200 and a success message.
|
||||
*
|
||||
* @returns {Object} An object with a status and body. The status is 200 if the synchronization is successful, and the body contains a success message.
|
||||
*/
|
||||
function syncPointsToCount() {
|
||||
const counts = JSON.parse(localStorage.counts);
|
||||
|
||||
for (const user in counts.users) {
|
||||
counts.users[user].points = calculatePoints(user);
|
||||
}
|
||||
|
||||
localStorage.setItem(`counts`, JSON.stringify(counts));
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
message: "Successfully synced counts to points",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the leaderboard of users based on task count.
|
||||
*
|
||||
* @param {number} limit - The maximum number of users to include in the leaderboard.
|
||||
* @returns {Object} An object with a status and body. The status is 200 if successful, and the body contains an array of user objects, each with a username and task count, sorted in descending order of task count.
|
||||
*/
|
||||
function leaderboardTaskCount(limit) {
|
||||
const counts = JSON.parse(localStorage.counts);
|
||||
|
||||
let leaderboardArray = [];
|
||||
|
||||
for (const user in counts.users) {
|
||||
leaderboardArray.push({
|
||||
username: user,
|
||||
taskCount: getUserTotalTaskCount(user),
|
||||
});
|
||||
}
|
||||
|
||||
leaderboardArray.sort((a, b) => b.taskCount - a.taskCount);
|
||||
|
||||
// shorten to limit
|
||||
leaderboardArray = leaderboardArray.slice(0, limit);
|
||||
|
||||
let leaderboardstring = "";
|
||||
|
||||
leaderboardArray.map((user, index) => {
|
||||
leaderboardstring += `${index + 1}. @${user.username} : ${
|
||||
user.taskCount
|
||||
} | `;
|
||||
});
|
||||
|
||||
leaderboardstring = leaderboardstring.slice(0, -3);
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
leaderboard: leaderboardstring,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the total count of completed tasks in the board to zero.
|
||||
*/
|
||||
function resetBoardCount() {
|
||||
const counts = JSON.parse(localStorage.counts);
|
||||
|
||||
counts.totalCompleteCount = 0;
|
||||
|
||||
localStorage.setItem(`counts`, JSON.stringify(counts));
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
message: "Successfully reset board count",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the task count for all users.
|
||||
*/
|
||||
function resetUsersCount() {
|
||||
const counts = JSON.parse(localStorage.counts);
|
||||
|
||||
counts.users = {};
|
||||
|
||||
localStorage.setItem(`counts`, JSON.stringify(counts));
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
message: "Successfully reset users count",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a task to the task list for a given user.
|
||||
* If the task is successfully added,
|
||||
* the function returns an object with a status of 200 and the task text.
|
||||
* If the task is not added due to reaching the task limit, being a duplicate task, or being invalid input,
|
||||
* the function returns an object with a status indicating the error and an error message.
|
||||
* Adds a task to a user's task list.
|
||||
*
|
||||
* @param {string} username - The name of the user to whom the task is to be added.
|
||||
* @param {string} userColor - The color associated with the user.
|
||||
* @param {string} task - The text of the task to be added.
|
||||
* @returns {Object} An object with a status and body. The status is 200 if the task is successfully added, and the body contains the task text. If the task is not added, the status indicates the error and the body contains an error message.
|
||||
* @param {string} username - The user's name.
|
||||
* @param {string} userColor - The user's associated color.
|
||||
* @param {string} task - The task text.
|
||||
* @returns {Object} An object with a status and body. The status is 200 if successful, otherwise it indicates the error. The body contains the task text or an error message.
|
||||
*/
|
||||
function addTask(username, userColor, task) {
|
||||
const tasks = JSON.parse(localStorage.tasks);
|
||||
|
|
|
|||
Loading…
Reference in a new issue