Addition of search to Quotegrabs

This commit is contained in:
Daniel DiPaolo 2005-02-01 01:33:16 +00:00
parent 1b631ad1f2
commit 32d535c1d6
2 changed files with 17 additions and 9 deletions

View File

@ -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

View File

@ -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 }