mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
Fixed lack of case-insensitivity in randomquote
This commit is contained in:
parent
f886d6529f
commit
629dd867f1
@ -209,6 +209,33 @@ class QuoteGrabs(plugins.ChannelDBHandler,
|
|||||||
l.append(item_str)
|
l.append(item_str)
|
||||||
irc.reply(msg, utils.commaAndify(l))
|
irc.reply(msg, utils.commaAndify(l))
|
||||||
|
|
||||||
|
def randomquote(self, irc, msg, args):
|
||||||
|
"""[<nick>]
|
||||||
|
|
||||||
|
Returns a randomly grabbed quote, optionally choosing only from those
|
||||||
|
quotes grabbed for <nick>.
|
||||||
|
"""
|
||||||
|
channel = privmsgs.getChannel(msg, args)
|
||||||
|
nick = privmsgs.getArgs(args, required=0, optional=1)
|
||||||
|
db = self.getDb(channel)
|
||||||
|
cursor = db.cursor()
|
||||||
|
if nick:
|
||||||
|
cursor.execute("""SELECT quote FROM quotegrabs
|
||||||
|
WHERE nick LIKE %s ORDER BY random() LIMIT 1""",
|
||||||
|
nick)
|
||||||
|
else:
|
||||||
|
cursor.execute("""SELECT quote FROM quotegrabs
|
||||||
|
ORDER BY random() LIMIT 1""")
|
||||||
|
if cursor.rowcount == 0:
|
||||||
|
if nick:
|
||||||
|
irc.error(msg, 'Couldn\'t get a random quote for that nick.')
|
||||||
|
else:
|
||||||
|
irc.error(msg, 'Couldn\'t get a random quote. Are there any'
|
||||||
|
'grabbed quotes in the database?')
|
||||||
|
return
|
||||||
|
quote = cursor.fetchone()[0]
|
||||||
|
irc.reply(msg, quote)
|
||||||
|
|
||||||
def get(self, irc, msg, args):
|
def get(self, irc, msg, args):
|
||||||
"""<id>
|
"""<id>
|
||||||
|
|
||||||
|
@ -91,6 +91,17 @@ if sqlite:
|
|||||||
self.assertNotError('quote FoO')
|
self.assertNotError('quote FoO')
|
||||||
self.assertNotError('quote Foo')
|
self.assertNotError('quote Foo')
|
||||||
|
|
||||||
|
def testRandomquote(self):
|
||||||
|
testPrefix = 'foo!bar@baz'
|
||||||
|
self.assertError('randomquote')
|
||||||
|
self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'test',
|
||||||
|
prefix=testPrefix))
|
||||||
|
self.assertError('randomquote') # still none in the db
|
||||||
|
self.assertNotError('grab foo')
|
||||||
|
self.assertResponse('randomquote', '<foo> test')
|
||||||
|
self.assertResponse('randomquote foo', '<foo> test')
|
||||||
|
self.assertResponse('randomquote FOO', '<foo> test')
|
||||||
|
|
||||||
def testGet(self):
|
def testGet(self):
|
||||||
testPrefix= 'foo!bar@baz'
|
testPrefix= 'foo!bar@baz'
|
||||||
self.assertError('quotegrabs get asdf')
|
self.assertError('quotegrabs get asdf')
|
||||||
|
Loading…
Reference in New Issue
Block a user