Updated to use commands.wrap.

This commit is contained in:
Jeremy Fincher 2004-12-06 22:46:13 +00:00
parent eac5d2f9f8
commit fee37e43cc

View File

@ -50,6 +50,7 @@ import string
import supybot.dbi as dbi import supybot.dbi as dbi
import supybot.conf as conf import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
from supybot.commands import *
import supybot.privmsgs as privmsgs import supybot.privmsgs as privmsgs
import supybot.registry as registry import supybot.registry as registry
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
@ -250,13 +251,11 @@ class Lookup(callbacks.Privmsg):
def die(self): def die(self):
self.db.close() self.db.close()
def remove(self, irc, msg, args): def remove(self, irc, msg, args, name):
"""<name> """<name>
Removes the lookup for <name>. Removes the lookup for <name>.
""" """
name = privmsgs.getArgs(args)
name = callbacks.canonicalName(name)
if name not in self.lookupDomains: if name not in self.lookupDomains:
irc.error('That\'s not a valid lookup to remove.') irc.error('That\'s not a valid lookup to remove.')
return return
@ -267,10 +266,10 @@ class Lookup(callbacks.Privmsg):
irc.replySuccess() irc.replySuccess()
except dbi.NoRecordError: except dbi.NoRecordError:
irc.error('No such lookup exists.') irc.error('No such lookup exists.')
remove = privmsgs.checkCapability(remove, 'admin') remove = wrap(remove, [('checkCapability', 'admin'), 'commandName'])
_splitRe = re.compile(r'(?<!\\):') _splitRe = re.compile(r'(?<!\\):')
def add(self, irc, msg, args): def add(self, irc, msg, args, optlist, name, filename):
"""[--nokey] <name> <filename> """[--nokey] <name> <filename>
Adds a lookup for <name> with the key/value pairs specified in the Adds a lookup for <name> with the key/value pairs specified in the
@ -280,17 +279,11 @@ class Lookup(callbacks.Privmsg):
option is specified, the new lookup will display only the value when option is specified, the new lookup will display only the value when
queried, and will omit the key from the response. queried, and will omit the key from the response.
""" """
opts = ['nokey']
(optlist, rest) = getopt.getopt(args, '', opts)
(name, filename) = privmsgs.getArgs(rest, required=2)
nokey = False nokey = False
for (option, argument) in optlist: for (option, argument) in optlist:
option = option.lstrip('-')
if option == 'nokey': if option == 'nokey':
nokey = True nokey = True
#print 'nokey: %s' % nokey
name = utils.depluralize(name) name = utils.depluralize(name)
name = callbacks.canonicalName(name)
if hasattr(self, name): if hasattr(self, name):
s = 'I already have a command in this plugin named %s' % name s = 'I already have a command in this plugin named %s' % name
irc.error(s) irc.error(s)
@ -304,7 +297,8 @@ class Lookup(callbacks.Privmsg):
self.addCommand(name) self.addCommand(name)
self.addRegistryValue(name, filename, nokey) self.addRegistryValue(name, filename, nokey)
irc.replySuccess('Lookup %s added.' % name) irc.replySuccess('Lookup %s added.' % name)
add = privmsgs.checkCapability(add, 'admin') add = wrap(add, [('checkCapability', 'admin'), getopts({'nokey':''}),
'commandName', 'filename'])
def addRegistryValue(self, name, filename, nokey = False): def addRegistryValue(self, name, filename, nokey = False):
group = conf.supybot.plugins.Lookup.lookups group = conf.supybot.plugins.Lookup.lookups
@ -363,12 +357,11 @@ class Lookup(callbacks.Privmsg):
else: else:
irc.error('I don\'t have a domain %s' % name) irc.error('I don\'t have a domain %s' % name)
def _lookup(self, irc, msg, args): def _lookup(self, irc, msg, args, name, key):
"""<name> <key> """<name> <key>
Looks up the value of <key> in the domain <name>. Looks up the value of <key> in the domain <name>.
""" """
(name, key) = privmsgs.getArgs(args, optional=1)
if self.db.checkLookup(name): if self.db.checkLookup(name):
results = [] results = []
if key: if key:
@ -391,7 +384,7 @@ class Lookup(callbacks.Privmsg):
irc.reply('%s' % value) irc.reply('%s' % value)
else: else:
irc.error('I don\'t have a domain %s' % name) irc.error('I don\'t have a domain %s' % name)
return _lookup = wrap(_lookup, ['something', additional('text')])
Class = Lookup Class = Lookup