mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-25 12:19:24 +01:00
callbacks: Add/improve method docstrings
This commit is contained in:
parent
66ba7cb020
commit
f11684a1cf
@ -894,19 +894,30 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
|
|||||||
"""
|
"""
|
||||||
Keyword arguments:
|
Keyword arguments:
|
||||||
|
|
||||||
* `noLengthCheck=False`: True if the length shouldn't be checked
|
:arg bool noLengthCheck:
|
||||||
(used for 'more' handling)
|
True if the length shouldn't be checked (used for 'more' handling)
|
||||||
* `prefixNick=True`: False if the nick shouldn't be prefixed to the
|
|
||||||
reply.
|
:arg bool prefixNick:
|
||||||
* `action=False`: True if the reply should be an action.
|
False if the nick shouldn't be prefixed to the reply.
|
||||||
* `private=False`: True if the reply should be in private.
|
|
||||||
* `notice=False`: True if the reply should be noticed when the
|
:arg bool action:
|
||||||
bot is configured to do so.
|
True if the reply should be an action.
|
||||||
* `to=<nick|channel>`: The nick or channel the reply should go to.
|
|
||||||
Defaults to msg.args[0] (or msg.nick if private)
|
:arg bool private:
|
||||||
* `sendImmediately=False`: True if the reply should use sendMsg() which
|
True if the reply should be in private.
|
||||||
bypasses conf.supybot.protocols.irc.throttleTime
|
|
||||||
and gets sent before any queued messages
|
:arg bool notice:
|
||||||
|
True if the reply should be noticed when the bot is configured
|
||||||
|
to do so.
|
||||||
|
|
||||||
|
:arg str to:
|
||||||
|
The nick or channel the reply should go to.
|
||||||
|
Defaults to msg.args[0] (or msg.nick if private)
|
||||||
|
|
||||||
|
:arg bool sendImmediately:
|
||||||
|
True if the reply should use sendMsg() which
|
||||||
|
bypasses conf.supybot.protocols.irc.throttleTime
|
||||||
|
and gets sent before any queued messages
|
||||||
"""
|
"""
|
||||||
# These use and or or based on whether or not they default to True or
|
# These use and or or based on whether or not they default to True or
|
||||||
# False. Those that default to True use and; those that default to
|
# False. Those that default to True use and; those that default to
|
||||||
@ -1369,16 +1380,22 @@ class Commands(BasePlugin, SynchronizedAndFirewalled):
|
|||||||
_disabled = DisabledCommands()
|
_disabled = DisabledCommands()
|
||||||
pre_command_callbacks = []
|
pre_command_callbacks = []
|
||||||
def name(self):
|
def name(self):
|
||||||
|
"""Returns the name of this Commands object (usually the plugin
|
||||||
|
name)."""
|
||||||
return self.__class__.__name__
|
return self.__class__.__name__
|
||||||
|
|
||||||
def canonicalName(self):
|
def canonicalName(self):
|
||||||
|
"""Same as :py:meth:`name`, but normalized."""
|
||||||
return canonicalName(self.name())
|
return canonicalName(self.name())
|
||||||
|
|
||||||
def isDisabled(self, command):
|
def isDisabled(self, command):
|
||||||
|
"""Returns whether the given ``command`` is disabled."""
|
||||||
return self._disabled.disabled(command, self.name())
|
return self._disabled.disabled(command, self.name())
|
||||||
|
|
||||||
def isCommandMethod(self, name):
|
def isCommandMethod(self, name):
|
||||||
"""Returns whether a given method name is a command in this plugin."""
|
"""Returns whether a given method name is a command in this plugin.
|
||||||
|
Plugins only need to implement this if they have a dynamic set of
|
||||||
|
commands."""
|
||||||
# This function is ugly, but I don't want users to call methods like
|
# This function is ugly, but I don't want users to call methods like
|
||||||
# doPrivmsg or __init__ or whatever, and this is good to stop them.
|
# doPrivmsg or __init__ or whatever, and this is good to stop them.
|
||||||
|
|
||||||
@ -1409,6 +1426,9 @@ class Commands(BasePlugin, SynchronizedAndFirewalled):
|
|||||||
return self.getCommand(command) == command
|
return self.getCommand(command) == command
|
||||||
|
|
||||||
def getCommand(self, args, stripOwnName=True):
|
def getCommand(self, args, stripOwnName=True):
|
||||||
|
"""Among all the commands in this Commands object, recursively
|
||||||
|
searches for the command whose name is the longst substring
|
||||||
|
of ``args``, and returns its name, splitted on spaces."""
|
||||||
assert args == list(map(canonicalName, args))
|
assert args == list(map(canonicalName, args))
|
||||||
first = args[0]
|
first = args[0]
|
||||||
for cb in self.cbs:
|
for cb in self.cbs:
|
||||||
@ -1424,7 +1444,10 @@ class Commands(BasePlugin, SynchronizedAndFirewalled):
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
def getCommandMethod(self, command):
|
def getCommandMethod(self, command):
|
||||||
"""Gets the given command from this plugin."""
|
"""Gets the given command from this plugin, using
|
||||||
|
:py:meth:`getCommand`.
|
||||||
|
Plugins only need to implement this if they have a dynamic set of
|
||||||
|
commands."""
|
||||||
#print '*** %s.getCommandMethod(%r)' % (self.name(), command)
|
#print '*** %s.getCommandMethod(%r)' % (self.name(), command)
|
||||||
assert not isinstance(command, minisix.string_types)
|
assert not isinstance(command, minisix.string_types)
|
||||||
assert command == list(map(canonicalName, command))
|
assert command == list(map(canonicalName, command))
|
||||||
@ -1445,6 +1468,9 @@ class Commands(BasePlugin, SynchronizedAndFirewalled):
|
|||||||
raise AttributeError
|
raise AttributeError
|
||||||
|
|
||||||
def listCommands(self, pluginCommands=[]):
|
def listCommands(self, pluginCommands=[]):
|
||||||
|
"""List all the commands in this ``Commands`` object.
|
||||||
|
Plugins only need to implement this if they have a dynamic set of
|
||||||
|
commands."""
|
||||||
commands = set(pluginCommands)
|
commands = set(pluginCommands)
|
||||||
for s in dir(self):
|
for s in dir(self):
|
||||||
if self.isCommandMethod(s):
|
if self.isCommandMethod(s):
|
||||||
@ -1461,6 +1487,8 @@ class Commands(BasePlugin, SynchronizedAndFirewalled):
|
|||||||
return L
|
return L
|
||||||
|
|
||||||
def callCommand(self, command, irc, msg, *args, **kwargs):
|
def callCommand(self, command, irc, msg, *args, **kwargs):
|
||||||
|
"""Given a command name, gets the method with
|
||||||
|
:py:meth:`getCommandMethod` and calls it."""
|
||||||
# We run all callbacks before checking if one of them returned True
|
# We run all callbacks before checking if one of them returned True
|
||||||
if any(bool, list(cb(self, command, irc, msg, *args, **kwargs)
|
if any(bool, list(cb(self, command, irc, msg, *args, **kwargs)
|
||||||
for cb in self.pre_command_callbacks)):
|
for cb in self.pre_command_callbacks)):
|
||||||
@ -1526,6 +1554,8 @@ class Commands(BasePlugin, SynchronizedAndFirewalled):
|
|||||||
irc.replyError(msg=msg)
|
irc.replyError(msg=msg)
|
||||||
|
|
||||||
def getCommandHelp(self, command, simpleSyntax=None):
|
def getCommandHelp(self, command, simpleSyntax=None):
|
||||||
|
"""Returns the help string of the given command, using
|
||||||
|
:py:meth:`getCommandMethod`."""
|
||||||
method = self.getCommandMethod(command)
|
method = self.getCommandMethod(command)
|
||||||
help = getHelp
|
help = getHelp
|
||||||
chan = None
|
chan = None
|
||||||
@ -1581,6 +1611,16 @@ class PluginMixin(BasePlugin, irclib.IrcCallback):
|
|||||||
self.__parent.__call__(irc, msg)
|
self.__parent.__call__(irc, msg)
|
||||||
|
|
||||||
def registryValue(self, name, channel=None, network=None, *, value=True):
|
def registryValue(self, name, channel=None, network=None, *, value=True):
|
||||||
|
"""Returns the value of a configuration variable specified by
|
||||||
|
``name``.
|
||||||
|
|
||||||
|
If the configuration variable has a channel- or network-specific
|
||||||
|
variable (ie. if its value can change across channels or networks),
|
||||||
|
``channel`` and ``network`` allow getting the most specific value.
|
||||||
|
If neither is given, returns the generic value.
|
||||||
|
|
||||||
|
If ``value=False``, returns the variable itself (an instance
|
||||||
|
of :py:class:`supybot.registry.Value`) instead of its value."""
|
||||||
if isinstance(network, bool):
|
if isinstance(network, bool):
|
||||||
# Network-unaware plugin that uses 'value' as a positional
|
# Network-unaware plugin that uses 'value' as a positional
|
||||||
# argument.
|
# argument.
|
||||||
@ -1598,6 +1638,7 @@ class PluginMixin(BasePlugin, irclib.IrcCallback):
|
|||||||
return group
|
return group
|
||||||
|
|
||||||
def setRegistryValue(self, name, value, channel=None, network=None):
|
def setRegistryValue(self, name, value, channel=None, network=None):
|
||||||
|
"""Sets a configuration variable. See :py:meth:`registryValue`"""
|
||||||
plugin = self.name()
|
plugin = self.name()
|
||||||
group = conf.supybot.plugins.get(plugin)
|
group = conf.supybot.plugins.get(plugin)
|
||||||
names = registry.split(name)
|
names = registry.split(name)
|
||||||
|
Loading…
Reference in New Issue
Block a user