Skip to content

Commit

Permalink
feat: Add !plugins command
Browse files Browse the repository at this point in the history
  • Loading branch information
3urobeat committed Jan 4, 2025
1 parent b6967e6 commit 6fac016
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/wiki/commands_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ This is the full documentation of all commands. Most commands have aliases but s
| !block | `profileid`      | Blocks a user with all bot accounts on Steam. (Owner only.) |
| !unblock | `profileid`      | Unblocks a user with all bot accounts on Steam. Note: The user can still get ignored by Steam for a while. (Owner only.) |
| !jobs | No arguments | Lists all currently registered jobs. (Owner only.) |
| !plugins | No arguments | Lists all currently active and installed but inactive plugins, including their version, botVersion and description. (Owner only.) |
| !reload | No arguments | Reloads all commands and plugins without needing to restart. Please only use it for testing/development. Alias: !rl (Owner only.) |
| !restart | No arguments | Restarts the bot and checks for available updates. Alias: !rs (Owner only.) |
| !stop | No arguments | Stops the bot. (Owner only.) |
Expand Down
60 changes: 59 additions & 1 deletion src/commands/core/system.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-02 13:23:12
* Last Modified: 2025-01-04 17:31:00
* Modified By: 3urobeat
*
* Copyright (c) 2021 - 2025 3urobeat <https://github.com/3urobeat>
Expand Down Expand Up @@ -65,6 +65,64 @@ module.exports.jobs = {
};


module.exports.plugins = {
names: ["plugins"],
description: "Lists all installed plugins",
args: [],
ownersOnly: true,

/**
* The jobs 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

// Compile list of all enabled plugins
const activePlugins = commandHandler.controller.pluginSystem.getActivePlugins();
let activePluginsStr = "";

activePlugins.forEach(([pluginName, pluginVersion]) => {
pluginVersion = pluginVersion.replace("^", ""); // Remove ^ from version string, it looks weird in the message

try {
const pluginPackageJson = require(srcdir + "/../node_modules/" + pluginName + "/package.json");

activePluginsStr += `- ${pluginName} v${pluginVersion} for v${pluginPackageJson.botVersion} by ${pluginPackageJson.author} - '${pluginPackageJson.description}'\n`;
} catch (err) {
logger("warn", `Couldn't load package.json of plugin '${pluginName}', displaying shallow information. ${err}`);
activePluginsStr += `- ${pluginName} v${pluginVersion}`;
}
});

// Compile list of all installed plugins but exclude the active ones
const installedPlugins = commandHandler.controller.pluginSystem.getInstalledPlugins();
const inactivePlugins = installedPlugins.filter(([pluginName]) => !activePlugins.map(([name]) => name).includes(pluginName)); // Reduce activePlugins [[name, version], ...] to [name, ...] and filter plugins included in it
let inactivePluginsStr = "";

inactivePlugins.forEach(([pluginName, pluginVersion]) => {
pluginVersion = pluginVersion.replace("^", ""); // Remove ^ from version string, it looks weird in the message

try {
const pluginPackageJson = require(srcdir + "/../node_modules/" + pluginName + "/package.json");

inactivePluginsStr += `- ${pluginName} v${pluginVersion} for v${pluginPackageJson.botVersion} by ${pluginPackageJson.author} - '${pluginPackageJson.description}'\n`;
} catch (err) {
logger("warn", `Couldn't load package.json of plugin '${pluginName}', displaying shallow information. ${err}`);
inactivePluginsStr += `- ${pluginName} v${pluginVersion}`;
}
});

// Send message
respond(await commandHandler.data.getLang("pluginscmdresponse", { "activeplugins": activePluginsStr.trim(), "inactiveplugins": inactivePluginsStr.trim() }, resInfo.userID));
}
};


module.exports.restart = {
names: ["restart", "rs"],
description: "Restarts the bot and checks for available updates",
Expand Down
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": "906a73f90236dd974fdf9d8e4cff7025"
"checksum": "0d76ebafc08eaef99f2884876859b435"
},
{
"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": "1b703865e31c2a604606b8e4dd092d69"
"checksum": "e624b3fbd03ecf67da2789a1b45a6e73"
},
{
"path": "src/data/lang/english.json",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/data/lang/english.json",
"checksum": "403032426144d8f05b859e183848671d"
"checksum": "b6d022ca850d4261fcd0a457cccd4cef"
},
{
"path": "src/data/lang/portuguese.json",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/data/lang/portuguese.json",
"checksum": "7f360b933a4b317a4aeec502dfa8e233"
"checksum": "197f5dd07af01dc0a2769cd2f440de8e"
},
{
"path": "src/data/lang/russian.json",
"url": "https://raw.githubusercontent.com/3urobeat/steam-comment-service-bot/beta-testing/src/data/lang/russian.json",
"checksum": "10a3592d60de8d1b9542dd60eaba1c08"
"checksum": "454e4cdcf8f2fdc3441cb7f80eb06b50"
},
{
"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": "3fbb763499dc7105b3c908aece6a6f4e"
"checksum": "382ff2ac962af4350082041a49a06ab2"
},
{
"path": "src/dataManager/dataCheck.js",
Expand Down
1 change: 1 addition & 0 deletions src/data/lang/chinese.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

"jobscmdregistered": "这些作业目前已注册: ",
"jobscmdnoneregistered": "目前没有作业注册。",
"pluginscmdresponse": "These plugins are currently active:\n${activeplugins}\n\nThese plugins are installed but currently inactive:\n${inactiveplugins}",
"reloadcmdreloaded": "重新加载所有命令和插件。",
"activerelog": "机器人目前正在等待最后一个活动请求完成,以便重新登录帐户。\n请稍等片刻,然后重试。",
"updatecmdforce": "Forcing an update from the ${branchname} branch...",
Expand Down
1 change: 1 addition & 0 deletions src/data/lang/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

"jobscmdregistered": "These jobs are currently registered:",
"jobscmdnoneregistered": "There are currently no jobs registered.",
"pluginscmdresponse": "These plugins are currently active:\n${activeplugins}\n\nThese plugins are installed but currently inactive:\n${inactiveplugins}",
"reloadcmdreloaded": "Reloaded all commands and plugins.",
"activerelog": "The bot is currently waiting for the last active requests to be finished in order to relog accounts.\nPlease wait a few minutes and try again.",
"updatecmdforce": "Forcing an update from the ${branchname} branch...",
Expand Down
1 change: 1 addition & 0 deletions src/data/lang/portuguese.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

"jobscmdregistered": "These jobs are currently registered:",
"jobscmdnoneregistered": "There are currently no jobs registered.",
"pluginscmdresponse": "These plugins are currently active:\n${activeplugins}\n\nThese plugins are installed but currently inactive:\n${inactiveplugins}",
"reloadcmdreloaded": "Recarregou todos os comandos e plugins.",
"activerelog": "O bot está aguardando as últimas solicitações ativas serem concluídas para reiniciar as contas.\nAguarde alguns minutos e tente novamente.",
"updatecmdforce": "Forçando uma atualização do ${branchname}...",
Expand Down
1 change: 1 addition & 0 deletions src/data/lang/russian.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@

"jobscmdregistered": "Эти работы сейчас зарегистрированны:",
"jobscmdnoneregistered": "Сейчас нет зарегистрированных работ.",
"pluginscmdresponse": "These plugins are currently active:\n${activeplugins}\n\nThese plugins are installed but currently inactive:\n${inactiveplugins}",
"reloadcmdreloaded": "Перезагружены все команды и плагины.",
"activerelog": "В настоящее время бот ожидает завершения последних активных запросов, чтобы заново войти.\nПожалуйста, подождите несколько минут и повторите попытку.",
"updatecmdforce": "Принудительное обновление из ветки ${branchname}...",
Expand Down
1 change: 1 addition & 0 deletions src/data/lang/traditional-chinese.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@

"jobscmdregistered": "已註冊:",
"jobscmdnoneregistered": "未註冊",
"pluginscmdresponse": "These plugins are currently active:\n${activeplugins}\n\nThese plugins are installed but currently inactive:\n${inactiveplugins}",
"reloadcmdreloaded": "已重新讀取所有功能 / 插件",
"activerelog": "目前正等待最後一個活動完成,以便重新登入帳戶。",
"updatecmdforce": "強制更新 ${branchname}",
Expand Down

0 comments on commit 6fac016

Please sign in to comment.