added reply function

This commit is contained in:
liyunze 2025-01-12 21:29:37 +08:00
parent 9a1ed5c8a4
commit cae6b501dd
6 changed files with 112 additions and 106 deletions

View file

@ -2,6 +2,7 @@ const configs = (function () {
"use strict"; "use strict";
const settings = { const settings = {
replyInChat: true, // true or false
enableLimit: false, // true or false enableLimit: false, // true or false
limit: 10, // integer limit: 10, // integer
automaticDoneIndex: false, // true or false - Automatically assume first unfinished task is complete automaticDoneIndex: false, // true or false - Automatically assume first unfinished task is complete
@ -16,7 +17,7 @@ const configs = (function () {
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: true, // true or false enableTaskMaster: true, // true or false
hideWhenNoTasks: true, // true or false hideWhenNoTasks: false, // true or false
taskCharacterLimit: 15, // integer taskCharacterLimit: 15, // integer
taskCharacterLimitEnabled: false, // true or false taskCharacterLimitEnabled: false, // true or false
}; };

View file

@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="http://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js"></script>
<script src="https://cdn.jsdelivr.net/npm/comfy.js@latest/dist/comfy.min.js"></script> <script src="./lib/comfy.min.js"></script>
<script src="./auth.js"></script> <script src="./auth.js"></script>
<script src="./configs.js"></script> <script src="./configs.js"></script>

1
lib/comfy.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -2,6 +2,7 @@ const defaultConfigs = (function () {
"use strict"; "use strict";
const settings = { const settings = {
replyInChat: true, // true or false
enableLimit: false, // true or false enableLimit: false, // true or false
limit: 10, // integer limit: 10, // integer
automaticDoneIndex: false, // true or false - Automatically assume first unfinished task is complete automaticDoneIndex: false, // true or false - Automatically assume first unfinished task is complete
@ -16,7 +17,7 @@ const defaultConfigs = (function () {
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: true, // true or false enableTaskMaster: true, // true or false
hideWhenNoTasks: true, // true or false hideWhenNoTasks: false, // true or false
taskCharacterLimit: 15, // integer taskCharacterLimit: 15, // integer
taskCharacterLimitEnabled: false, // true or false taskCharacterLimitEnabled: false, // true or false
}; };

View file

@ -1,14 +1,17 @@
let params = {}; let params = {};
function respond(template, params) { function respond(template, params, parentId = null) {
Object.keys(params).forEach((key) => { if (getSetting("replyInChat")) {
console.log(`{${key}}: ${params[key]}`); Object.keys(params).forEach((key) => {
template = template.replaceAll(`{${key}}`, params[key]); console.log(`{${key}}: ${params[key]}`);
}); template = template.replaceAll(`{${key}}`, params[key]);
});
console.log(template); if (!parentId) {
ComfyJS.Say(template);
ComfyJS.Say(template); } else {
ComfyJS.Reply(parentId, template);
}
}
} }
function isMod(flags) { function isMod(flags) {

View file

@ -15,7 +15,7 @@ async function processCommand(user, command, message, flags, extra) {
if (addRequest.status !== 200) { if (addRequest.status !== 200) {
params.task = `${openQuote}${message}${closeQuote}`; params.task = `${openQuote}${message}${closeQuote}`;
respond(addRequest.body.error, params); respond(addRequest.body.error, params, extra.id);
return; return;
} }
@ -26,12 +26,12 @@ async function processCommand(user, command, message, flags, extra) {
addedResponse += ` | Failed to add task(s): "${addRequest.body.tasksFailedToAdd}"`; addedResponse += ` | Failed to add task(s): "${addRequest.body.tasksFailedToAdd}"`;
} }
await respond(addedResponse, params); await respond(addedResponse, params, extra.id);
} else if (getCommand("editTaskCommands").includes(command)) { } else if (getCommand("editTaskCommands").includes(command)) {
let editRequest = await editTask(user, message); let editRequest = await editTask(user, message);
if (editRequest.status !== 200) { if (editRequest.status !== 200) {
respond(editRequest.body.error, params); respond(editRequest.body.error, params, extra.id);
return; return;
} }
@ -41,12 +41,12 @@ async function processCommand(user, command, message, flags, extra) {
params.task = `${openQuote}${newTask}${closeQuote}`; params.task = `${openQuote}${newTask}${closeQuote}`;
params.originalTask = `${openQuote}${originalTask}${closeQuote}`; params.originalTask = `${openQuote}${originalTask}${closeQuote}`;
respond(getResponse("taskEdited"), params); respond(getResponse("taskEdited"), params, extra.id);
} else if (getCommand("deleteTaskCommands").includes(command)) { } else if (getCommand("deleteTaskCommands").includes(command)) {
let removeRequest = await removeTask(user, message); let removeRequest = await removeTask(user, message);
if (removeRequest.status !== 200) { if (removeRequest.status !== 200) {
respond(removeRequest.body.error, params); respond(removeRequest.body.error, params, extra.id);
return; return;
} }
let deletedResponse = getResponse("taskDeleted"); let deletedResponse = getResponse("taskDeleted");
@ -60,13 +60,13 @@ async function processCommand(user, command, message, flags, extra) {
deletedResponse += ` | Failed to delete task(s): ${openQuote}${failedTasks}${closeQuote}`; deletedResponse += ` | Failed to delete task(s): ${openQuote}${failedTasks}${closeQuote}`;
} }
respond(deletedResponse, params); respond(deletedResponse, params, extra.id);
} else if (getCommand("finishTaskCommands").includes(command)) { } else if (getCommand("finishTaskCommands").includes(command)) {
if (message === "all") { if (message === "all") {
let finishAllRequest = await markAllTasksAsDone(user); let finishAllRequest = await markAllTasksAsDone(user);
if (finishAllRequest.status !== 200) { if (finishAllRequest.status !== 200) {
respond(finishAllRequest.body.error, params); respond(finishAllRequest.body.error, params, extra.id);
return; return;
} }
@ -82,14 +82,14 @@ async function processCommand(user, command, message, flags, extra) {
getSetting("taskName") getSetting("taskName")
); );
respond(finishedAllResponse, params); respond(finishedAllResponse, params, extra.id);
return; return;
} }
let finishRequest = await markTaskDone(user, message); let finishRequest = await markTaskDone(user, message);
if (finishRequest.status !== 200) { if (finishRequest.status !== 200) {
respond(finishRequest.body.error, params); respond(finishRequest.body.error, params, extra.id);
return; return;
} }
@ -113,12 +113,12 @@ async function processCommand(user, command, message, flags, extra) {
getSetting("taskName") getSetting("taskName")
); );
respond(finishedResponse, params); respond(finishedResponse, params, extra.id);
} else if (getCommand("unfinishTaskCommands").includes(command)) { } else if (getCommand("unfinishTaskCommands").includes(command)) {
let unfinishRequest = await markTaskUndone(user, message); let unfinishRequest = await markTaskUndone(user, message);
if (unfinishRequest.status !== 200) { if (unfinishRequest.status !== 200) {
respond(unfinishRequest.body.error, params); respond(unfinishRequest.body.error, params, extra.id);
return; return;
} }
@ -131,13 +131,13 @@ async function processCommand(user, command, message, flags, extra) {
unfinishedResponse += ` | Failed to unfinish task(s): "${unfinishRequest.body.failedTasks}"`; unfinishedResponse += ` | Failed to unfinish task(s): "${unfinishRequest.body.failedTasks}"`;
} }
respond(unfinishedResponse, params); respond(unfinishedResponse, params, extra.id);
} else if (getCommand("nextTaskCommands").includes(command)) { } else if (getCommand("nextTaskCommands").includes(command)) {
let nextRequest = await nextTask(user, message); let nextRequest = await nextTask(user, message);
if (nextRequest.status !== 200) { if (nextRequest.status !== 200) {
params.task = `${openQuote}${nextRequest.body.task}${closeQuote}`; params.task = `${openQuote}${nextRequest.body.task}${closeQuote}`;
await respond(nextRequest.body.error, params); await respond(nextRequest.body.error, params, extra.id);
return; return;
} }
@ -147,12 +147,12 @@ async function processCommand(user, command, message, flags, extra) {
params.oldTask = `${openQuote}${nextRequest.body.oldTask}${closeQuote}`; params.oldTask = `${openQuote}${nextRequest.body.oldTask}${closeQuote}`;
params.newTask = `${openQuote}${nextRequest.body.newTask}${closeQuote}`; params.newTask = `${openQuote}${nextRequest.body.newTask}${closeQuote}`;
respond(nextResponse, params); respond(nextResponse, params, extra.id);
} else if (getCommand("logTaskCommands").includes(command)) { } else if (getCommand("logTaskCommands").includes(command)) {
let logRequest = await logTask(user, extra.userColor, message); let logRequest = await logTask(user, extra.userColor, message);
if (logRequest.status !== 200) { if (logRequest.status !== 200) {
respond(logRequest.body.error, params); respond(logRequest.body.error, params, extra.id);
return; return;
} }
@ -165,7 +165,7 @@ async function processCommand(user, command, message, flags, extra) {
loggedResponse += ` | Failed to log task(s): ${openQuote}${logRequest.body.tasksFailedToLog}${closeQuote}`; loggedResponse += ` | Failed to log task(s): ${openQuote}${logRequest.body.tasksFailedToLog}${closeQuote}`;
} }
await respond(loggedResponse, params); await respond(loggedResponse, params, extra.id);
} else if ( } else if (
getCommand("focusTaskCommands").includes(command) || getCommand("focusTaskCommands").includes(command) ||
getCommand("nowTaskCommands").includes(command) getCommand("nowTaskCommands").includes(command)
@ -173,7 +173,7 @@ async function processCommand(user, command, message, flags, extra) {
let focusRequest = await focusTask(user, extra.userColor, message); let focusRequest = await focusTask(user, extra.userColor, message);
if (focusRequest.status !== 200) { if (focusRequest.status !== 200) {
respond(focusRequest.body.error, params); respond(focusRequest.body.error, params, extra.id);
return; return;
} }
@ -182,12 +182,12 @@ async function processCommand(user, command, message, flags, extra) {
params.task = `${openQuote}${focusRequest.body.focusedTask}${closeQuote}`; params.task = `${openQuote}${focusRequest.body.focusedTask}${closeQuote}`;
respond(focusedResponse, params); respond(focusedResponse, params, extra.id);
} else if (getCommand("focusedTaskCommands").includes(command)) { } else if (getCommand("focusedTaskCommands").includes(command)) {
let focusedRequest = await focusedTask(user); let focusedRequest = await focusedTask(user);
if (focusedRequest.status !== 200) { if (focusedRequest.status !== 200) {
respond(focusedRequest.body.error, params); respond(focusedRequest.body.error, params, extra.id);
return; return;
} }
@ -196,19 +196,19 @@ async function processCommand(user, command, message, flags, extra) {
params.task = `${openQuote}${focusedRequest.body.focusedTask}${closeQuote}`; params.task = `${openQuote}${focusedRequest.body.focusedTask}${closeQuote}`;
await respond(focusedResponse, params); await respond(focusedResponse, params, extra.id);
} else if (getCommand("unfocusTaskCommands").includes(command)) { } else if (getCommand("unfocusTaskCommands").includes(command)) {
let unfocusRequest = await unfocusTask(user); let unfocusRequest = await unfocusTask(user);
if (unfocusRequest.status !== 200) { if (unfocusRequest.status !== 200) {
respond(unfocusRequest.body.error, params); respond(unfocusRequest.body.error, params, extra.id);
return; return;
} }
// task unfocused // task unfocused
let unfocusedResponse = getResponse("clearFocused"); let unfocusedResponse = getResponse("clearFocused");
respond(unfocusedResponse, params); respond(unfocusedResponse, params, extra.id);
} else if ( } else if (
getCommand("checkCommands").includes(command) || getCommand("checkCommands").includes(command) ||
getCommand("checkCompletedCommands").includes(command) getCommand("checkCompletedCommands").includes(command)
@ -219,7 +219,7 @@ async function processCommand(user, command, message, flags, extra) {
let checkRequest = await checkTasks(user, completed); let checkRequest = await checkTasks(user, completed);
if (checkRequest.status !== 200) { if (checkRequest.status !== 200) {
// no tasks // no tasks
respond(checkRequest.body.error, params); respond(checkRequest.body.error, params, extra.id);
return; return;
} }
@ -236,14 +236,14 @@ async function processCommand(user, command, message, flags, extra) {
var checkingUser = user; var checkingUser = user;
params.checkingUser = checkingUser; params.checkingUser = checkingUser;
await respond(`{tasks}`, params); await respond(`{tasks}`, params, extra.id);
await sleep(200); await sleep(200);
} }
} else { } else {
let mentioned = message.replace("@", ""); let mentioned = message.replace("@", "");
if (mentioned.toLowerCase() === "id") { if (mentioned.toLowerCase() === "id") {
await respond(getResponse("noTaskA"), params); await respond(getResponse("noTaskA"), params, extra.id);
return; return;
} }
@ -254,7 +254,7 @@ async function processCommand(user, command, message, flags, extra) {
if (checkRequest.status !== 200) { if (checkRequest.status !== 200) {
// no tasks // no tasks
respond(getResponse("noTaskA"), params); respond(getResponse("noTaskA"), params, extra.id);
return; return;
} }
@ -270,19 +270,19 @@ async function processCommand(user, command, message, flags, extra) {
params.checkingUser = checkingUser; params.checkingUser = checkingUser;
await respond(`{checkingUser} {tasks}`, params); await respond(`{checkingUser} {tasks}`, params, extra.id);
await sleep(200); await sleep(200);
} }
} }
} else if (getCommand("adminDeleteCommands").includes(command)) { } else if (getCommand("adminDeleteCommands").includes(command)) {
if (!isMod(flags)) { if (!isMod(flags)) {
respond(getResponse("notMod"), params); respond(getResponse("notMod"), params, extra.id);
return; return;
} }
let mentioned = message.replace("@", ""); let mentioned = message.replace("@", "");
if (mentioned === "") { if (mentioned === "") {
respond(getResponse("specifyUser"), params); respond(getResponse("specifyUser"), params, extra.id);
return; return;
} }
@ -292,58 +292,58 @@ async function processCommand(user, command, message, flags, extra) {
if (clearUserTaskResponse.status === 0) { if (clearUserTaskResponse.status === 0) {
// no tasks // no tasks
respond(getResponse("noTaskA"), params); respond(getResponse("noTaskA"), params, extra.id);
return; return;
} }
respond(getResponse("adminDeleteTasks"), params); respond(getResponse("adminDeleteTasks"), params, extra.id);
return; return;
} else if (getCommand("adminClearDoneCommands").includes(command)) { } else if (getCommand("adminClearDoneCommands").includes(command)) {
if (!isStreamer(flags)) { if (!isStreamer(flags)) {
respond(getResponse("notStreamer"), params); respond(getResponse("notStreamer"), params, extra.id);
return; return;
} }
await clearAllDoneTasks(); await clearAllDoneTasks();
respond(getResponse("clearedDone"), params); respond(getResponse("clearedDone"), params, extra.id);
return; return;
} else if (getCommand("adminClearAllCommands").includes(command)) { } else if (getCommand("adminClearAllCommands").includes(command)) {
if (!isStreamer(flags)) { if (!isStreamer(flags)) {
respond(getResponse("notStreamer"), params); respond(getResponse("notStreamer"), params, extra.id);
return; return;
} }
await clearAll(); await clearAll();
respond(getResponse("clearedAll"), params); respond(getResponse("clearedAll"), params, extra.id);
return; return;
} else if (getCommand("clearMyDoneCommands").includes(command)) { } else if (getCommand("clearMyDoneCommands").includes(command)) {
let clearOwnDoneResponse = await clearOwnDoneTasks(user); let clearOwnDoneResponse = await clearOwnDoneTasks(user);
if (clearOwnDoneResponse.status !== 200) { if (clearOwnDoneResponse.status !== 200) {
// no tasks // no tasks
respond(getResponse("noTask"), params); respond(getResponse("noTask"), params, extra.id);
return; return;
} }
respond(getResponse("clearedMyDone"), params); respond(getResponse("clearedMyDone"), params, extra.id);
} else if (getCommand("adminClearNotStreamerCommands").includes(command)) { } else if (getCommand("adminClearNotStreamerCommands").includes(command)) {
if (!isStreamer(flags)) { if (!isStreamer(flags)) {
respond(getResponse("notStreamer"), params); respond(getResponse("notStreamer"), params, extra.id);
return; return;
} }
await clearMemory(); await clearMemory();
await clearAllExceptStreamer(auth.channel); await clearAllExceptStreamer(auth.channel);
respond(getResponse("clearTasksExceptBroadcaster"), params); respond(getResponse("clearTasksExceptBroadcaster"), params, extra.id);
} else if (getCommand("adminClearTasksCommands").includes(command)) { } else if (getCommand("adminClearTasksCommands").includes(command)) {
if (!isStreamer(flags)) { if (!isStreamer(flags)) {
respond(getResponse("notStreamer"), params); respond(getResponse("notStreamer"), params, extra.id);
return; return;
} }
await clearMemory(); await clearMemory();
await clearAllTasks(); await clearAllTasks();
respond(getResponse("clearedTasks"), params); respond(getResponse("clearedTasks"), params, extra.id);
} else if (getCommand("listCommands").includes(command)) { } else if (getCommand("listCommands").includes(command)) {
const interval = 100; const interval = 100;
if (message === "") { if (message === "") {
@ -351,13 +351,13 @@ async function processCommand(user, command, message, flags, extra) {
if (listTaskResponse.status !== 200) { if (listTaskResponse.status !== 200) {
// no tasks // no tasks
respond(listTaskResponse.body.error, params); respond(listTaskResponse.body.error, params, extra.id);
return; return;
} }
for (reply of listTaskResponse.body.replies) { for (reply of listTaskResponse.body.replies) {
params.tasks = reply; params.tasks = reply;
await respond("{tasks}", params); await respond("{tasks}", params, extra.id);
await sleep(interval); await sleep(interval);
} }
} else { } else {
@ -388,7 +388,7 @@ async function processCommand(user, command, message, flags, extra) {
} }
if (mentioned.toLowerCase() === "id") { if (mentioned.toLowerCase() === "id") {
await respond(getResponse("noTaskA"), params); await respond(getResponse("noTaskA"), params, extra.id);
return; return;
} }
@ -396,16 +396,16 @@ async function processCommand(user, command, message, flags, extra) {
if (listTaskResponse.status !== 200 && anotherUser) { if (listTaskResponse.status !== 200 && anotherUser) {
// no tasks // no tasks
respond(getResponse("noTaskA"), params); respond(getResponse("noTaskA"), params, extra.id);
return; return;
} else if (listTaskResponse.status !== 200 && !anotherUser) { } else if (listTaskResponse.status !== 200 && !anotherUser) {
respond(getResponse("noTask"), params); respond(getResponse("noTask"), params, extra.id);
return; return;
} }
for (reply of listTaskResponse.body.replies) { for (reply of listTaskResponse.body.replies) {
params.tasks = reply; params.tasks = reply;
await respond("{tasks}", params); await respond("{tasks}", params, extra.id);
await sleep(interval); await sleep(interval);
} }
} }
@ -415,7 +415,7 @@ async function processCommand(user, command, message, flags, extra) {
params.doneCount = count; params.doneCount = count;
return respond(getResponse("checkYourCount"), params); return respond(getResponse("checkYourCount"), params, extra.id);
} else { } else {
let mentioned = message.replace("@", ""); let mentioned = message.replace("@", "");
let count = await completedTasksCount(mentioned); let count = await completedTasksCount(mentioned);
@ -423,26 +423,26 @@ async function processCommand(user, command, message, flags, extra) {
params.doneCount = count; params.doneCount = count;
params.mentioned = mentioned; params.mentioned = mentioned;
return respond(getResponse("checkUserCount"), params); return respond(getResponse("checkUserCount"), params, extra.id);
} }
} else if (getCommand("checkAllCountCommands").includes(command)) { } else if (getCommand("checkAllCountCommands").includes(command)) {
let count = await getBoardTotalTaskCount(); let count = await getBoardTotalTaskCount();
if (count === 0) { if (count === 0) {
respond(getResponse("noCountAll"), params); respond(getResponse("noCountAll"), params, extra.id);
return; return;
} }
params.doneCount = count; params.doneCount = count;
respond(getResponse("checkAllCount"), params); respond(getResponse("checkAllCount"), params, extra.id);
} else if (getCommand("checkMyPointsCommands").includes(command)) { } else if (getCommand("checkMyPointsCommands").includes(command)) {
if (message === "") { if (message === "") {
let points = await getUserPoints(user); let points = await getUserPoints(user);
params.pointCount = points; params.pointCount = points;
return respond(getResponse("checkMyPoints"), params); return respond(getResponse("checkMyPoints"), params, extra.id);
} else { } else {
let mentioned = message.replace("@", ""); let mentioned = message.replace("@", "");
let points = await getUserPoints(mentioned); let points = await getUserPoints(mentioned);
@ -450,40 +450,40 @@ async function processCommand(user, command, message, flags, extra) {
params.pointCount = points; params.pointCount = points;
params.mentioned = mentioned; params.mentioned = mentioned;
return respond(getResponse("checkUserPoints"), params); return respond(getResponse("checkUserPoints"), params, extra.id);
} }
} else if (getCommand("syncCountPointsCommands").includes(command)) { } else if (getCommand("syncCountPointsCommands").includes(command)) {
if (!isStreamer(flags)) { if (!isStreamer(flags)) {
respond(getResponse("notStreamer"), params); respond(getResponse("notStreamer"), params, extra.id);
return; return;
} }
await syncPointsToCount(); await syncPointsToCount();
respond(getResponse("syncCountPoints"), params); respond(getResponse("syncCountPoints"), params, extra.id);
} else if (getCommand("addPointsCommands").includes(command)) { } else if (getCommand("addPointsCommands").includes(command)) {
// !addpoints @user 100 // !addpoints @user 100
if (!isMod(flags)) { if (!isMod(flags)) {
respond(getResponse("notMod"), params); respond(getResponse("notMod"), params, extra.id);
return; return;
} }
let mentioned = message.split(" ")[0].replace("@", ""); let mentioned = message.split(" ")[0].replace("@", "");
if (mentioned === "") { if (mentioned === "") {
respond(getResponse("specifyUser"), params); respond(getResponse("specifyUser"), params, extra.id);
return; return;
} }
let points = message.split(" ")[1]; let points = message.split(" ")[1];
if (points === undefined) { if (points === undefined) {
respond(getResponse("specifyPoints"), params); respond(getResponse("specifyPoints"), params, extra.id);
return; return;
} }
if (!/^\d+$/.test(points)) { if (!/^\d+$/.test(points)) {
respond(getResponse("invalidNumber"), params); respond(getResponse("invalidNumber"), params, extra.id);
return; return;
} }
@ -494,29 +494,29 @@ async function processCommand(user, command, message, flags, extra) {
params.mentioned = mentioned; params.mentioned = mentioned;
params.pointCount = points; params.pointCount = points;
respond(getResponse("addPoints"), params); respond(getResponse("addPoints"), params, extra.id);
} else if (getCommand("reducePointsCommands").includes(command)) { } else if (getCommand("reducePointsCommands").includes(command)) {
if (!isMod(flags)) { if (!isMod(flags)) {
respond(getResponse("notMod"), params); respond(getResponse("notMod"), params, extra.id);
return; return;
} }
let mentioned = message.split(" ")[0].replace("@", ""); let mentioned = message.split(" ")[0].replace("@", "");
if (mentioned === "") { if (mentioned === "") {
respond(getResponse("specifyUser"), params); respond(getResponse("specifyUser"), params, extra.id);
return; return;
} }
let points = message.split(" ")[1]; let points = message.split(" ")[1];
if (points == undefined) { if (points == undefined) {
respond(getResponse("specifyPoints"), params); respond(getResponse("specifyPoints"), params, extra.id);
return; return;
} }
if (!/^\d+$/.test(points)) { if (!/^\d+$/.test(points)) {
respond(getResponse("invalidNumber"), params); respond(getResponse("invalidNumber"), params, extra.id);
return; return;
} }
@ -525,29 +525,29 @@ async function processCommand(user, command, message, flags, extra) {
params.mentioned = mentioned; params.mentioned = mentioned;
params.pointCount = points; params.pointCount = points;
respond(getResponse("reducePoints"), params); respond(getResponse("reducePoints"), params, extra.id);
} else if (getCommand("setUserPointsCommands").includes(command)) { } else if (getCommand("setUserPointsCommands").includes(command)) {
if (!isMod(flags)) { if (!isMod(flags)) {
respond(getResponse("notMod"), params); respond(getResponse("notMod"), params, extra.id);
return; return;
} }
let mentioned = message.split(" ")[0].replace("@", ""); let mentioned = message.split(" ")[0].replace("@", "");
if (mentioned === "") { if (mentioned === "") {
respond(getResponse("specifyUser"), params); respond(getResponse("specifyUser"), params, extra.id);
return; return;
} }
let points = message.split(" ")[1]; let points = message.split(" ")[1];
if (points === undefined) { if (points === undefined) {
respond(getResponse("specifyPoints"), params); respond(getResponse("specifyPoints"), params, extra.id);
return; return;
} }
if (!/^\d+$/.test(points)) { if (!/^\d+$/.test(points)) {
respond(getResponse("invalidNumber"), params); respond(getResponse("invalidNumber"), params, extra.id);
return; return;
} }
@ -558,63 +558,63 @@ async function processCommand(user, command, message, flags, extra) {
params.mentioned = mentioned; params.mentioned = mentioned;
params.pointCount = points; params.pointCount = points;
respond(getResponse("setUserPoints"), params); respond(getResponse("setUserPoints"), params, extra.id);
} else if (getCommand("setUserTaskCountCommands").includes(command)) { } else if (getCommand("setUserTaskCountCommands").includes(command)) {
if (!isMod(flags)) { if (!isMod(flags)) {
respond(getResponse("notMod"), params); respond(getResponse("notMod"), params, extra.id);
return; return;
} }
let mentioned = message.split(" ")[0].replace("@", ""); let mentioned = message.split(" ")[0].replace("@", "");
if (mentioned === "") { if (mentioned === "") {
respond(getResponse("specifyUser"), params); respond(getResponse("specifyUser"), params, extra.id);
return; return;
} }
let count = message.split(" ")[1]; let count = message.split(" ")[1];
if (count === undefined) { if (count === undefined) {
respond(getResponse("specifyCount"), params); respond(getResponse("specifyCount"), params, extra.id);
return; return;
} }
if (!/^\d+$/.test(count)) { if (!/^\d+$/.test(count)) {
respond(getResponse("invalidNumber"), params); respond(getResponse("invalidNumber"), params, extra.id);
return; return;
} }
let setUserTaskCountResponse = await setUserTaskCount(mentioned, count); let setUserTaskCountResponse = await setUserTaskCount(mentioned, count);
if (setUserTaskCountResponse.status !== 200) { if (setUserTaskCountResponse.status !== 200) {
respond(setUserTaskCountResponse.body.message, params); respond(setUserTaskCountResponse.body.message, params, extra.id);
return; return;
} }
params.mentioned = mentioned; params.mentioned = mentioned;
params.taskCount = count; params.taskCount = count;
respond(setUserTaskCountResponse.body.message, params); respond(setUserTaskCountResponse.body.message, params, extra.id);
} else if (getCommand("leaderboardCommands").includes(command)) { } else if (getCommand("leaderboardCommands").includes(command)) {
let leaderboardResponse = await leaderboardTaskCount(5); let leaderboardResponse = await leaderboardTaskCount(5);
if (leaderboardResponse.status !== 200) { if (leaderboardResponse.status !== 200) {
respond(leaderboardResponse.body.error, params); respond(leaderboardResponse.body.error, params, extra.id);
return; return;
} }
let leaderboard = leaderboardResponse.body.leaderboard; let leaderboard = leaderboardResponse.body.leaderboard;
await respond(leaderboard, params); await respond(leaderboard, params, extra.id);
} else if (getCommand("adminSetBoardCountCommands").includes(command)) { } else if (getCommand("adminSetBoardCountCommands").includes(command)) {
if (!isStreamer(flags)) { if (!isStreamer(flags)) {
respond(getResponse("notStreamer"), params); respond(getResponse("notStreamer"), params, extra.id);
return; return;
} }
// check if message is a number using regex // check if message is a number using regex
if (!/^\d+$/.test(message)) { if (!/^\d+$/.test(message)) {
respond(getResponse("invalidNumber"), params); respond(getResponse("invalidNumber"), params, extra.id);
return; return;
} }
@ -622,23 +622,23 @@ async function processCommand(user, command, message, flags, extra) {
await setTotalCompleteCount(message); await setTotalCompleteCount(message);
respond(getResponse("setBoardCount"), params); respond(getResponse("setBoardCount"), params, extra.id);
} else if (getCommand("adminResetBoardCountCommands").includes(command)) { } else if (getCommand("adminResetBoardCountCommands").includes(command)) {
if (!isStreamer(flags)) { if (!isStreamer(flags)) {
respond(getResponse("notStreamer"), params); respond(getResponse("notStreamer"), params, extra.id);
return; return;
} }
await resetBoardCount(); await resetBoardCount();
respond(getResponse("clearedBoardCount"), params); respond(getResponse("clearedBoardCount"), params, extra.id);
} else if (getCommand("adminResetUsersCountCommands").includes(command)) { } else if (getCommand("adminResetUsersCountCommands").includes(command)) {
if (!isStreamer(flags)) { if (!isStreamer(flags)) {
respond(getResponse("notStreamer"), params); respond(getResponse("notStreamer"), params, extra.id);
return; return;
} }
await resetUsersCount(); await resetUsersCount();
respond(getResponse("clearedUsersCount"), params); respond(getResponse("clearedUsersCount"), params, extra.id);
} else if (getCommand("taskMasterCommands").includes(command)) { } else if (getCommand("taskMasterCommands").includes(command)) {
if (!getSetting("enableTaskMaster")) { if (!getSetting("enableTaskMaster")) {
return; return;
@ -647,46 +647,46 @@ async function processCommand(user, command, message, flags, extra) {
let champion = await getTaskMasterChampion(); let champion = await getTaskMasterChampion();
if (champion === null) { if (champion === null) {
respond(getResponse("noTaskMaster"), params); respond(getResponse("noTaskMaster"), params, extra.id);
return; return;
} }
params.taskMaster = champion.username; params.taskMaster = champion.username;
params.taskMasterCount = champion.count; params.taskMasterCount = champion.count;
respond(getResponse("taskMaster"), params); respond(getResponse("taskMaster"), params, extra.id);
} else if (getCommand("resetTaskMasterCommands").includes(command)) { } else if (getCommand("resetTaskMasterCommands").includes(command)) {
if (!getSetting("enableTaskMaster")) { if (!getSetting("enableTaskMaster")) {
return; return;
} }
if (!isStreamer(flags)) { if (!isStreamer(flags)) {
respond(getResponse("notStreamer"), params); respond(getResponse("notStreamer"), params, extra.id);
return; return;
} }
await resetTaskMaster(); await resetTaskMaster();
respond(getResponse("resetTaskMaster"), params); respond(getResponse("resetTaskMaster"), params, extra.id);
} else if (getCommand("helpCommands").includes(command)) { } else if (getCommand("helpCommands").includes(command)) {
respond(getResponse("help"), params); respond(getResponse("help"), params, extra.id);
} else if (command === "!clearlocalstorage") { } else if (command === "!clearlocalstorage") {
if (!isStreamer(flags)) { if (!isStreamer(flags)) {
respond(getResponse("notStreamer"), params); respond(getResponse("notStreamer"), params, extra.id);
return; return;
} }
clearLocalStorage(); clearLocalStorage();
respond(getResponse("clearLocalStorage"), params); respond(getResponse("clearLocalStorage"), params, extra.id);
} else if (["!transferdata"].includes(command)) { } else if (["!transferdata"].includes(command)) {
if (!isStreamer(flags)) { if (!isStreamer(flags)) {
respond(getResponse("notStreamer"), params); respond(getResponse("notStreamer"), params, extra.id);
return; return;
} }
await transferLocalStorageToIndexedDB(); await transferLocalStorageToIndexedDB();
} else if (commands.additionalCommands[command]) { } else if (commands.additionalCommands[command]) {
respond(commands.additionalCommands[command], params); respond(commands.additionalCommands[command], params, extra.id);
} else { } else {
// command not found // command not found
} }