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

View File

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