|
|
QAPlugin API
|
|
|
===========
|
|
|
Local questions
|
|
|
---------------------
|
|
|
Local questions are very simple questions. They work by matching words, counting how many matched and returning a response. The advantages are that they are fast, can have meta information (such as priority, required permission, ...) but are limited in pattern matching. If you need to create a question that is simple without variable data, it is best to choose this.
|
|
|
|
|
|
###What will you need?
|
|
|
Everything related to local questions is located in `be.maximvdw.qaplugin.question.*`
|
|
|
The basic thing you need is a `Question` object. Every question has one or more `QuestionLine`'s:
|
|
|
these are just normal questions or matches like you put them in the configuration. But you can assign more
|
|
|
meta information to them like setting them as a word, making them required, ... .
|
|
|
|
|
|
###Creating a Question object
|
|
|
|
|
|
#### Simple question and response
|
|
|
```
|
|
|
Question question = new Question();
|
|
|
question.addQuestion(new QuestionLine("who are you"));
|
|
|
question.addQuestion(new QuestionLine("what are you"));
|
|
|
question.addAnswer(new AnswerLine("A robot!"));
|
|
|
question.addAnswer(new AnswerLine("I am Gary!"));
|
|
|
```
|
|
|
A question like this will be matched if you say a phrase that contains the trigger word and either one of those question lines.
|
|
|
|
|
|
The answer will randomly be one of the two.
|
|
|
|
|
|
For more information about how the question matching works please refer to the questions.yml file on the main plugin page.
|
|
|
|
|
|
Another small example:
|
|
|
```
|
|
|
Question question = new Question();
|
|
|
question.addQuestion(new QuestionLine("who"));
|
|
|
question.addQuestion(new QuestionLine("|required:name|word|Maxim"));
|
|
|
question.addQuestion(new QuestionLine("|required:name|word|Maximvdw"));
|
|
|
question.setMinimumMatches(2);
|
|
|
question.addAnswer(new AnswerLine("A cool guy"));
|
|
|
```
|
|
|
The "setMinimumMatches" makes sure that "who" and ("maxim" OR "maximvdw") are both matched
|
|
|
You do not need to use the `|required:....|` formatting. You can use the setters in `QuestionLine` for this.
|
|
|
|
|
|
|
|
|
|
|
|
#### Setting priority and required permission
|
|
|
```
|
|
|
...
|
|
|
question.setPriority(1); // Will have higher priority than a question with
|
|
|
// same matches but priority 0
|
|
|
question.setRequiredPermission("this.is.a.test"); // Will only match when
|
|
|
// permission is met
|
|
|
```
|
|
|
Priority is useful for when you have multiple of the same questions that are similar.
|
|
|
|
|
|
#### Dynamic response
|
|
|
Dynamic responses triggers a piece of code for the response. This means you can return an API response, or extract data from the question using whatever method you prefer.
|
|
|
```
|
|
|
Question question = new Question();
|
|
|
question.getQuestions().add(new QuestionLine("tell a joke"));
|
|
|
question.setDynamicResponse(new DynamicResponse() {
|
|
|
@Override
|
|
|
public AnswerLine getResponse(Player player, String question) {
|
|
|
String joke = "";
|
|
|
// Contact an API for a joke, because we don't have humor
|
|
|
return new AnswerLine(joke);
|
|
|
}
|
|
|
});
|
|
|
```
|
|
|
|
|
|
#### What else you can do?
|
|
|
Please refer to the Javadocs for more information.
|
|
|
There is the possibility to hide the question and response and much more ... |
|
|
\ No newline at end of file |