From 273e4a7a0cf51a25ab81d1a88b07716c98b986a2 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Wed, 10 Sep 2003 21:15:09 +0000 Subject: [PATCH] Added removeAlias method for easy access from within other plugins. --- plugins/Alias.py | 26 +++++++++++++++----------- test/test_Alias.py | 7 +++++-- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/plugins/Alias.py b/plugins/Alias.py index 39b090b0b..f22babe9f 100644 --- a/plugins/Alias.py +++ b/plugins/Alias.py @@ -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): """ @@ -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 diff --git a/test/test_Alias.py b/test/test_Alias.py index 2d679bd9f..72d022baa 100644 --- a/test/test_Alias.py +++ b/test/test_Alias.py @@ -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)