Writing BotBlock questions

Writing BotBlock questions

Because a key component of this is not having everybody with the same questions, you should at least edit the questions that come with the plugin---changing numbers or phrasing of questions---and if possible, write your own. Adding a new question requires minimal programming skills.

To start out, copy the commented-out question template, and uncomment it. Give your question a name; the only requirements are that it be unique, not start or end with spaces, and not contain any end-of-line characters.

The PROMPT string is the question itself, which will be followed by a randomly-generated number between 0 and 999 (inclusive).

The EXPECT function is then a function that calculates the number or string that the user is supposed to type in. The variable $key is pre-set to be the key that was generated; all you have to do is write an expression using $key that performs the same computation you expect the user to do. The value calculated here will be compared to what the user types; it must be an exact match (though case-insensitive).

Advanced usage

There are a few more complicated things you can do, too.

If you provide a GEN function, then that will be used to generate the number. Do this if your question needs a more or less than a thousand possible inputs, or if they need to start somewhere other than zero, or whatever.

The number that is printed out does not have to be exactly the number that was generated. If you provide an OUT function, that function is used to display the number (again, provided in $key. You can modify the number, print out certain words based on the number, whatever. If you want the number in the middle of the question, set PROMPT to the empty string and put the whole shebang in the OUTPUT function.

You might want to ask a question that has multiple possible answers. In that case, EXPECT won't work, since it calls for an exact match. For these situations, you can provide a VALID function instead (if VALID is present, EXPECT is ignored). This function has two provided variables: $key as before, and $response containing the value provided by the user. The function should return true if the user's response was, in fact, valid. Remember that in perl, == and != perform numeric comparisons; if you want to compare strings, use eq, ne, and related operators. (Or, just use regexes.)

Available helper functions

Quite possibly of use is the num_to_words function, which takes one (numeric) argument and converts it into its (North American English) written-out form. It can readily handle numbers up to 999 trillion, which is really much higher than you should be using for this purpose. (The built-in question that uses this only ranges from 0 to 999.)