From 32d535c1d6ac42105dea5fbef8f61e4dd27902fc Mon Sep 17 00:00:00 2001 From: Daniel DiPaolo Date: Tue, 1 Feb 2005 01:33:16 +0000 Subject: [PATCH] Addition of search to Quotegrabs --- plugins/QuoteGrabs/plugin.py | 15 +++++++-------- plugins/QuoteGrabs/test.py | 11 ++++++++++- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/plugins/QuoteGrabs/plugin.py b/plugins/QuoteGrabs/plugin.py index a3f541998..1fc8b88c5 100644 --- a/plugins/QuoteGrabs/plugin.py +++ b/plugins/QuoteGrabs/plugin.py @@ -181,21 +181,22 @@ class SqliteQuoteGrabsDB(object): def search(self, channel, text): db = self._getDb(channel) cursor = db.cursor() - cursor.execute("""SELECT id, quote FROM quotegrabs + text = '%' + text + '%' + cursor.execute("""SELECT id, nick, quote FROM quotegrabs WHERE quote LIKE %s ORDER BY id DESC""", text) if cursor.rowcount == 0: raise dbi.NoRecordError - return [QuoteGrabsRecord(id, text=quote) - for (id, quote) in cursor.fetchall()] + return [QuoteGrabsRecord(id, text=quote, by=nick) + for (id, nick, quote) in cursor.fetchall()] QuoteGrabsDB = plugins.DB('QuoteGrabs', {'sqlite': SqliteQuoteGrabsDB}) class QuoteGrabs(callbacks.Privmsg): """Add the help for "@help QuoteGrabs" here.""" - def __init__(self): + def __init__(self, irc): self.__parent = super(QuoteGrabs, self) - self.__parent.__init__() + self.__parent.__init__(irc) self.db = QuoteGrabsDB() def doPrivmsg(self, irc, msg): @@ -329,7 +330,7 @@ class QuoteGrabs(callbacks.Privmsg): L = [] for record in records: # strip the nick from the quote - quote = record.text.replace('<%s> ' % nick, '', 1) + quote = record.text.replace('<%s> ' % record.by, '', 1) item = utils.str.ellipsisify('#%s: %s' % (record.id, quote),50) L.append(item) irc.reply(utils.str.commaAndify(L)) @@ -338,8 +339,6 @@ class QuoteGrabs(callbacks.Privmsg): Raise=True) search = wrap(search, ['channeldb', 'text']) - - Class = QuoteGrabs diff --git a/plugins/QuoteGrabs/test.py b/plugins/QuoteGrabs/test.py index f54a9b777..5f2a7b48c 100644 --- a/plugins/QuoteGrabs/test.py +++ b/plugins/QuoteGrabs/test.py @@ -29,7 +29,7 @@ from supybot.test import * -class QuoteGrabsTestCase(PluginTestCase): +class QuoteGrabsTestCase(ChannelPluginTestCase): plugins = ('QuoteGrabs',) def testQuoteGrab(self): testPrefix = 'foo!bar@baz' @@ -102,6 +102,15 @@ class QuoteGrabsTestCase(PluginTestCase): self.assertNotError('grab foo') self.assertNotError('quotegrabs get 1') + def testSearch(self): + testPrefix= 'foo!bar@baz' + self.irc.feedMsg(ircmsgs.privmsg(self.channel, 'test', + prefix=testPrefix)) + self.assertError('quotegrabs search test') # still none in db + self.assertNotError('grab foo') + self.assertNotError('quotegrabs search test') + + class QuoteGrabsNonChannelTestCase(QuoteGrabsTestCase): config = { 'databases.plugins.channelSpecific' : False }