What Will I Learn?
- What is Command in Supbot API?
- What is Feature in Supbot API?
- How to create Command using Supbot API?
In this Supbot API tutorial, we will understand what is
Feature and why it is used. We will then create a custom command that shows meaning of a term using Urban Dictionary REST API.
Commands are the functions that can be called by a client. So, the clients can use command to tell the bot what to do. When a client writes a command in a group, Supbot reads the command and performs actions depending on the command client used, arguments the client passed, and the client themself.
To create a command, create a class and extend it with
Command class and then implement its abstract methods and override its Constructor.
When a command is called, the
compute method is called.
getHelper method is used when the client uses help commands, which explains them how the command should work.
Feature encapsulates many commands into one group. For example, if we want to make voting in our bot, there will be commands like, start-vote, vote, end-vote, show-vote-results so we can group all these commands into one group called Voting.
To create a feature, create a class and extend it with
Feature calss and then implement its abstract methods and override its Constructor.
getDescription simply returns a string which says what is the purpose of the feature, it is shown when the help-feature command is used.
How to add it in the Supbot?
So to add your own command to the bot, you will have to first Create the Command
Then Create the feature, and put the command in its constructor parameter
Then finally add the feature to the bot, using
Bot.getFeatureManager().add() function, in the addThingsInBot method in the main class