Add wiki and rename no space feature
This commit is contained in:
parent
e6aae3c282
commit
4991eef1f1
@ -33,5 +33,35 @@ As an example, if you want to restrict the updates to photos only, then you may
|
||||
}
|
||||
```
|
||||
|
||||
## Custom Command Processing
|
||||
### Command Prefix
|
||||
Customizing the command prefix is as simple as overriding the `getCommandPrefix` method as shown below.
|
||||
```java
|
||||
@Override
|
||||
protected String getCommandPrefix() {
|
||||
return "!";
|
||||
}
|
||||
```
|
||||
|
||||
### Command Regex Split
|
||||
The method that the bot uses to capture command tokens is through the regex splitters. By default, it's set to `" "`. However, this can be customized. For example,
|
||||
if you'd like to split on digits and whitespaces, then you may do the following:
|
||||
```java
|
||||
@Override
|
||||
protected String getCommandRegexSplit() {
|
||||
return "\\s\\d";
|
||||
}
|
||||
```
|
||||
### Commands with Continuous Text
|
||||
Feeling ambitious? You may allow your bot to process tokens that are technically attached to your command. Imagine you have a command
|
||||
`/do` and you'd like users to send commands as `/do1` and still trigger the `do` ability. In order to do that, override the `allowContinuousText` function.
|
||||
```java
|
||||
@Override
|
||||
protected boolean allowContinuousText() {
|
||||
return true;
|
||||
}
|
||||
```
|
||||
Please note that this may cause ability overlap. If multiple abilities can match the same command, the longest match will be taken. For example,
|
||||
if you have two abilities `do` and `do1`, the command `/do1` will trigger the `do1` ability.
|
||||
## Statistics
|
||||
AbilityBot can accrue basic statistics about the usage of your abilities and replies. Simply `enableStats()` on an Ability builder or `enableStats(<name>)` on replies to activate this feature. Once activated, you may call `/stats` and the bot will print a basic list of statistics. At the moment, AbilityBot only tracks hits. In the future, this will be enhanced to track more stats.
|
@ -241,7 +241,7 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
|
||||
return " ";
|
||||
}
|
||||
|
||||
protected boolean allowNoSpaceText() {
|
||||
protected boolean allowContinuousText() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -507,13 +507,17 @@ public abstract class BaseAbilityBot extends DefaultAbsSender implements Ability
|
||||
return Trio.of(update, abilities.get(DEFAULT), new String[]{});
|
||||
|
||||
Ability ability;
|
||||
String[] tokens = msg.getText().split(getCommandRegexSplit());
|
||||
if (allowNoSpaceText()) {
|
||||
String[] tokens;
|
||||
if (allowContinuousText()) {
|
||||
String abName = abilities.keySet().stream()
|
||||
.filter(name -> msg.getText().startsWith(format("%s%s", getCommandPrefix(), name)))
|
||||
.findFirst().orElse(DEFAULT);
|
||||
tokens = msg.getText()
|
||||
.replaceFirst(getCommandPrefix() + abName, "")
|
||||
.split(getCommandRegexSplit());
|
||||
ability = abilities.get(abName);
|
||||
} else {
|
||||
tokens = msg.getText().split(getCommandRegexSplit());
|
||||
if (tokens[0].startsWith(getCommandPrefix())) {
|
||||
String abilityToken = stripBotUsername(tokens[0].substring(1)).toLowerCase();
|
||||
ability = abilities.get(abilityToken);
|
||||
|
Loading…
Reference in New Issue
Block a user