From 2ad62c502af3c14e7345fcb0a59f0d3111088f42 Mon Sep 17 00:00:00 2001 From: James Vega Date: Tue, 17 Aug 2004 03:45:30 +0000 Subject: [PATCH] Add conf.supybot.plugins.Quotes.requireRegistration and fix a bug with Quotes.random --- ChangeLog | 8 ++++++++ plugins/Quotes.py | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3d3b18e3a..7cc9f5084 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ + * Added supybot.plugins.Quotes.requireRegistration, which + determines whether a user need be registered to add Quotes to + the Quotes database. + + * Added supybot.plugins.RSS.showLinks, which determines whether + the bot will show links to the RSS headlines along with the + normally displayed titles. + * Removed supybot.reply.withPrivateNotice and split it into two separate configuration variables, supybot.reply.withNotice and supybot.reply.inPrivate. diff --git a/plugins/Quotes.py b/plugins/Quotes.py index 2503ffbb5..6cb4c179d 100644 --- a/plugins/Quotes.py +++ b/plugins/Quotes.py @@ -47,6 +47,7 @@ import supybot.conf as conf import supybot.utils as utils import supybot.ircdb as ircdb import supybot.privmsgs as privmsgs +import supybot.registry as registry import supybot.callbacks as callbacks try: @@ -55,6 +56,11 @@ except ImportError: raise callbacks.Error, 'You need to have PySQLite installed to use this '\ 'plugin. Download it at ' +conf.registerPlugin('Quotes') +conf.registerGlobalValue(conf.supybot.plugins.Quotes, 'requireRegistration', + registry.Boolean(False, """Determines whether the bot should require people + trying to use this plugin to be registered.""")) + class QuoteRecord(object): __metaclass__ = dbi.Record __fields__ = [ @@ -64,8 +70,14 @@ class QuoteRecord(object): ] def __str__(self): format = conf.supybot.humanTimestampFormat() + try: + user = ircdb.users.getUser(int(self.by)).name + except ValueError: + user = self.by + except KeyError: + user = 'a user that is no longer registered' return 'Quote %r added by %s at %s.' % \ - (self.text, self.by, + (self.text, user, time.strftime(format, time.localtime(float(self.at)))) class SqliteQuotesDB(object): @@ -109,6 +121,8 @@ class SqliteQuotesDB(object): cursor = db.cursor() cursor.execute("""SELECT id, added_by, added_at, quote FROM quotes ORDER BY random() LIMIT 1""") + if cursor.rowcount == 0: + raise dbi.NoRecordError (id, by, at, text) = cursor.fetchone() return QuoteRecord(id, by=by, at=int(at), text=text) @@ -186,7 +200,18 @@ class Quotes(callbacks.Privmsg): """ channel = privmsgs.getChannel(msg, args) quote = privmsgs.getArgs(args) - id = self.db.add(channel, msg.nick, quote) + if self.registryValue('requireRegistration'): + try: + by = ircdb.users.getUserId(msg.prefix) + except KeyError: + irc.errorNotRegistered() + return + else: + try: + by = ircdb.users.getUserId(msg.prefix) + except KeyError: + by = msg.nick + id = self.db.add(channel, by, quote) irc.replySuccess('(Quote #%s added)' % id) def stats(self, irc, msg, args): @@ -265,11 +290,11 @@ class Quotes(callbacks.Privmsg): the message isn't sent in the channel itself. """ channel = privmsgs.getChannel(msg, args) - quote = self.db.random(channel) - if quote: + try: + quote = self.db.random(channel) self._replyQuote(irc, quote) - else: - self.error('I have no quotes for this channel.') + except dbi.NoRecordError: + irc.error('I have no quotes for this channel.') def info(self, irc, msg, args): """[]