mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 19:19:32 +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:
|
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:
|
|
||||||
delattr(self.__class__, name)
|
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
else:
|
except AliasError, e:
|
||||||
irc.error(msg, 'That alias is frozen.')
|
irc.error(msg, str(e))
|
||||||
else:
|
|
||||||
irc.error(msg, 'There is no such alias.')
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Class = Alias
|
Class = Alias
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user