mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Added RFE #804955, lookup should return a random key: value if not given an argument.
This commit is contained in:
parent
fb60da149b
commit
caa099dfc1
@ -104,6 +104,7 @@ class Lookup(callbacks.Privmsg):
|
||||
irc.reply(msg, conf.replySuccess)
|
||||
except sqlite.DatabaseError:
|
||||
irc.error(msg, 'No such lookup exists.')
|
||||
|
||||
def addlookup(self, irc, msg, args):
|
||||
"""<name> <filename>
|
||||
|
||||
@ -120,7 +121,7 @@ class Lookup(callbacks.Privmsg):
|
||||
cb = irc.getCallback('Alias')
|
||||
if cb is not None:
|
||||
try:
|
||||
cb.addAlias(irc, name, 'lookup %s $1' % name, freeze=True)
|
||||
cb.addAlias(irc, name, 'lookup %s @1' % name, freeze=True)
|
||||
except sys.modules[cb.__module__].AliasError, e:
|
||||
pass
|
||||
irc.reply(msg, conf.replySuccess)
|
||||
@ -146,7 +147,7 @@ class Lookup(callbacks.Privmsg):
|
||||
cb = irc.getCallback('Alias')
|
||||
if cb is not None:
|
||||
try:
|
||||
cb.addAlias(irc, name, 'lookup %s $1' % name, freeze=True)
|
||||
cb.addAlias(irc, name, 'lookup %s @1' % name, freeze=True)
|
||||
except sys.modules[cb.__module__].AliasError, e:
|
||||
irc.error(msg, str(e))
|
||||
return
|
||||
@ -157,9 +158,10 @@ class Lookup(callbacks.Privmsg):
|
||||
|
||||
Looks up the value of <key> in the domain <name>.
|
||||
"""
|
||||
(name, key) = privmsgs.getArgs(args, needed=2)
|
||||
(name, key) = privmsgs.getArgs(args, optional=1)
|
||||
db = getDb()
|
||||
cursor = db.cursor()
|
||||
if key:
|
||||
sql = """SELECT value FROM %s WHERE key LIKE %%s""" % name
|
||||
try:
|
||||
cursor.execute(sql, key)
|
||||
@ -176,6 +178,19 @@ class Lookup(callbacks.Privmsg):
|
||||
else:
|
||||
values = [t[0] for t in cursor.fetchall()]
|
||||
irc.reply(msg, '%s could be %s' % (key, ', or '.join(values)))
|
||||
else:
|
||||
sql = """SELECT key, value FROM %s
|
||||
ORDER BY random() LIMIT 1""" % name
|
||||
try:
|
||||
cursor.execute(sql)
|
||||
except sqlite.DatabaseError, e:
|
||||
if 'no such table' in str(e):
|
||||
irc.error(msg, 'I don\'t have a domain %r' % name)
|
||||
else:
|
||||
irc.error(msg, str(e))
|
||||
return
|
||||
(key, value) = cursor.fetchone()
|
||||
irc.reply(msg, '%s: %s' % (key, value))
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user