From 7517091756fe87ad6ea620b842e5c30e533886e9 Mon Sep 17 00:00:00 2001 From: 3urobeat <35304405+3urobeat@users.noreply.github.com> Date: Wed, 26 Jul 2023 18:10:37 +0200 Subject: [PATCH] Added runCommand example and note about userID & ownerIDs params --- docs/wiki/creating_plugins.md | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/docs/wiki/creating_plugins.md b/docs/wiki/creating_plugins.md index 9b07ff4b..ae98c3fa 100644 --- a/docs/wiki/creating_plugins.md +++ b/docs/wiki/creating_plugins.md @@ -156,14 +156,36 @@ From there, every other module of the bot is accessible. Worth noting: ## **Command System** -The CommandHandler allows you to register and run commands. +The CommandHandler allows you to register new and run existing commands. Commands are the core functionalities that allow you to request comments, retrieve information and manage the bot. -Any command you register will instantly be available to all message handlers. +Any command you register will instantly be available to all message handlers (e.g. to other plugins as well). By default the bot has built-in Steam Chat message handling. You can implement your own message handler as well, allowing you to integrate all registered commands into other platforms. Take a look at the developer documentation (TODO) for more information about how to write a custom message handler. +Running existing commands is very easy. Let's take a look at how requesting 5 comments for 3urobeat would work: +```js +this.plugin.commandHandler.runCommand( + "comment", // Command Name + ["5", "3urobeat"], // Arguments Array + (x, y, msg) => { logger("info", "Comment Command said: " + msg) }, // Response Function + this, // The current context + { cmdprefix: "/", userID: "12345", ownerIDs: ["12345"] // The resInfo object +}) +``` + +This would cause the comment command to send 5 comments to the Steam Profile "3urobeat". +The comments are requested by the user "12345", who has owner privileges. +Every response from the command will be logged to the terminal output using the logger function. + +**Note:** +It is very important to provide a unique `userID` parameter in the `resInfo` object, which must not clash with steamID64s. +This ID is used to uniquely identify the requesting user, for example apply cooldown for them and check for owner privileges. +Failing to provide an ID will result in either unprotected or no access. + +This is also where the `ownerIDs` array comes into play: It allows you to overwrite the `ownerid` array set in the config to enable owner privilege checking when using commands from outside the Steam Chat. Very cool, right? +