mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Added removeAlias method for easy access from within other plugins.
This commit is contained in:
parent
dca69510f3
commit
273e4a7a0c
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user