added task master command
This commit is contained in:
parent
892674476e
commit
6cd20763ae
8 changed files with 619 additions and 538 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -2,3 +2,4 @@
|
||||||
styles/taskList.css.map
|
styles/taskList.css.map
|
||||||
styles/taskList.scss
|
styles/taskList.scss
|
||||||
to-do.md
|
to-do.md
|
||||||
|
updates
|
||||||
12
configs.js
12
configs.js
|
|
@ -252,6 +252,8 @@ const configs = (function () {
|
||||||
|
|
||||||
leaderboardCommands: ["!leaderboard", "!lb", "!top", "!toppoints"],
|
leaderboardCommands: ["!leaderboard", "!lb", "!top", "!toppoints"],
|
||||||
|
|
||||||
|
TaskMasterCommands: ["!taskmaster", "!taskchampion"],
|
||||||
|
|
||||||
// Help commands - please add commands in the exact format
|
// Help commands - please add commands in the exact format
|
||||||
helpCommands: [
|
helpCommands: [
|
||||||
"!taskh",
|
"!taskh",
|
||||||
|
|
@ -282,13 +284,13 @@ const configs = (function () {
|
||||||
|
|
||||||
adminClearTasksCommands: ["!cleartasks"],
|
adminClearTasksCommands: ["!cleartasks"],
|
||||||
|
|
||||||
adminResetBoardCount: ["!resetboardcount", "!resetallcount"],
|
adminResetBoardCountCommands: ["!resetboardcount", "!resetallcount"],
|
||||||
|
|
||||||
adminResetUsersCount: ["!resetuserscount"],
|
adminResetUsersCountCommands: ["!resetuserscount"],
|
||||||
|
|
||||||
adminClearAllCommands: ["!clearallnoregrets"],
|
adminClearAllCommands: ["!clearallnoregrets"],
|
||||||
|
|
||||||
adminSetBoardCount: ["!setboardcount", "!setallcount"],
|
adminSetBoardCountCommands: ["!setboardcount", "!setallcount"],
|
||||||
additionalCommands: {
|
additionalCommands: {
|
||||||
"!botcred":
|
"!botcred":
|
||||||
"{user} Ryan is the creator of this bot! You can find him on https://github.com/liyunze-coding or https://www.twitch.tv/RythonDev",
|
"{user} Ryan is the creator of this bot! You can find him on https://github.com/liyunze-coding or https://www.twitch.tv/RythonDev",
|
||||||
|
|
@ -367,6 +369,10 @@ const configs = (function () {
|
||||||
leaderboard: "Leaderboard: {leaderboard}",
|
leaderboard: "Leaderboard: {leaderboard}",
|
||||||
setUserTaskCount: "{mentioned} now has {taskCount} tasks!",
|
setUserTaskCount: "{mentioned} now has {taskCount} tasks!",
|
||||||
|
|
||||||
|
// Grouped by taskmaster-related responses
|
||||||
|
taskMaster: "{user} Task Master: {taskMaster} [{taskMasterCount}]",
|
||||||
|
noTaskMaster: "No task master yet, {user}!",
|
||||||
|
|
||||||
// Grouped by permission-related responses
|
// Grouped by permission-related responses
|
||||||
notMod: "Permission denied, {user}; Mods only",
|
notMod: "Permission denied, {user}; Mods only",
|
||||||
notStreamer: "Permission denied, {user}; Streamer only",
|
notStreamer: "Permission denied, {user}; Streamer only",
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,9 @@
|
||||||
|
|
||||||
<script src="./auth.js"></script>
|
<script src="./auth.js"></script>
|
||||||
<script src="./configs.js"></script>
|
<script src="./configs.js"></script>
|
||||||
<script defer src="scripts/functions.js"></script>
|
<script src="scripts/defaultConfigs.js"></script>
|
||||||
<script defer src="scripts/defaultConfigs.js"></script>
|
<script src="scripts/functions.js"></script>
|
||||||
|
<script defer src="scripts/processCommand.js"></script>
|
||||||
<script defer src="scripts/index.js"></script>
|
<script defer src="scripts/index.js"></script>
|
||||||
<script defer src="scripts/taskList.js"></script>
|
<script defer src="scripts/taskList.js"></script>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,8 @@ 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]
|
||||||
);
|
);
|
||||||
|
|
|
||||||
529
scripts/index.js
529
scripts/index.js
|
|
@ -1,5 +1,3 @@
|
||||||
const commands = configs.commands;
|
|
||||||
|
|
||||||
let params = {};
|
let params = {};
|
||||||
|
|
||||||
function respond(template, params) {
|
function respond(template, params) {
|
||||||
|
|
@ -18,530 +16,15 @@ function isStreamer(flags) {
|
||||||
return flags.broadcaster;
|
return flags.broadcaster;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function processCommand(user, command, message, flags, extra) {
|
|
||||||
params = {
|
|
||||||
user: user,
|
|
||||||
message: message,
|
|
||||||
pointName: configs.settings.pointsName,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (commands.addTaskCommands.includes(command)) {
|
|
||||||
let addRequest = await addTask(user, extra.userColor, message);
|
|
||||||
|
|
||||||
if (addRequest.status !== 200) {
|
|
||||||
respond(addRequest.body.error, params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let addedResponse = getResponse("taskAdded");
|
|
||||||
params.task = addRequest.body.task;
|
|
||||||
|
|
||||||
if (addRequest.body.tasksFailedToAdd !== "") {
|
|
||||||
addedResponse += ` | Failed to add task(s): "${addRequest.body.tasksFailedToAdd}"`;
|
|
||||||
}
|
|
||||||
|
|
||||||
respond(addedResponse, params);
|
|
||||||
} else if (commands.editTaskCommands.includes(command)) {
|
|
||||||
let editRequest = await editTask(user, message);
|
|
||||||
|
|
||||||
if (editRequest.status !== 200) {
|
|
||||||
respond(editRequest.body.error, params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let originalTask = editRequest.body.originalTask;
|
|
||||||
let newTask = editRequest.body.newTask;
|
|
||||||
|
|
||||||
params.task = newTask;
|
|
||||||
params.originalTask = originalTask;
|
|
||||||
|
|
||||||
respond(getResponse("taskEdited"), params);
|
|
||||||
} else if (commands.deleteTaskCommands.includes(command)) {
|
|
||||||
let removeRequest = await removeTask(user, message);
|
|
||||||
|
|
||||||
if (removeRequest.status !== 200) {
|
|
||||||
respond(removeRequest.body.error, params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let deletedResponse = getResponse("taskDeleted");
|
|
||||||
|
|
||||||
let removedTasks = removeRequest.body.removedTasks;
|
|
||||||
let failedTasks = removeRequest.body.failedTasks;
|
|
||||||
|
|
||||||
params.task = removedTasks;
|
|
||||||
|
|
||||||
if (failedTasks !== "") {
|
|
||||||
deletedResponse += ` | Failed to delete task(s): "${failedTasks}"`;
|
|
||||||
}
|
|
||||||
|
|
||||||
respond(deletedResponse, params);
|
|
||||||
} else if (commands.finishTaskCommands.includes(command)) {
|
|
||||||
if (message === "all") {
|
|
||||||
let finishAllRequest = await markAllTasksAsDone(user);
|
|
||||||
|
|
||||||
if (finishAllRequest.status !== 200) {
|
|
||||||
respond(finishAllRequest.body.error, params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let finishedAllResponse = getResponse("allTasksFinished");
|
|
||||||
params.doneCount = await completedTasksCount(user);
|
|
||||||
|
|
||||||
respond(finishedAllResponse, params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let finishRequest = await markTaskDone(user, message);
|
|
||||||
|
|
||||||
if (finishRequest.status !== 200) {
|
|
||||||
respond(finishRequest.body.error, params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let finishedResponse = getResponse("taskFinished");
|
|
||||||
|
|
||||||
params.task = finishRequest.body.markedTasks;
|
|
||||||
params.doneCount = await completedTasksCount(user);
|
|
||||||
params.pointCount =
|
|
||||||
finishRequest.body.markedTasksCount *
|
|
||||||
configs.settings.pointsPerTask;
|
|
||||||
|
|
||||||
if (finishRequest.body.failedTasks !== "") {
|
|
||||||
finishedResponse += ` | Failed to finish task(s): "${finishRequest.body.failedTasks}"`;
|
|
||||||
}
|
|
||||||
|
|
||||||
respond(finishedResponse, params);
|
|
||||||
} else if (commands.unfinishTaskCommands.includes(command)) {
|
|
||||||
let unfinishRequest = await markTaskUndone(user, message);
|
|
||||||
|
|
||||||
if (unfinishRequest.status !== 200) {
|
|
||||||
respond(unfinishRequest.body.error, params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// task unfinished
|
|
||||||
let unfinishedResponse = getResponse("taskUnfinished");
|
|
||||||
|
|
||||||
params.task = unfinishRequest.body.markedTasks;
|
|
||||||
|
|
||||||
if (unfinishRequest.body.failedTasks !== "") {
|
|
||||||
unfinishedResponse += ` | Failed to unfinish task(s): "${unfinishRequest.body.failedTasks}"`;
|
|
||||||
}
|
|
||||||
|
|
||||||
respond(unfinishedResponse, params);
|
|
||||||
} else if (commands.nextTaskCommands.includes(command)) {
|
|
||||||
let nextRequest = await nextTask(user, message);
|
|
||||||
|
|
||||||
if (nextRequest.status !== 200) {
|
|
||||||
respond(nextRequest.body.error, params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// task next
|
|
||||||
let nextResponse = getResponse("taskNext");
|
|
||||||
|
|
||||||
params.oldTask = nextRequest.body.oldTask;
|
|
||||||
params.newTask = nextRequest.body.newTask;
|
|
||||||
|
|
||||||
respond(nextResponse, params);
|
|
||||||
} else if (commands.nowTaskCommands.includes(command)) {
|
|
||||||
let nowRequest = await nowTask(user, extra.userColor, message);
|
|
||||||
|
|
||||||
if (nowRequest.status !== 200) {
|
|
||||||
respond(nowRequest.body.error, params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// task now
|
|
||||||
let nowResponse = getResponse("nowTask");
|
|
||||||
|
|
||||||
params.task = nowRequest.body.task;
|
|
||||||
|
|
||||||
respond(nowResponse, params);
|
|
||||||
} else if (commands.focusTaskCommands.includes(command)) {
|
|
||||||
let focusRequest = await focusTask(user, message);
|
|
||||||
|
|
||||||
if (focusRequest.status !== 200) {
|
|
||||||
respond(focusRequest.body.error, params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// task focused
|
|
||||||
let focusedResponse = getResponse("taskFocused");
|
|
||||||
|
|
||||||
params.task = focusRequest.body.focusedTask;
|
|
||||||
|
|
||||||
respond(focusedResponse, params);
|
|
||||||
} else if (commands.unfocusTaskCommands.includes(command)) {
|
|
||||||
let unfocusRequest = await unfocusTask(user);
|
|
||||||
|
|
||||||
if (unfocusRequest.status !== 200) {
|
|
||||||
respond(unfocusRequest.body.error, params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// task unfocused
|
|
||||||
let unfocusedResponse = getResponse("clearFocused");
|
|
||||||
|
|
||||||
respond(unfocusedResponse, params);
|
|
||||||
} else if (commands.checkCommands.includes(command)) {
|
|
||||||
if (message === "") {
|
|
||||||
let checkRequest = await checkTasks(user);
|
|
||||||
if (checkRequest.status !== 200) {
|
|
||||||
// no tasks
|
|
||||||
respond(checkRequest.body.error, params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return respond(checkRequest.body.reply, params);
|
|
||||||
} else {
|
|
||||||
let mentioned = message.replace("@", "");
|
|
||||||
let checkRequest = await checkTasks(mentioned);
|
|
||||||
|
|
||||||
if (checkRequest.status !== 200) {
|
|
||||||
// no tasks
|
|
||||||
respond(checkRequest.body.error, params);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
return respond(checkRequest.body.reply, params);
|
|
||||||
}
|
|
||||||
} else if (commands.adminDeleteCommands.includes(command)) {
|
|
||||||
if (!isMod(flags)) {
|
|
||||||
respond(getResponse("notMod"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let mentioned = message.replace("@", "");
|
|
||||||
|
|
||||||
if (mentioned === "") {
|
|
||||||
respond(getResponse("specifyUser"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let clearUserTaskResponse = await clearUserTasks(mentioned);
|
|
||||||
|
|
||||||
params.mentioned = mentioned;
|
|
||||||
|
|
||||||
if (clearUserTaskResponse.status === 0) {
|
|
||||||
// no tasks
|
|
||||||
respond(getResponse("noTaskA"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
respond(getResponse("adminDeleteTasks"), params);
|
|
||||||
return;
|
|
||||||
} else if (commands.adminClearDoneCommands.includes(command)) {
|
|
||||||
if (!isStreamer(flags)) {
|
|
||||||
respond(getResponse("notStreamer"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
clearAllDoneTasks();
|
|
||||||
respond(getResponse("clearedDone"), params);
|
|
||||||
return;
|
|
||||||
} else if (commands.adminClearAllCommands.includes(command)) {
|
|
||||||
if (!isStreamer(flags)) {
|
|
||||||
respond(getResponse("notStreamer"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
clearAll();
|
|
||||||
respond(getResponse("clearedAll"), params);
|
|
||||||
return;
|
|
||||||
} else if (commands.clearMyDoneCommands.includes(command)) {
|
|
||||||
let clearOwnDoneResponse = await clearOwnDoneTasks(user);
|
|
||||||
|
|
||||||
if (clearOwnDoneResponse.status !== 200) {
|
|
||||||
// no tasks
|
|
||||||
respond(getResponse("noTask"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
respond(getResponse("clearedMyDone"), params);
|
|
||||||
} else if (commands.adminClearNotStreamerCommands.includes(command)) {
|
|
||||||
if (!isStreamer(flags)) {
|
|
||||||
respond(getResponse("notStreamer"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await clearMemory();
|
|
||||||
|
|
||||||
await clearAllExceptStreamer(configs.StreamerUsernames);
|
|
||||||
respond(getResponse("clearTasksExceptBroadcaster"), params);
|
|
||||||
} else if (commands.adminClearTasksCommands.includes(command)) {
|
|
||||||
if (!isStreamer(flags)) {
|
|
||||||
respond(getResponse("notStreamer"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await clearMemory();
|
|
||||||
|
|
||||||
await clearAllTasks();
|
|
||||||
respond(getResponse("clearedTasks"), params);
|
|
||||||
} else if (commands.listCommands.includes(command)) {
|
|
||||||
let listTaskResponse = await listTasks(user);
|
|
||||||
|
|
||||||
if (listTaskResponse.status !== 200) {
|
|
||||||
// no tasks
|
|
||||||
respond(listTaskResponse.body.error, params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
respond(listTaskResponse.body.reply, params);
|
|
||||||
} else if (commands.checkCountCommands.includes(command)) {
|
|
||||||
if (message === "") {
|
|
||||||
let count = await completedTasksCount(user);
|
|
||||||
|
|
||||||
params.doneCount = count;
|
|
||||||
|
|
||||||
return respond(getResponse("checkYourCount"), params);
|
|
||||||
} else {
|
|
||||||
let mentioned = message.replace("@", "");
|
|
||||||
let count = await completedTasksCount(mentioned);
|
|
||||||
|
|
||||||
params.doneCount = count;
|
|
||||||
params.mentioned = mentioned;
|
|
||||||
|
|
||||||
return respond(getResponse("checkUserCount"), params);
|
|
||||||
}
|
|
||||||
} else if (commands.checkAllCountCommands.includes(command)) {
|
|
||||||
let count = getBoardTotalTaskCount();
|
|
||||||
|
|
||||||
if (count === 0) {
|
|
||||||
respond(getResponse("noCountAll"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
params.doneCount = count;
|
|
||||||
|
|
||||||
respond(getResponse("checkAllCount"), params);
|
|
||||||
} else if (commands.checkMyPointsCommands.includes(command)) {
|
|
||||||
if (message === "") {
|
|
||||||
let points = await getUserPoints(user);
|
|
||||||
|
|
||||||
params.pointCount = points;
|
|
||||||
|
|
||||||
return respond(getResponse("checkMyPoints"), params);
|
|
||||||
} else {
|
|
||||||
let mentioned = message.replace("@", "");
|
|
||||||
let points = await getUserPoints(mentioned);
|
|
||||||
|
|
||||||
params.pointCount = points;
|
|
||||||
params.mentioned = mentioned;
|
|
||||||
|
|
||||||
return respond(getResponse("checkUserPoints"), params);
|
|
||||||
}
|
|
||||||
} else if (commands.syncCountPointsCommands.includes(command)) {
|
|
||||||
if (!isStreamer(flags)) {
|
|
||||||
respond(getResponse("notStreamer"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await syncPointsToCount();
|
|
||||||
respond(getResponse("syncCountPoints"), params);
|
|
||||||
} else if (commands.addPointsCommands.includes(command)) {
|
|
||||||
// !addpoints @user 100
|
|
||||||
|
|
||||||
if (!isMod(flags)) {
|
|
||||||
respond(getResponse("notMod"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mentioned = message.split(" ")[0].replace("@", "");
|
|
||||||
|
|
||||||
if (mentioned === "") {
|
|
||||||
respond(getResponse("specifyUser"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let points = message.split(" ")[1];
|
|
||||||
|
|
||||||
if (points === undefined) {
|
|
||||||
respond(getResponse("specifyPoints"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!/^\d+$/.test(points)) {
|
|
||||||
respond(getResponse("invalidNumber"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
points = parseInt(points);
|
|
||||||
|
|
||||||
await addPoints(mentioned, points);
|
|
||||||
|
|
||||||
params.mentioned = mentioned;
|
|
||||||
params.pointCount = points;
|
|
||||||
|
|
||||||
respond(getResponse("addPoints"), params);
|
|
||||||
} else if (commands.reducePointsCommands.includes(command)) {
|
|
||||||
if (!isMod(flags)) {
|
|
||||||
respond(getResponse("notMod"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mentioned = message.split(" ")[0].replace("@", "");
|
|
||||||
|
|
||||||
if (mentioned === "") {
|
|
||||||
respond(getResponse("specifyUser"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let points = message.split(" ")[1];
|
|
||||||
|
|
||||||
if (points == undefined) {
|
|
||||||
respond(getResponse("specifyPoints"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!/^\d+$/.test(points)) {
|
|
||||||
respond(getResponse("invalidNumber"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await reducePoints(mentioned, points);
|
|
||||||
|
|
||||||
params.mentioned = mentioned;
|
|
||||||
params.pointCount = points;
|
|
||||||
|
|
||||||
respond(getResponse("reducePoints"), params);
|
|
||||||
} else if (commands.setUserPointsCommands.includes(command)) {
|
|
||||||
if (!isMod(flags)) {
|
|
||||||
respond(getResponse("notMod"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mentioned = message.split(" ")[0].replace("@", "");
|
|
||||||
|
|
||||||
if (mentioned === "") {
|
|
||||||
respond(getResponse("specifyUser"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let points = message.split(" ")[1];
|
|
||||||
|
|
||||||
if (points === undefined) {
|
|
||||||
respond(getResponse("specifyPoints"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!/^\d+$/.test(points)) {
|
|
||||||
respond(getResponse("invalidNumber"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
points = parseInt(points);
|
|
||||||
|
|
||||||
await setUserPoints(mentioned, points);
|
|
||||||
|
|
||||||
params.mentioned = mentioned;
|
|
||||||
params.pointCount = points;
|
|
||||||
|
|
||||||
respond(getResponse("setUserPoints"), params);
|
|
||||||
} else if (commands.setUserTaskCountCommands.includes(commands)) {
|
|
||||||
if (!isMod(flags)) {
|
|
||||||
respond(getResponse("notMod"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let mentioned = message.split(" ")[0].replace("@", "");
|
|
||||||
|
|
||||||
if (mentioned === "") {
|
|
||||||
respond(getResponse("specifyUser"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let count = message.split(" ")[1];
|
|
||||||
|
|
||||||
if (count === undefined) {
|
|
||||||
respond(getResponse("specifyCount"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!/^\d+$/.test(count)) {
|
|
||||||
respond(getResponse("invalidNumber"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
points = parseInt(points);
|
|
||||||
|
|
||||||
await setUserTaskCount(mentioned, count);
|
|
||||||
|
|
||||||
params.mentioned = mentioned;
|
|
||||||
params.pointCount = count;
|
|
||||||
|
|
||||||
respond(getResponse("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(getResponse("notStreamer"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if message is a number using regex
|
|
||||||
if (!/^\d+$/.test(message)) {
|
|
||||||
respond(getResponse("invalidNumber"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
params.count = message;
|
|
||||||
|
|
||||||
await setTotalCompleteCount(message);
|
|
||||||
|
|
||||||
respond(getResponse("setBoardCount"), params);
|
|
||||||
} else if (commands.adminResetBoardCount.includes(command)) {
|
|
||||||
if (!isStreamer(flags)) {
|
|
||||||
respond(getResponse("notStreamer"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await resetBoardCount();
|
|
||||||
respond(getResponse("clearedBoardCount"), params);
|
|
||||||
} else if (commands.adminResetUsersCount.includes(command)) {
|
|
||||||
if (!isStreamer(flags)) {
|
|
||||||
respond(getResponse("notStreamer"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await resetUsersCount();
|
|
||||||
respond(getResponse("clearedUsersCount"), params);
|
|
||||||
} else if (commands.helpCommands.includes(command)) {
|
|
||||||
respond(getResponse("help"), params);
|
|
||||||
} else if (command === "!clearlocalstorage") {
|
|
||||||
if (!isStreamer(flags)) {
|
|
||||||
respond(getResponse("notStreamer"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
clearLocalStorage();
|
|
||||||
|
|
||||||
respond(getResponse("clearLocalStorage"), params);
|
|
||||||
} else if (["!transferdata"].includes(command)) {
|
|
||||||
if (!isStreamer(flags)) {
|
|
||||||
respond(getResponse("notStreamer"), params);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await transferLocalStorageToIndexedDB();
|
|
||||||
} else if (commands.additionalCommands[command]) {
|
|
||||||
respond(commands.additionalCommands[command], params);
|
|
||||||
} else {
|
|
||||||
// command not found
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ComfyJS.onCommand = (user, command, message, flags, extra) => {
|
ComfyJS.onCommand = (user, command, message, flags, extra) => {
|
||||||
command = `!${command.toLowerCase()}`;
|
command = `!${command.toLowerCase()}`;
|
||||||
|
|
||||||
processCommand(user, command, message, flags, extra);
|
processCommand(user, command, message, flags, extra);
|
||||||
};
|
};
|
||||||
|
|
||||||
ComfyJS.Init(auth.username, `oauth:${auth.oauth}`, [auth.channel]);
|
const oauth_token = auth.oauth.includes("oauth:")
|
||||||
|
? auth.oauth
|
||||||
|
: `oauth:${auth.oauth}`;
|
||||||
|
const auth_username = auth.username ? auth.username : auth.channel;
|
||||||
|
|
||||||
|
ComfyJS.Init(auth_username, `${oauth_token}`, [auth.channel]);
|
||||||
|
|
|
||||||
531
scripts/processCommand.js
Normal file
531
scripts/processCommand.js
Normal file
|
|
@ -0,0 +1,531 @@
|
||||||
|
async function processCommand(user, command, message, flags, extra) {
|
||||||
|
params = {
|
||||||
|
user: user,
|
||||||
|
message: message,
|
||||||
|
pointName: configs.settings.pointsName,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (getCommand("addTaskCommands").includes(command)) {
|
||||||
|
let addRequest = await addTask(user, extra.userColor, message);
|
||||||
|
|
||||||
|
if (addRequest.status !== 200) {
|
||||||
|
respond(addRequest.body.error, params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let addedResponse = getResponse("taskAdded");
|
||||||
|
params.task = addRequest.body.task;
|
||||||
|
|
||||||
|
if (addRequest.body.tasksFailedToAdd !== "") {
|
||||||
|
addedResponse += ` | Failed to add task(s): "${addRequest.body.tasksFailedToAdd}"`;
|
||||||
|
}
|
||||||
|
|
||||||
|
respond(addedResponse, params);
|
||||||
|
} else if (getCommand("editTaskCommands").includes(command)) {
|
||||||
|
let editRequest = await editTask(user, message);
|
||||||
|
|
||||||
|
if (editRequest.status !== 200) {
|
||||||
|
respond(editRequest.body.error, params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let originalTask = editRequest.body.originalTask;
|
||||||
|
let newTask = editRequest.body.newTask;
|
||||||
|
|
||||||
|
params.task = newTask;
|
||||||
|
params.originalTask = originalTask;
|
||||||
|
|
||||||
|
respond(getResponse("taskEdited"), params);
|
||||||
|
} else if (getCommand("deleteTaskCommands").includes(command)) {
|
||||||
|
let removeRequest = await removeTask(user, message);
|
||||||
|
|
||||||
|
if (removeRequest.status !== 200) {
|
||||||
|
respond(removeRequest.body.error, params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let deletedResponse = getResponse("taskDeleted");
|
||||||
|
|
||||||
|
let removedTasks = removeRequest.body.removedTasks;
|
||||||
|
let failedTasks = removeRequest.body.failedTasks;
|
||||||
|
|
||||||
|
params.task = removedTasks;
|
||||||
|
|
||||||
|
if (failedTasks !== "") {
|
||||||
|
deletedResponse += ` | Failed to delete task(s): "${failedTasks}"`;
|
||||||
|
}
|
||||||
|
|
||||||
|
respond(deletedResponse, params);
|
||||||
|
} else if (getCommand("finishTaskCommands").includes(command)) {
|
||||||
|
if (message === "all") {
|
||||||
|
let finishAllRequest = await markAllTasksAsDone(user);
|
||||||
|
|
||||||
|
if (finishAllRequest.status !== 200) {
|
||||||
|
respond(finishAllRequest.body.error, params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let finishedAllResponse = getResponse("allTasksFinished");
|
||||||
|
params.doneCount = await completedTasksCount(user);
|
||||||
|
|
||||||
|
respond(finishedAllResponse, params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let finishRequest = await markTaskDone(user, message);
|
||||||
|
|
||||||
|
if (finishRequest.status !== 200) {
|
||||||
|
respond(finishRequest.body.error, params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let finishedResponse = getResponse("taskFinished");
|
||||||
|
|
||||||
|
params.task = finishRequest.body.markedTasks;
|
||||||
|
params.doneCount = await completedTasksCount(user);
|
||||||
|
params.pointCount =
|
||||||
|
finishRequest.body.markedTasksCount *
|
||||||
|
configs.settings.pointsPerTask;
|
||||||
|
|
||||||
|
if (finishRequest.body.failedTasks !== "") {
|
||||||
|
finishedResponse += ` | Failed to finish task(s): "${finishRequest.body.failedTasks}"`;
|
||||||
|
}
|
||||||
|
|
||||||
|
respond(finishedResponse, params);
|
||||||
|
} else if (getCommand("unfinishTaskCommands").includes(command)) {
|
||||||
|
let unfinishRequest = await markTaskUndone(user, message);
|
||||||
|
|
||||||
|
if (unfinishRequest.status !== 200) {
|
||||||
|
respond(unfinishRequest.body.error, params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// task unfinished
|
||||||
|
let unfinishedResponse = getResponse("taskUnfinished");
|
||||||
|
|
||||||
|
params.task = unfinishRequest.body.markedTasks;
|
||||||
|
|
||||||
|
if (unfinishRequest.body.failedTasks !== "") {
|
||||||
|
unfinishedResponse += ` | Failed to unfinish task(s): "${unfinishRequest.body.failedTasks}"`;
|
||||||
|
}
|
||||||
|
|
||||||
|
respond(unfinishedResponse, params);
|
||||||
|
} else if (getCommand("nextTaskCommands").includes(command)) {
|
||||||
|
let nextRequest = await nextTask(user, message);
|
||||||
|
|
||||||
|
if (nextRequest.status !== 200) {
|
||||||
|
respond(nextRequest.body.error, params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// task next
|
||||||
|
let nextResponse = getResponse("taskNext");
|
||||||
|
|
||||||
|
params.oldTask = nextRequest.body.oldTask;
|
||||||
|
params.newTask = nextRequest.body.newTask;
|
||||||
|
|
||||||
|
respond(nextResponse, params);
|
||||||
|
} else if (getCommand("nowTaskCommands").includes(command)) {
|
||||||
|
let nowRequest = await nowTask(user, extra.userColor, message);
|
||||||
|
|
||||||
|
if (nowRequest.status !== 200) {
|
||||||
|
respond(nowRequest.body.error, params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// task now
|
||||||
|
let nowResponse = getResponse("nowTask");
|
||||||
|
|
||||||
|
params.task = nowRequest.body.task;
|
||||||
|
|
||||||
|
respond(nowResponse, params);
|
||||||
|
} else if (getCommand("focusTaskCommands").includes(command)) {
|
||||||
|
let focusRequest = await focusTask(user, message);
|
||||||
|
|
||||||
|
if (focusRequest.status !== 200) {
|
||||||
|
respond(focusRequest.body.error, params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// task focused
|
||||||
|
let focusedResponse = getResponse("taskFocused");
|
||||||
|
|
||||||
|
params.task = focusRequest.body.focusedTask;
|
||||||
|
|
||||||
|
respond(focusedResponse, params);
|
||||||
|
} else if (getCommand("unfocusTaskCommands").includes(command)) {
|
||||||
|
let unfocusRequest = await unfocusTask(user);
|
||||||
|
|
||||||
|
if (unfocusRequest.status !== 200) {
|
||||||
|
respond(unfocusRequest.body.error, params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// task unfocused
|
||||||
|
let unfocusedResponse = getResponse("clearFocused");
|
||||||
|
|
||||||
|
respond(unfocusedResponse, params);
|
||||||
|
} else if (getCommand("checkCommands").includes(command)) {
|
||||||
|
if (message === "") {
|
||||||
|
let checkRequest = await checkTasks(user);
|
||||||
|
if (checkRequest.status !== 200) {
|
||||||
|
// no tasks
|
||||||
|
respond(checkRequest.body.error, params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return respond(checkRequest.body.reply, params);
|
||||||
|
} else {
|
||||||
|
let mentioned = message.replace("@", "");
|
||||||
|
let checkRequest = await checkTasks(mentioned);
|
||||||
|
|
||||||
|
if (checkRequest.status !== 200) {
|
||||||
|
// no tasks
|
||||||
|
respond(checkRequest.body.error, params);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return respond(checkRequest.body.reply, params);
|
||||||
|
}
|
||||||
|
} else if (getCommand("adminDeleteCommands").includes(command)) {
|
||||||
|
if (!isMod(flags)) {
|
||||||
|
respond(getResponse("notMod"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let mentioned = message.replace("@", "");
|
||||||
|
|
||||||
|
if (mentioned === "") {
|
||||||
|
respond(getResponse("specifyUser"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let clearUserTaskResponse = await clearUserTasks(mentioned);
|
||||||
|
|
||||||
|
params.mentioned = mentioned;
|
||||||
|
|
||||||
|
if (clearUserTaskResponse.status === 0) {
|
||||||
|
// no tasks
|
||||||
|
respond(getResponse("noTaskA"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
respond(getResponse("adminDeleteTasks"), params);
|
||||||
|
return;
|
||||||
|
} else if (getCommand("adminClearDoneCommands").includes(command)) {
|
||||||
|
if (!isStreamer(flags)) {
|
||||||
|
respond(getResponse("notStreamer"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearAllDoneTasks();
|
||||||
|
respond(getResponse("clearedDone"), params);
|
||||||
|
return;
|
||||||
|
} else if (getCommand("adminClearAllCommands").includes(command)) {
|
||||||
|
if (!isStreamer(flags)) {
|
||||||
|
respond(getResponse("notStreamer"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearAll();
|
||||||
|
respond(getResponse("clearedAll"), params);
|
||||||
|
return;
|
||||||
|
} else if (getCommand("clearMyDoneCommands").includes(command)) {
|
||||||
|
let clearOwnDoneResponse = await clearOwnDoneTasks(user);
|
||||||
|
|
||||||
|
if (clearOwnDoneResponse.status !== 200) {
|
||||||
|
// no tasks
|
||||||
|
respond(getResponse("noTask"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
respond(getResponse("clearedMyDone"), params);
|
||||||
|
} else if (getCommand("adminClearNotStreamerCommands").includes(command)) {
|
||||||
|
if (!isStreamer(flags)) {
|
||||||
|
respond(getResponse("notStreamer"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await clearMemory();
|
||||||
|
|
||||||
|
await clearAllExceptStreamer(configs.StreamerUsernames);
|
||||||
|
respond(getResponse("clearTasksExceptBroadcaster"), params);
|
||||||
|
} else if (getCommand("adminClearTasksCommands").includes(command)) {
|
||||||
|
if (!isStreamer(flags)) {
|
||||||
|
respond(getResponse("notStreamer"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await clearMemory();
|
||||||
|
|
||||||
|
await clearAllTasks();
|
||||||
|
respond(getResponse("clearedTasks"), params);
|
||||||
|
} else if (getCommand("listCommands").includes(command)) {
|
||||||
|
let listTaskResponse = await listTasks(user);
|
||||||
|
|
||||||
|
if (listTaskResponse.status !== 200) {
|
||||||
|
// no tasks
|
||||||
|
respond(listTaskResponse.body.error, params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
respond(listTaskResponse.body.reply, params);
|
||||||
|
} else if (getCommand("checkCountCommands").includes(command)) {
|
||||||
|
if (message === "") {
|
||||||
|
let count = await completedTasksCount(user);
|
||||||
|
|
||||||
|
params.doneCount = count;
|
||||||
|
|
||||||
|
return respond(getResponse("checkYourCount"), params);
|
||||||
|
} else {
|
||||||
|
let mentioned = message.replace("@", "");
|
||||||
|
let count = await completedTasksCount(mentioned);
|
||||||
|
|
||||||
|
params.doneCount = count;
|
||||||
|
params.mentioned = mentioned;
|
||||||
|
|
||||||
|
return respond(getResponse("checkUserCount"), params);
|
||||||
|
}
|
||||||
|
} else if (getCommand("checkAllCountCommands").includes(command)) {
|
||||||
|
let count = getBoardTotalTaskCount();
|
||||||
|
|
||||||
|
if (count === 0) {
|
||||||
|
respond(getResponse("noCountAll"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
params.doneCount = count;
|
||||||
|
|
||||||
|
respond(getResponse("checkAllCount"), params);
|
||||||
|
} else if (getCommand("checkMyPointsCommands").includes(command)) {
|
||||||
|
if (message === "") {
|
||||||
|
let points = await getUserPoints(user);
|
||||||
|
|
||||||
|
params.pointCount = points;
|
||||||
|
|
||||||
|
return respond(getResponse("checkMyPoints"), params);
|
||||||
|
} else {
|
||||||
|
let mentioned = message.replace("@", "");
|
||||||
|
let points = await getUserPoints(mentioned);
|
||||||
|
|
||||||
|
params.pointCount = points;
|
||||||
|
params.mentioned = mentioned;
|
||||||
|
|
||||||
|
return respond(getResponse("checkUserPoints"), params);
|
||||||
|
}
|
||||||
|
} else if (getCommand("syncCountPointsCommands").includes(command)) {
|
||||||
|
if (!isStreamer(flags)) {
|
||||||
|
respond(getResponse("notStreamer"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await syncPointsToCount();
|
||||||
|
respond(getResponse("syncCountPoints"), params);
|
||||||
|
} else if (getCommand("addPointsCommands").includes(command)) {
|
||||||
|
// !addpoints @user 100
|
||||||
|
|
||||||
|
if (!isMod(flags)) {
|
||||||
|
respond(getResponse("notMod"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mentioned = message.split(" ")[0].replace("@", "");
|
||||||
|
|
||||||
|
if (mentioned === "") {
|
||||||
|
respond(getResponse("specifyUser"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let points = message.split(" ")[1];
|
||||||
|
|
||||||
|
if (points === undefined) {
|
||||||
|
respond(getResponse("specifyPoints"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!/^\d+$/.test(points)) {
|
||||||
|
respond(getResponse("invalidNumber"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
points = parseInt(points);
|
||||||
|
|
||||||
|
await addPoints(mentioned, points);
|
||||||
|
|
||||||
|
params.mentioned = mentioned;
|
||||||
|
params.pointCount = points;
|
||||||
|
|
||||||
|
respond(getResponse("addPoints"), params);
|
||||||
|
} else if (getCommand("reducePointsCommands").includes(command)) {
|
||||||
|
if (!isMod(flags)) {
|
||||||
|
respond(getResponse("notMod"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mentioned = message.split(" ")[0].replace("@", "");
|
||||||
|
|
||||||
|
if (mentioned === "") {
|
||||||
|
respond(getResponse("specifyUser"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let points = message.split(" ")[1];
|
||||||
|
|
||||||
|
if (points == undefined) {
|
||||||
|
respond(getResponse("specifyPoints"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!/^\d+$/.test(points)) {
|
||||||
|
respond(getResponse("invalidNumber"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await reducePoints(mentioned, points);
|
||||||
|
|
||||||
|
params.mentioned = mentioned;
|
||||||
|
params.pointCount = points;
|
||||||
|
|
||||||
|
respond(getResponse("reducePoints"), params);
|
||||||
|
} else if (getCommand("setUserPointsCommands").includes(command)) {
|
||||||
|
if (!isMod(flags)) {
|
||||||
|
respond(getResponse("notMod"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mentioned = message.split(" ")[0].replace("@", "");
|
||||||
|
|
||||||
|
if (mentioned === "") {
|
||||||
|
respond(getResponse("specifyUser"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let points = message.split(" ")[1];
|
||||||
|
|
||||||
|
if (points === undefined) {
|
||||||
|
respond(getResponse("specifyPoints"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!/^\d+$/.test(points)) {
|
||||||
|
respond(getResponse("invalidNumber"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
points = parseInt(points);
|
||||||
|
|
||||||
|
await setUserPoints(mentioned, points);
|
||||||
|
|
||||||
|
params.mentioned = mentioned;
|
||||||
|
params.pointCount = points;
|
||||||
|
|
||||||
|
respond(getResponse("setUserPoints"), params);
|
||||||
|
} else if (getCommand("setUserTaskCountCommands").includes(command)) {
|
||||||
|
if (!isMod(flags)) {
|
||||||
|
respond(getResponse("notMod"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let mentioned = message.split(" ")[0].replace("@", "");
|
||||||
|
|
||||||
|
if (mentioned === "") {
|
||||||
|
respond(getResponse("specifyUser"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let count = message.split(" ")[1];
|
||||||
|
|
||||||
|
if (count === undefined) {
|
||||||
|
respond(getResponse("specifyCount"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!/^\d+$/.test(count)) {
|
||||||
|
respond(getResponse("invalidNumber"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
points = parseInt(points);
|
||||||
|
|
||||||
|
await setUserTaskCount(mentioned, count);
|
||||||
|
|
||||||
|
params.mentioned = mentioned;
|
||||||
|
params.pointCount = count;
|
||||||
|
|
||||||
|
respond(getResponse("setUserTaskCount"), params);
|
||||||
|
} else if (getCommand("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 (getCommand("adminSetBoardCountCommands").includes(command)) {
|
||||||
|
if (!isStreamer(flags)) {
|
||||||
|
respond(getResponse("notStreamer"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if message is a number using regex
|
||||||
|
if (!/^\d+$/.test(message)) {
|
||||||
|
respond(getResponse("invalidNumber"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
params.count = message;
|
||||||
|
|
||||||
|
await setTotalCompleteCount(message);
|
||||||
|
|
||||||
|
respond(getResponse("setBoardCount"), params);
|
||||||
|
} else if (getCommand("adminResetBoardCountCommands").includes(command)) {
|
||||||
|
if (!isStreamer(flags)) {
|
||||||
|
respond(getResponse("notStreamer"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await resetBoardCount();
|
||||||
|
respond(getResponse("clearedBoardCount"), params);
|
||||||
|
} else if (getCommand("adminResetUsersCountCommands").includes(command)) {
|
||||||
|
if (!isStreamer(flags)) {
|
||||||
|
respond(getResponse("notStreamer"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await resetUsersCount();
|
||||||
|
respond(getResponse("clearedUsersCount"), params);
|
||||||
|
} else if (getCommand("TaskMasterCommands")) {
|
||||||
|
let champion = await getTaskMasterChampion();
|
||||||
|
|
||||||
|
if (champion === "") {
|
||||||
|
respond(getResponse("noTaskMaster"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
params.taskMaster = champion.username;
|
||||||
|
params.taskMasterCount = champion.count;
|
||||||
|
|
||||||
|
respond(getResponse("taskMaster"), params);
|
||||||
|
} else if (getCommand("helpCommands").includes(command)) {
|
||||||
|
respond(getResponse("help"), params);
|
||||||
|
} else if (command === "!clearlocalstorage") {
|
||||||
|
if (!isStreamer(flags)) {
|
||||||
|
respond(getResponse("notStreamer"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
clearLocalStorage();
|
||||||
|
|
||||||
|
respond(getResponse("clearLocalStorage"), params);
|
||||||
|
} else if (["!transferdata"].includes(command)) {
|
||||||
|
if (!isStreamer(flags)) {
|
||||||
|
respond(getResponse("notStreamer"), params);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await transferLocalStorageToIndexedDB();
|
||||||
|
} else if (commands.additionalCommands[command]) {
|
||||||
|
respond(commands.additionalCommands[command], params);
|
||||||
|
} else {
|
||||||
|
// command not found
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,6 +12,13 @@ DB structure:
|
||||||
- completeCount
|
- completeCount
|
||||||
- points
|
- points
|
||||||
- totalCompleteCount
|
- totalCompleteCount
|
||||||
|
|
||||||
|
- taskmaster
|
||||||
|
- users
|
||||||
|
- [username]:
|
||||||
|
- completeCount
|
||||||
|
- totalCompleteCount
|
||||||
|
- startDate
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const settings = configs.settings;
|
const settings = configs.settings;
|
||||||
|
|
@ -152,6 +159,7 @@ function convertToCSSVar(name) {
|
||||||
let cssVar = name.replace(/([A-Z])/g, "-$1").toLowerCase();
|
let cssVar = name.replace(/([A-Z])/g, "-$1").toLowerCase();
|
||||||
return `--${cssVar}`;
|
return `--${cssVar}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a hexadecimal color value to its RGB equivalent.
|
* Converts a hexadecimal color value to its RGB equivalent.
|
||||||
*
|
*
|
||||||
|
|
@ -189,18 +197,60 @@ function hexToRgb(hex) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current month and year.
|
* adds a count to user for 'taskmaster'
|
||||||
*
|
*
|
||||||
* @returns {Object} An object containing the current month as a number and the current year as a number.
|
* @param {string} username
|
||||||
*/
|
*/
|
||||||
function getMonthYear() {
|
async function addCountToTaskMasterUser(username, count = 1) {
|
||||||
let date = new Date();
|
const taskmaster = (await DBHandler.get("taskmaster")) || {
|
||||||
let month = date.toLocaleString("default", { month: "numeric" });
|
users: {},
|
||||||
let year = date.getFullYear();
|
startDate: new Date(),
|
||||||
return {
|
totalCompleteCount: 0,
|
||||||
month: month,
|
|
||||||
year: year,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (!taskmaster.users[username.toLowerCase()]) {
|
||||||
|
taskmaster.users[username.toLowerCase()] = {
|
||||||
|
completeCount: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
taskmaster.users[username.toLowerCase()].completeCount += count;
|
||||||
|
|
||||||
|
await DBHandler.set("taskmaster", taskmaster);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets the count of a user from 'taskmaster'
|
||||||
|
*
|
||||||
|
* @param {string} username
|
||||||
|
* @returns {number} the count of the user
|
||||||
|
*/
|
||||||
|
async function getUserTaskMasterCount(username) {
|
||||||
|
const taskmaster = await DBHandler.get("taskmaster");
|
||||||
|
|
||||||
|
if (!taskmaster.users[username.toLowerCase()]) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return taskmaster.users[username.toLowerCase()].completeCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getTaskMasterChampion() {
|
||||||
|
const taskmaster = await DBHandler.get("taskmaster");
|
||||||
|
|
||||||
|
let champion = {
|
||||||
|
username: "",
|
||||||
|
count: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const user in taskmaster.users) {
|
||||||
|
if (taskmaster.users[user].completeCount > champion.count) {
|
||||||
|
champion.username = user;
|
||||||
|
champion.count = taskmaster.users[user].completeCount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return champion;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -410,6 +460,9 @@ async function addDoneCount(username, value) {
|
||||||
counts.users[username.toLowerCase()].points +=
|
counts.users[username.toLowerCase()].points +=
|
||||||
value * settings.pointsPerTask;
|
value * settings.pointsPerTask;
|
||||||
|
|
||||||
|
// add to taskmaster
|
||||||
|
addCountToTaskMasterUser(username, value);
|
||||||
|
|
||||||
await DBHandler.set("counts", counts);
|
await DBHandler.set("counts", counts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,10 @@
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background: gray;
|
||||||
|
}
|
||||||
|
|
||||||
#main-container {
|
#main-container {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue