From fe778c60bf6a6352f7885bc317dd8228a4560d77 Mon Sep 17 00:00:00 2001 From: GLolol Date: Tue, 16 Dec 2014 16:18:25 -0800 Subject: [PATCH 1/8] Aka: add 'list' command (Closes ProgVal/Limnoria#572) --- plugins/Aka/plugin.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/plugins/Aka/plugin.py b/plugins/Aka/plugin.py index c09a8d451..2dc2f2d01 100644 --- a/plugins/Aka/plugin.py +++ b/plugins/Aka/plugin.py @@ -713,6 +713,25 @@ class Aka(callbacks.Plugin): irc.replySuccess() importaliasdatabase = wrap(importaliasdatabase, ['owner']) + def list(self, irc, msg, args, optlist): + """[--channel] <#channel> + + Lists all Akas defined for . If is not specified, + lists all global Akas.""" + channel = 'global' + for (option, arg) in optlist: + if option == 'channel': + if not ircutils.isChannel(arg): + irc.error(_('%r is not a valid channel.') % arg, + Raise=True) + channel = arg + aka_list = self._db.get_aka_list(channel) + aka_values = [self._db.get_alias(channel, aka) for aka in aka_list] + s = ('{0}: "{1}"'.format(ircutils.bold(k), v) for (k, v) in + zip(aka_list, aka_values)) + irc.replies(s) + list = wrap(list, [getopts({'channel': 'somethingWithoutSpaces'})]) + Class = Aka From f802f779047732e6a762e9afe5c1c0d282b89c4d Mon Sep 17 00:00:00 2001 From: James Lu Date: Tue, 16 Dec 2014 16:27:22 -0800 Subject: [PATCH 2/8] Aka: update listCommands override to only include built in cmds The old behavior is superseded by 'aka list'. This makes it easier for people to find Aka plugin's core commands, as 'list Aka' won't be filled with random, irrelevant alias definitions. --- plugins/Aka/plugin.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plugins/Aka/plugin.py b/plugins/Aka/plugin.py index 2dc2f2d01..9a57d8dba 100644 --- a/plugins/Aka/plugin.py +++ b/plugins/Aka/plugin.py @@ -32,7 +32,6 @@ import re import os import sys import datetime -import operator import supybot.conf as conf import supybot.utils as utils @@ -397,11 +396,9 @@ class Aka(callbacks.Plugin): isCommand = isCommandMethod def listCommands(self): - channel = dynamic.channel or 'global' - return list(set(list(map(callbacks.formatCommand, - self._db.get_aka_list(channel) + - self._db.get_aka_list('global'))) + - ['add', 'remove', 'lock', 'unlock', 'importaliasdatabase'])) + commands = ['add', 'remove', 'lock', 'unlock', 'importaliasdatabase', + 'show', 'list', 'set'] + return commands def getCommand(self, args, check_other_plugins=True): canonicalName = callbacks.canonicalName From f05f04807d268ceff00c91832f630b80a3e9c5cf Mon Sep 17 00:00:00 2001 From: James Lu Date: Tue, 16 Dec 2014 16:36:55 -0800 Subject: [PATCH 3/8] Aka: update tests --- plugins/Aka/test.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugins/Aka/test.py b/plugins/Aka/test.py index 45ecc9845..87bb160aa 100644 --- a/plugins/Aka/test.py +++ b/plugins/Aka/test.py @@ -112,10 +112,10 @@ class AkaChannelTestCase(ChannelPluginTestCase): cb._add_aka('global', 'foobar', 'echo sbbone') cb._db.lock_aka('global', 'foobar', 'evil_admin') self.assertResponse('foobar', 'sbbone') - self.assertRegexp('list Aka', 'foobar') + self.assertRegexp('aka list', 'foobar') self.assertRaises(Aka.AkaError, cb._remove_aka, 'global', 'foobar') cb._remove_aka('global', 'foobar', evenIfLocked=True) - self.assertNotRegexp('list Aka', 'foobar') + self.assertNotRegexp('aka list', 'foobar') self.assertError('foobar') def testOptionalArgs(self): @@ -226,5 +226,10 @@ class AkaTestCase(PluginTestCase): self.assertRegexp('alias spam', 'there is no command named') self.assertResponse('aka spam', 'egg') + def testList(self): + self.assertNotError('aka add foo bar') + self.assertRegexp('aka list', 'foo.*?bar \$\*') + self.assertNotError('aka add "foo bar" baz') + self.assertRegexp('aka list', 'foo.*?bar \$\*.*?foo bar.*?baz \$\*') # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: From 26df32086d19a2ecd2f79bed2f54f6d79bd30729 Mon Sep 17 00:00:00 2001 From: James Lu Date: Tue, 16 Dec 2014 16:51:52 -0800 Subject: [PATCH 4/8] Aka: catch with error if 'aka list' response is empty --- plugins/Aka/plugin.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/plugins/Aka/plugin.py b/plugins/Aka/plugin.py index 9a57d8dba..e80aed941 100644 --- a/plugins/Aka/plugin.py +++ b/plugins/Aka/plugin.py @@ -723,10 +723,13 @@ class Aka(callbacks.Plugin): Raise=True) channel = arg aka_list = self._db.get_aka_list(channel) - aka_values = [self._db.get_alias(channel, aka) for aka in aka_list] - s = ('{0}: "{1}"'.format(ircutils.bold(k), v) for (k, v) in - zip(aka_list, aka_values)) - irc.replies(s) + if aka_list: + aka_values = [self._db.get_alias(channel, aka) for aka in aka_list] + s = ('{0}: "{1}"'.format(ircutils.bold(k), v) for (k, v) in + zip(aka_list, aka_values)) + irc.replies(s) + else: + irc.error(_("No Akas found.")) list = wrap(list, [getopts({'channel': 'somethingWithoutSpaces'})]) From a1a7864f54e4db69181562309dfc822ca94d4dcd Mon Sep 17 00:00:00 2001 From: GLolol Date: Wed, 17 Dec 2014 07:35:26 -0800 Subject: [PATCH 5/8] Aka: update list command --- plugins/Aka/plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/Aka/plugin.py b/plugins/Aka/plugin.py index e80aed941..e5d939039 100644 --- a/plugins/Aka/plugin.py +++ b/plugins/Aka/plugin.py @@ -711,7 +711,7 @@ class Aka(callbacks.Plugin): importaliasdatabase = wrap(importaliasdatabase, ['owner']) def list(self, irc, msg, args, optlist): - """[--channel] <#channel> + """[--channel <#channel>] Lists all Akas defined for . If is not specified, lists all global Akas.""" @@ -730,7 +730,7 @@ class Aka(callbacks.Plugin): irc.replies(s) else: irc.error(_("No Akas found.")) - list = wrap(list, [getopts({'channel': 'somethingWithoutSpaces'})]) + list = wrap(list, [getopts({'channel': 'channel'})]) Class = Aka From 231c250b75357988cdc48ab91656c3043f9fdcec Mon Sep 17 00:00:00 2001 From: James Lu Date: Mon, 22 Dec 2014 19:57:26 -0800 Subject: [PATCH 6/8] Aka: update converters to use 'channel' instead of 'somethingWithoutSpaces' --- plugins/Aka/plugin.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/Aka/plugin.py b/plugins/Aka/plugin.py index e5d939039..f87390cbb 100644 --- a/plugins/Aka/plugin.py +++ b/plugins/Aka/plugin.py @@ -549,7 +549,7 @@ class Aka(callbacks.Plugin): except AkaError as e: irc.error(str(e)) add = wrap(add, [getopts({ - 'channel': 'somethingWithoutSpaces', + 'channel': 'channel', }), 'something', 'text']) def set(self, irc, msg, args, optlist, name, alias): @@ -586,7 +586,7 @@ class Aka(callbacks.Plugin): except AkaError as e: irc.error(str(e)) set = wrap(set, [getopts({ - 'channel': 'somethingWithoutSpaces', + 'channel': 'channel', }), 'something', 'text']) def remove(self, irc, msg, args, optlist, name): @@ -608,7 +608,7 @@ class Aka(callbacks.Plugin): except AkaError as e: irc.error(str(e)) remove = wrap(remove, [getopts({ - 'channel': 'somethingWithoutSpaces', + 'channel': 'channel', }), 'something']) def _checkManageCapabilities(self, irc, msg, channel): @@ -641,7 +641,7 @@ class Aka(callbacks.Plugin): else: irc.replySuccess() lock = wrap(lock, [getopts({ - 'channel': 'somethingWithoutSpaces', + 'channel': 'channel', }), 'user', 'something']) def unlock(self, irc, msg, args, optlist, user, name): @@ -664,7 +664,7 @@ class Aka(callbacks.Plugin): else: irc.replySuccess() unlock = wrap(unlock, [getopts({ - 'channel': 'somethingWithoutSpaces', + 'channel': 'channel', }), 'user', 'something']) def show(self, irc, msg, args, optlist, name): @@ -683,8 +683,8 @@ class Aka(callbacks.Plugin): if command: irc.reply(command) else: - irc.error(_('This Aka does not exist')) - show = wrap(show, [getopts({'channel': 'somethingWithoutSpaces'}), + irc.error(_('This Aka does not exist.')) + show = wrap(show, [getopts({'channel': 'channel'}), 'text']) def importaliasdatabase(self, irc, msg, args): From b76cff73a80759ce3f047d309b9a801bac848e04 Mon Sep 17 00:00:00 2001 From: GLolol Date: Fri, 26 Dec 2014 16:18:39 -0500 Subject: [PATCH 7/8] Revert "Aka: update converters to use 'channel' instead of 'somethingWithoutSpaces'" This reverts commit 231c250b75357988cdc48ab91656c3043f9fdcec. --- plugins/Aka/plugin.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/Aka/plugin.py b/plugins/Aka/plugin.py index ab4eb064e..4367efe76 100644 --- a/plugins/Aka/plugin.py +++ b/plugins/Aka/plugin.py @@ -549,7 +549,7 @@ class Aka(callbacks.Plugin): except AkaError as e: irc.error(str(e)) add = wrap(add, [getopts({ - 'channel': 'channel', + 'channel': 'somethingWithoutSpaces', }), 'something', 'text']) def set(self, irc, msg, args, optlist, name, alias): @@ -586,7 +586,7 @@ class Aka(callbacks.Plugin): except AkaError as e: irc.error(str(e)) set = wrap(set, [getopts({ - 'channel': 'channel', + 'channel': 'somethingWithoutSpaces', }), 'something', 'text']) def remove(self, irc, msg, args, optlist, name): @@ -608,7 +608,7 @@ class Aka(callbacks.Plugin): except AkaError as e: irc.error(str(e)) remove = wrap(remove, [getopts({ - 'channel': 'channel', + 'channel': 'somethingWithoutSpaces', }), 'something']) def _checkManageCapabilities(self, irc, msg, channel): @@ -641,7 +641,7 @@ class Aka(callbacks.Plugin): else: irc.replySuccess() lock = wrap(lock, [getopts({ - 'channel': 'channel', + 'channel': 'somethingWithoutSpaces', }), 'user', 'something']) def unlock(self, irc, msg, args, optlist, user, name): @@ -664,7 +664,7 @@ class Aka(callbacks.Plugin): else: irc.replySuccess() unlock = wrap(unlock, [getopts({ - 'channel': 'channel', + 'channel': 'somethingWithoutSpaces', }), 'user', 'something']) def show(self, irc, msg, args, optlist, name): @@ -683,8 +683,8 @@ class Aka(callbacks.Plugin): if command: irc.reply(command) else: - irc.error(_('This Aka does not exist.')) - show = wrap(show, [getopts({'channel': 'channel'}), + irc.error(_('This Aka does not exist')) + show = wrap(show, [getopts({'channel': 'somethingWithoutSpaces'}), 'text']) def importaliasdatabase(self, irc, msg, args): From c492cb40e1481c541d51ff99356e1299fa8d71ef Mon Sep 17 00:00:00 2001 From: GLolol Date: Fri, 26 Dec 2014 16:21:20 -0500 Subject: [PATCH 8/8] Aka: add a missing '.' in the error message --- plugins/Aka/locales/fi.po | 2 +- plugins/Aka/plugin.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/Aka/locales/fi.po b/plugins/Aka/locales/fi.po index 6af708ba5..090688d92 100644 --- a/plugins/Aka/locales/fi.po +++ b/plugins/Aka/locales/fi.po @@ -32,7 +32,7 @@ msgstr "Tämä Aka on jo olemassa." #: plugin.py:169 plugin.py:181 plugin.py:195 plugin.py:291 plugin.py:308 #: plugin.py:325 -msgid "This Aka does not exist" +msgid "This Aka does not exist." msgstr "Tätä Akaa ei ole olemassa." #: plugin.py:293 diff --git a/plugins/Aka/plugin.py b/plugins/Aka/plugin.py index 4367efe76..6501bdfbf 100644 --- a/plugins/Aka/plugin.py +++ b/plugins/Aka/plugin.py @@ -165,7 +165,7 @@ if sqlite3: SET locked=1, locked_at=?, locked_by=? WHERE name = ?""", (datetime.datetime.now(), by, name)) if cursor.rowcount == 0: - raise AkaError(_('This Aka does not exist')) + raise AkaError(_('This Aka does not exist.')) db.commit() def unlock_aka(self, channel, name, by): @@ -177,7 +177,7 @@ if sqlite3: cursor.execute("""UPDATE aliases SET locked=0, locked_at=? WHERE name = ?""", (datetime.datetime.now(), name)) if cursor.rowcount == 0: - raise AkaError(_('This Aka does not exist')) + raise AkaError(_('This Aka does not exist.')) db.commit() def get_aka_lock(self, channel, name): @@ -191,7 +191,7 @@ if sqlite3: if r: return (bool(r[0]), r[1], r[2]) else: - raise AkaError(_('This Aka does not exist')) + raise AkaError(_('This Aka does not exist.')) available_db.update({'sqlite3': SQLiteAkaDB}) elif sqlalchemy: Base = sqlalchemy.ext.declarative.declarative_base() @@ -287,7 +287,7 @@ elif sqlalchemy: aka = db.query(SQLAlchemyAlias) \ .filter(SQLAlchemyAlias.name == name).one() except sqlalchemy.orm.exc.NoResultFound: - raise AkaError(_('This Aka does not exist')) + raise AkaError(_('This Aka does not exist.')) if aka.locked: raise AkaError(_('This Aka is already locked.')) aka.locked = True @@ -304,7 +304,7 @@ elif sqlalchemy: aka = db.query(SQLAlchemyAlias) \ .filter(SQLAlchemyAlias.name == name).one() except sqlalchemy.orm.exc.NoResultFound: - raise AkaError(_('This Aka does not exist')) + raise AkaError(_('This Aka does not exist.')) if not aka.locked: raise AkaError(_('This Aka is already unlocked.')) aka.locked = False @@ -321,7 +321,7 @@ elif sqlalchemy: .query(SQLAlchemyAlias.locked, SQLAlchemyAlias.locked_by, SQLAlchemyAlias.locked_at)\ .filter(SQLAlchemyAlias.name == name).one() except sqlalchemy.orm.exc.NoResultFound: - raise AkaError(_('This Aka does not exist')) + raise AkaError(_('This Aka does not exist.')) available_db.update({'sqlalchemy': SqlAlchemyAkaDB}) @@ -683,7 +683,7 @@ class Aka(callbacks.Plugin): if command: irc.reply(command) else: - irc.error(_('This Aka does not exist')) + irc.error(_('This Aka does not exist.')) show = wrap(show, [getopts({'channel': 'somethingWithoutSpaces'}), 'text'])