2005-01-29 21:07:22 +01:00
|
|
|
###
|
|
|
|
# Copyright (c) 2004, Daniel DiPaolo
|
2010-01-28 14:14:44 +01:00
|
|
|
# Copyright (c) 2008-2010, James Vega
|
2005-01-29 21:07:22 +01:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# * Neither the name of the author of this software nor the name of
|
|
|
|
# contributors to this software may be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written consent.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
###
|
|
|
|
|
|
|
|
import os
|
|
|
|
import time
|
|
|
|
import random
|
|
|
|
|
|
|
|
import supybot.dbi as dbi
|
|
|
|
import supybot.conf as conf
|
|
|
|
import supybot.utils as utils
|
|
|
|
from supybot.commands import *
|
|
|
|
import supybot.ircmsgs as ircmsgs
|
|
|
|
import supybot.plugins as plugins
|
|
|
|
import supybot.ircutils as ircutils
|
|
|
|
import supybot.callbacks as callbacks
|
2010-10-17 18:37:13 +02:00
|
|
|
from supybot.i18n import PluginInternationalization, internationalizeDocstring
|
|
|
|
_ = PluginInternationalization('QuoteGrabs')
|
2005-01-29 21:07:22 +01:00
|
|
|
|
2010-04-21 07:24:13 +02:00
|
|
|
try:
|
|
|
|
import sqlite3
|
|
|
|
except ImportError:
|
|
|
|
from pysqlite2 import dbapi2 as sqlite3 # for python2.4
|
|
|
|
|
|
|
|
import traceback
|
|
|
|
|
|
|
|
#sqlite3.register_converter('bool', bool)
|
|
|
|
|
2005-01-29 21:07:22 +01:00
|
|
|
class QuoteGrabsRecord(dbi.Record):
|
|
|
|
__fields__ = [
|
|
|
|
'by',
|
|
|
|
'text',
|
|
|
|
'grabber',
|
|
|
|
'at',
|
|
|
|
'hostmask',
|
|
|
|
]
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
grabber = plugins.getUserName(self.grabber)
|
2010-10-17 18:37:13 +02:00
|
|
|
return format(_('%s (Said by: %s; grabbed by %s at %t)'),
|
2009-02-27 20:17:05 +01:00
|
|
|
self.text, self.hostmask, grabber, self.at)
|
2005-01-29 21:07:22 +01:00
|
|
|
|
|
|
|
class SqliteQuoteGrabsDB(object):
|
|
|
|
def __init__(self, filename):
|
|
|
|
self.dbs = ircutils.IrcDict()
|
|
|
|
self.filename = filename
|
|
|
|
|
|
|
|
def close(self):
|
|
|
|
for db in self.dbs.itervalues():
|
|
|
|
db.close()
|
|
|
|
|
|
|
|
def _getDb(self, channel):
|
|
|
|
filename = plugins.makeChannelFilename(self.filename, channel)
|
|
|
|
def p(s1, s2):
|
2010-04-21 07:24:13 +02:00
|
|
|
# text_factory seems to only apply as an output adapter,
|
|
|
|
# so doesn't apply to created functions; so we use str()
|
|
|
|
return ircutils.nickEqual(str(s1), str(s2))
|
2005-01-29 21:07:22 +01:00
|
|
|
if filename in self.dbs:
|
|
|
|
return self.dbs[filename]
|
|
|
|
if os.path.exists(filename):
|
2010-04-21 07:24:13 +02:00
|
|
|
db = sqlite3.connect(filename)
|
|
|
|
db.text_factory = str
|
|
|
|
db.create_function('nickeq', 2, p)
|
|
|
|
self.dbs[filename] = db
|
|
|
|
return db
|
|
|
|
db = sqlite3.connect(filename)
|
|
|
|
db.text_factory = str
|
|
|
|
db.create_function('nickeq', 2, p)
|
2005-01-29 21:07:22 +01:00
|
|
|
self.dbs[filename] = db
|
|
|
|
cursor = db.cursor()
|
|
|
|
cursor.execute("""CREATE TABLE quotegrabs (
|
|
|
|
id INTEGER PRIMARY KEY,
|
2010-04-21 07:24:13 +02:00
|
|
|
nick BLOB,
|
2005-01-29 21:07:22 +01:00
|
|
|
hostmask TEXT,
|
|
|
|
added_by TEXT,
|
|
|
|
added_at TIMESTAMP,
|
|
|
|
quote TEXT
|
|
|
|
);""")
|
|
|
|
db.commit()
|
|
|
|
return db
|
|
|
|
|
|
|
|
def get(self, channel, id):
|
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
cursor.execute("""SELECT id, nick, quote, hostmask, added_at, added_by
|
2010-04-21 07:24:13 +02:00
|
|
|
FROM quotegrabs WHERE id = ?""", (id,))
|
|
|
|
results = cursor.fetchall()
|
|
|
|
if len(results) == 0:
|
2005-01-29 21:07:22 +01:00
|
|
|
raise dbi.NoRecordError
|
2010-04-21 07:24:13 +02:00
|
|
|
(id, by, quote, hostmask, at, grabber) = results[0]
|
2005-01-29 21:07:22 +01:00
|
|
|
return QuoteGrabsRecord(id, by=by, text=quote, hostmask=hostmask,
|
2009-07-19 02:27:45 +02:00
|
|
|
at=int(at), grabber=grabber)
|
2005-01-29 21:07:22 +01:00
|
|
|
|
|
|
|
def random(self, channel, nick):
|
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
if nick:
|
|
|
|
cursor.execute("""SELECT quote FROM quotegrabs
|
2010-04-21 07:24:13 +02:00
|
|
|
WHERE nickeq(nick, ?)
|
2005-01-29 21:07:22 +01:00
|
|
|
ORDER BY random() LIMIT 1""",
|
2010-04-21 07:24:13 +02:00
|
|
|
(nick,))
|
2005-01-29 21:07:22 +01:00
|
|
|
else:
|
|
|
|
cursor.execute("""SELECT quote FROM quotegrabs
|
|
|
|
ORDER BY random() LIMIT 1""")
|
2010-04-21 07:24:13 +02:00
|
|
|
results = cursor.fetchall()
|
|
|
|
if len(results) == 0:
|
2005-01-29 21:07:22 +01:00
|
|
|
raise dbi.NoRecordError
|
2010-04-21 07:24:13 +02:00
|
|
|
return results[0][0]
|
2005-01-29 21:07:22 +01:00
|
|
|
|
|
|
|
def list(self, channel, nick):
|
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
cursor.execute("""SELECT id, quote FROM quotegrabs
|
2010-04-21 07:24:13 +02:00
|
|
|
WHERE nickeq(nick, ?)
|
|
|
|
ORDER BY id DESC""", (nick,))
|
|
|
|
results = cursor.fetchall()
|
|
|
|
if len(results) == 0:
|
2009-08-19 16:00:57 +02:00
|
|
|
raise dbi.NoRecordError
|
2005-01-29 21:07:22 +01:00
|
|
|
return [QuoteGrabsRecord(id, text=quote)
|
2010-04-21 07:24:13 +02:00
|
|
|
for (id, quote) in results]
|
2005-01-29 21:07:22 +01:00
|
|
|
|
|
|
|
def getQuote(self, channel, nick):
|
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
cursor.execute("""SELECT quote FROM quotegrabs
|
2010-04-21 07:24:13 +02:00
|
|
|
WHERE nickeq(nick, ?)
|
|
|
|
ORDER BY id DESC LIMIT 1""", (nick,))
|
|
|
|
results = cursor.fetchall()
|
|
|
|
if len(results) == 0:
|
2005-01-29 21:07:22 +01:00
|
|
|
raise dbi.NoRecordError
|
2010-04-21 07:24:13 +02:00
|
|
|
return results[0][0]
|
2005-01-29 21:07:22 +01:00
|
|
|
|
|
|
|
def select(self, channel, nick):
|
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
cursor.execute("""SELECT added_at FROM quotegrabs
|
2010-04-21 07:24:13 +02:00
|
|
|
WHERE nickeq(nick, ?)
|
|
|
|
ORDER BY id DESC LIMIT 1""", (nick,))
|
|
|
|
results = cursor.fetchall()
|
|
|
|
if len(results) == 0:
|
2005-01-29 21:07:22 +01:00
|
|
|
raise dbi.NoRecordError
|
2010-04-21 07:24:13 +02:00
|
|
|
return results[0][0]
|
2005-01-29 21:07:22 +01:00
|
|
|
|
2009-02-27 20:17:05 +01:00
|
|
|
def add(self, channel, msg, by):
|
2005-01-29 21:07:22 +01:00
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
text = ircmsgs.prettyPrint(msg)
|
|
|
|
# Check to see if the latest quotegrab is identical
|
|
|
|
cursor.execute("""SELECT quote FROM quotegrabs
|
2010-04-21 07:24:13 +02:00
|
|
|
WHERE nick=?
|
|
|
|
ORDER BY id DESC LIMIT 1""", (msg.nick,))
|
|
|
|
results = cursor.fetchall()
|
|
|
|
if len(results) != 0:
|
|
|
|
if text == results[0][0]:
|
2005-01-29 21:07:22 +01:00
|
|
|
return
|
|
|
|
cursor.execute("""INSERT INTO quotegrabs
|
2010-04-21 07:24:13 +02:00
|
|
|
VALUES (NULL, ?, ?, ?, ?, ?)""",
|
|
|
|
(msg.nick, msg.prefix, by, int(time.time()), text,))
|
2005-01-29 21:07:22 +01:00
|
|
|
db.commit()
|
|
|
|
|
2009-08-19 16:00:57 +02:00
|
|
|
def remove(self, channel, grab=None):
|
|
|
|
db = self._getDb(channel)
|
|
|
|
cursor = db.cursor()
|
|
|
|
if grab is not None:
|
|
|
|
# the testing if there actually *is* the to-be-deleted record is
|
|
|
|
# strictly unnecessary -- the DELETE operation would "succeed"
|
|
|
|
# anyway, but it's silly to just keep saying 'OK' no matter what,
|
|
|
|
# so...
|
2010-04-21 07:24:13 +02:00
|
|
|
cursor.execute("""SELECT * FROM quotegrabs WHERE id = ?""", (grab,))
|
|
|
|
results = cursor.fetchall()
|
|
|
|
if len(results) == 0:
|
2009-08-19 16:00:57 +02:00
|
|
|
raise dbi.NoRecordError
|
2010-04-21 07:24:13 +02:00
|
|
|
cursor.execute("""DELETE FROM quotegrabs WHERE id = ?""", (grab,))
|
2009-08-19 16:00:57 +02:00
|
|
|
else:
|
|
|
|
cursor.execute("""SELECT * FROM quotegrabs WHERE id = (SELECT MAX(id)
|
|
|
|
FROM quotegrabs)""")
|
2010-04-21 07:24:13 +02:00
|
|
|
results = cursor.fetchall()
|
|
|
|
if len(results) == 0:
|
2009-08-19 16:00:57 +02:00
|
|
|
raise dbi.NoRecordError
|
|
|
|
cursor.execute("""DELETE FROM quotegrabs WHERE id = (SELECT MAX(id)
|
|
|
|
FROM quotegrabs)""")
|
|
|
|
db.commit()
|
|
|
|
|
2005-01-29 21:07:22 +01:00
|
|
|
def search(self, channel, text):
|
|
|
|
db = self._getDb(channel)
|
2005-02-01 14:57:51 +01:00
|
|
|
cursor = db.cursor()
|
2005-02-01 02:33:16 +01:00
|
|
|
text = '%' + text + '%'
|
2005-02-01 14:57:51 +01:00
|
|
|
cursor.execute("""SELECT id, nick, quote FROM quotegrabs
|
2010-04-21 07:24:13 +02:00
|
|
|
WHERE quote LIKE ?
|
|
|
|
ORDER BY id DESC""", (text,))
|
|
|
|
results = cursor.fetchall()
|
|
|
|
if len(results) == 0:
|
2005-01-29 21:07:22 +01:00
|
|
|
raise dbi.NoRecordError
|
2005-02-01 02:33:16 +01:00
|
|
|
return [QuoteGrabsRecord(id, text=quote, by=nick)
|
2010-04-21 07:24:13 +02:00
|
|
|
for (id, nick, quote) in results]
|
2005-01-29 21:07:22 +01:00
|
|
|
|
2010-04-21 07:24:13 +02:00
|
|
|
QuoteGrabsDB = plugins.DB('QuoteGrabs', {'sqlite3': SqliteQuoteGrabsDB})
|
2005-01-29 21:07:22 +01:00
|
|
|
|
2005-02-09 08:04:04 +01:00
|
|
|
class QuoteGrabs(callbacks.Plugin):
|
2005-01-29 21:07:22 +01:00
|
|
|
"""Add the help for "@help QuoteGrabs" here."""
|
2005-02-01 02:33:16 +01:00
|
|
|
def __init__(self, irc):
|
2005-01-29 21:07:22 +01:00
|
|
|
self.__parent = super(QuoteGrabs, self)
|
2005-02-01 02:33:16 +01:00
|
|
|
self.__parent.__init__(irc)
|
2005-01-29 21:07:22 +01:00
|
|
|
self.db = QuoteGrabsDB()
|
|
|
|
|
|
|
|
def doPrivmsg(self, irc, msg):
|
2010-01-28 14:14:44 +01:00
|
|
|
if ircmsgs.isCtcp(msg) and not ircmsgs.isAction(msg):
|
|
|
|
return
|
2005-01-29 21:07:22 +01:00
|
|
|
irc = callbacks.SimpleProxy(irc, msg)
|
|
|
|
if irc.isChannel(msg.args[0]):
|
2009-02-27 20:17:05 +01:00
|
|
|
(chan, payload) = msg.args
|
|
|
|
words = self.registryValue('randomGrabber.minimumWords', chan)
|
|
|
|
length = self.registryValue('randomGrabber.minimumCharacters',chan)
|
2005-01-29 21:07:22 +01:00
|
|
|
grabTime = \
|
2009-02-27 20:17:05 +01:00
|
|
|
self.registryValue('randomGrabber.averageTimeBetweenGrabs', chan)
|
|
|
|
channel = plugins.getChannel(chan)
|
|
|
|
if self.registryValue('randomGrabber', chan):
|
2005-01-29 21:07:22 +01:00
|
|
|
if len(payload) > length and len(payload.split()) > words:
|
|
|
|
try:
|
|
|
|
last = int(self.db.select(channel, msg.nick))
|
|
|
|
except dbi.NoRecordError:
|
2009-06-26 22:58:46 +02:00
|
|
|
self._grab(channel, irc, msg, irc.prefix)
|
2005-01-29 21:07:22 +01:00
|
|
|
self._sendGrabMsg(irc, msg)
|
|
|
|
else:
|
|
|
|
elapsed = int(time.time()) - last
|
2009-02-27 20:17:05 +01:00
|
|
|
if (random.random() * elapsed) > (grabTime / 2):
|
|
|
|
self._grab(channel, irc, msg, irc.prefix)
|
2005-01-29 21:07:22 +01:00
|
|
|
self._sendGrabMsg(irc, msg)
|
|
|
|
|
2009-02-27 20:17:05 +01:00
|
|
|
def _grab(self, channel, irc, msg, addedBy):
|
|
|
|
self.db.add(channel, msg, addedBy)
|
2005-01-29 21:07:22 +01:00
|
|
|
|
|
|
|
def _sendGrabMsg(self, irc, msg):
|
|
|
|
s = 'jots down a new quote for %s' % msg.nick
|
2005-06-01 23:08:30 +02:00
|
|
|
irc.reply(s, action=True, prefixNick=False)
|
2005-01-29 21:07:22 +01:00
|
|
|
|
2010-10-17 18:37:13 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-29 21:07:22 +01:00
|
|
|
def grab(self, irc, msg, args, channel, nick):
|
|
|
|
"""[<channel>] <nick>
|
|
|
|
|
|
|
|
Grabs a quote from <channel> by <nick> for the quotegrabs table.
|
|
|
|
<channel> is only necessary if the message isn't sent in the channel
|
|
|
|
itself.
|
|
|
|
"""
|
|
|
|
# chan is used to make sure we know where to grab the quote from, as
|
|
|
|
# opposed to channel which is used to determine which db to store the
|
|
|
|
# quote in
|
|
|
|
chan = msg.args[0]
|
|
|
|
if chan is None:
|
|
|
|
raise callbacks.ArgumentError
|
|
|
|
if ircutils.nickEqual(nick, msg.nick):
|
2010-10-17 18:37:13 +02:00
|
|
|
irc.error(_('You can\'t quote grab yourself.'), Raise=True)
|
2005-01-29 21:07:22 +01:00
|
|
|
for m in reversed(irc.state.history):
|
|
|
|
if m.command == 'PRIVMSG' and ircutils.nickEqual(m.nick, nick) \
|
|
|
|
and ircutils.strEqual(m.args[0], chan):
|
2009-02-27 20:17:05 +01:00
|
|
|
self._grab(channel, irc, m, msg.prefix)
|
2005-01-29 21:07:22 +01:00
|
|
|
irc.replySuccess()
|
|
|
|
return
|
2010-10-17 18:37:13 +02:00
|
|
|
irc.error(_('I couldn\'t find a proper message to grab.'))
|
2005-01-29 21:07:22 +01:00
|
|
|
grab = wrap(grab, ['channeldb', 'nick'])
|
|
|
|
|
2010-10-17 18:37:13 +02:00
|
|
|
@internationalizeDocstring
|
2009-08-19 16:00:57 +02:00
|
|
|
def ungrab(self, irc, msg, args, channel, grab):
|
|
|
|
"""[<channel>] <number>
|
|
|
|
|
|
|
|
Removes the grab <number> (the last by default) on <channel>.
|
|
|
|
<channel> is only necessary if the message isn't sent in the channel
|
|
|
|
itself.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
self.db.remove(channel, grab)
|
|
|
|
irc.replySuccess()
|
|
|
|
except dbi.NoRecordError:
|
|
|
|
if grab is None:
|
2010-10-17 18:37:13 +02:00
|
|
|
irc.error(_('Nothing to ungrab.'))
|
2009-08-19 16:00:57 +02:00
|
|
|
else:
|
2010-10-17 18:37:13 +02:00
|
|
|
irc.error(_('Invalid grab number.'))
|
2009-08-19 16:00:57 +02:00
|
|
|
ungrab = wrap(ungrab, ['channeldb', optional('id')])
|
|
|
|
|
2010-10-17 18:37:13 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-29 21:07:22 +01:00
|
|
|
def quote(self, irc, msg, args, channel, nick):
|
|
|
|
"""[<channel>] <nick>
|
|
|
|
|
|
|
|
Returns <nick>'s latest quote grab in <channel>. <channel> is only
|
|
|
|
necessary if the message isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
irc.reply(self.db.getQuote(channel, nick))
|
|
|
|
except dbi.NoRecordError:
|
2010-10-17 18:37:13 +02:00
|
|
|
irc.error(_('I couldn\'t find a matching quotegrab for %s.') %
|
|
|
|
nick, Raise=True)
|
2005-01-29 21:07:22 +01:00
|
|
|
quote = wrap(quote, ['channeldb', 'nick'])
|
|
|
|
|
2010-10-17 18:37:13 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-29 21:07:22 +01:00
|
|
|
def list(self, irc, msg, args, channel, nick):
|
|
|
|
"""[<channel>] <nick>
|
|
|
|
|
|
|
|
Returns a list of shortened quotes that have been grabbed for <nick>
|
|
|
|
as well as the id of each quote. These ids can be used to get the
|
|
|
|
full quote. <channel> is only necessary if the message isn't sent in
|
|
|
|
the channel itself.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
records = self.db.list(channel, nick)
|
|
|
|
L = []
|
|
|
|
for record in records:
|
|
|
|
# strip the nick from the quote
|
|
|
|
quote = record.text.replace('<%s> ' % nick, '', 1)
|
|
|
|
item = utils.str.ellipsisify('#%s: %s' % (record.id, quote),50)
|
|
|
|
L.append(item)
|
|
|
|
irc.reply(utils.str.commaAndify(L))
|
|
|
|
except dbi.NoRecordError:
|
2010-10-17 18:37:13 +02:00
|
|
|
irc.error(_('I couldn\'t find any quotegrabs for %s.') % nick,
|
2005-01-29 21:07:22 +01:00
|
|
|
Raise=True)
|
|
|
|
list = wrap(list, ['channeldb', 'nick'])
|
|
|
|
|
2010-10-17 18:37:13 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-29 21:07:22 +01:00
|
|
|
def random(self, irc, msg, args, channel, nick):
|
|
|
|
"""[<channel>] [<nick>]
|
|
|
|
|
|
|
|
Returns a randomly grabbed quote, optionally choosing only from those
|
|
|
|
quotes grabbed for <nick>. <channel> is only necessary if the message
|
|
|
|
isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
irc.reply(self.db.random(channel, nick))
|
|
|
|
except dbi.NoRecordError:
|
|
|
|
if nick:
|
2010-10-17 18:37:13 +02:00
|
|
|
irc.error(_('Couldn\'t get a random quote for that nick.'))
|
2005-01-29 21:07:22 +01:00
|
|
|
else:
|
2010-10-17 18:37:13 +02:00
|
|
|
irc.error(_('Couldn\'t get a random quote. Are there any '
|
|
|
|
'grabbed quotes in the database?'))
|
2005-01-29 21:07:22 +01:00
|
|
|
random = wrap(random, ['channeldb', additional('nick')])
|
|
|
|
|
2010-10-17 18:37:13 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-29 21:07:22 +01:00
|
|
|
def get(self, irc, msg, args, channel, id):
|
|
|
|
"""[<channel>] <id>
|
|
|
|
|
|
|
|
Return the quotegrab with the given <id>. <channel> is only necessary
|
|
|
|
if the message isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
irc.reply(self.db.get(channel, id))
|
|
|
|
except dbi.NoRecordError:
|
2010-10-17 18:37:13 +02:00
|
|
|
irc.error(_('No quotegrab for id %s') % utils.str.quoted(id),
|
2005-01-29 21:07:22 +01:00
|
|
|
Raise=True)
|
|
|
|
get = wrap(get, ['channeldb', 'id'])
|
|
|
|
|
2010-10-17 18:37:13 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-29 21:07:22 +01:00
|
|
|
def search(self, irc, msg, args, channel, text):
|
|
|
|
"""[<channel>] <text>
|
|
|
|
|
|
|
|
Searches for <text> in a quote. <channel> is only necessary if the
|
|
|
|
message isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
records = self.db.search(channel, text)
|
|
|
|
L = []
|
|
|
|
for record in records:
|
|
|
|
# strip the nick from the quote
|
2005-02-01 02:33:16 +01:00
|
|
|
quote = record.text.replace('<%s> ' % record.by, '', 1)
|
2005-01-29 21:07:22 +01:00
|
|
|
item = utils.str.ellipsisify('#%s: %s' % (record.id, quote),50)
|
|
|
|
L.append(item)
|
|
|
|
irc.reply(utils.str.commaAndify(L))
|
|
|
|
except dbi.NoRecordError:
|
2010-10-17 18:37:13 +02:00
|
|
|
irc.error(_('No quotegrabs matching %s') % utils.str.quoted(text),
|
2005-01-29 21:07:22 +01:00
|
|
|
Raise=True)
|
|
|
|
search = wrap(search, ['channeldb', 'text'])
|
|
|
|
|
|
|
|
Class = QuoteGrabs
|
|
|
|
|
2006-02-11 16:52:51 +01:00
|
|
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|