Skip to content

Commit

Permalink
feat: Rework !addfriend to take amount as first parameter #249
Browse files Browse the repository at this point in the history
  • Loading branch information
3urobeat committed Jan 5, 2025
1 parent f8b4088 commit 982f046
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 50 deletions.
82 changes: 48 additions & 34 deletions src/commands/core/friend.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* Created Date: 2021-07-09 16:26:00
* Author: 3urobeat
*
* Last Modified: 2024-08-10 15:09:08
* Last Modified: 2025-01-05 15:21:02
* Modified By: 3urobeat
*
* Copyright (c) 2021 - 2024 3urobeat <https://github.com/3urobeat>
* Copyright (c) 2021 - 2025 3urobeat <https://github.com/3urobeat>
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Expand All @@ -22,8 +22,15 @@ const CommandHandler = require("../commandHandler.js"); // eslint-disable-line

module.exports.addFriend = {
names: ["addfriend", "add"],
description: "Adds the ID with all bot accounts. Requires unlimited accounts!",
description: "Adds the ID with amount/all available bot accounts. Requires unlimited accounts!",
args: [
{
name: "amount",
description: "The amount of accounts to request to add",
type: "string",
isOptional: false,
ownersOnly: true
},
{
name: "ID",
description: "The link, steamID64 or vanity of the profile to add",
Expand All @@ -46,43 +53,50 @@ module.exports.addFriend = {
const respond = ((txt) => respondModule(context, resInfo, txt)); // Shorten each call
const requesterID = resInfo.userID;

if (commandHandler.controller.info.readyAfter == 0) return respondModule(context, { prefix: "/me", ...resInfo }, await commandHandler.data.getLang("botnotready", null, requesterID)); // Check if bot isn't fully started yet - Pass new resInfo object which contains prefix and everything the original resInfo obj contained

if (!args[0]) return respond(await commandHandler.data.getLang("invalidprofileid", null, requesterID));

commandHandler.controller.handleSteamIdResolving(args[0], "profile", async (err, res) => {
if (err) return respond((await commandHandler.data.getLang("invalidprofileid", null, requesterID)) + "\n\nError: " + err);
// Deny request if bot is not fully started yet. Add msg prefix to existing resInfo object
if (commandHandler.controller.info.readyAfter == 0) {
respondModule(context, { prefix: "/me", ...resInfo }, await commandHandler.data.getLang("botnotready", null, requesterID));
return;
}

// Check if first bot account is limited to be able to display error message instantly
if (commandHandler.controller.main.user.limitations && commandHandler.controller.main.user.limitations.limited == true) {
respond(await commandHandler.data.getLang("addfriendcmdacclimited", { "profileid": res }, requesterID));
// Process !number amount parameter, set to max if "all", otherwise deny
if (isNaN(args[0])) {
if (args[0] != undefined && (args[0].toLowerCase() == "all" || args[0].toLowerCase() == "max")) {
args[0] = Infinity;
} else {
respond(await commandHandler.data.getLang("invalidnumber", { "cmdusage": resInfo.cmdprefix + "addfriend amount id" }, requesterID));
return;
}
}

respondModule(context, { prefix: "/me", ...resInfo }, await commandHandler.data.getLang("addfriendcmdsuccess", { "profileid": res, "estimatedtime": 5 * commandHandler.controller.getBots().length }, requesterID));
logger("info", `Adding friend '${res}' with all bot accounts... This will take ~${5 * commandHandler.controller.getBots().length} seconds.`);
// Deny request if ID parameter is missing
if (!args[1]) {
respond(await commandHandler.data.getLang("invalidprofileid", null, requesterID));
return;
}

commandHandler.controller.getBots().forEach((e, i) => {
// Check if this bot account is limited
if (e.user.limitations && e.user.limitations.limited == true) {
logger("error", `[${e.logPrefix}] Can't add user '${res}' as a friend because the bot account is limited.`);
return;
}
// Resolve ID
commandHandler.controller.handleSteamIdResolving(args[1], "profile", async (err, id) => {
if (err) return respond((await commandHandler.data.getLang("invalidprofileid", null, requesterID)) + "\n\nError: " + err);

if (e.user.myFriends[res] != 3 && e.user.myFriends[res] != 1) { // Check if provided user is not friend and not blocked
setTimeout(() => {
e.user.addFriend(new SteamID(res), (err) => {
if (err) logger("error", `[${e.logPrefix}] Failed to add '${res}' as a friend: ${err}`);
else logger("info", `[${e.logPrefix}] Added '${res}' as a friend.`);
});

commandHandler.controller.friendListCapacityCheck(e, (remaining) => { // Check remaining friendlist space
if (remaining < 25) logger("warn", `[${e.logPrefix}] Friendlist space is running low! There are ${remaining} spots remaining.`);
});
}, 5000 * i);
} else {
logger("warn", `[${e.logPrefix}] This bot account is already friend with '${res}' or the account was blocked/blocked you.`);
}
// Get all bot accounts up until amount which are unlimited and not already in group
const unlimitedAccs = commandHandler.controller.filterAccounts(commandHandler.controller.filters.unlimited);
const accsToAdd = unlimitedAccs.filter((e) => e.user.myFriends[id] != 3 && e.user.myFriends[id] != 1).slice(0, args[0]); // Check if provided user is not friend and not blocked

respond(await commandHandler.data.getLang("addfriendcmdsuccess", { "profileid": id, "numberOfAdds": accsToAdd.length, "estimatedtime": 5 * accsToAdd.length }, requesterID));
logger("info", `Adding friend '${id}' with ${accsToAdd.length} bot accounts... This will take ~${5 * accsToAdd.length} seconds.`);

accsToAdd.forEach((e, i) => {
setTimeout(() => {
e.user.addFriend(new SteamID(id), (err) => {
if (err) logger("error", `[${e.logPrefix}] Failed to add '${id}' as a friend: ${err}`);
else logger("info", `[${e.logPrefix}] Added '${id}' as a friend.`);
});

commandHandler.controller.friendListCapacityCheck(e, (remaining) => { // Check remaining friendlist space
if (remaining < 25) logger("warn", `[${e.logPrefix}] Friendlist space is running low! There are ${remaining} spots remaining.`);
});
}, 5000 * i);
});
});
}
Expand Down
12 changes: 6 additions & 6 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/friend.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/commands/core/friend.js",
"checksum": "951e82328f07638dcf1f1fb1092f93fa"
"checksum": "b87cba1970db0f5f1ea5a10aabe6614a"
},
{
"path": "src/commands/core/general.js",
Expand Down Expand Up @@ -338,27 +338,27 @@
{
"path": "src/data/lang/chinese.json",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/data/lang/chinese.json",
"checksum": "71260995bfadb41f7437b82ad9fb6183"
"checksum": "711fe9acf0cbddf7c7bae534ca4c8c1f"
},
{
"path": "src/data/lang/english.json",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/data/lang/english.json",
"checksum": "aaf607fb01e691c4bec270fbfd7450b4"
"checksum": "0563cc31ab26ffb57ba3fa12f8873abb"
},
{
"path": "src/data/lang/portuguese.json",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/data/lang/portuguese.json",
"checksum": "363c2d42ab4399cfb47ea05ae4910885"
"checksum": "efad56152be204baf93c6afb8ec9005b"
},
{
"path": "src/data/lang/russian.json",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/data/lang/russian.json",
"checksum": "914390b3392e884e9971d400d51a011c"
"checksum": "970602bc3817c68ca98c69a7fe4452fb"
},
{
"path": "src/data/lang/traditional-chinese.json",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/data/lang/traditional-chinese.json",
"checksum": "a26117c7647c570ca2e122ff2acf0be7"
"checksum": "613f00285459ec035d5548ae14ff142c"
},
{
"path": "src/dataManager/dataCheck.js",
Expand Down
3 changes: 1 addition & 2 deletions src/data/lang/chinese.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@
"sessionscmdmsg": "目前有${amount}个活动会话:",
"mysessionscmdnosessions": "目前没有您启动的活动会话。",

"addfriendcmdacclimited": "无法使用bot0添加${profileid}为好友,因为机器人账户受限。",
"addfriendcmdsuccess": "正在使用所有机器人帐户添加好友${profileid}...这将花费约${estimatedtime}秒。请检查日志以查看潜在错误。",
"addfriendcmdsuccess": "Adding friend ${profileid} with ${numberOfAdds} bot accounts... This will take ~${estimatedtime} seconds. Please check the log for potential errors.",
"unfriendcmdsuccess": "我正在使用所有机器人帐户取消与您的好友关系。这将需要一些时间...\n您随时可以再次向我发送好友请求。",
"unfriendidcmdsuccess": "已从所有机器人帐户中移除好友${profileid}。",

Expand Down
3 changes: 1 addition & 2 deletions src/data/lang/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@
"sessionscmdmsg": "There are currently ${amount} active session(s):",
"mysessionscmdnosessions": "There are currently no active sessions that you have started.",

"addfriendcmdacclimited": "Can't add friend ${profileid} with bot0 because the bot account is limited.",
"addfriendcmdsuccess": "Adding friend ${profileid} with all bot accounts... This will take ~${estimatedtime} seconds. Please check the log for potential errors.",
"addfriendcmdsuccess": "Adding friend ${profileid} with ${numberOfAdds} bot accounts... This will take ~${estimatedtime} seconds. Please check the log for potential errors.",
"unfriendcmdsuccess": "I am unfriending you with all bot accounts. This will take a moment...\nYou can send me a friend request again at any time.",
"unfriendidcmdsuccess": "Removed friend ${profileid} from all bot accounts.",

Expand Down
3 changes: 1 addition & 2 deletions src/data/lang/portuguese.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@
"sessionscmdmsg": "Atualmente há ${amount} sessão(ões) ativa(s):",
"mysessionscmdnosessions": "Atualmente não há sessões ativas que você iniciou.",

"addfriendcmdacclimited": "Não é possível adicionar o amigo ${profileid} com o bot0 porque a conta do bot está limitada.",
"addfriendcmdsuccess": "Adicionando amigo ${profileid} com todas as contas de bot... Isso levará aproximadamente ~${estimatedtime} segundos. Por favor, verifique o log para possíveis erros.",
"addfriendcmdsuccess": "Adicionando amigo ${profileid} com ${numberOfAdds} as contas de bot... Isso levará aproximadamente ~${estimatedtime} segundos. Por favor, verifique o log para possíveis erros.",
"unfriendcmdsuccess": "Estou cancelando a amizade com você em todas as contas de bot. Isso levará um momento...\nVocê pode me enviar um pedido de amizade novamente a qualquer momento.",
"unfriendidcmdsuccess": "Removido o amigo ${profileid} de todas as contas de bot.",

Expand Down
3 changes: 1 addition & 2 deletions src/data/lang/russian.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@
"sessionscmdmsg": "В настоящее время есть ${amount} активных сессий:",
"mysessionscmdnosessions": "В настоящее время нет активных сессий, которые вы начали.",

"addfriendcmdacclimited": "Невозможно добавить ${profileid} в друзья с помощью bot0, потому что аккаунт бота ограничен.",
"addfriendcmdsuccess": "Добавление ${profileid} в друзья ко всем аккаунтам ботов... Это займёт ~${estimatedtime} сек. Пожалуйста, проверьте журнал на наличие возможных ошибок.",
"addfriendcmdsuccess": "Добавление ${profileid} в друзья со ${numberOfAdds} аккаунтам ботов... Это займёт ~${estimatedtime} сек. Пожалуйста, проверьте журнал на наличие возможных ошибок.",
"unfriendcmdsuccess": "Я удаляю вас из друзей со всех аккаунтов ботов. Это займёт некоторое время...\nВы можете отправить мне запрос в друзья в любое время.",
"unfriendidcmdsuccess": "Удалён ${profileid} из друзей из всех аккаунтов ботов.",

Expand Down
3 changes: 1 addition & 2 deletions src/data/lang/traditional-chinese.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@
"sessionscmdmsg": "目前有 ${amount}個活耀秒(s):",
"mysessionscmdnosessions": "目前沒有",

"addfriendcmdacclimited": "無法添加 ${profileid} bot0可能不是課金帳號",
"addfriendcmdsuccess": "正在添加 ${profileid} 所有機器人同時添加,這可能需要一點時間",
"addfriendcmdsuccess": "Adding friend ${profileid} with ${numberOfAdds} bot accounts... This will take ~${estimatedtime} seconds. Please check the log for potential errors.",
"unfriendcmdsuccess": "所有機器人同時解除好友,這可能需要一點時間。",
"unfriendidcmdsuccess": "所有機器人已解除${profileid}好友",

Expand Down

0 comments on commit 982f046

Please sign in to comment.