Skip to content

Commit

Permalink
feat: Rework !joingroup 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 eaa7dd8 commit f8b4088
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 22 deletions.
52 changes: 41 additions & 11 deletions src/commands/core/group.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-05-08 20:40:33
* Last Modified: 2025-01-05 14:52:17
* 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 Down Expand Up @@ -57,8 +57,15 @@ module.exports.group = {

module.exports.joinGroup = {
names: ["joingroup"],
description: "Joins a Steam Group with all bot accounts",
description: "Joins a Steam Group with amount/all available bot accounts",
args: [
{
name: "amount",
description: "The amount of accounts to request to join",
type: "string",
isOptional: false,
ownersOnly: true
},
{
name: "ID",
description: "The link or groupID64 of the group to join",
Expand All @@ -81,21 +88,44 @@ module.exports.joinGroup = {
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
// 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;
}

if (isNaN(args[0]) && !String(args[0]).startsWith("https://steamcommunity.com/groups/")) return respond(await commandHandler.data.getLang("invalidgroupid", null, 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 + "joingroup amount id" }, requesterID));
return;
}
}

commandHandler.controller.handleSteamIdResolving(args[0], "group", async (err, id) => {
// Deny request if ID parameter does not appear to be a Steam group URL
if (isNaN(args[1]) && !String(args[1]).startsWith("https://steamcommunity.com/groups/")) {
respond(await commandHandler.data.getLang("invalidgroupid", null, requesterID));
return;
}

// Resolve ID
commandHandler.controller.handleSteamIdResolving(args[1], "group", async (err, id) => {
if (err) return respond((await commandHandler.data.getLang("invalidgroupid", null, requesterID)) + "\n\nError: " + err);

commandHandler.controller.getBots().forEach((e, i) => {
// Get all bot accounts up until amount which are not already in the group
const accsToJoin = commandHandler.controller.getBots().filter((e) => e.user.myGroups[id] !== 3).slice(0, args[0]);

logger("info", `Joining group '${id}' with ${accsToJoin.length} bot accounts...`);
respond(await commandHandler.data.getLang("joingroupcmdsuccess", { "groupid": id, "numberOfJoins": accsToJoin.length }, requesterID));

accsToJoin.forEach((e, i) => {
setTimeout(() => {
if (e.user.myGroups[id] !== 3) e.community.joinGroup(new SteamID(id));
logger("info", `[${e.logPrefix}] Joining group '${id}'...`);
e.community.joinGroup(new SteamID(id));
}, 1000 * i); // Delay every iteration so that we don't make a ton of requests at once
});

respond(await commandHandler.data.getLang("joingroupcmdsuccess", { "groupid": id }, requesterID));
logger("info", `Joining group '${id}' with all bot accounts...`);
});
}
};
Expand Down
12 changes: 6 additions & 6 deletions src/data/fileStructure.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
{
"path": "src/commands/core/group.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/commands/core/group.js",
"checksum": "dc04c054f927211c18a61913c06d5c15"
"checksum": "034751f153668b6aa07e4519db535d62"
},
{
"path": "src/commands/core/requests.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": "e624b3fbd03ecf67da2789a1b45a6e73"
"checksum": "71260995bfadb41f7437b82ad9fb6183"
},
{
"path": "src/data/lang/english.json",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/data/lang/english.json",
"checksum": "b6d022ca850d4261fcd0a457cccd4cef"
"checksum": "aaf607fb01e691c4bec270fbfd7450b4"
},
{
"path": "src/data/lang/portuguese.json",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/data/lang/portuguese.json",
"checksum": "197f5dd07af01dc0a2769cd2f440de8e"
"checksum": "363c2d42ab4399cfb47ea05ae4910885"
},
{
"path": "src/data/lang/russian.json",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/data/lang/russian.json",
"checksum": "454e4cdcf8f2fdc3441cb7f80eb06b50"
"checksum": "914390b3392e884e9971d400d51a011c"
},
{
"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": "382ff2ac962af4350082041a49a06ab2"
"checksum": "a26117c7647c570ca2e122ff2acf0be7"
},
{
"path": "src/dataManager/dataCheck.js",
Expand Down
2 changes: 1 addition & 1 deletion src/data/lang/chinese.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"unfriendallcmdpending": "在30秒内使用所有机器人帐户取消所有人(除所有者之外)的好友关系...\n键入'${cmdprefix}unfriendall abort'以中止/停止过程。",
"unfriendallcmdstart": "开始取消所有人的好友关系...",

"joingroupcmdsuccess": "使用所有机器人帐户加入组'${groupid}'...",
"joingroupcmdsuccess": "Joining group '${groupid}' with ${numberOfJoins} bot accounts...",

"leavegroupcmdsuccess": "使用所有机器人帐户退出组'${groupid}'...",

Expand Down
2 changes: 1 addition & 1 deletion src/data/lang/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"unfriendallcmdpending": "Unfriending all people (except owners) with all bot accounts in 30 seconds...\nType '${cmdprefix}unfriendall abort' to abort/stop the process.",
"unfriendallcmdstart": "Starting to unfriend everyone...",

"joingroupcmdsuccess": "Joining group '${groupid}' with all bot accounts...",
"joingroupcmdsuccess": "Joining group '${groupid}' with ${numberOfJoins} bot accounts...",

"leavegroupcmdsuccess": "Leaving group '${groupid}' with all bot accounts...",

Expand Down
2 changes: 1 addition & 1 deletion src/data/lang/portuguese.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"unfriendallcmdpending": "Cancelando a amizade de todas as pessoas (exceto proprietários) com todas as contas de bot em 30 segundos...\nDigite '${cmdprefix}unfriendall abort' para abortar/parar o processo.",
"unfriendallcmdstart": "Iniciando o cancelamento de amizade com todos...",

"joingroupcmdsuccess": "Entrando no grupo '${groupid}' com todas as contas de bot...",
"joingroupcmdsuccess": "Entrando no grupo '${groupid}' com ${numberOfJoins} as contas de bot...",

"leavegroupcmdsuccess": "Saindo do grupo '${groupid}' com todas as contas de bot...",

Expand Down
2 changes: 1 addition & 1 deletion src/data/lang/russian.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
"unfriendallcmdpending": "Удаление всех людей (кроме владельцев) со всех аккаунтов бота за 30 секунд...\nВведите «${cmdprefix}unfriendall abort» для прерывания/остановки процесса.",
"unfriendallcmdstart": "Начинаю всех удалять из друзей...",

"joingroupcmdsuccess": "Вступление в группу «${groupid}» со всеми аккаунтами ботов...",
"joingroupcmdsuccess": "Вступление в группу «${groupid}» со ${numberOfJoins} аккаунтами ботов...",

"leavegroupcmdsuccess": "Покидаю группу «${groupid}» со всеми аккаунтами ботов...",

Expand Down
2 changes: 1 addition & 1 deletion src/data/lang/traditional-chinese.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"unfriendallcmdpending": "除了開發者,我需要30秒時間解除所有好友\n填寫 '${cmdprefix}unfriendall abort' abort/stop 可停止",
"unfriendallcmdstart": "開始解除所有好友",

"joingroupcmdsuccess": "所有的機器人正在加入'${groupid}'",
"joingroupcmdsuccess": "Joining group '${groupid}' with ${numberOfJoins} bot accounts",

"leavegroupcmdsuccess": "所有的機器人正在退出'${groupid}'",

Expand Down

0 comments on commit f8b4088

Please sign in to comment.