Genuflect before the master of anality (and rejoice that bug #944861 has been fixed).

This commit is contained in:
Jeremy Fincher 2004-04-30 05:21:13 +00:00
parent 550f6cd5c1
commit b21b3af3c2

View File

@ -95,17 +95,19 @@ class Dunno(callbacks.Privmsg):
""" """
# Must be registered to use this # Must be registered to use this
try: try:
id = ircdb.users.getUserId(msg.prefix) user_id = ircdb.users.getUserId(msg.prefix)
except KeyError: except KeyError:
irc.errorNotRegistered() irc.errorNotRegistered()
return return
text = privmsgs.getArgs(args, required=1) text = privmsgs.getArgs(args)
cursor = self.db.cursor() cursor = self.db.cursor()
cursor.execute("""INSERT INTO dunnos at = int(time.time())
VALUES(NULL, %s, %s, %s)""", cursor.execute("""INSERT INTO dunnos VALUES(NULL, %s, %s, %s)""",
id, int(time.time()), text) user_id, at, text)
self.db.commit() self.db.commit()
irc.replySuccess() cursor.execute("""SELECT id FROM dunnos WHERE added_at=%s""", at)
id = cursor.fetchone()[0]
irc.replySuccess('Dunno #%s added.' % id)
def remove(self, irc, msg, args): def remove(self, irc, msg, args):
"""<id> """<id>
@ -120,19 +122,17 @@ class Dunno(callbacks.Privmsg):
return return
dunno_id = privmsgs.getArgs(args, required=1) dunno_id = privmsgs.getArgs(args, required=1)
cursor = self.db.cursor() cursor = self.db.cursor()
cursor.execute("""SELECT added_by, dunno cursor.execute("""SELECT added_by, dunno FROM dunnos
FROM dunnos WHERE id=%s""", dunno_id)
WHERE id = %s""" % dunno_id)
if cursor.rowcount == 0: if cursor.rowcount == 0:
irc.error('No dunno with id: %s' % dunno_id) irc.error('No dunno with id #%s.' % dunno_id)
return return
(added_by, dunno) = cursor.fetchone() (added_by, dunno) = cursor.fetchone()
if not (ircdb.checkCapability(user_id, 'admin') or \ if not (ircdb.checkCapability(user_id, 'admin') or \
added_by == user_id): added_by == user_id):
irc.error('Only admins and the dunno creator may delete a ' irc.error('Only admins and the dunno creator may delete a dunno.')
'dunno.')
return return
cursor.execute("""DELETE FROM dunnos WHERE id = %s""" % dunno_id) cursor.execute("""DELETE FROM dunnos WHERE id=%s""", dunno_id)
self.db.commit() self.db.commit()
irc.replySuccess() irc.replySuccess()
@ -145,13 +145,12 @@ class Dunno(callbacks.Privmsg):
text = privmsgs.getArgs(args, required=1) text = privmsgs.getArgs(args, required=1)
glob = "%" + text + "%" glob = "%" + text + "%"
cursor = self.db.cursor() cursor = self.db.cursor()
cursor.execute("""SELECT id FROM dunnos cursor.execute("""SELECT id FROM dunnos WHERE dunno LIKE %s""", glob)
WHERE dunno LIKE %s""", glob)
if cursor.rowcount == 0: if cursor.rowcount == 0:
irc.error('No dunnos with %r found.' % text) irc.error('No dunnos with %r found.' % text)
return return
ids = [str(t[0]) for t in cursor.fetchall()] ids = [str(t[0]) for t in cursor.fetchall()]
s = 'Dunno search for %r (%s found): %s' % \ s = 'Dunno search for %r (%s found): %s.' % \
(text, len(ids), utils.commaAndify(ids)) (text, len(ids), utils.commaAndify(ids))
irc.reply(s) irc.reply(s)
@ -164,15 +163,15 @@ class Dunno(callbacks.Privmsg):
try: try:
id = int(id) id = int(id)
except ValueError: except ValueError:
irc.error('%r is not a valid dunno id' % id) irc.error('%r is not a valid dunno id.' % id)
return return
cursor = self.db.cursor() cursor = self.db.cursor()
cursor.execute("""SELECT dunno FROM dunnos WHERE id = %s""", id) cursor.execute("""SELECT dunno FROM dunnos WHERE id=%s""", id)
if cursor.rowcount == 0: if cursor.rowcount == 0:
irc.error('No dunno found with id #%s' % id) irc.error('No dunno found with id #%s.' % id)
return return
dunno = cursor.fetchone()[0] dunno = cursor.fetchone()[0]
irc.reply("Dunno #%s: %r" % (id, dunno)) irc.reply("Dunno #%s: %r." % (id, dunno))
def change(self, irc, msg, args): def change(self, irc, msg, args):
"""<id> <regexp> """<id> <regexp>
@ -184,23 +183,23 @@ class Dunno(callbacks.Privmsg):
try: try:
user_id = ircdb.users.getUserId(msg.prefix) user_id = ircdb.users.getUserId(msg.prefix)
except KeyError: except KeyError:
irc.error(msg, conf.replyNotRegistered) irc.errorNotRegistered()
return return
# Check id arg # Check id arg
try: try:
id = int(id) id = int(id)
except ValueError: except ValueError:
irc.error(msg, '%r is not a valid dunno id' % id) irc.error('%r is not a valid dunno id.' % id)
return return
cursor = self.db.cursor() cursor = self.db.cursor()
cursor.execute("""SELECT dunno FROM dunnos WHERE id=%s""", id) cursor.execute("""SELECT dunno FROM dunnos WHERE id=%s""", id)
if cursor.rowcount == 0: if cursor.rowcount == 0:
irc.error(msg, 'There is no dunno #%s' % id) irc.error('There is no dunno #%s.' % id)
return return
try: try:
replacer = utils.perlReToReplacer(regexp) replacer = utils.perlReToReplacer(regexp)
except: except:
irc.error(msg, '%r is not a valid regexp' % regexp) irc.error('%r is not a valid regular expression.' % regexp)
return return
dunno = cursor.fetchone()[0] dunno = cursor.fetchone()[0]
new_dunno = replacer(dunno) new_dunno = replacer(dunno)