OsListenRegex

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(Add exemple using OS_LISTEN_REGEX_NAME)
(Add exemple using OS_LISTEN_REGEX_MESSAGE)
Line 7: Line 7:
 
If the regex strings are invalid, an error will be shouted on the debug channel.
 
If the regex strings are invalid, an error will be shouted on the debug channel.
 
|ossl_example=
 
|ossl_example=
'''With OS_LISTEN_REGEX_NAME:''' Filter only the detected name
+
'''With OS_LISTEN_REGEX_NAME:''' Filtering only the detected name
 
<source lang="lsl">
 
<source lang="lsl">
 
//
 
//
Line 35: Line 35:
 
             llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is open.");
 
             llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is open.");
 
             llSay(PUBLIC_CHANNEL, "The regex name is " + (string)name);
 
             llSay(PUBLIC_CHANNEL, "The regex name is " + (string)name);
 +
            llSetText("[ON]", <1.0, 1.0, 1.0>, 1.0);
 +
            llSetTimerEvent(30.0);
 +
        }
 +
 +
        else
 +
        {
 +
            llSetTimerEvent(0.0);
 +
            llListenRemove(handler);
 +
            llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is closed.");
 +
            llSetText("[OFF]", <1.0, 1.0, 1.0>, 1.0);
 +
        }
 +
    }
 +
 +
    listen(integer channel, string name, key id, string message)
 +
    {
 +
        if (channel == channelID)
 +
        {
 +
            llSay(PUBLIC_CHANNEL, (string)channel + ") " + (string)id + " " + name + " " + message);
 +
        }
 +
    }
 +
 +
    timer()
 +
    {
 +
        swith = !swith;
 +
        llSetTimerEvent(0.0);
 +
        llListenRemove(handler);
 +
        llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is closed.");
 +
        llSetText("[OFF]", <1.0, 1.0, 1.0>, 1.0);
 +
    }
 +
}
 +
</source>
 +
'''With OS_LISTEN_REGEX_MESSAGE:''' Filtering only the message
 +
<source lang="lsl">
 +
//
 +
// osListenRegex Script Example
 +
// Author: djphil
 +
//
 +
 +
integer channelID = PUBLIC_CHANNEL;
 +
integer handler;
 +
integer swith;
 +
 +
default
 +
{
 +
    state_entry()
 +
    {
 +
        llSay(PUBLIC_CHANNEL, "Touch to see osListenRegex usage.");
 +
        llSay(PUBLIC_CHANNEL, "This with the use of the Regex Bitfield OS_LISTEN_REGEX_MESSAGE.");
 +
        llSetText("[OFF]", <1.0, 1.0, 1.0>, 1.0);
 +
    }
 +
 +
    touch_start(integer number)
 +
    {
 +
        if (swith = !swith)
 +
        {
 +
            string regex = "^(?i)(hi|hello|bonjour|ola)(?-i)";
 +
            handler = osListenRegex(channelID, "", NULL_KEY, regex, OS_LISTEN_REGEX_MESSAGE);
 +
            llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is open.");
 +
            llSay(PUBLIC_CHANNEL, "The regex message is " + (string)regex);
 
             llSetText("[ON]", <1.0, 1.0, 1.0>, 1.0);
 
             llSetText("[ON]", <1.0, 1.0, 1.0>, 1.0);
 
             llSetTimerEvent(30.0);
 
             llSetTimerEvent(30.0);

Revision as of 00:47, 13 December 2020

integer osListenRegex(integer channelID, string name, key ID, string msg, integer regexBitfield)
Allows the server to filter listen events by regular expressions. name or message parameters can be regular expressions, these are behaviours are controlled via the regexBitField parameter using the constants OS_LISTEN_REGEX_NAME and OS_LISTEN_REGEX_MESSAGE.

If the regex strings are invalid, an error will be shouted on the debug channel.

Threat Level Low
Permissions Use of this function is always allowed by default
Extra Delay 0 seconds
Example(s)
With OS_LISTEN_REGEX_NAME: Filtering only the detected name
//
// osListenRegex Script Example
// Author: djphil
//
 
integer channelID = PUBLIC_CHANNEL;
integer handler;
integer swith;
 
default
{
    state_entry()
    {
        llSay(PUBLIC_CHANNEL, "Touch to see osListenRegex usage.");
        llSay(PUBLIC_CHANNEL, "This with the use of the Regex Bitfield OS_LISTEN_REGEX_NAME.");
        llSetText("[OFF]", <1.0, 1.0, 1.0>, 1.0);
    }
 
    touch_start(integer number)
    {
        if (swith = !swith)
        {
            string name = llDetectedName(0);
            handler = osListenRegex(channelID, name, NULL_KEY, "", OS_LISTEN_REGEX_NAME);
            llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is open.");
            llSay(PUBLIC_CHANNEL, "The regex name is " + (string)name);
            llSetText("[ON]", <1.0, 1.0, 1.0>, 1.0);
            llSetTimerEvent(30.0);
        }
 
        else
        {
            llSetTimerEvent(0.0);
            llListenRemove(handler);
            llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is closed.");
            llSetText("[OFF]", <1.0, 1.0, 1.0>, 1.0);
        }
    }
 
    listen(integer channel, string name, key id, string message)
    {
        if (channel == channelID)
        {
            llSay(PUBLIC_CHANNEL, (string)channel + ") " + (string)id + " " + name + " " + message);
        }
    }
 
    timer()
    {
        swith = !swith;
        llSetTimerEvent(0.0);
        llListenRemove(handler);
        llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is closed.");
        llSetText("[OFF]", <1.0, 1.0, 1.0>, 1.0);
    }
}

With OS_LISTEN_REGEX_MESSAGE: Filtering only the message

//
// osListenRegex Script Example
// Author: djphil
//
 
integer channelID = PUBLIC_CHANNEL;
integer handler;
integer swith;
 
default
{
    state_entry()
    {
        llSay(PUBLIC_CHANNEL, "Touch to see osListenRegex usage.");
        llSay(PUBLIC_CHANNEL, "This with the use of the Regex Bitfield OS_LISTEN_REGEX_MESSAGE.");
        llSetText("[OFF]", <1.0, 1.0, 1.0>, 1.0);
    }
 
    touch_start(integer number)
    {
        if (swith = !swith)
        {
            string regex = "^(?i)(hi|hello|bonjour|ola)(?-i)";
            handler = osListenRegex(channelID, "", NULL_KEY, regex, OS_LISTEN_REGEX_MESSAGE);
            llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is open.");
            llSay(PUBLIC_CHANNEL, "The regex message is " + (string)regex);
            llSetText("[ON]", <1.0, 1.0, 1.0>, 1.0);
            llSetTimerEvent(30.0);
        }
 
        else
        {
            llSetTimerEvent(0.0);
            llListenRemove(handler);
            llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is closed.");
            llSetText("[OFF]", <1.0, 1.0, 1.0>, 1.0);
        }
    }
 
    listen(integer channel, string name, key id, string message)
    {
        if (channel == channelID)
        {
            llSay(PUBLIC_CHANNEL, (string)channel + ") " + (string)id + " " + name + " " + message);
        }
    }
 
    timer()
    {
        swith = !swith;
        llSetTimerEvent(0.0);
        llListenRemove(handler);
        llSay(PUBLIC_CHANNEL, "The listen regex on channel " + (string)channelID + " is closed.");
        llSetText("[OFF]", <1.0, 1.0, 1.0>, 1.0);
    }
}
Notes
This function was added in 0.7.5-post-fixes


See Also

Personal tools
General
About This Wiki