Converted Alias to use commands.wrap (for the most part).

This commit is contained in:
Jeremy Fincher 2004-11-11 16:37:47 +00:00
parent a0e863deef
commit ed2488c1f8
2 changed files with 13 additions and 14 deletions

View File

@ -44,6 +44,7 @@ import sets
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
@ -185,35 +186,31 @@ class Alias(callbacks.Privmsg):
del self.__class__.__call__ del self.__class__.__call__
callbacks.Privmsg.__call__(self, irc, msg) callbacks.Privmsg.__call__(self, irc, msg)
def lock(self, irc, msg, args): def lock(self, irc, msg, args, name):
"""<alias> """<alias>
Locks an alias so that no one else can change it. Locks an alias so that no one else can change it.
""" """
name = privmsgs.getArgs(args)
name = callbacks.canonicalName(name)
if hasattr(self, name) and self.isCommand(name): if hasattr(self, name) and self.isCommand(name):
self.aliases[name][1] = True self.aliases[name][1] = True
conf.supybot.plugins.Alias.aliases.get(name).locked.setValue(True) conf.supybot.plugins.Alias.aliases.get(name).locked.setValue(True)
irc.replySuccess() irc.replySuccess()
else: else:
irc.error('There is no such alias.') irc.error('There is no such alias.')
lock = privmsgs.checkCapability(lock, 'admin') lock = wrap(lock, [('checkCapability', 'admin'), 'commandName'])
def unlock(self, irc, msg, args): def unlock(self, irc, msg, args, name):
"""<alias> """<alias>
Unlocks an alias so that people can define new aliases over it. Unlocks an alias so that people can define new aliases over it.
""" """
name = privmsgs.getArgs(args)
name = callbacks.canonicalName(name)
if hasattr(self, name) and self.isCommand(name): if hasattr(self, name) and self.isCommand(name):
self.aliases[name][1] = False self.aliases[name][1] = False
conf.supybot.plugins.Alias.aliases.get(name).locked.setValue(False) conf.supybot.plugins.Alias.aliases.get(name).locked.setValue(False)
irc.replySuccess() irc.replySuccess()
else: else:
irc.error('There is no such alias.') irc.error('There is no such alias.')
unlock = privmsgs.checkCapability(unlock, 'admin') unlock = wrap(unlock, [('checkCapability', 'admin'), 'commandName'])
_invalidCharsRe = re.compile(r'[\[\]\s]') _invalidCharsRe = re.compile(r'[\[\]\s]')
def addAlias(self, irc, name, alias, lock=False): def addAlias(self, irc, name, alias, lock=False):
@ -264,18 +261,16 @@ class Alias(callbacks.Privmsg):
else: else:
raise AliasError, 'There is no such alias.' raise AliasError, 'There is no such alias.'
def add(self, irc, msg, args): def add(self, irc, msg, args, name, alias):
"""<name> <alias> """<name> <alias>
Defines an alias <name> that executes <alias>. The <alias> Defines an alias <name> that executes <alias>. The <alias>
should be in the standard "command argument [nestedcommand argument]" should be in the standard "command argument [nestedcommand argument]"
arguments to the alias; they'll be filled with the first, second, etc. arguments to the alias; they'll be filled with the first, second, etc.
arguments to the alias; they'll be filled with the first, second, etc.
arguments. @1, @2 can be used for optional arguments. $* simply arguments. @1, @2 can be used for optional arguments. $* simply
means "all remaining arguments," and cannot be combined with optional means "all remaining arguments," and cannot be combined with optional
arguments. arguments.
""" """
(name, alias) = privmsgs.getArgs(args, required=2)
if ' ' not in alias: if ' ' not in alias:
# If it's a single word, they probably want $*. # If it's a single word, they probably want $*.
alias += ' $*' alias += ' $*'
@ -286,13 +281,13 @@ class Alias(callbacks.Privmsg):
irc.replySuccess() irc.replySuccess()
except AliasError, e: except AliasError, e:
irc.error(str(e)) irc.error(str(e))
add = wrap(add, ['commandName', 'text'])
def remove(self, irc, msg, args): def remove(self, irc, msg, args, name):
"""<name> """<name>
Removes the given alias, if unlocked. Removes the given alias, if unlocked.
""" """
name = privmsgs.getArgs(args)
try: try:
self.removeAlias(name) self.removeAlias(name)
self.log.info('Removing alias %s (from %s)' % (utils.quoted(name), self.log.info('Removing alias %s (from %s)' % (utils.quoted(name),
@ -300,6 +295,7 @@ class Alias(callbacks.Privmsg):
irc.replySuccess() irc.replySuccess()
except AliasError, e: except AliasError, e:
irc.error(str(e)) irc.error(str(e))
remove = wrap(remove, ['commandName'])
Class = Alias Class = Alias

View File

@ -453,7 +453,10 @@ def getNow(irc, msg, args, state):
state.args.append(int(time.time())) state.args.append(int(time.time()))
def getCommandName(irc, msg, args, state): def getCommandName(irc, msg, args, state):
state.args.append(callbacks.canonicalName(args.pop(0))) if ' ' in args[0]:
irc.errorInvalid('command name', args[0])
else:
state.args.append(callbacks.canonicalName(args.pop(0)))
def getIp(irc, msg, args, state): def getIp(irc, msg, args, state):
if utils.isIP(args[0]): if utils.isIP(args[0]):