From 099b8bc14b69c135755ccd1396698e41cb356301 Mon Sep 17 00:00:00 2001 From: Jeremy Fincher Date: Thu, 8 Jan 2004 15:24:56 +0000 Subject: [PATCH] Updated some capabilities stuff. --- plugins/Factoids.py | 102 ++++++++++++++++++-------------------------- plugins/Quotes.py | 15 +++---- src/Channel.py | 2 +- src/callbacks.py | 26 ++++++----- src/configurable.py | 2 +- src/privmsgs.py | 6 +-- 6 files changed, 64 insertions(+), 89 deletions(-) diff --git a/plugins/Factoids.py b/plugins/Factoids.py index 1d8935e9b..b1605b4b6 100644 --- a/plugins/Factoids.py +++ b/plugins/Factoids.py @@ -107,13 +107,14 @@ class Factoids(plugins.ChannelDBHandler, db.commit() return db - def learn(self, irc, msg, args): + def learn(self, irc, msg, args, channel): """[] as Associates with . is only necessary if the - message isn't sent on the channel itself. + message isn't sent on the channel itself. The word "as" is necessary + to separate the key from the value. It can be changed to another + word via the learn-separator configurable. """ - channel = privmsgs.getChannel(msg, args) try: separator = self.configurables.get('learn-separator', channel) i = args.index(separator) @@ -132,9 +133,6 @@ class Factoids(plugins.ChannelDBHandler, (id, locked) = imap(int, cursor.fetchone()) capability = ircdb.makeChannelCapability(channel, 'factoids') if not locked: - if not ircdb.checkCapability(msg.prefix, capability): - irc.error(conf.replyNoCapability % capability) - return if ircdb.users.hasUser(msg.prefix): name = ircdb.users.getUser(msg.prefix).name else: @@ -191,45 +189,35 @@ class Factoids(plugins.ChannelDBHandler, irc.error('That\'s not a valid number for this key.') return - def lock(self, irc, msg, args): + def lock(self, irc, msg, args, channel): """[] Locks the factoid(s) associated with so that they cannot be removed or added to. is only necessary if the message isn't sent in the channel itself. """ - channel = privmsgs.getChannel(msg, args) key = privmsgs.getArgs(args) db = self.getDb(channel) - capability = ircdb.makeChannelCapability(channel, 'factoids') - if ircdb.checkCapability(msg.prefix, capability): - cursor = db.cursor() - cursor.execute("UPDATE keys SET locked=1 WHERE key LIKE %s", key) - db.commit() - irc.replySuccess() - else: - irc.error(conf.replyNoCapability % capability) + cursor = db.cursor() + cursor.execute("UPDATE keys SET locked=1 WHERE key LIKE %s", key) + db.commit() + irc.replySuccess() - def unlock(self, irc, msg, args): + def unlock(self, irc, msg, args, channel): """[] Unlocks the factoid(s) associated with so that they can be removed or added to. is only necessary if the message isn't sent in the channel itself. """ - channel = privmsgs.getChannel(msg, args) key = privmsgs.getArgs(args) db = self.getDb(channel) - capability = ircdb.makeChannelCapability(channel, 'factoids') - if ircdb.checkCapability(msg.prefix, capability): - cursor = db.cursor() - cursor.execute("UPDATE keys SET locked=0 WHERE key LIKE %s", key) - db.commit() - irc.replySuccess() - else: - irc.error(conf.replyNoCapability % capability) + cursor = db.cursor() + cursor.execute("UPDATE keys SET locked=0 WHERE key LIKE %s", key) + db.commit() + irc.replySuccess() - def forget(self, irc, msg, args): + def forget(self, irc, msg, args, channel): """[] [|*] Removes the factoid from the factoids database. If there are @@ -238,7 +226,6 @@ class Factoids(plugins.ChannelDBHandler, factoids associated with a key. is only necessary if the message isn't sent in the channel itself. """ - channel = privmsgs.getChannel(msg, args) if args[-1].isdigit(): number = int(args.pop()) number -= 1 @@ -252,39 +239,35 @@ class Factoids(plugins.ChannelDBHandler, number = None key = privmsgs.getArgs(args) db = self.getDb(channel) - capability = ircdb.makeChannelCapability(channel, 'factoids') - if ircdb.checkCapability(msg.prefix, capability): - cursor = db.cursor() - cursor.execute("""SELECT keys.id, factoids.id - FROM keys, factoids - WHERE key LIKE %s AND - factoids.key_id=keys.id""", key) - if cursor.rowcount == 0: - irc.error('There is no such factoid.') - elif cursor.rowcount == 1 or number is True: - (id, _) = cursor.fetchone() - cursor.execute("""DELETE FROM factoids WHERE key_id=%s""", id) - cursor.execute("""DELETE FROM keys WHERE key LIKE %s""", key) + cursor = db.cursor() + cursor.execute("""SELECT keys.id, factoids.id + FROM keys, factoids + WHERE key LIKE %s AND + factoids.key_id=keys.id""", key) + if cursor.rowcount == 0: + irc.error('There is no such factoid.') + elif cursor.rowcount == 1 or number is True: + (id, _) = cursor.fetchone() + cursor.execute("""DELETE FROM factoids WHERE key_id=%s""", id) + cursor.execute("""DELETE FROM keys WHERE key LIKE %s""", key) + db.commit() + irc.replySuccess() + else: + if number is not None: + results = cursor.fetchall() + try: + (_, id) = results[number] + except IndexError: + irc.error('Invalid factoid number.') + return + cursor.execute("DELETE FROM factoids WHERE id=%s", id) db.commit() irc.replySuccess() else: - if number is not None: - results = cursor.fetchall() - try: - (_, id) = results[number] - except IndexError: - irc.error('Invalid factoid number.') - return - cursor.execute("DELETE FROM factoids WHERE id=%s", id) - db.commit() - irc.replySuccess() - else: - irc.error('%s factoids have that key. ' \ - 'Please specify which one to remove, ' \ - 'or use * to designate all of them.' % \ - cursor.rowcount) - else: - irc.error(conf.replyNoCapability % capability) + irc.error('%s factoids have that key. ' \ + 'Please specify which one to remove, ' \ + 'or use * to designate all of them.' % \ + cursor.rowcount) def random(self, irc, msg, args): """[] @@ -341,13 +324,12 @@ class Factoids(plugins.ChannelDBHandler, utils.nItems('factoid', counter), factoids) irc.reply(s) - def change(self, irc, msg, args): + def change(self, irc, msg, args, channel): """[] Changes the factoid # associated with according to . """ - channel = privmsgs.getChannel(msg, args) (key, number, regexp) = privmsgs.getArgs(args, required=3) try: replacer = utils.perlReToReplacer(regexp) diff --git a/plugins/Quotes.py b/plugins/Quotes.py index a87226335..6b718dde2 100644 --- a/plugins/Quotes.py +++ b/plugins/Quotes.py @@ -227,25 +227,20 @@ class Quotes(plugins.ChannelDBHandler, callbacks.Privmsg): else: irc.error('There isn\'t a quote with that id.') - def remove(self, irc, msg, args): + def remove(self, irc, msg, args, channel): """[] Removes quote from the quotes database for . is only necessary if the message isn't sent in the channel itself. """ - channel = privmsgs.getChannel(msg, args) id = privmsgs.getArgs(args) db = self.getDb(channel) cursor = db.cursor() - capability = ircdb.makeChannelCapability(channel, 'op') - if ircdb.checkCapability(msg.prefix, capability): - cursor.execute("""DELETE FROM quotes WHERE id=%s""", id) - if cursor.rowcount == 0: - irc.error('There was no such quote.') - else: - irc.replySuccess() + cursor.execute("""DELETE FROM quotes WHERE id=%s""", id) + if cursor.rowcount == 0: + irc.error('There was no such quote.') else: - irc.error(conf.replyNoCapability % capability) + irc.replySuccess() Class = Quotes diff --git a/src/Channel.py b/src/Channel.py index a76d53d7a..e7addb137 100755 --- a/src/Channel.py +++ b/src/Channel.py @@ -257,7 +257,7 @@ class Channel(callbacks.Privmsg): else: self.log.warning('%r attempted kban without %s', msg.prefix, capability) - irc.error(conf.replyNoCapability % capability) + irc.errorNoCapability(capability) def unban(self, irc, msg, args, channel): """[] diff --git a/src/callbacks.py b/src/callbacks.py index df4547ad5..8cc060909 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -299,26 +299,24 @@ class RichReplyMethods(object): def replySuccess(self, s='', **kwargs): self.reply(self._makeReply(conf.replySuccess, s), **kwargs) - def replyNoCapability(self, capability, s='', **kwargs): - s = self._makeReply(conf.replyNoCapability % s, s) - self.reply(s, **kwargs) - - def replyNotRegistered(self, s='', **kwargs): - self.reply(self._makeReply(conf.replyNotRegistered, s), **kwargs) - def replyPossibleBug(self, s='', **kwargs): self.reply(self._makeReply(conf.replyPossibleBug, s), **kwargs) - def replyNoUser(self, s='', **kwargs): - self.reply(self._makeReply(conf.replyNoUser, s), **kwargs) - - def replyRequiresPrivacy(self, s='', **kwargs): - s = self._makeReply(conf.replyRequiresPrivacy, s) - self.reply(s, **kwargs) - def replyError(self, s='', **kwargs): self.reply(self._makeReply(conf.replyError, s), **kwargs) + def errorNoCapability(self, capability, s='', **kwargs): + self.error(self._makeReply(conf.replyNoCapability % s, s), **kwargs) + + def errorNotRegistered(self, s='', **kwargs): + self.error(self._makeReply(conf.replyNotRegistered, s), **kwargs) + + def errorNoUser(self, s='', **kwargs): + self.error(self._makeReply(conf.replyNoUser, s), **kwargs) + + def errorRequiresPrivacy(self, s='', **kwargs): + self.error(self._makeReply(conf.replyRequiresPrivacy, s), **kwargs) + class IrcObjectProxy(RichReplyMethods): "A proxy object to allow proper nested of commands (even threaded ones)." diff --git a/src/configurable.py b/src/configurable.py index a873f082a..bfbd15754 100644 --- a/src/configurable.py +++ b/src/configurable.py @@ -295,7 +295,7 @@ class Mixin(object): except Error, e: irc.error(str(e)) else: - irc.error(conf.replyNoCapability % capability) + irc.errorNoCapability(capability) else: help(self.configurables) elif hasattr(self, 'globalConfigurables') and \ diff --git a/src/privmsgs.py b/src/privmsgs.py index a25028ffd..380c68c59 100644 --- a/src/privmsgs.py +++ b/src/privmsgs.py @@ -98,7 +98,7 @@ def checkCapability(f, capability): else: self.log.warning('%r attempted %s without %s.', msg.prefix, f.func_name, capability) - irc.error(conf.replyNoCapability % capability) + irc.errorNoCapability(capability) newf = types.FunctionType(newf.func_code, newf.func_globals, f.func_name, closure=newf.func_closure) newf.__doc__ = f.__doc__ @@ -119,7 +119,7 @@ def checkChannelCapability(f, capability): else: self.log.warning('%r attempted %s without %s.', msg.prefix, f.func_name, capability) - irc.error(conf.replyNoCapability % chancap) + irc.errorNoCapability(chancap) newf = types.FunctionType(newf.func_code, newf.func_globals, f.func_name, closure=newf.func_closure) newf.__doc__ = f.__doc__ @@ -209,7 +209,7 @@ class CapabilityCheckingPrivmsg(callbacks.Privmsg): else: self.log.warning('%r tried to call %s without %s.', msg.prefix, f.im_func.func_name, self.capability) - irc.error(conf.replyNoCapability % self.capability) + irc.errorNoCapability(self.capability) # vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: