2010-08-25 00:24:52 +02:00
|
|
|
Using commands.wrap to parse your command's arguments.
|
|
|
|
------------------------------------------------------
|
2006-03-13 16:39:38 +01:00
|
|
|
This document illustrates how to use the new 'wrap' function present in Supybot
|
|
|
|
0.80 to handle argument parsing and validation for your plugin's commands.
|
|
|
|
|
|
|
|
Introduction
|
|
|
|
============
|
|
|
|
To plugin developers for older (pre-0.80) versions of Supybot, one of the more
|
|
|
|
annoying aspects of writing commands was handling the arguments that were
|
|
|
|
passed in. In fact, many commands often had to duplicate parsing and
|
|
|
|
verification code, resulting in lots of duplicated code for not a whole lot of
|
|
|
|
action. So, instead of forcing plugin writers to come up with their own ways of
|
|
|
|
cleaning it up, we wrote up the wrap function to handle all of it.
|
|
|
|
|
|
|
|
It allows a much simpler and more flexible way of checking things than before
|
|
|
|
and it doesn't require that you know the bot internals to do things like check
|
|
|
|
and see if a user exists, or check if a command name exists and whatnot.
|
|
|
|
|
|
|
|
If you are a plugin author this document is absolutely required reading, as it
|
|
|
|
will massively ease the task of writing commands.
|
|
|
|
|
|
|
|
Using Wrap
|
|
|
|
==========
|
|
|
|
First off, to get the wrap function, it is recommended (strongly) that you use
|
2010-08-25 00:24:52 +02:00
|
|
|
the following import line::
|
2006-03-13 16:39:38 +01:00
|
|
|
|
|
|
|
from supybot.commands import *
|
|
|
|
|
|
|
|
This will allow you to access the wrap command (and it allows you to do it
|
2009-01-19 23:24:59 +01:00
|
|
|
without the commands prefix). Note that this line is added to the imports of
|
2006-03-13 16:48:38 +01:00
|
|
|
plugin templates generated by the supybot-plugin-create script.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
|
|
|
Let's write a quickie command that uses wrap to get a feel for how it makes our
|
|
|
|
lives better. Let's write a command that repeats a string of text a given
|
|
|
|
number of times. So you could say "repeat 3 foo" and it would say "foofoofoo".
|
|
|
|
Not a very useful command, but it will serve our purpose just fine. Here's how
|
2010-08-25 00:24:52 +02:00
|
|
|
it would be done without wrap::
|
2006-03-13 16:39:38 +01:00
|
|
|
|
|
|
|
def repeat(self, irc, msg, args):
|
2006-03-13 16:48:38 +01:00
|
|
|
"""<num> <text>
|
2006-03-13 16:39:38 +01:00
|
|
|
|
|
|
|
Repeats <text> <num> times.
|
|
|
|
"""
|
|
|
|
(num, text) = privmsg.getArgs(args, required=2)
|
|
|
|
try:
|
|
|
|
num = int(num)
|
|
|
|
except ValueError:
|
|
|
|
raise callbacks.ArgumentError
|
|
|
|
irc.reply(num * text)
|
|
|
|
|
2006-03-13 16:48:38 +01:00
|
|
|
Note that all of the argument validation and parsing takes up 5 of the 6 lines
|
2006-03-13 16:39:38 +01:00
|
|
|
(and you should have seen it before we had privmsg.getArgs!). Now, here's what
|
2010-08-25 00:24:52 +02:00
|
|
|
our command will look like with wrap applied::
|
2006-03-13 16:39:38 +01:00
|
|
|
|
|
|
|
def repeat(self, irc, msg, args, num, text):
|
|
|
|
"""<num> <text>
|
|
|
|
|
|
|
|
Repeats <text> <num> times.
|
|
|
|
"""
|
|
|
|
irc.reply(text * num)
|
|
|
|
repeat = wrap(repeat, ['int', 'text'])
|
|
|
|
|
|
|
|
Pretty short, eh? With wrap all of the argument parsing and validation is
|
|
|
|
handled for us and we get the arguments we want, formatted how we want them,
|
|
|
|
and converted into whatever types we want them to be - all in one simple
|
|
|
|
function call that is used to wrap the function! So now the code inside each
|
|
|
|
command really deals with how to execute the command and not how to deal with
|
|
|
|
the input.
|
|
|
|
|
|
|
|
So, now that you see the benefits of wrap, let's figure out what stuff we have
|
|
|
|
to do to use it.
|
|
|
|
|
|
|
|
Syntax Changes
|
|
|
|
==============
|
|
|
|
There are two syntax changes to the old style that are implemented. First, the
|
|
|
|
definition of the command function must be changed. The basic syntax for the
|
2010-08-25 00:24:52 +02:00
|
|
|
new definition is::
|
2006-03-13 16:39:38 +01:00
|
|
|
|
|
|
|
def commandname(self, irc, msg, args, <arg1>, <arg2>, ...):
|
|
|
|
|
|
|
|
Where arg1 and arg2 (up through as many as you want) are the variables that
|
|
|
|
will store the parsed arguments. "Now where do these parsed arguments come
|
|
|
|
from?" you ask. Well, that's where the second syntax change comes in. The
|
|
|
|
second syntax change is the actual use of the wrap function itself to decorate
|
2010-08-25 00:24:52 +02:00
|
|
|
our command names. The basic decoration syntax is::
|
2006-03-13 16:39:38 +01:00
|
|
|
|
|
|
|
commandname = wrap(commandname, [converter1, converter2, ...])
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
This should go on the line immediately following the body of the command's
|
|
|
|
definition, so it can easily be located (and it obviously must go after the
|
|
|
|
command's definition so that commandname is defined).
|
2006-03-13 16:39:38 +01:00
|
|
|
|
|
|
|
Each of the converters in the above listing should be one of the converters in
|
|
|
|
commands.py (I will describe each of them in detail later.) The converters are
|
|
|
|
applied in order to the arguments given to the command, generally taking
|
|
|
|
arguments off of the front of the argument list as they go. Note that each of
|
|
|
|
the arguments is actually a string containing the NAME of the converter to use
|
|
|
|
and not a reference to the actual converter itself. This way we can have
|
|
|
|
converters with names like int and not have to worry about polluting the
|
|
|
|
builtin namespace by overriding the builtin int.
|
|
|
|
|
|
|
|
As you will find out when you look through the list of converters below, some
|
|
|
|
of the converters actually take arguments. The syntax for supplying them (since
|
|
|
|
we aren't actually calling the converters, but simply specifying them), is to
|
2010-08-25 00:24:52 +02:00
|
|
|
wrap the converter name and args list into a tuple. For example::
|
2006-03-13 16:39:38 +01:00
|
|
|
|
|
|
|
commandname = wrap(commandname, [(converterWithArgs, arg1, arg2),
|
|
|
|
converterWithoutArgs1, converterWithoutArgs2])
|
|
|
|
|
|
|
|
For the most part you won't need to use an argument with the converters you use
|
|
|
|
either because the defaults are satisfactory or because it doesn't even take
|
|
|
|
any.
|
|
|
|
|
|
|
|
Customizing Wrap
|
|
|
|
================
|
|
|
|
Converters alone are a pretty powerful tool, but for even more advanced (yet
|
|
|
|
simpler!) argument handling you may want to use contexts. Contexts describe how
|
|
|
|
the converters are applied to the arguments, while the converters themselves
|
2009-08-16 23:17:05 +02:00
|
|
|
do the actual parsing and validation.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
|
|
|
For example, one of the contexts is "optional". By using this context, you're
|
|
|
|
saying that a given argument is not required, and if the supplied converter
|
2009-08-16 23:17:05 +02:00
|
|
|
doesn't find anything it likes, we should use some default. Yet another
|
2006-03-13 16:39:38 +01:00
|
|
|
example is the "reverse" context. This context tells the supplied converter to
|
|
|
|
look at the last argument and work backwards instead of the normal
|
|
|
|
first-to-last way of looking at arguments.
|
|
|
|
|
|
|
|
So, that should give you a feel for the role that contexts play. They are not
|
|
|
|
by any means necessary to use wrap. All of the stuff we've done to this point
|
|
|
|
will work as-is. However, contexts let you do some very powerful things in very
|
|
|
|
easy ways, and are a good thing to know how to use.
|
|
|
|
|
|
|
|
Now, how do you use them? Well, they are in the global namespace of
|
2009-08-16 23:17:05 +02:00
|
|
|
src/commands.py, so your previous import line will import them all; you can
|
2006-03-13 16:39:38 +01:00
|
|
|
call them just as you call wrap. In fact, the way you use them is you simply
|
2009-08-16 23:17:05 +02:00
|
|
|
call the context function you want to use, with the converter (and its
|
2010-08-25 00:24:52 +02:00
|
|
|
arguments) as arguments. It's quite simple. Here's an example::
|
2006-03-13 16:39:38 +01:00
|
|
|
|
|
|
|
commandname = wrap(commandname, [optional('int'), many('something')])
|
|
|
|
|
2009-08-16 23:17:05 +02:00
|
|
|
In this example, our command is looking for an optional integer argument first.
|
|
|
|
Then, after that, any number of arguments which can be anything (as long as
|
|
|
|
they are something, of course).
|
2006-03-13 16:39:38 +01:00
|
|
|
|
|
|
|
Do note, however, that the type of the arguments that are returned can be
|
|
|
|
changed if you apply a context to it. So, optional("int") may very well return
|
|
|
|
None as well as something that passes the "int" converter, because after all
|
|
|
|
it's an optional argument and if it is None, that signifies that nothing was
|
|
|
|
there. Also, for another example, many("something") doesn't return the same
|
|
|
|
thing that just "something" would return, but rather a list of "something"s.
|
|
|
|
|
|
|
|
Converter List
|
|
|
|
==============
|
|
|
|
Below is a list of all the available converters to use with wrap. If the
|
|
|
|
converter accepts any arguments, they are listed after it and if they are
|
|
|
|
optional, the default value is shown.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* id, kind="integer"
|
|
|
|
|
|
|
|
- Returns something that looks like an integer ID number. Takes an optional
|
2006-03-13 16:39:38 +01:00
|
|
|
"kind" argument for you to state what kind of ID you are looking for,
|
|
|
|
though this doesn't affect the integrity-checking. Basically requires that
|
|
|
|
the argument be an integer, does no other integrity-checking, and provides
|
|
|
|
a nice error message with the kind in it.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* ip
|
|
|
|
|
|
|
|
- Checks and makes sure the argument looks like a valid IP and then returns
|
2006-03-13 16:39:38 +01:00
|
|
|
it.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* int, type="integer", p=None
|
|
|
|
|
|
|
|
- Gets an integer. The "type" text can be used to customize the error message
|
2009-08-16 23:17:05 +02:00
|
|
|
received when the argument is not an integer. "p" is an optional predicate
|
|
|
|
to test the integer with. If p(i) fails (where i is the integer arg parsed
|
|
|
|
out of the argument string), the arg will not be accepted.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* index
|
|
|
|
|
|
|
|
- Basically ("int", "index"), but with a twist. This will take a 1-based
|
2006-03-13 16:39:38 +01:00
|
|
|
index and turn it into a 0-based index (which is more useful in code). It
|
|
|
|
doesn't transform 0, and it maintains negative indices as is (note that it
|
|
|
|
does allow them!).
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* color
|
|
|
|
|
|
|
|
- Accepts arguments that describe a text color code (e.g., "black", "light
|
2006-03-13 16:39:38 +01:00
|
|
|
blue") and returns the mIRC color code for that color. (Note that many
|
|
|
|
other IRC clients support the mIRC color code scheme, not just mIRC)
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* now
|
|
|
|
|
|
|
|
- Simply returns the current timestamp as an arg, does not reference or
|
2006-03-13 16:48:38 +01:00
|
|
|
modify the argument list.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* url
|
|
|
|
|
|
|
|
- Checks for a valid URL.
|
|
|
|
|
|
|
|
* httpUrl
|
|
|
|
|
|
|
|
- Checks for a valid HTTP URL.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* long, type="long"
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
- Basically the same as int minus the predicate, except that it converts the
|
2006-03-13 16:39:38 +01:00
|
|
|
argument to a long integer regardless of the size of the int.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* float, type="floating point number"
|
|
|
|
|
|
|
|
- Basically the same as int minus the predicate, except that it converts the
|
2006-03-13 16:39:38 +01:00
|
|
|
argument to a float.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* nonInt, type="non-integer value"
|
|
|
|
|
|
|
|
- Accepts everything but integers, and returns them unchanged. The "type"
|
2006-03-13 16:39:38 +01:00
|
|
|
value, as always, can be used to customize the error message that is
|
|
|
|
displayed upon failure.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* positiveInt
|
|
|
|
|
|
|
|
- Accepts only positive integers.
|
|
|
|
|
|
|
|
* nonNegativeInt
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
- Accepts only non-negative integers.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* letter
|
|
|
|
|
|
|
|
- Looks for a single letter. (Technically, it looks for any one-element
|
2009-08-16 23:17:05 +02:00
|
|
|
sequence).
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* haveOp, action="do that"
|
|
|
|
|
|
|
|
- Simply requires that the bot have ops in the channel that the command is
|
2006-03-13 16:39:38 +01:00
|
|
|
called in. The action parameter completes the error message: "I need to be
|
|
|
|
opped to ...".
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* expiry
|
|
|
|
|
|
|
|
- Takes a number of seconds and adds it to the current time to create an
|
2006-03-13 16:39:38 +01:00
|
|
|
expiration timestamp.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* literal, literals, errmsg=None
|
|
|
|
|
|
|
|
- Takes a required sequence or string (literals) and any argument that
|
2006-03-13 16:39:38 +01:00
|
|
|
uniquely matches the starting substring of one of the literals is
|
2010-08-25 00:24:52 +02:00
|
|
|
transformed into the full literal. For example, with ``("literal", ("bar",
|
|
|
|
"baz", "qux"))``, you'd get "bar" for "bar", "baz" for "baz", and "qux"
|
|
|
|
for any of "q", "qu", or "qux". "b" and "ba" would raise errors because
|
|
|
|
they don't uniquely identify one of the literals in the list. You can
|
|
|
|
override errmsg to provide a specific (full) error message, otherwise the
|
|
|
|
default argument error message is displayed.
|
|
|
|
|
|
|
|
* to
|
|
|
|
|
|
|
|
- Returns the string "to" if the arg is any form of "to" (case-insensitive).
|
|
|
|
|
|
|
|
* nick
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
- Checks that the arg is a valid nick on the current IRC server.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* seenNick
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
- Checks that the arg is a nick that the bot has seen (NOTE: this is limited
|
2009-08-16 23:17:05 +02:00
|
|
|
by the size of the history buffer that the bot has).
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* channel
|
|
|
|
|
|
|
|
- Gets a channel to use the command in. If the channel isn't supplied, uses
|
2006-03-13 16:39:38 +01:00
|
|
|
the channel the message was sent in. If using a different channel, does
|
|
|
|
sanity-checking to make sure the channel exists on the current IRC network.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* inChannel
|
|
|
|
|
|
|
|
- Requires that the command be called from within any channel that the bot
|
2009-05-04 17:44:10 +02:00
|
|
|
is currently in or with one of those channels used as an argument to the
|
|
|
|
command.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* onlyInChannel
|
|
|
|
|
|
|
|
- Requires that the command be called from within any channel that the bot
|
2009-05-04 17:44:10 +02:00
|
|
|
is currently in.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* nickInChannel
|
|
|
|
|
|
|
|
- Requires that the argument be a nick that is in the current channel, and
|
2006-03-13 16:39:38 +01:00
|
|
|
returns that nick.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* networkIrc, errorIfNoMatch=False
|
|
|
|
|
|
|
|
- Returns the IRC object of the specified IRC network. If one isn't
|
2006-03-13 16:39:38 +01:00
|
|
|
specified, the IRC object of the IRC network the command was called on is
|
|
|
|
returned.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* callerInGivenChannel
|
|
|
|
|
|
|
|
- Takes the given argument as a channel and makes sure that the caller is in
|
2006-03-13 16:39:38 +01:00
|
|
|
that channel.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* plugin, require=True
|
|
|
|
|
|
|
|
- Returns the plugin specified by the arg or None. If require is True, an
|
2006-03-13 16:39:38 +01:00
|
|
|
error is raised if the plugin cannot be retrieved.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* boolean
|
|
|
|
|
|
|
|
- Converts the text string to a boolean value. Acceptable true values are:
|
2006-03-13 16:39:38 +01:00
|
|
|
"1", "true", "on", "enable", or "enabled" (case-insensitive). Acceptable
|
|
|
|
false values are: "0", false", "off", "disable", or "disabled"
|
|
|
|
(case-insensitive).
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* lowered
|
|
|
|
|
|
|
|
- Returns the argument lowered (NOTE: it is lowered according to IRC
|
2006-03-13 16:39:38 +01:00
|
|
|
conventions, which does strange mapping with some punctuation characters).
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* anything
|
|
|
|
|
|
|
|
- Returns anything as is.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* something, errorMsg=None, p=None
|
|
|
|
|
|
|
|
- Takes anything but the empty string. errorMsg can be used to customize the
|
2006-03-13 16:39:38 +01:00
|
|
|
error message. p is any predicate function that can be used to test the
|
|
|
|
validity of the input.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* filename
|
|
|
|
|
|
|
|
- Used to get a filename argument.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* commandName
|
|
|
|
|
|
|
|
- Returns the canonical command name version of the given string (ie, the
|
2006-03-13 16:39:38 +01:00
|
|
|
string is lowercased and dashes and underscores are removed).
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* text
|
|
|
|
|
|
|
|
- Takes the rest of the arguments as one big string. Note that this differs
|
2006-03-13 16:39:38 +01:00
|
|
|
from the "anything" context in that it clobbers the arg string when it's
|
|
|
|
done. Using any converters after this is most likely incorrect.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* glob
|
|
|
|
|
|
|
|
- Gets a glob string. Basically, if there are no wildcards (``*``, ``?``) in
|
|
|
|
the argument, returns ``*string*``, making a glob string that matches
|
|
|
|
anything containing the given argument.
|
|
|
|
|
|
|
|
* somethingWithoutSpaces
|
|
|
|
|
|
|
|
- Same as something, only with the exception of disallowing spaces of course.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* capability
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
- Used to retrieve an argument that describes a capability.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* channelDb
|
|
|
|
|
|
|
|
- Sets the channel appropriately in order to get to the databases for that
|
2006-03-13 16:39:38 +01:00
|
|
|
channel (handles whether or not a given channel uses channel-specific
|
|
|
|
databases and whatnot).
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* hostmask
|
|
|
|
|
|
|
|
- Returns the hostmask of any provided nick or hostmask argument.
|
|
|
|
|
|
|
|
* banmask
|
|
|
|
|
|
|
|
- Returns a generic banmask of the provided nick or hostmask argument.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* user
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
- Requires that the caller be a registered user.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* matches, regexp, errmsg
|
|
|
|
|
|
|
|
- Searches the args with the given regexp and returns the matches. If no
|
2006-03-13 16:39:38 +01:00
|
|
|
match is found, errmsg is given.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* public
|
|
|
|
|
|
|
|
- Requires that the command be sent in a channel instead of a private
|
2006-03-13 16:39:38 +01:00
|
|
|
message.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* private
|
|
|
|
|
|
|
|
- Requires that the command be sent in a private message instead of a
|
2006-03-13 16:39:38 +01:00
|
|
|
channel.
|
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* otherUser
|
|
|
|
|
|
|
|
- Returns the user specified by the username or hostmask in the argument.
|
|
|
|
|
|
|
|
* regexpMatcher
|
|
|
|
|
|
|
|
- Gets a matching regexp argument (m// or //).
|
|
|
|
|
|
|
|
* validChannel
|
|
|
|
|
|
|
|
- Gets a channel argument once it makes sure it's a valid channel.
|
|
|
|
|
|
|
|
* regexpReplacer
|
|
|
|
|
|
|
|
- Gets a replacing regexp argument (s//).
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* owner
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
- Requires that the command caller has the "owner" capability.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* admin
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
- Requires that the command caller has the "admin" capability.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
* checkCapability, capability
|
2006-03-13 16:39:38 +01:00
|
|
|
|
2010-08-25 00:24:52 +02:00
|
|
|
- Checks to make sure that the caller has the specified capability.
|
2006-03-13 16:39:38 +01:00
|
|
|
|
|
|
|
"checkChannelCapability", capability
|
|
|
|
Checks to make sure that the caller has the specified capability on the
|
|
|
|
channel the command is called in.
|
|
|
|
|
|
|
|
Contexts List
|
|
|
|
=============
|
|
|
|
What contexts are available for me to use?
|
|
|
|
|
|
|
|
The list of available contexts is below. Unless specified otherwise, it can be
|
|
|
|
assumed that the type returned by the context itself matches the type of the
|
|
|
|
converter it is applied to.
|
|
|
|
|
|
|
|
any
|
|
|
|
Looks for any number of arguments matching the supplied converter. Will
|
|
|
|
return a sequence of converted arguments or None.
|
|
|
|
|
|
|
|
many
|
|
|
|
Looks for multiple arguments matching the supplied converter. Expects at
|
|
|
|
least one to work, otherwise it will fail. Will return the sequence of
|
|
|
|
converted arguments.
|
|
|
|
|
|
|
|
optional
|
|
|
|
Look for an argument that satisfies the supplied converter, but if it's not
|
|
|
|
the type I'm expecting or there are no arguments for us to check, then use
|
|
|
|
the default value. Will return the converted argument as is or None.
|
|
|
|
|
|
|
|
additional
|
|
|
|
Look for an argument that satisfies the supplied converter, making sure
|
|
|
|
that it's the right type. If there aren't any arguments to check, then use
|
|
|
|
the default value. Will return the converted argument as is or None.
|
|
|
|
|
|
|
|
rest
|
|
|
|
Treat the rest of the arguments as one big string, and then convert. If the
|
|
|
|
conversion is unsuccessful, restores the arguments.
|
|
|
|
|
|
|
|
getopts
|
|
|
|
Handles --option style arguments. Each option should be a key in a
|
|
|
|
dictionary that maps to the name of the converter that is to be used on
|
|
|
|
that argument. To make the option take no argument, use "" as the converter
|
|
|
|
name in the dictionary. For no conversion, use None as the converter name
|
|
|
|
in the dictionary.
|
|
|
|
|
|
|
|
first
|
|
|
|
Tries each of the supplied converters in order and returns the result of
|
|
|
|
the first successfully applied converter.
|
|
|
|
|
|
|
|
reverse
|
|
|
|
Reverse the argument list, apply the converters, and then reverse the
|
|
|
|
argument list back.
|
|
|
|
|
|
|
|
commalist
|
|
|
|
Looks for a comma separated list of arguments that match the supplied
|
|
|
|
converter. Returns a list of the successfully converted arguments. If any
|
|
|
|
of the arguments fail, this whole context fails.
|
|
|
|
|
|
|
|
|
|
|
|
Final Word
|
|
|
|
==========
|
|
|
|
|
|
|
|
Now that you know how to use wrap, and you have a list of converters and
|
|
|
|
contexts you can use, your task of writing clean, simple, and safe plugin code
|
|
|
|
should become much easier. Enjoy!
|
|
|
|
|