Skip to content

Commit

Permalink
fix: Fix bot not auto-reducing comment amount on missing friends & ac…
Browse files Browse the repository at this point in the history
…ceptFriendRequests false when 'all' was requested
  • Loading branch information
3urobeat committed Feb 11, 2025
1 parent 88d9fd0 commit 29f2fe1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
34 changes: 20 additions & 14 deletions src/commands/core/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 2021-07-09 16:26:00
* Author: 3urobeat
*
* Last Modified: 2025-01-29 22:08:31
* Last Modified: 2025-02-11 18:35:46
* Modified By: 3urobeat
*
* Copyright (c) 2021 - 2025 3urobeat <https://github.com/3urobeat>
Expand Down Expand Up @@ -85,7 +85,7 @@ module.exports.comment = {


/* --------- Calculate maxRequestAmount and get arguments from comment request --------- */
const { maxRequestAmount, numberOfComments, profileID, idType, quotesArr } = await getCommentArgs(commandHandler, args, resInfo, respond);
let { maxRequestAmount, numberOfComments, userRequestedMax, profileID, idType, quotesArr } = await getCommentArgs(commandHandler, args, resInfo, respond); // eslint-disable-line prefer-const

if (!maxRequestAmount && !numberOfComments && !quotesArr) return; // Looks like the helper aborted the request

Expand Down Expand Up @@ -140,22 +140,28 @@ module.exports.comment = {
respondModule(context, { charLimit: 500, cutChars: ["\n"], ...resInfo }, addStr); // Manually limit part length to 500 chars as addStr can cause many messages and only allow cuts at newlines to prevent links from getting embedded
return;
} else {
// TODO: This could become obsolete (or need rethinking) when comment mode 2 is implemented
let commentcmdUsage;
const maxReducedAccsRequestAmount = Math.trunc((availableAccounts.length - accsToAdd.length) * (maxRequestAmount / commandHandler.controller.getBots().length));

if (owners.includes(requesterID)) {
if (availableAccounts.length - accsToAdd.length > 1) commentcmdUsage = await commandHandler.data.getLang("commentcmdusageowner", { "cmdprefix": resInfo.cmdprefix }, requesterID);
else commentcmdUsage = await commandHandler.data.getLang("commentcmdusageowner2", { "cmdprefix": resInfo.cmdprefix }, requesterID);
if (userRequestedMax && maxReducedAccsRequestAmount > 0) {
logger("info", `Reduced comment amount from ${numberOfComments} to ${maxReducedAccsRequestAmount} because user requested 'all' but hasn't added enough accounts and 'acceptFriendRequests' is disabled.`);
numberOfComments = maxReducedAccsRequestAmount;
} else {
if (availableAccounts.length - accsToAdd.length > 1) commentcmdUsage = await commandHandler.data.getLang("commentcmdusage", { "cmdprefix": resInfo.cmdprefix }, requesterID);
else commentcmdUsage = await commandHandler.data.getLang("commentcmdusage2", { "cmdprefix": resInfo.cmdprefix }, requesterID);
}
// TODO: This could become obsolete (or need rethinking) when comment mode 2 is implemented
let commentcmdUsage;

logger("warn", "Found enough available accounts which the user would need to add first but 'acceptFriendRequests' is disabled in 'advancedconfig.json'! Sending 'request less' message instead...");
if (owners.includes(requesterID)) {
if (availableAccounts.length - accsToAdd.length > 1) commentcmdUsage = await commandHandler.data.getLang("commentcmdusageowner", { "cmdprefix": resInfo.cmdprefix }, requesterID);
else commentcmdUsage = await commandHandler.data.getLang("commentcmdusageowner2", { "cmdprefix": resInfo.cmdprefix }, requesterID);
} else {
if (availableAccounts.length - accsToAdd.length > 1) commentcmdUsage = await commandHandler.data.getLang("commentcmdusage", { "cmdprefix": resInfo.cmdprefix }, requesterID);
else commentcmdUsage = await commandHandler.data.getLang("commentcmdusage2", { "cmdprefix": resInfo.cmdprefix }, requesterID);
}

const maxReducedAccsRequestAmount = Math.trunc((availableAccounts.length - accsToAdd.length) * (maxRequestAmount / commandHandler.controller.getBots().length));
respond(await commandHandler.data.getLang("requesttoohigh", { "maxRequestAmount": maxReducedAccsRequestAmount, "cmdusage": commentcmdUsage }, requesterID));
return;
logger("warn", "Found enough available accounts which the user would need to add first but 'acceptFriendRequests' is disabled in 'advancedconfig.json'! Sending 'request less' message instead...");

respond(await commandHandler.data.getLang("requesttoohigh", { "maxRequestAmount": maxReducedAccsRequestAmount, "cmdusage": commentcmdUsage }, requesterID));
return;
}
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/commands/helpers/getCommentArgs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 2022-02-28 11:55:06
* Author: 3urobeat
*
* Last Modified: 2025-01-12 18:26:16
* Last Modified: 2025-02-11 17:59:38
* Modified By: 3urobeat
*
* Copyright (c) 2022 - 2025 3urobeat <https://github.com/3urobeat>
Expand Down Expand Up @@ -58,7 +58,7 @@ function _getVisibilityStatus(commandHandler, steamID64, type, callback) {
* @param {Array} args The command arguments
* @param {CommandHandler.resInfo} resInfo Object containing additional information your respondModule might need to process the response (for example the userID who executed the command).
* @param {function(string): void} respond The shortened respondModule call
* @returns {Promise.<{ maxRequestAmount: number, commentcmdUsage: string, numberOfComments: number, profileID: string, idType: string, quotesArr: Array.<string> }>} Resolves promise with object containing all relevant data when done
* @returns {Promise.<{ maxRequestAmount: number, commentcmdUsage: string, numberOfComments: number, userRequestedMax: boolean, profileID: string, idType: string, quotesArr: Array.<string> }>} Resolves promise with object containing all relevant data when done
*/
module.exports.getCommentArgs = (commandHandler, args, resInfo, respond) => {
return new Promise((resolve) => {
Expand All @@ -68,9 +68,10 @@ module.exports.getCommentArgs = (commandHandler, args, resInfo, respond) => {
let owners = commandHandler.data.cachefile.ownerid;
if (resInfo.ownerIDs && resInfo.ownerIDs.length > 0) owners = resInfo.ownerIDs;

const requesterID = resInfo.userID;
const requesterID = resInfo.userID;
let maxRequestAmount = commandHandler.data.config.maxRequests; // Set to default value and if the requesting user is an owner it gets changed below
let numberOfComments = 0;
let userRequestedMax = false;
let quotesArr = commandHandler.data.quotes;

let profileID;
Expand All @@ -96,6 +97,7 @@ module.exports.getCommentArgs = (commandHandler, args, resInfo, respond) => {
if (isNaN(args[0])) { // Isn't a number?
if (args[0].toLowerCase() == "all" || args[0].toLowerCase() == "max") {
args[0] = maxRequestAmount; // Replace the argument with the max amount of comments this user is allowed to request
userRequestedMax = true;
} else {
logger("debug", `CommandHandler getCommentArgs(): User provided invalid request amount "${args[0]}". Stopping...`);

Expand Down Expand Up @@ -182,7 +184,7 @@ module.exports.getCommentArgs = (commandHandler, args, resInfo, respond) => {
logger("debug", `CommandHandler getCommentArgs() success. maxRequestAmount: ${maxRequestAmount} | numberOfComments: ${numberOfComments} | ID: ${profileID} | idType: ${idType} | quotesArr.length: ${quotesArr.length}`);

// Return obj if profileID is not null, otherwise return false as an error has occurred, the user was informed and execution should be stopped
if (profileID) resolve({ maxRequestAmount, numberOfComments, profileID, idType, quotesArr });
if (profileID) resolve({ maxRequestAmount, numberOfComments, userRequestedMax, profileID, idType, quotesArr });
else return resolve(false);
}
}, 250);
Expand Down
4 changes: 2 additions & 2 deletions src/data/fileStructure.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@
{
"path": "src/commands/core/comment.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/commands/core/comment.js",
"checksum": "eff99a9f8c285831de8919c7c37efbeb"
"checksum": "a2d67656e609ccefed2cf5c8c901d1fd"
},
{
"path": "src/commands/core/favorite.js",
Expand Down Expand Up @@ -233,7 +233,7 @@
{
"path": "src/commands/helpers/getCommentArgs.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/commands/helpers/getCommentArgs.js",
"checksum": "8dd0dbeca221c7ff66deb8be3b779635"
"checksum": "513e0bffaeaa854ac4f0f678f6ad3799"
},
{
"path": "src/commands/helpers/getCommentBots.js",
Expand Down

0 comments on commit 29f2fe1

Please sign in to comment.