Add conf.supybot.plugins.Quotes.requireRegistration and fix a bug with

Quotes.random
This commit is contained in:
James Vega 2004-08-17 03:45:30 +00:00
parent 0ee2ff4fbb
commit 2ad62c502a
2 changed files with 39 additions and 6 deletions

View File

@ -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 * Removed supybot.reply.withPrivateNotice and split it into two
separate configuration variables, supybot.reply.withNotice and separate configuration variables, supybot.reply.withNotice and
supybot.reply.inPrivate. supybot.reply.inPrivate.

View File

@ -47,6 +47,7 @@ import supybot.conf as conf
import supybot.utils as utils import supybot.utils as utils
import supybot.ircdb as ircdb import supybot.ircdb as ircdb
import supybot.privmsgs as privmsgs import supybot.privmsgs as privmsgs
import supybot.registry as registry
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
try: try:
@ -55,6 +56,11 @@ except ImportError:
raise callbacks.Error, 'You need to have PySQLite installed to use this '\ raise callbacks.Error, 'You need to have PySQLite installed to use this '\
'plugin. Download it at <http://pysqlite.sf.net/>' 'plugin. Download it at <http://pysqlite.sf.net/>'
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): class QuoteRecord(object):
__metaclass__ = dbi.Record __metaclass__ = dbi.Record
__fields__ = [ __fields__ = [
@ -64,8 +70,14 @@ class QuoteRecord(object):
] ]
def __str__(self): def __str__(self):
format = conf.supybot.humanTimestampFormat() 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.' % \ return 'Quote %r added by %s at %s.' % \
(self.text, self.by, (self.text, user,
time.strftime(format, time.localtime(float(self.at)))) time.strftime(format, time.localtime(float(self.at))))
class SqliteQuotesDB(object): class SqliteQuotesDB(object):
@ -109,6 +121,8 @@ class SqliteQuotesDB(object):
cursor = db.cursor() cursor = db.cursor()
cursor.execute("""SELECT id, added_by, added_at, quote FROM quotes cursor.execute("""SELECT id, added_by, added_at, quote FROM quotes
ORDER BY random() LIMIT 1""") ORDER BY random() LIMIT 1""")
if cursor.rowcount == 0:
raise dbi.NoRecordError
(id, by, at, text) = cursor.fetchone() (id, by, at, text) = cursor.fetchone()
return QuoteRecord(id, by=by, at=int(at), text=text) return QuoteRecord(id, by=by, at=int(at), text=text)
@ -186,7 +200,18 @@ class Quotes(callbacks.Privmsg):
""" """
channel = privmsgs.getChannel(msg, args) channel = privmsgs.getChannel(msg, args)
quote = privmsgs.getArgs(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) irc.replySuccess('(Quote #%s added)' % id)
def stats(self, irc, msg, args): def stats(self, irc, msg, args):
@ -265,11 +290,11 @@ class Quotes(callbacks.Privmsg):
the message isn't sent in the channel itself. the message isn't sent in the channel itself.
""" """
channel = privmsgs.getChannel(msg, args) channel = privmsgs.getChannel(msg, args)
try:
quote = self.db.random(channel) quote = self.db.random(channel)
if quote:
self._replyQuote(irc, quote) self._replyQuote(irc, quote)
else: except dbi.NoRecordError:
self.error('I have no quotes for this channel.') irc.error('I have no quotes for this channel.')
def info(self, irc, msg, args): def info(self, irc, msg, args):
"""[<channel>] <id> """[<channel>] <id>