mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-23 19:22:45 +01:00
Addition of search to Quotegrabs
This commit is contained in:
parent
1b631ad1f2
commit
32d535c1d6
@ -181,21 +181,22 @@ class SqliteQuoteGrabsDB(object):
|
|||||||
def search(self, channel, text):
|
def search(self, channel, text):
|
||||||
db = self._getDb(channel)
|
db = self._getDb(channel)
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""SELECT id, quote FROM quotegrabs
|
text = '%' + text + '%'
|
||||||
|
cursor.execute("""SELECT id, nick, quote FROM quotegrabs
|
||||||
WHERE quote LIKE %s
|
WHERE quote LIKE %s
|
||||||
ORDER BY id DESC""", text)
|
ORDER BY id DESC""", text)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
raise dbi.NoRecordError
|
raise dbi.NoRecordError
|
||||||
return [QuoteGrabsRecord(id, text=quote)
|
return [QuoteGrabsRecord(id, text=quote, by=nick)
|
||||||
for (id, quote) in cursor.fetchall()]
|
for (id, nick, quote) in cursor.fetchall()]
|
||||||
|
|
||||||
QuoteGrabsDB = plugins.DB('QuoteGrabs', {'sqlite': SqliteQuoteGrabsDB})
|
QuoteGrabsDB = plugins.DB('QuoteGrabs', {'sqlite': SqliteQuoteGrabsDB})
|
||||||
|
|
||||||
class QuoteGrabs(callbacks.Privmsg):
|
class QuoteGrabs(callbacks.Privmsg):
|
||||||
"""Add the help for "@help QuoteGrabs" here."""
|
"""Add the help for "@help QuoteGrabs" here."""
|
||||||
def __init__(self):
|
def __init__(self, irc):
|
||||||
self.__parent = super(QuoteGrabs, self)
|
self.__parent = super(QuoteGrabs, self)
|
||||||
self.__parent.__init__()
|
self.__parent.__init__(irc)
|
||||||
self.db = QuoteGrabsDB()
|
self.db = QuoteGrabsDB()
|
||||||
|
|
||||||
def doPrivmsg(self, irc, msg):
|
def doPrivmsg(self, irc, msg):
|
||||||
@ -329,7 +330,7 @@ class QuoteGrabs(callbacks.Privmsg):
|
|||||||
L = []
|
L = []
|
||||||
for record in records:
|
for record in records:
|
||||||
# strip the nick from the quote
|
# 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)
|
item = utils.str.ellipsisify('#%s: %s' % (record.id, quote),50)
|
||||||
L.append(item)
|
L.append(item)
|
||||||
irc.reply(utils.str.commaAndify(L))
|
irc.reply(utils.str.commaAndify(L))
|
||||||
@ -338,8 +339,6 @@ class QuoteGrabs(callbacks.Privmsg):
|
|||||||
Raise=True)
|
Raise=True)
|
||||||
search = wrap(search, ['channeldb', 'text'])
|
search = wrap(search, ['channeldb', 'text'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Class = QuoteGrabs
|
Class = QuoteGrabs
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
from supybot.test import *
|
from supybot.test import *
|
||||||
|
|
||||||
class QuoteGrabsTestCase(PluginTestCase):
|
class QuoteGrabsTestCase(ChannelPluginTestCase):
|
||||||
plugins = ('QuoteGrabs',)
|
plugins = ('QuoteGrabs',)
|
||||||
def testQuoteGrab(self):
|
def testQuoteGrab(self):
|
||||||
testPrefix = 'foo!bar@baz'
|
testPrefix = 'foo!bar@baz'
|
||||||
@ -102,6 +102,15 @@ class QuoteGrabsTestCase(PluginTestCase):
|
|||||||
self.assertNotError('grab foo')
|
self.assertNotError('grab foo')
|
||||||
self.assertNotError('quotegrabs get 1')
|
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):
|
class QuoteGrabsNonChannelTestCase(QuoteGrabsTestCase):
|
||||||
config = { 'databases.plugins.channelSpecific' : False }
|
config = { 'databases.plugins.channelSpecific' : False }
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user