Updated to use the helper functions conf.register*

This commit is contained in:
Jeremy Fincher 2004-07-23 06:54:29 +00:00
parent 3d039fcdc4
commit 2e4a8e3567
3 changed files with 118 additions and 98 deletions

View File

@ -270,14 +270,15 @@ class Tokenizer:
args[-1].append(ends.pop()) args[-1].append(ends.pop())
return args return args
def tokenize(s, brackets=None): def tokenize(s, brackets=None, channel=None):
"""A utility function to create a Tokenizer and tokenize a string.""" """A utility function to create a Tokenizer and tokenize a string."""
start = time.time() start = time.time()
try: try:
tokens = brackets
if brackets is None: if brackets is None:
tokens = conf.supybot.reply.brackets() tokens = conf.channelValue(conf.supybot.reply.brackets, channel)
if conf.supybot.reply.pipeSyntax(): else:
tokens = brackets
if conf.channelValue(conf.supybot.reply.pipeSyntax, channel):
tokens = '%s|' % tokens tokens = '%s|' % tokens
return Tokenizer(tokens).tokenize(s) return Tokenizer(tokens).tokenize(s)
except ValueError, e: except ValueError, e:
@ -304,11 +305,11 @@ def findCallbackForCommand(irc, commandName):
L.append(callback) L.append(callback)
return L return L
def formatArgumentError(method, name=None): def formatArgumentError(method, name=None, channel=None):
if name is None: if name is None:
name = method.__name__ name = method.__name__
if hasattr(method, '__doc__') and method.__doc__: if hasattr(method, '__doc__') and method.__doc__:
if conf.supybot.showSimpleSyntax(): if conf.channelValue(conf.supybot.reply.showSimpleSyntax, channel):
return getSyntax(method, name=name) return getSyntax(method, name=name)
else: else:
return getHelp(method, name=name) return getHelp(method, name=name)

View File

@ -103,6 +103,12 @@ def registerPlugin(name, currentValue=None):
supybot.plugins.get(name).setValue(currentValue) supybot.plugins.get(name).setValue(currentValue)
return registerGroup(users.plugins, name) return registerGroup(users.plugins, name)
def channelValue(group, channel=None):
if channel is None:
return group()
else:
return group.get(channel)()
### ###
# The user info registry. # The user info registry.
### ###
@ -294,79 +300,87 @@ registerChannelValue(supybot.reply, 'pipeSyntax',
option will allow nested commands with a syntax similar to UNIX pipes, for option will allow nested commands with a syntax similar to UNIX pipes, for
example: 'bot: foo | bar'.""")) example: 'bot: foo | bar'."""))
supybot.reply.register('whenNotCommand', registry.Boolean(True, """ registerChannelValue(supybot.reply, 'whenNotCommand',
Determines whether the bot will reply with an error message when it is registry.Boolean(True, """Determines whether the bot will reply with an
addressed but not given a valid command. If this value is False, the bot error message when it is addressed but not given a valid command. If this
will remain silent.""")) value is False, the bot will remain silent."""))
supybot.reply.register('detailedErrors', registry.Boolean(False, """Determines registerGlobalValue(supybot.reply, 'detailedErrors',
whether error messages that result from bugs in the bot will show a detailed registry.Boolean(False, """Determines whether error messages that result
error message (the uncaught exception) or a generic error message.""")) from bugs in the bot will show a detailed error message (the uncaught
exception) or a generic error message."""))
supybot.reply.register('errorInPrivate', registry.Boolean(False, """ registerChannelValue(supybot.reply, 'errorInPrivate',
Determines whether the bot will send error messages to users in private. You registry.Boolean(False, """Determines whether the bot will send error
might want to do this in order to keep channel traffic to minimum. This can messages to users in private. You might want to do this in order to keep
be used in combination with supybot.reply.errorWithNotice.""")) channel traffic to minimum. This can be used in combination with
supybot.reply.errorWithNotice."""))
supybot.reply.register('errorWithNotice', registry.Boolean(False, """ registerChannelValue(supybot.reply, 'errorWithNotice',
Determines whether the bot will send error messages to users via NOTICE instead registry.Boolean(False, """Determines whether the bot will send error
of PRIVMSG. You might want to do this so users can ignore NOTICEs from the bot messages to users via NOTICE instead of PRIVMSG. You might want to do this
and not have to see error messages; or you might want to use it in combination so users can ignore NOTICEs from the bot and not have to see error
with supybot.reply.errorInPrivate so private errors don't open a query window messages; or you might want to use it in combination with
supybot.reply.errorInPrivate so private errors don't open a query window
in most IRC clients.""")) in most IRC clients."""))
supybot.reply.register('noCapabilityError', registry.Boolean(False, """ registerChannelValue(supybot.reply, 'noCapabilityError',
Determines whether the bot will send an error message to users who attempt to registry.Boolean(False, """Determines whether the bot will send an error
call a command for which they do not have the necessary capability. You may message to users who attempt to call a command for which they do not have
wish to make this True if you don't want users to understand the underlying the necessary capability. You may wish to make this True if you don't want
security system preventing them from running certain commands.""")) users to understand the underlying security system preventing them from
running certain commands."""))
supybot.reply.register('withPrivateNotice', registry.Boolean(False, """ registerChannelValue(supybot.reply, 'withPrivateNotice',
Determines whether the bot will reply with a private notice to users rather registry.Boolean(False, """Determines whether the bot will reply with a
than sending a message to a channel. Private notices are particularly nice private notice to users rather than sending a message to a channel.
because they don't generally cause IRC clients to open a new query window.""")) Private notices are particularly nice because they don't generally cause
IRC clients to open a new query window."""))
supybot.reply.register('withNickPrefix', registry.Boolean(True, """ registerChannelValue(supybot.reply, 'withNickPrefix',
Determines whether the bot will always prefix the user's nick to its reply to registry.Boolean(True, """Determines whether the bot will always prefix the
that user's command.""")) user's nick to its reply to that user's command."""))
supybot.reply.register('whenAddressedByNick', registry.Boolean(True, """ registerChannelValue(supybot.reply, 'whenAddressedByNick',
Determines whether the bot will reply when people address it by its nick, registry.Boolean(True, """Determines whether the bot will reply when people
rather than with a prefix character.""")) address it by its nick, rather than with a prefix character."""))
supybot.reply.register('whenNotAddressed', registry.Boolean(False, """ registerChannelValue(supybot.reply, 'whenNotAddressed',
Determines whether the bot should attempt to reply to all messages even if they registry.Boolean(False, """Determines whether the bot should attempt to
don't address it (either via its nick or a prefix character). If you set this reply to all messages even if they don't address it (either via its nick
to True, you almost certainly want to set supybot.reply.whenNotCommand to or a prefix character). If you set this to True, you almost certainly want
False.""")) to set supybot.reply.whenNotCommand to False."""))
supybot.reply.register('requireChannelCommandsToBeSentInChannel', registerChannelValue(supybot.reply, 'requireChannelCommandsToBeSentInChannel',
registry.Boolean(False, """Determines whether the bot will allow you to send registry.Boolean(False, """Determines whether the bot will allow you to
channel-related commands outside of that channel. Sometimes people find it send channel-related commands outside of that channel. Sometimes people
confusing if a channel-related command (like Filter.outfilter) changes the find it confusing if a channel-related command (like Filter.outfilter)
behavior of the channel but was sent outside the channel itself.""")) changes the behavior of the channel but was sent outside the channel
itself."""))
supybot.register('followIdentificationThroughNickChanges', registerGlobalValue(supybot, 'followIdentificationThroughNickChanges',
registry.Boolean(False, """Determines whether the bot will unidentify someone registry.Boolean(False, """Determines whether the bot will unidentify
when that person changes his or her nick. Setting this to True will cause the someone when that person changes his or her nick. Setting this to True
bot to track such changes. It defaults to false for a little greater security. will cause the bot to track such changes. It defaults to False for a
""")) little greater security."""))
supybot.register('alwaysJoinOnInvite', registry.Boolean(False, """Determines registerGlobalValue(supybot, 'alwaysJoinOnInvite',
whether the bot will always join a channel when it's invited. If this value registry.Boolean(False, """Determines whether the bot will always join a
is False, the bot will only join a channel if the user inviting it has the channel when it's invited. If this value is False, the bot will only join
'admin' capability (or if it's explicitly told to join the channel using the a channel if the user inviting it has the 'admin' capability (or if it's
Admin.join command)""")) explicitly told to join the channel using the Admin.join command)"""))
supybot.register('showSimpleSyntax', registry.Boolean(False, """Supybot # XXX: ChannelValue not respected for this.
normally replies with the full help whenever a user misuses a command. If this registerChannelValue(supybot.reply, 'showSimpleSyntax',
value is set to True, the bot will only reply with the syntax of the command registry.Boolean(False, """Supybot normally replies with the full help
(the first line of the docstring) rather than the full help.""")) whenever a user misuses a command. If this value is set to True, the bot
will only reply with the syntax of the command (the first line of the
help) rather than the full help."""))
### ###
# Replies # Replies
### ###
supybot.register('replies') registerGroup(supybot, 'replies')
registerChannelValue(supybot.replies, 'success', registerChannelValue(supybot.replies, 'success',
registry.NormalizedString("""The operation succeeded.""", """Determines registry.NormalizedString("""The operation succeeded.""", """Determines
@ -436,29 +450,31 @@ registerChannelValue(supybot.replies, 'possibleBug',
# End supybot.replies. # End supybot.replies.
### ###
# XXX: This should be SpaceSeparated, if it survives.
supybot.register('nickmods', registry.CommaSeparatedListOfStrings( supybot.register('nickmods', registry.CommaSeparatedListOfStrings(
'__%s__,%s^,%s`,%s_,%s__,_%s,__%s,[%s]'.split(','), '__%s__,%s^,%s`,%s_,%s__,_%s,__%s,[%s]'.split(','),
"""A list of modifications to be made to a nick when the nick the bot tries """A list of modifications to be made to a nick when the nick the bot tries
to get from the server is in use. There should be one %s in each string; to get from the server is in use. There should be one %s in each string;
this will get replaced with the original nick.""")) this will get replaced with the original nick."""))
supybot.register('snarfThrottle', registry.Float(10.0, """A floating point registerGlobalValue(supybot, 'snarfThrottle',
number of seconds to throttle snarfed URLs, in order to prevent loops between registry.Float(10.0, """A floating point number of seconds to throttle
two bots snarfing the same URLs and having the snarfed URL in the output of snarfed URLs, in order to prevent loops between two bots snarfing the same
the snarf message.""")) URLs and having the snarfed URL in the output of the snarf message."""))
supybot.register('upkeepInterval', registry.PositiveInteger(3600, """Determines registerGlobalValue(supybot, 'upkeepInterval',
the number of seconds between running the upkeep function that flushes registry.PositiveInteger(3600, """Determines the number of seconds between
(commits) open databases, collects garbage, and records some useful statistics running the upkeep function that flushes (commits) open databases, collects
at the debugging level.""")) garbage, and records some useful statistics at the debugging level."""))
supybot.register('flush', registry.Boolean(True, """Determines whether the bot registerGlobalValue(supybot, 'flush',
will periodically flush data and configuration files to disk. Generally, the registry.Boolean(True, """Determines whether the bot will periodically
only time you'll want to set this to False is when you want to modify those flush data and configuration files to disk. Generally, the only time
configuration files by hand and don't want the bot to flush its current version you'll want to set this to False is when you want to modify those
over your modifications. Do note that if you change this to False inside the configuration files by hand and don't want the bot to flush its current
bot, your changes won't be flushed. To make this change permanent, you must version over your modifications. Do note that if you change this to False
edit the registry yourself.""")) inside the bot, your changes won't be flushed. To make this change
permanent, you must edit the registry yourself."""))
### ###
# supybot.drivers. For stuff relating to Supybot's drivers (duh!) # supybot.drivers. For stuff relating to Supybot's drivers (duh!)

View File

@ -253,18 +253,21 @@ class LogLevel(ValidLogLevel):
ValidLogLevel.setValue(self, v) ValidLogLevel.setValue(self, v)
_logger.setLevel(self.value) # _logger defined later. _logger.setLevel(self.value) # _logger defined later.
conf.supybot.directories.register('log', registry.String('logs', """Determines conf.registerGlobalValue(conf.supybot.directories, 'log',
what directory the bot will store its logfiles in.""")) registry.String('logs', """Determines what directory the bot will store its
logfiles in."""))
conf.supybot.register('log') conf.registerGroup(conf.supybot, 'log')
conf.supybot.log.register('level', LogLevel(logging.INFO, """Determines what conf.registerGlobalValue(conf.supybot.log, 'level',
the minimum priority level logged will be. Valid values are DEBUG, INFO, LogLevel(logging.INFO, """Determines what the minimum priority level logged
WARNING, ERROR, and CRITICAL, in order of increasing priority.""")) will be. Valid values are DEBUG, INFO, WARNING, ERROR, and CRITICAL, in
conf.supybot.log.register('stdout', registry.Boolean(True, """Determines order of increasing priority."""))
whether the bot will log to stdout.""")) conf.registerGlobalValue(conf.supybot.log, 'stdout',
conf.supybot.log.register('individualPluginLogfiles', registry.Boolean(True, registry.Boolean(True, """Determines whether the bot will log to
"""Determines whether the bot will separate plugin logs into their own stdout."""))
individual logfiles.""")) conf.registerGlobalValue(conf.supybot.log, 'individualPluginLogfiles',
registry.Boolean(True, """Determines whether the bot will separate plugin
logs into their own individual logfiles."""))
class BooleanRequiredFalseOnWindows(registry.Boolean): class BooleanRequiredFalseOnWindows(registry.Boolean):
def set(self, s): def set(self, s):
@ -272,16 +275,16 @@ class BooleanRequiredFalseOnWindows(registry.Boolean):
if self.value and os.name == 'nt': if self.value and os.name == 'nt':
raise InvalidRegistryValue, 'Value cannot be true on Windows.' raise InvalidRegistryValue, 'Value cannot be true on Windows.'
conf.supybot.log.stdout.register('colorized', conf.registerGlobalValue(conf.supybot.log.stdout, 'colorized',
BooleanRequiredFalseOnWindows(False, """Determines whether the bot's logs to BooleanRequiredFalseOnWindows(False, """Determines whether the bot's logs
stdout (if enabled) will be colorized with ANSI color.""")) to stdout (if enabled) will be colorized with ANSI color."""))
conf.supybot.log.register('timestampFormat', conf.registerGlobalValue(conf.supybot.log, 'timestampFormat',
registry.String('[%d-%b-%Y %H:%M:%S]', registry.String('[%d-%b-%Y %H:%M:%S]', """Determines the format string for
"""Determines the format string for timestamps in logfiles. Refer to the timestamps in logfiles. Refer to the Python documentation for the time
Python documentation for the time module to see what formats are accepted. module to see what formats are accepted. If you set this variable to the
If you set this variable to the empty string, times will be logged in a empty string, times will be logged in a simple seconds-since-epoch
simple seconds-since-epoch format.""")) format."""))
_logDir = conf.supybot.directories.log() _logDir = conf.supybot.directories.log()
if not os.path.exists(_logDir): if not os.path.exists(_logDir):