Module handlers-utils
The Handler Utils module is a lightweight Lua utility library designed to provide common functionalities for handling and processing messages within the AOS computer system.
It offers a set of functions to check message attributes and send replies, simplifying the development of more complex scripts and modules. This document will guide you through the module's functionalities, installation, and usage. Returns the _utils table.
Functions
| hasMatchingTag (name, value) | Checks if a given message has a tag that matches the specified name and value. |
| hasMatchingTagOf (name, values) | Checks if a given message has a tag that matches the specified name and one of the specified values. |
| hasMatchingData (value) | Checks if a given message has data that matches the specified value. |
| reply (string) | Given an input, returns a function that takes a message and replies to it. |
| continue (function) | Inverts the provided pattern's result if it matches, so that it continues execution with the next matching handler. |
Tables
| _utils | The _utils table |
Functions
- hasMatchingTag (name, value)
-
Checks if a given message has a tag that matches the specified name and value.
Parameters:
Returns:
-
{function}
A function that takes a message and returns whether there is a tag match (-1 if matches, 0 otherwise)
- hasMatchingTagOf (name, values)
-
Checks if a given message has a tag that matches the specified name and one of the specified values.
Parameters:
- name {string} The tag name to check
- values {string[]} The list of values of which one should match
Returns:
-
{function}
A function that takes a message and returns whether there is a tag match (-1 if matches, 0 otherwise)
- hasMatchingData (value)
-
Checks if a given message has data that matches the specified value.
Parameters:
- value {string} The value to match against the message data
Returns:
-
{function}
A function that takes a message and returns whether the data matches the value (-1 if matches, 0 otherwise)
- reply (string)
-
Given an input, returns a function that takes a message and replies to it.
Parameters:
- string {table } input The content to send back. If a string, it sends it as data. If a table, it assumes a structure with `Tags`.
Returns:
-
{function}
A function that takes a message and replies to it
- continue (function)
-
Inverts the provided pattern's result if it matches, so that it continues execution with the next matching handler.
Parameters:
- function {table } pattern The pattern to check for in the message
Returns:
-
{function}
Function that executes the pattern matching function and returns `1` (continue), so that the execution of handlers continues.