forked from aichaos/rivescript-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleMacro.java
32 lines (28 loc) · 1.04 KB
/
ExampleMacro.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* An example object macro written in Java.
*
* To define a Java object macro, you must implement the interface
* com.rivescript.ObjectMacro and register it using setSubroutine().
*
* This macro does two things: returns their message reversed, and sets
* a user variable named `java`.
*
* This implements the `reverse` object macro used in Aiden/obj-java.rive
*
* See RSBot.java for more details.
*/
import com.rivescript.ObjectMacro;
import java.lang.String;
import java.lang.StringBuilder;
public class ExampleMacro implements com.rivescript.ObjectMacro {
public String call (com.rivescript.RiveScript rs, String[] args) {
String message = String.join(" ", args);
// To get/set user variables for the user, you can use currentUser
// to find their ID and then use the usual methods.
String user = rs.currentUser();
rs.setUservar(user, "java", "This variable was set by Java "
+ "when you said 'reverse " + message + "'");
// Reverse their message and return it.
return new StringBuilder(message).reverse().toString();
}
}