Updated some capabilities stuff.

This commit is contained in:
Jeremy Fincher 2004-01-08 15:24:56 +00:00
parent 25918481ad
commit 099b8bc14b
6 changed files with 64 additions and 89 deletions

View File

@ -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):
"""[<channel>] <key> as <value>
Associates <key> with <value>. <channel> 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):
"""[<channel>] <key>
Locks the factoid(s) associated with <key> so that they cannot be
removed or added to. <channel> 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)
def unlock(self, irc, msg, args):
def unlock(self, irc, msg, args, channel):
"""[<channel>] <key>
Unlocks the factoid(s) associated with <key> so that they can be
removed or added to. <channel> 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)
def forget(self, irc, msg, args):
def forget(self, irc, msg, args, channel):
"""[<channel>] <key> [<number>|*]
Removes the factoid <key> from the factoids database. If there are
@ -238,7 +226,6 @@ class Factoids(plugins.ChannelDBHandler,
factoids associated with a key. <channel> 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,8 +239,6 @@ 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
@ -283,8 +268,6 @@ class Factoids(plugins.ChannelDBHandler,
'Please specify which one to remove, ' \
'or use * to designate all of them.' % \
cursor.rowcount)
else:
irc.error(conf.replyNoCapability % capability)
def random(self, irc, msg, args):
"""[<channel>]
@ -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):
"""[<channel>] <key> <number> <regexp>
Changes the factoid #<number> associated with <key> according to
<regexp>.
"""
channel = privmsgs.getChannel(msg, args)
(key, number, regexp) = privmsgs.getArgs(args, required=3)
try:
replacer = utils.perlReToReplacer(regexp)

View File

@ -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):
"""[<channel>] <id>
Removes quote <id> from the quotes database for <channel>. <channel>
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()
else:
irc.error(conf.replyNoCapability % capability)
Class = Quotes

View File

@ -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):
"""[<channel>] <hostmask>

View File

@ -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)."

View File

@ -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 \

View File

@ -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: