Fixed lack of case-insensitivity in randomquote

This commit is contained in:
Daniel DiPaolo 2003-12-29 11:12:37 +00:00
parent f886d6529f
commit 629dd867f1
2 changed files with 38 additions and 0 deletions

View File

@ -209,6 +209,33 @@ class QuoteGrabs(plugins.ChannelDBHandler,
l.append(item_str)
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):
"""<id>

View File

@ -91,6 +91,17 @@ if sqlite:
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):
testPrefix= 'foo!bar@baz'
self.assertError('quotegrabs get asdf')