The Conditional plugin allows you to execute the equivalent of "if-then" statements in the bot. Using command nesting, you can test conditions of arbitrary complexity. This is useful if you want a varying bot response depending on some other inputs (e.g., time of day, topic, weather in some location, etc.)
The plugin has a number of commands for logical operations to help out with the task.
The code for this plugin lives in the git repository of the gribble sourceforge project.
The cif command is the main workhorse. It would have been named just 'if', but it's not a good idea to name python functions after reserved keywords. :) The function takes three arguments, a boolean condition, command to execute when boolean is true, and command to execute when boolean is false.
Here's a simple example:
cif true "echo i'm true" "echo i'm false"
This would result in output of "i'm true".
This is of course not very useful... so let's use command nesting to our advantage, along with the other functions from this plugin:
cif [cand [nle [echo $hour] 19] [nge [echo $hour] 8]] "echo it is daytime!" "echo it is nighttime!"
Which has the bot claiming it is daytime between 0800 and 1900 hours, and nighttime otherwise.
cif [match "Conditions: Clear" [weather 10010]] "echo weather is good" "echo weather is not so good"
Will have your bot talk about the weather. (This example is using MTughan's WunderWeather plugin.
Takes a list of booleans, and evaluates whether all of them are true.
cand true true true
Would return 'true'.
Use command nesting with other functions from this plugin to your advantage.
Takes a list of booleans, and evaluates whether at least one of them is true.
cor false true true
would return 'true'.
Takes a list of booleans, and evaluates whether one and only one of them is true.
cor false true true
would return 'false'.
The following string comparison functions, each taking two string arguments, are available:
Use these to your advantage as nested commands with cif.
The following numeric comparison functions, each taking two numeric arguments, are available:
Use these to your advantage as nested commands with cif.
See also: [MessageParser_Plugin]
@alias add sayhi "echo [cif [nlt 0 [len @1]] \"echo @1:\" \" echo \\\"\\\"\"] \"Hi\""
"@sayhi" will display " Hi" and "@sayhi somebody" will display "somebody: Hi"
FIXME: remove the prefix space in the first output.
Wiki: Gribble_Project_Git_Repository
Wiki: MessageParser_Plugin