···11+# Playbook: Rhai
22+33+The experimental rhai matcher uses the [rhai](https://rhai.rs/) scripting language to evaluate expressions.
44+55+## Builds
66+77+To use this feature, the `rhai` feature flag must be enabled at build time.
88+99+Locally:
1010+1111+```shell
1212+cargo run --features rhai
1313+```
1414+1515+Container:
1616+1717+```shell
1818+docker build --build-arg=CARGO_FEATURES=rhai .
1919+```
2020+2121+## Scripting
2222+2323+Rhai matchers evaluate a script that returns a `MatcherResult` object. The script must return an object that matches this type.
2424+2525+The `new_matcher_result()` function is available to create a new `MatcherResult` object.
2626+2727+```rhai
2828+let result = new_matcher_result();
2929+3030+// do some stuff ...
3131+3232+result
3333+```
3434+3535+## Usage
3636+3737+The feed matcher type `rhai` is used with a `source` attribute that points to an rhai script file.
3838+3939+Rhai scripts are evaluated with scope that includes the following variables:
4040+4141+* `event` - The event to match against.
4242+4343+An example config file:
4444+4545+```yaml
4646+feeds:
4747+- uri: "at://did:plc:decafbad/app.bsky.feed.generator/Dcuz0bZP1"
4848+ name: "rhai'ya doing"
4949+ description: "This feed uses the rhai matcher to match against a complex expression."
5050+ matchers:
5151+ - source: "/opt/supercell/rhaiyadoin.rhai"
5252+ type: rhai
5353+```
5454+5555+An example rhai script:
5656+5757+```rhai
5858+let result = new_matcher_result();
5959+6060+let rtype = event?.commit?.record["$type"];
6161+6262+if rtype != "app.bsky.feed.post" {
6363+ return result;
6464+}
6565+6666+let root_uri = event?.commit?.record?.reply?.root?.uri;
6767+6868+result.matched = root_uri.starts_with("at://did:plc:cbkjy5n7bk3ax2wplmtjofq2/app.bsky.feed.post/");
6969+7070+result
7171+```
7272+