Added removeAlias method for easy access from within other plugins.

This commit is contained in:
Jeremy Fincher 2003-09-10 21:15:09 +00:00
parent dca69510f3
commit 273e4a7a0c
2 changed files with 20 additions and 13 deletions

View File

@ -191,6 +191,16 @@ class Alias(callbacks.Privmsg):
if freeze:
self.frozen.add(name)
def removeAlias(self, name, evenIfFrozen=False):
name = callbacks.canonicalName(name)
if hasattr(self, name) and self.isCommand(name):
if evenIfFrozen or name not in self.frozen:
delattr(self.__class__, name)
else:
raise AliasError, 'That alias is frozen.'
else:
raise AliasError, 'There is no such alias.'
def alias(self, irc, msg, args):
"""<name> <alias commands>
@ -212,17 +222,11 @@ class Alias(callbacks.Privmsg):
Removes the given alias, if unfrozen.
"""
name = privmsgs.getArgs(args)
name = callbacks.canonicalName(name)
if hasattr(self, name) and self.isCommand(name):
if name not in self.frozen:
delattr(self.__class__, name)
irc.reply(msg, conf.replySuccess)
else:
irc.error(msg, 'That alias is frozen.')
else:
irc.error(msg, 'There is no such alias.')
try:
self.removeAlias(name)
irc.reply(msg, conf.replySuccess)
except AliasError, e:
irc.error(msg, str(e))
Class = Alias

View File

@ -102,10 +102,13 @@ class AliasTestCase(PluginTestCase, PluginDocumentation):
self.assertNotError('mytell #foo bugs')
self.assertNoResponse('blah blah blah', 2)
def testAddAlias(self):
def testAddRemoveAlias(self):
cb = self.irc.getCallback('Alias')
cb.addAlias(self.irc, 'foobar', 'rot13 foobar')
cb.addAlias(self.irc, 'foobar', 'rot13 foobar', freeze=True)
self.assertResponse('foobar', 'sbbone')
self.assertRaises(Alias.AliasError, cb.removeAlias, 'foobar')
cb.removeAlias('foobar', evenIfFrozen=True)
self.assertNoResponse('foobar', 2)