Merge pull request #952 from GLolol/aka-2

Aka: add 'list' command & update listCommands override
This commit is contained in:
Valentin Lorentz 2014-12-26 22:37:24 +01:00
commit f4425de7c5
3 changed files with 39 additions and 15 deletions

View File

@ -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

View File

@ -32,7 +32,6 @@ import re
import os
import sys
import datetime
import operator
import supybot.conf as conf
import supybot.utils as utils
@ -166,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):
@ -178,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):
@ -192,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()
@ -288,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
@ -305,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
@ -322,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})
@ -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
@ -713,6 +710,28 @@ class Aka(callbacks.Plugin):
irc.replySuccess()
importaliasdatabase = wrap(importaliasdatabase, ['owner'])
def list(self, irc, msg, args, optlist):
"""[--channel <#channel>]
Lists all Akas defined for <channel>. If <channel> 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)
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': 'channel'})])
Class = Aka

View File

@ -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: