Made quote.py return quotes from all channels if called with .q <nick>

This commit is contained in:
lukeroge 2012-03-06 18:33:45 +13:00
parent db52b15570
commit f4435f4557

View file

@ -60,8 +60,28 @@ def get_quote_num(num, count, name):
num = random.randint(1, count) num = random.randint(1, count)
return num return num
def get_quote_by_nick(db, chan, nick, num=False): def get_quote_by_nick(db, nick, num=False):
"Returns a formatted quote from a nick, random or selected by number" "Returns a formatted quote from a nick, random or selected by number"
count = db.execute('''SELECT COUNT(*)
FROM quote
WHERE deleted != 1
AND lower(nick) = lower(?)''', [nick]).fetchall()[0][0]
try:
num = get_quote_num(num, count, nick)
except Exception as error_message:
return error_message
quote = db.execute('''SELECT time, nick, msg
FROM quote
WHERE deleted != 1
AND lower(nick) = lower(?)
ORDER BY time
LIMIT ?, 1''', (nick, (num-1))).fetchall()[0]
return format_quote(quote, num, count)
def get_quote_by_nick_chan(db, chan, nick, num=False):
"Returns a formatted quote from a nick in a channel, random or selected by number"
count = db.execute('''SELECT COUNT(*) count = db.execute('''SELECT COUNT(*)
FROM quote FROM quote
WHERE deleted != 1 WHERE deleted != 1
@ -122,9 +142,9 @@ def quote(inp, nick='', chan='', db=None, notice=None):
if by_chan: if by_chan:
return get_quote_by_chan(db, select, num) return get_quote_by_chan(db, select, num)
else: else:
return get_quote_by_nick(db, chan, select, num) return get_quote_by_nick(db, select, num)
elif retrieve_chan: elif retrieve_chan:
chan, nick, num = retrieve_chan.groups() chan, nick, num = retrieve_chan.groups()
return get_quote_by_nick(db, chan, nick, num) return get_quote_by_nick_chan(db, chan, nick, num)
notice(quote.__doc__) notice(quote.__doc__)