mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 05:09:23 +01:00
Aka: Add @importAliasDatabase command.
This commit is contained in:
parent
d5c0df39f3
commit
41581dac2f
@ -454,6 +454,30 @@ class Aka(callbacks.Plugin):
|
||||
'channel': 'somethingWithoutSpaces',
|
||||
}), 'user', 'something'])
|
||||
|
||||
def importaliasdatabase(self, irc, msg, args):
|
||||
"""takes no arguments
|
||||
|
||||
Imports the Alias database into Aka's, and clean the former."""
|
||||
alias_plugin = irc.getCallback('Alias')
|
||||
if alias_plugin is None:
|
||||
irc.error(_('Alias plugin is not loaded.'), Raise=True)
|
||||
errors = {}
|
||||
for (name, (command, locked, func)) in alias_plugin.aliases.items():
|
||||
try:
|
||||
self._add_aka('global', name, command)
|
||||
except AkaError as e:
|
||||
errors[name] = e.args[0]
|
||||
else:
|
||||
alias_plugin.removeAlias(name)
|
||||
if errors:
|
||||
irc.error(format(_('Error occured when importing the %n: %L'),
|
||||
(len(errors), 'following', 'command'),
|
||||
map(lambda x:'%s (%s)' % x, errors.items())))
|
||||
else:
|
||||
irc.replySuccess()
|
||||
importaliasdatabase = wrap(importaliasdatabase, ['owner'])
|
||||
|
||||
|
||||
Class = Aka
|
||||
|
||||
|
||||
|
@ -157,7 +157,7 @@ class AkaChannelTestCase(ChannelPluginTestCase):
|
||||
self.assertRegexp('fact 50', 'more nesting')
|
||||
|
||||
class AkaTestCase(PluginTestCase):
|
||||
plugins = ('Aka', 'User')
|
||||
plugins = ('Aka', 'Alias', 'User', 'Utilities')
|
||||
|
||||
def testAkaLockedHelp(self):
|
||||
self.assertNotError('register evil_admin foo')
|
||||
@ -170,4 +170,33 @@ class AkaTestCase(PluginTestCase):
|
||||
self.assertNotError('aka unlock slashdot')
|
||||
self.assertNotRegexp('help slashdot', 'Locked by')
|
||||
|
||||
def testAliasImport(self):
|
||||
self.assertNotError('alias add foo "echo bar"')
|
||||
self.assertNotError(u'alias add baz "echo café"')
|
||||
self.assertNotError('aka add qux "echo quux"')
|
||||
self.assertResponse('alias foo', 'bar')
|
||||
self.assertResponse('alias baz', 'café')
|
||||
self.assertRegexp('aka foo', 'there is no command named')
|
||||
self.assertResponse('aka qux', 'quux')
|
||||
|
||||
self.assertNotError('aka importaliasdatabase')
|
||||
|
||||
self.assertRegexp('alias foo', 'there is no command named')
|
||||
self.assertResponse('aka foo', 'bar')
|
||||
self.assertResponse('aka baz', 'café')
|
||||
self.assertResponse('aka qux', 'quux')
|
||||
|
||||
self.assertNotError('alias add foo "echo test"')
|
||||
self.assertNotError('alias add spam "echo egg"')
|
||||
|
||||
self.assertRegexp('aka importaliasdatabase',
|
||||
r'the 1 following command: foo \(This Aka already exists.\)$')
|
||||
self.assertResponse('aka foo', 'bar')
|
||||
self.assertResponse('alias foo', 'test')
|
||||
self.assertRegexp('alias spam', 'there is no command named')
|
||||
self.assertResponse('aka spam', 'egg')
|
||||
|
||||
|
||||
|
||||
|
||||
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|
||||
|
Loading…
Reference in New Issue
Block a user