Skip to content

Commit

Permalink
Block certain commands when bot is not fully started yet
Browse files Browse the repository at this point in the history
This also fixes the comment cmd from sending a misleading message when requesting comments while the bot isn't fully started yet.
  • Loading branch information
3urobeat committed May 6, 2023
1 parent 5fb0542 commit 8347cb6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/commands/core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 09.07.2021 16:26:00
* Author: 3urobeat
*
* Last Modified: 02.05.2023 20:41:37
* Last Modified: 06.05.2023 10:44:56
* Modified By: 3urobeat
*
* Copyright (c) 2021 3urobeat <https://github.com/HerrEurobeat>
Expand Down Expand Up @@ -37,6 +37,8 @@ module.exports.block = {
run: (commandHandler, args, steamID64, respondModule, context, resInfo) => {
let respond = ((txt) => respondModule(context, resInfo, txt)); // Shorten each call

if (commandHandler.controller.info.readyAfter == 0) return respond(commandHandler.data.lang.botnotready); // Check if bot isn't fully started yet

if (!args[0]) return respond(commandHandler.data.lang.invalidprofileid);

handleSteamIdResolving(args[0], SteamID.Type.INDIVIDUAL, (err, res) => {
Expand Down Expand Up @@ -70,6 +72,8 @@ module.exports.unblock = {
run: (commandHandler, args, steamID64, respondModule, context, resInfo) => {
let respond = ((txt) => respondModule(context, resInfo, txt)); // Shorten each call

if (commandHandler.controller.info.readyAfter == 0) return respond(commandHandler.data.lang.botnotready); // Check if bot isn't fully started yet

if (!args[0]) return respond(commandHandler.data.lang.invalidprofileid);

handleSteamIdResolving(args[0], SteamID.Type.INDIVIDUAL, (err, res) => {
Expand Down
9 changes: 5 additions & 4 deletions src/commands/core/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 09.07.2021 16:26:00
* Author: 3urobeat
*
* Last Modified: 05.05.2023 19:56:41
* Last Modified: 06.05.2023 10:38:30
* Modified By: 3urobeat
*
* Copyright (c) 2021 3urobeat <https://github.com/HerrEurobeat>
Expand Down Expand Up @@ -39,16 +39,17 @@ module.exports.comment = {
*/
run: async (commandHandler, args, steamID64, respondModule, context, resInfo) => {
let respond = ((txt) => respondModule(context, resInfo, txt)); // Shorten each call
if (commandHandler.data.advancedconfig.disableCommentCmd) return respond(commandHandler.data.lang.botmaintenance);

let requesterSteamID64 = steamID64;
let receiverSteamID64 = requesterSteamID64;
let ownercheck = commandHandler.data.cachefile.ownerid.includes(requesterSteamID64);


/* --------- Check for disabled comment cmd or if update is queued --------- */
if (commandHandler.controller.info.activeLogin) return respond(commandHandler.data.lang.commentactiverelog);
if (commandHandler.data.config.maxComments == 0 && !ownercheck) return respond(commandHandler.data.lang.commentcmdowneronly);
if (commandHandler.controller.info.readyAfter == 0) return respond(commandHandler.data.lang.botnotready); // Bot isn't fully started yet
if (commandHandler.data.advancedconfig.disableCommentCmd) return respond(commandHandler.data.lang.botmaintenance); // Bot is set to maintenance mode
if (commandHandler.controller.info.activeLogin) return respond(commandHandler.data.lang.commentactiverelog); // Bot is waiting for relog
if (commandHandler.data.config.maxComments == 0 && !ownercheck) return respond(commandHandler.data.lang.commentcmdowneronly); // Comment command is restricted to owners only


/* --------- Calculate maxRequestAmount and get arguments from comment request --------- */
Expand Down
5 changes: 3 additions & 2 deletions src/commands/core/commentmisc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 09.07.2021 16:26:00
* Author: 3urobeat
*
* Last Modified: 05.05.2023 12:39:48
* Last Modified: 06.05.2023 10:42:45
* Modified By: 3urobeat
*
* Copyright (c) 2021 3urobeat <https://github.com/HerrEurobeat>
Expand Down Expand Up @@ -35,7 +35,8 @@ module.exports.abort = {
* @param {Object} resInfo Object containing additional information your respondModule might need to process the response (for example the userID who executed the command).
*/
run: (commandHandler, args, steamID64, respondModule, context, resInfo) => {
let respond = ((txt) => respondModule(context, resInfo, txt)); // Shorten each call
let respond = ((txt) => respondModule(context, resInfo, txt)); // Shorten each call
if (commandHandler.controller.info.readyAfter == 0) return respond(commandHandler.data.lang.botnotready); // Check if bot isn't fully started yet

handleSteamIdResolving(args[0], null, (err, res) => {
if (res) {
Expand Down
8 changes: 7 additions & 1 deletion src/commands/core/friend.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 09.07.2021 16:26:00
* Author: 3urobeat
*
* Last Modified: 02.05.2023 20:46:16
* Last Modified: 06.05.2023 10:44:05
* Modified By: 3urobeat
*
* Copyright (c) 2021 3urobeat <https://github.com/HerrEurobeat>
Expand Down Expand Up @@ -37,6 +37,8 @@ module.exports.addFriend = {
run: (commandHandler, args, steamID64, respondModule, context, resInfo) => {
let respond = ((txt) => respondModule(context, resInfo, txt)); // Shorten each call

if (commandHandler.controller.info.readyAfter == 0) return respond(commandHandler.data.lang.botnotready); // Check if bot isn't fully started yet

if (!args[0]) return respond(commandHandler.data.lang.invalidprofileid);

handleSteamIdResolving(args[0], SteamID.Type.INDIVIDUAL, (err, res) => {
Expand Down Expand Up @@ -94,6 +96,8 @@ module.exports.unfriend = {
run: (commandHandler, args, steamID64, respondModule, context, resInfo) => {
let respond = ((txt) => respondModule(context, resInfo, txt)); // Shorten each call

if (commandHandler.controller.info.readyAfter == 0) return respond(commandHandler.data.lang.botnotready); // Check if bot isn't fully started yet

// Unfriend message sender with all bot accounts if no id was provided
if (!args[0]) {
respond(commandHandler.data.lang.unfriendcmdsuccess);
Expand Down Expand Up @@ -144,6 +148,8 @@ module.exports.unfriendall = {
run: (commandHandler, args, steamID64, respondModule, context, resInfo) => {
let respond = ((txt) => respondModule(context, resInfo, txt)); // Shorten each call

if (commandHandler.controller.info.readyAfter == 0) return respond(commandHandler.data.lang.botnotready); // Check if bot isn't fully started yet

// TODO: This is bad. Rewrite using a message collector, maybe add one to steamChatInteraction helper
var abortunfriendall; // eslint-disable-line no-var

Expand Down
6 changes: 5 additions & 1 deletion src/commands/core/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Created Date: 09.07.2021 16:26:00
* Author: 3urobeat
*
* Last Modified: 02.05.2023 21:03:47
* Last Modified: 06.05.2023 10:44:26
* Modified By: 3urobeat
*
* Copyright (c) 2021 3urobeat <https://github.com/HerrEurobeat>
Expand Down Expand Up @@ -70,6 +70,8 @@ module.exports.leaveGroup = {
run: (commandHandler, args, steamID64, respondModule, context, resInfo) => {
let respond = ((txt) => respondModule(context, resInfo, txt)); // Shorten each call

if (commandHandler.controller.info.readyAfter == 0) return respond(commandHandler.data.lang.botnotready); // Check if bot isn't fully started yet

if (isNaN(args[0]) && !String(args[0]).startsWith("https://steamcommunity.com/groups/")) return respond(commandHandler.data.lang.leavegroupcmdinvalidgroup);

if (String(args[0]).startsWith("https://steamcommunity.com/groups/")) {
Expand Down Expand Up @@ -123,6 +125,8 @@ module.exports.leaveAllGroups = {
run: (commandHandler, args, steamID64, respondModule, context, resInfo) => {
let respond = ((txt) => respondModule(context, resInfo, txt)); // Shorten each call

if (commandHandler.controller.info.readyAfter == 0) return respond(commandHandler.data.lang.botnotready); // Check if bot isn't fully started yet

// TODO: This is bad. Rewrite using a message collector, maybe add one to steamChatInteraction helper
var abortleaveallgroups; // eslint-disable-line no-var

Expand Down

0 comments on commit 8347cb6

Please sign in to comment.