···20202121## Scripting
22222323-Rhai matchers evaluate a script that returns a `MatcherResult` object. The script must return an object that matches this type.
2323+Rhai matchers evaluate a script that returns a `Match` object or a `string` containing the AT-URI of the post that has matched. Return values of `false` or `0` are considered not matched.
24242525-The `new_matcher_result()` function is available to create a new `MatcherResult` object.
2525+The `upsert_match(aturi)` function is available to create a new `Match` object. It has one parameter, the AT-URI of the post that is matched.
26262727```rhai
2828-let result = new_matcher_result();
2929-2828+let condition_thing = true;
3029// do some stuff ...
31303232-result
3131+if condition_thing {
3232+ return upsert_match();
3333+}
3434+3535+false
3336```
34373538## Provided Methods
···5457 name: "rhai'ya doing"
5558 description: "This feed uses the rhai matcher to match against a complex expression."
5659 matchers:
5757- - source: "/opt/supercell/rhaiyadoin.rhai"
6060+ - script: "/opt/supercell/rhaiyadoin.rhai"
5861 type: rhai
5962```
60636164An example rhai script:
62656366```rhai
6464-let result = new_matcher_result();
6767+// Only match events from the bsky feed where the did is "did:plc:cbkjy5n7bk3ax2wplmtjofq2" (@ngerakines.me).
6868+if event.did != "did:plc:cbkjy5n7bk3ax2wplmtjofq2" {
6969+ return false;
7070+}
65717272+// If the event has a commit that has a record that has a $type, set rtype. Otherwise the value will be ().
6673let rtype = event?.commit?.record["$type"];
6767-6868-if rtype != "app.bsky.feed.post" {
6969- return result;
7070-}
7171-7272-let root_uri = event?.commit?.record?.reply?.root?.uri;
7373-7474-result.matched = `${root_uri}`.starts_with("at://did:plc:cbkjy5n7bk3ax2wplmtjofq2/app.bsky.feed.post/");
7575-7676-if result.matched {
7777- result.aturi = build_aturi(event);
7474+switch rtype {
7575+ "app.bsky.feed.post" => {
7676+ // Compose the at-uri of the post that has matched.
7777+ return build_aturi(event);
7878+ }
7979+ "app.bsky.feed.like" => {
8080+ // Returns the subject uri of the like event or false if it doesn't exist.
8181+ return event?.commit?.record?.subject?.uri ?? false;
8282+ }
8383+ _ => { }
7884}
79858080-result
8686+// Nothing else matches
8787+false
8188```
8289