Skip to content

Commit

Permalink
feat: Add !manage command which implements manage module #228
Browse files Browse the repository at this point in the history
  • Loading branch information
3urobeat committed Jan 2, 2025
1 parent 058573d commit 9d8f4ae
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 8 deletions.
97 changes: 95 additions & 2 deletions src/commands/core/system.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-03 13:08:52
* Last Modified: 2025-01-02 13:23:12
* 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 @@ -272,3 +272,96 @@ module.exports.eval = {
}
}
};


const availableManageModes = "addAccount, removeAccount, filterAccounts";

module.exports.manage = {
names: ["manage"],
description: "Interact with the manage module to administrate the active set of bot accounts",
args: [
{
name: "mode",
description: `Available modes: '${availableManageModes}'`,
type: "string",
isOptional: false,
ownersOnly: true
},
{
name: "argument",
description: "Argument(s) the selected mode requires. Run command without this parameter to display help for the selected mode",
type: "string",
isOptional: true, // Optional to display help for selected mode if no argument is provided
ownersOnly: true
}
],
ownersOnly: true,

/**
* The manage command
* @param {CommandHandler} commandHandler The commandHandler object
* @param {Array} args Array of arguments that will be passed to the command
* @param {function(object, object, string): void} respondModule Function that will be called to respond to the user's request. Passes context, resInfo and txt as parameters.
* @param {object} context The context (this.) of the object calling this command. Will be passed to respondModule() as first parameter.
* @param {CommandHandler.resInfo} resInfo Object containing additional information your respondModule might need to process the response (for example the userID who executed the command).
*/
run: async (commandHandler, args, respondModule, context, resInfo) => {
const respond = ((txt) => respondModule(context, resInfo, txt)); // Shorten each call

const cmdusage = `'${resInfo.cmdprefix}manage mode argument'`; // TODO: Can't we dynamically generate this in the future?

// Prevent error when calling toLowerCase below when user did not provide any mode
if (!args[0]) args[0] = "";

switch (args[0].toLowerCase()) {
case "addaccount": { // Block "fixes" eslint no-case-declarations warning
// Check if no or too short (= probably incorrect format) credentials were provided
if (!args[1] || args[1].split(":").length < 2) {
respond(await commandHandler.data.getLang("managecmdaddusage", { "credentialsformat": "username:password:sharedSecret", "optionalparameter": "sharedSecret", "cmdusage": cmdusage }, resInfo.userID));
}

// Split credentials into username, password and sharedSecret
const credentials = args[1].split(":");

// Run manage function with the provided credentials
commandHandler.controller.addAccount(credentials[0], credentials[1], credentials[2] || "");

respond(await commandHandler.data.getLang("managecmdaddsuccess", { "username": credentials[0] }, resInfo.userID));
break;
}

case "removeaccount":
// Check if no username was provided
if (!args[1]) return respond(await commandHandler.data.getLang("managecmdremoveusage", { "cmdusage": cmdusage }, resInfo.userID));

// Run manage function with the provided username
commandHandler.controller.removeAccount(args[1]);

respond(await commandHandler.data.getLang("managecmdremovesuccess", { "username": args[1] }, resInfo.userID));
break;

case "filteraccounts": { // Block "fixes" eslint no-case-declarations warning
const availableFilters = Object.keys(commandHandler.controller.filters);
const filtersLowercase = availableFilters.map((e) => e.toLowerCase());

// Check if no filter or an invalid filter was provided
if (!args[1] || !filtersLowercase.includes(args[1].toLowerCase())) {
respond(await commandHandler.data.getLang("managecmdfilterusage", { "availablefilters": availableFilters.join(", "), "cmdusage": cmdusage }, resInfo.userID));
return;
}

// Find the selected filter while ignoring case
const selectedFilter = availableFilters.find((e) => e.toLowerCase() == args[1].toLowerCase());

// Run manage function with the selected filter
const filterResult = commandHandler.controller.filterAccounts(commandHandler.controller.filters[selectedFilter]);

respond(await commandHandler.data.getLang("managecmdfiltersuccess", { "matchamount": filterResult.length, "selectedfilter": selectedFilter, "usernames": filterResult.map((e) => e.accountName).join(", ") }));
break;
}

default:
respond(await commandHandler.data.getLang("managecmdusage", { "availablemodes": availableManageModes, "cmdusage": cmdusage }, resInfo.userID));
}
}
};
12 changes: 6 additions & 6 deletions src/data/fileStructure.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
{
"path": "src/commands/core/system.js",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/commands/core/system.js",
"checksum": "b37fd364b9aa9f00d47b3a0d8094c700"
"checksum": "906a73f90236dd974fdf9d8e4cff7025"
},
{
"path": "src/commands/core/vote.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": "438eec25dd0c247c8b8396a9f2288d0c"
"checksum": "1b703865e31c2a604606b8e4dd092d69"
},
{
"path": "src/data/lang/english.json",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/data/lang/english.json",
"checksum": "aa163f0d8a84f49ce00075a23a3f9e4d"
"checksum": "403032426144d8f05b859e183848671d"
},
{
"path": "src/data/lang/portuguese.json",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/data/lang/portuguese.json",
"checksum": "2a0266a92ad46689e63ae386b3eaa48e"
"checksum": "7f360b933a4b317a4aeec502dfa8e233"
},
{
"path": "src/data/lang/russian.json",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/data/lang/russian.json",
"checksum": "5766fa2429c79523f67405eeef397fbe"
"checksum": "10a3592d60de8d1b9542dd60eaba1c08"
},
{
"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": "82363a6ac21306e03e638f99bebd64ac"
"checksum": "3fbb763499dc7105b3c908aece6a6f4e"
},
{
"path": "src/dataManager/dataCheck.js",
Expand Down
8 changes: 8 additions & 0 deletions src/data/lang/chinese.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,13 @@
"evalcmdturnedoff": "eval命令已关闭!",
"evalcmdlogininfoblock": "您的代码包含'logininfo'。为了保护密码,这是不允许的。",

"managecmdaddusage": "Provide the credentials of the account to add to the current set of bot accounts as argument in this format:\n'${credentialsformat}' (${optionalparameter} is optional)\n\nCommand usage: ${cmdusage}",
"managecmdaddsuccess": "The bot will attempt to add & login '${username}'. Please check the log for potential errors.",
"managecmdremoveusage": "Provide the username (accountName) of the bot account to remove from the current set of bot accounts as argument.\n\nCommand usage: ${cmdusage}",
"managecmdremovesuccess": "The bot will log off & remove account '${username}' if it exists. Please check the log for potential errors.",
"managecmdfilterusage": "Provide one of these arguments to filter the current list of bot accounts and display their names:\n'${availablefilters}'\n\nCommand usage: ${cmdusage}",
"managecmdfiltersuccess": "These ${matchamount} bot accounts match the selected filter '${selectedfilter}':\n'${usernames}'",
"managecmdusage": "Provide one of these modes: '${availablemodes}'.\nRun command with mode but without argument parameter to display help for that selected mode.\n\nCommand usage: ${cmdusage}",

"childbotmessage": "这是一个运行在机器人群集中的帐户。\n请添加主要的机器人并发送给他一个${cmdprefix}help消息。\n如果您想了解这是什么,请键入:${cmdprefix}about\n这是主要的机器人账户:"
}
8 changes: 8 additions & 0 deletions src/data/lang/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,13 @@
"evalcmdturnedoff": "The eval command has been turned off!",
"evalcmdlogininfoblock": "Your code includes 'logininfo'. In order to protect passwords this is not allowed.",

"managecmdaddusage": "Provide the credentials of the account to add to the current set of bot accounts as argument in this format:\n'${credentialsformat}' (${optionalparameter} is optional)\n\nCommand usage: ${cmdusage}",
"managecmdaddsuccess": "The bot will attempt to add & login '${username}'. Please check the log for potential errors.",
"managecmdremoveusage": "Provide the username (accountName) of the bot account to remove from the current set of bot accounts as argument.\n\nCommand usage: ${cmdusage}",
"managecmdremovesuccess": "The bot will log off & remove account '${username}' if it exists. Please check the log for potential errors.",
"managecmdfilterusage": "Provide one of these arguments to filter the current list of bot accounts and display their names:\n'${availablefilters}'\n\nCommand usage: ${cmdusage}",
"managecmdfiltersuccess": "These ${matchamount} bot accounts match the selected filter '${selectedfilter}':\n'${usernames}'",
"managecmdusage": "Provide one of these modes: '${availablemodes}'.\nRun command with mode but without argument parameter to display help for that selected mode.\n\nCommand usage: ${cmdusage}",

"childbotmessage": "This is one account running in a bot cluster.\nPlease add the main bot and send him a ${cmdprefix}help message.\nIf you want to check out what this is about, type: ${cmdprefix}about\nThis is the main bot account:"
}
8 changes: 8 additions & 0 deletions src/data/lang/portuguese.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,13 @@
"evalcmdturnedoff": "O comando eval foi desativado!",
"evalcmdlogininfoblock": "Seu código inclui 'logininfo'. Para proteger senhas, isso não é permitido.",

"managecmdaddusage": "Provide the credentials of the account to add to the current set of bot accounts as argument in this format:\n'${credentialsformat}' (${optionalparameter} is optional)\n\nCommand usage: ${cmdusage}",
"managecmdaddsuccess": "The bot will attempt to add & login '${username}'. Please check the log for potential errors.",
"managecmdremoveusage": "Provide the username (accountName) of the bot account to remove from the current set of bot accounts as argument.\n\nCommand usage: ${cmdusage}",
"managecmdremovesuccess": "The bot will log off & remove account '${username}' if it exists. Please check the log for potential errors.",
"managecmdfilterusage": "Provide one of these arguments to filter the current list of bot accounts and display their names:\n'${availablefilters}'\n\nCommand usage: ${cmdusage}",
"managecmdfiltersuccess": "These ${matchamount} bot accounts match the selected filter '${selectedfilter}':\n'${usernames}'",
"managecmdusage": "Provide one of these modes: '${availablemodes}'.\nRun command with mode but without argument parameter to display help for that selected mode.\n\nCommand usage: ${cmdusage}",

"childbotmessage": "Esta é uma conta em execução em um cluster de bots.\nPor favor, adicione o bot principal e envie a ele uma mensagem ${cmdprefix}help.\nSe quiser saber do que se trata, digite: ${cmdprefix}about\nEsta é a conta principal do bot:"
}
8 changes: 8 additions & 0 deletions src/data/lang/russian.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,13 @@
"evalcmdturnedoff": "Команда eval была отключена!",
"evalcmdlogininfoblock": "Ваш код включает «logininfo». В целях защиты паролей это запрещено.",

"managecmdaddusage": "Provide the credentials of the account to add to the current set of bot accounts as argument in this format:\n'${credentialsformat}' (${optionalparameter} is optional)\n\nCommand usage: ${cmdusage}",
"managecmdaddsuccess": "The bot will attempt to add & login '${username}'. Please check the log for potential errors.",
"managecmdremoveusage": "Provide the username (accountName) of the bot account to remove from the current set of bot accounts as argument.\n\nCommand usage: ${cmdusage}",
"managecmdremovesuccess": "The bot will log off & remove account '${username}' if it exists. Please check the log for potential errors.",
"managecmdfilterusage": "Provide one of these arguments to filter the current list of bot accounts and display their names:\n'${availablefilters}'\n\nCommand usage: ${cmdusage}",
"managecmdfiltersuccess": "These ${matchamount} bot accounts match the selected filter '${selectedfilter}':\n'${usernames}'",
"managecmdusage": "Provide one of these modes: '${availablemodes}'.\nRun command with mode but without argument parameter to display help for that selected mode.\n\nCommand usage: ${cmdusage}",

"childbotmessage": "Это один аккаунт, работающий в группе ботов.\nПожалуйста, добавьте главного бота и отправьте ему сообщение ${cmdprefix}help.\nЕсли вы хотите проверить, в чём дело, введите: ${cmdprefix}about\nЭто главный аккаунт бота:"
}
8 changes: 8 additions & 0 deletions src/data/lang/traditional-chinese.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,13 @@
"evalcmdturnedoff": "eval指令已關閉",
"evalcmdlogininfoblock": "您的程式碼包含'logininfo'這是保護密碼的\n請使用其他的",

"managecmdaddusage": "Provide the credentials of the account to add to the current set of bot accounts as argument in this format:\n'${credentialsformat}' (${optionalparameter} is optional)\n\nCommand usage: ${cmdusage}",
"managecmdaddsuccess": "The bot will attempt to add & login '${username}'. Please check the log for potential errors.",
"managecmdremoveusage": "Provide the username (accountName) of the bot account to remove from the current set of bot accounts as argument.\n\nCommand usage: ${cmdusage}",
"managecmdremovesuccess": "The bot will log off & remove account '${username}' if it exists. Please check the log for potential errors.",
"managecmdfilterusage": "Provide one of these arguments to filter the current list of bot accounts and display their names:\n'${availablefilters}'\n\nCommand usage: ${cmdusage}",
"managecmdfiltersuccess": "These ${matchamount} bot accounts match the selected filter '${selectedfilter}':\n'${usernames}'",
"managecmdusage": "Provide one of these modes: '${availablemodes}'.\nRun command with mode but without argument parameter to display help for that selected mode.\n\nCommand usage: ${cmdusage}",

"childbotmessage": "這是接收支援的機器人\n請使用以下機器人:"
}

0 comments on commit 9d8f4ae

Please sign in to comment.