Aka: Add @importAliasDatabase command.

This commit is contained in:
Valentin Lorentz 2013-07-31 19:08:49 +02:00
parent d5c0df39f3
commit 41581dac2f
2 changed files with 54 additions and 1 deletions

View File

@ -454,6 +454,30 @@ class Aka(callbacks.Plugin):
'channel': 'somethingWithoutSpaces', 'channel': 'somethingWithoutSpaces',
}), 'user', 'something']) }), '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 Class = Aka

View File

@ -157,7 +157,7 @@ class AkaChannelTestCase(ChannelPluginTestCase):
self.assertRegexp('fact 50', 'more nesting') self.assertRegexp('fact 50', 'more nesting')
class AkaTestCase(PluginTestCase): class AkaTestCase(PluginTestCase):
plugins = ('Aka', 'User') plugins = ('Aka', 'Alias', 'User', 'Utilities')
def testAkaLockedHelp(self): def testAkaLockedHelp(self):
self.assertNotError('register evil_admin foo') self.assertNotError('register evil_admin foo')
@ -170,4 +170,33 @@ class AkaTestCase(PluginTestCase):
self.assertNotError('aka unlock slashdot') self.assertNotError('aka unlock slashdot')
self.assertNotRegexp('help slashdot', 'Locked by') 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: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: