From 75288193ad893f2e7e9c9644bafc96fa35312068 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20L=C3=B6thberg?= Date: Sat, 24 Jan 2015 19:38:54 +0100 Subject: [PATCH] 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. --- plugins/QuoteGrabs/plugin.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/plugins/QuoteGrabs/plugin.py b/plugins/QuoteGrabs/plugin.py index 8eb43d968..00f444e6b 100644 --- a/plugins/QuoteGrabs/plugin.py +++ b/plugins/QuoteGrabs/plugin.py @@ -61,8 +61,11 @@ class QuoteGrabsRecord(dbi.Record): def __str__(self): grabber = plugins.getUserName(self.grabber) - return format(_('%s (Said by: %s; grabbed by %s at %t)'), - self.text, self.hostmask, grabber, self.at) + 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] - return QuoteGrabsRecord(id, by=by, text=quote, hostmask=hostmask, - at=int(at), grabber=grabber) + 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): + """[] + + Return the quotegrab with the given . 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): """[]