QuoteGrabs: Add say command

The say command just returns the text of the grab, so you can get just
the quote from a specific qid.
This commit is contained in:
Johannes Löthberg 2015-01-24 19:38:54 +01:00
parent 7bba16a55e
commit 75288193ad

View File

@ -61,8 +61,11 @@ class QuoteGrabsRecord(dbi.Record):
def __str__(self):
grabber = plugins.getUserName(self.grabber)
if self.at:
return format(_('%s (Said by: %s; grabbed by %s at %t)'),
self.text, self.hostmask, grabber, self.at)
else:
return format('%s', self.text)
class SqliteQuoteGrabsDB(object):
def __init__(self, filename):
@ -105,7 +108,7 @@ class SqliteQuoteGrabsDB(object):
db.commit()
return db
def get(self, channel, id):
def get(self, channel, id, quoteonly = 0):
db = self._getDb(channel)
cursor = db.cursor()
cursor.execute("""SELECT id, nick, quote, hostmask, added_at, added_by
@ -114,8 +117,11 @@ class SqliteQuoteGrabsDB(object):
if len(results) == 0:
raise dbi.NoRecordError
(id, by, quote, hostmask, at, grabber) = results[0]
if quoteonly is 0:
return QuoteGrabsRecord(id, by=by, text=quote, hostmask=hostmask,
at=int(at), grabber=grabber)
else:
return QuoteGrabsRecord(id, text=quote)
def random(self, channel, nick):
db = self._getDb(channel)
@ -359,6 +365,20 @@ class QuoteGrabs(callbacks.Plugin):
'grabbed quotes in the database?'))
random = wrap(random, ['channeldb', additional('nick')])
@internationalizeDocstring
def say(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, 1))
except dbi.NoRecordError:
irc.error(_('No quotegrab for id %s') % utils.str.quoted(id),
Raise=True)
say = wrap(say, ['channeldb', 'id'])
@internationalizeDocstring
def get(self, irc, msg, args, channel, id):
"""[<channel>] <id>