https://github.com/adsau59/supbot
✔Basic
Intermediate
Advanced
In this Supbot tutorial we will take a look on Console Commands.
During development, there could come a need to create custom code snippets that you want to execute during the execution of the bot, but writing it anywhere would disturb the Supbot's threads pipeline .
In in order to do the same, console commands can be used,
After you execute the bot, whatsapp web will get initialized. After the initialization is done, a greater than sign will appear in the console (>), here you can enter your console command. First the command keyword has to be written, followed by its arguments, like keyword arg1 arg2.
In order to learn how to use console command, we will see the help & run command.
help command is used to show the available commands that you can use and it also shows the usage of the target commands
just type help in the console without any arguments and hit enter to show a list of all the console commands available in the bot.
If you want to check the usage of any command type help followed by keyword of the command you want to check the usage of.
for example, help quit
The usage shows the name of the command, its description, its template and an example of how to use it.
run command is used to run feature commands, which is used by the clients in whatsapp, using console commands.
Using run command, Supbot creates a temporary client which has the highest privileges that is Role.SuperAdmin, which can run any command in any group even if it's feature is not added in the group, it is the only way to promote a Co-Admin to admin and demote Admin to Co-Admin.
The first argument of the run command is the group ID of the group you want the run the command in, as I explained before, it creates a temporary client which will belong to this group..
Second argument is the command keyword, which shows which feature command to run, remember you don't have to use the command prefix (;;) here.
Third and the next arguments are the arguments for the feature command which has to be executed, if the feature command doesn't take any arguments you can leave this empty.
The result of this command isn't displayed in the console, but it shows the result directly inside the whatsapp chat group.
You can create your own console command to run any code snippet you want, in order to do that you have to,
ConsoleCommand.Bot.getConsole().getConsoleCommandManager().add() method in the addThingsInBot() method in the main class.Lets have a look at the constructor and all the abstract methods that you have to implement to create Console Command
ConsoleCommand takes 2 parameters, keyword and noOfArgs.keyword is the string which is used to run the command.noOfArgs is the number of arguments required to use the command, you can keep this value -1 in order to skip number of argument check for variable number of arguments.compute(String[] args) method is the method which is executed when the command is entered in the console.args, it is a string array which contains the arguments passed from the console.getHelper() method is used to create usage helper which can be shown using help command.By creating this console command, you will learn where console command is used, and how to make it so that during the development of your own features, you wont have to waste time making a work around for it.
If you have any problems or you want to contact me on DefineX Community discord server