mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-11-09 12:17:30 +01:00
Updated some capabilities stuff.
This commit is contained in:
parent
25918481ad
commit
099b8bc14b
@ -107,13 +107,14 @@ class Factoids(plugins.ChannelDBHandler,
|
|||||||
db.commit()
|
db.commit()
|
||||||
return db
|
return db
|
||||||
|
|
||||||
def learn(self, irc, msg, args):
|
def learn(self, irc, msg, args, channel):
|
||||||
"""[<channel>] <key> as <value>
|
"""[<channel>] <key> as <value>
|
||||||
|
|
||||||
Associates <key> with <value>. <channel> is only necessary if the
|
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:
|
try:
|
||||||
separator = self.configurables.get('learn-separator', channel)
|
separator = self.configurables.get('learn-separator', channel)
|
||||||
i = args.index(separator)
|
i = args.index(separator)
|
||||||
@ -132,9 +133,6 @@ class Factoids(plugins.ChannelDBHandler,
|
|||||||
(id, locked) = imap(int, cursor.fetchone())
|
(id, locked) = imap(int, cursor.fetchone())
|
||||||
capability = ircdb.makeChannelCapability(channel, 'factoids')
|
capability = ircdb.makeChannelCapability(channel, 'factoids')
|
||||||
if not locked:
|
if not locked:
|
||||||
if not ircdb.checkCapability(msg.prefix, capability):
|
|
||||||
irc.error(conf.replyNoCapability % capability)
|
|
||||||
return
|
|
||||||
if ircdb.users.hasUser(msg.prefix):
|
if ircdb.users.hasUser(msg.prefix):
|
||||||
name = ircdb.users.getUser(msg.prefix).name
|
name = ircdb.users.getUser(msg.prefix).name
|
||||||
else:
|
else:
|
||||||
@ -191,45 +189,35 @@ class Factoids(plugins.ChannelDBHandler,
|
|||||||
irc.error('That\'s not a valid number for this key.')
|
irc.error('That\'s not a valid number for this key.')
|
||||||
return
|
return
|
||||||
|
|
||||||
def lock(self, irc, msg, args):
|
def lock(self, irc, msg, args, channel):
|
||||||
"""[<channel>] <key>
|
"""[<channel>] <key>
|
||||||
|
|
||||||
Locks the factoid(s) associated with <key> so that they cannot be
|
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
|
removed or added to. <channel> is only necessary if the message isn't
|
||||||
sent in the channel itself.
|
sent in the channel itself.
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
|
||||||
key = privmsgs.getArgs(args)
|
key = privmsgs.getArgs(args)
|
||||||
db = self.getDb(channel)
|
db = self.getDb(channel)
|
||||||
capability = ircdb.makeChannelCapability(channel, 'factoids')
|
|
||||||
if ircdb.checkCapability(msg.prefix, capability):
|
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("UPDATE keys SET locked=1 WHERE key LIKE %s", key)
|
cursor.execute("UPDATE keys SET locked=1 WHERE key LIKE %s", key)
|
||||||
db.commit()
|
db.commit()
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
else:
|
|
||||||
irc.error(conf.replyNoCapability % capability)
|
|
||||||
|
|
||||||
def unlock(self, irc, msg, args):
|
def unlock(self, irc, msg, args, channel):
|
||||||
"""[<channel>] <key>
|
"""[<channel>] <key>
|
||||||
|
|
||||||
Unlocks the factoid(s) associated with <key> so that they can be
|
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
|
removed or added to. <channel> is only necessary if the message isn't
|
||||||
sent in the channel itself.
|
sent in the channel itself.
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
|
||||||
key = privmsgs.getArgs(args)
|
key = privmsgs.getArgs(args)
|
||||||
db = self.getDb(channel)
|
db = self.getDb(channel)
|
||||||
capability = ircdb.makeChannelCapability(channel, 'factoids')
|
|
||||||
if ircdb.checkCapability(msg.prefix, capability):
|
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("UPDATE keys SET locked=0 WHERE key LIKE %s", key)
|
cursor.execute("UPDATE keys SET locked=0 WHERE key LIKE %s", key)
|
||||||
db.commit()
|
db.commit()
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
else:
|
|
||||||
irc.error(conf.replyNoCapability % capability)
|
|
||||||
|
|
||||||
def forget(self, irc, msg, args):
|
def forget(self, irc, msg, args, channel):
|
||||||
"""[<channel>] <key> [<number>|*]
|
"""[<channel>] <key> [<number>|*]
|
||||||
|
|
||||||
Removes the factoid <key> from the factoids database. If there are
|
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
|
factoids associated with a key. <channel> is only necessary if
|
||||||
the message isn't sent in the channel itself.
|
the message isn't sent in the channel itself.
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
|
||||||
if args[-1].isdigit():
|
if args[-1].isdigit():
|
||||||
number = int(args.pop())
|
number = int(args.pop())
|
||||||
number -= 1
|
number -= 1
|
||||||
@ -252,8 +239,6 @@ class Factoids(plugins.ChannelDBHandler,
|
|||||||
number = None
|
number = None
|
||||||
key = privmsgs.getArgs(args)
|
key = privmsgs.getArgs(args)
|
||||||
db = self.getDb(channel)
|
db = self.getDb(channel)
|
||||||
capability = ircdb.makeChannelCapability(channel, 'factoids')
|
|
||||||
if ircdb.checkCapability(msg.prefix, capability):
|
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("""SELECT keys.id, factoids.id
|
cursor.execute("""SELECT keys.id, factoids.id
|
||||||
FROM keys, factoids
|
FROM keys, factoids
|
||||||
@ -283,8 +268,6 @@ class Factoids(plugins.ChannelDBHandler,
|
|||||||
'Please specify which one to remove, ' \
|
'Please specify which one to remove, ' \
|
||||||
'or use * to designate all of them.' % \
|
'or use * to designate all of them.' % \
|
||||||
cursor.rowcount)
|
cursor.rowcount)
|
||||||
else:
|
|
||||||
irc.error(conf.replyNoCapability % capability)
|
|
||||||
|
|
||||||
def random(self, irc, msg, args):
|
def random(self, irc, msg, args):
|
||||||
"""[<channel>]
|
"""[<channel>]
|
||||||
@ -341,13 +324,12 @@ class Factoids(plugins.ChannelDBHandler,
|
|||||||
utils.nItems('factoid', counter), factoids)
|
utils.nItems('factoid', counter), factoids)
|
||||||
irc.reply(s)
|
irc.reply(s)
|
||||||
|
|
||||||
def change(self, irc, msg, args):
|
def change(self, irc, msg, args, channel):
|
||||||
"""[<channel>] <key> <number> <regexp>
|
"""[<channel>] <key> <number> <regexp>
|
||||||
|
|
||||||
Changes the factoid #<number> associated with <key> according to
|
Changes the factoid #<number> associated with <key> according to
|
||||||
<regexp>.
|
<regexp>.
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
|
||||||
(key, number, regexp) = privmsgs.getArgs(args, required=3)
|
(key, number, regexp) = privmsgs.getArgs(args, required=3)
|
||||||
try:
|
try:
|
||||||
replacer = utils.perlReToReplacer(regexp)
|
replacer = utils.perlReToReplacer(regexp)
|
||||||
|
|||||||
@ -227,25 +227,20 @@ class Quotes(plugins.ChannelDBHandler, callbacks.Privmsg):
|
|||||||
else:
|
else:
|
||||||
irc.error('There isn\'t a quote with that id.')
|
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>
|
"""[<channel>] <id>
|
||||||
|
|
||||||
Removes quote <id> from the quotes database for <channel>. <channel>
|
Removes quote <id> from the quotes database for <channel>. <channel>
|
||||||
is only necessary if the message isn't sent in the channel itself.
|
is only necessary if the message isn't sent in the channel itself.
|
||||||
"""
|
"""
|
||||||
channel = privmsgs.getChannel(msg, args)
|
|
||||||
id = privmsgs.getArgs(args)
|
id = privmsgs.getArgs(args)
|
||||||
db = self.getDb(channel)
|
db = self.getDb(channel)
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
capability = ircdb.makeChannelCapability(channel, 'op')
|
|
||||||
if ircdb.checkCapability(msg.prefix, capability):
|
|
||||||
cursor.execute("""DELETE FROM quotes WHERE id=%s""", id)
|
cursor.execute("""DELETE FROM quotes WHERE id=%s""", id)
|
||||||
if cursor.rowcount == 0:
|
if cursor.rowcount == 0:
|
||||||
irc.error('There was no such quote.')
|
irc.error('There was no such quote.')
|
||||||
else:
|
else:
|
||||||
irc.replySuccess()
|
irc.replySuccess()
|
||||||
else:
|
|
||||||
irc.error(conf.replyNoCapability % capability)
|
|
||||||
|
|
||||||
|
|
||||||
Class = Quotes
|
Class = Quotes
|
||||||
|
|||||||
@ -257,7 +257,7 @@ class Channel(callbacks.Privmsg):
|
|||||||
else:
|
else:
|
||||||
self.log.warning('%r attempted kban without %s',
|
self.log.warning('%r attempted kban without %s',
|
||||||
msg.prefix, capability)
|
msg.prefix, capability)
|
||||||
irc.error(conf.replyNoCapability % capability)
|
irc.errorNoCapability(capability)
|
||||||
|
|
||||||
def unban(self, irc, msg, args, channel):
|
def unban(self, irc, msg, args, channel):
|
||||||
"""[<channel>] <hostmask>
|
"""[<channel>] <hostmask>
|
||||||
|
|||||||
@ -299,26 +299,24 @@ class RichReplyMethods(object):
|
|||||||
def replySuccess(self, s='', **kwargs):
|
def replySuccess(self, s='', **kwargs):
|
||||||
self.reply(self._makeReply(conf.replySuccess, 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):
|
def replyPossibleBug(self, s='', **kwargs):
|
||||||
self.reply(self._makeReply(conf.replyPossibleBug, 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):
|
def replyError(self, s='', **kwargs):
|
||||||
self.reply(self._makeReply(conf.replyError, 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):
|
class IrcObjectProxy(RichReplyMethods):
|
||||||
"A proxy object to allow proper nested of commands (even threaded ones)."
|
"A proxy object to allow proper nested of commands (even threaded ones)."
|
||||||
|
|||||||
@ -295,7 +295,7 @@ class Mixin(object):
|
|||||||
except Error, e:
|
except Error, e:
|
||||||
irc.error(str(e))
|
irc.error(str(e))
|
||||||
else:
|
else:
|
||||||
irc.error(conf.replyNoCapability % capability)
|
irc.errorNoCapability(capability)
|
||||||
else:
|
else:
|
||||||
help(self.configurables)
|
help(self.configurables)
|
||||||
elif hasattr(self, 'globalConfigurables') and \
|
elif hasattr(self, 'globalConfigurables') and \
|
||||||
|
|||||||
@ -98,7 +98,7 @@ def checkCapability(f, capability):
|
|||||||
else:
|
else:
|
||||||
self.log.warning('%r attempted %s without %s.',
|
self.log.warning('%r attempted %s without %s.',
|
||||||
msg.prefix, f.func_name, capability)
|
msg.prefix, f.func_name, capability)
|
||||||
irc.error(conf.replyNoCapability % capability)
|
irc.errorNoCapability(capability)
|
||||||
newf = types.FunctionType(newf.func_code, newf.func_globals,
|
newf = types.FunctionType(newf.func_code, newf.func_globals,
|
||||||
f.func_name, closure=newf.func_closure)
|
f.func_name, closure=newf.func_closure)
|
||||||
newf.__doc__ = f.__doc__
|
newf.__doc__ = f.__doc__
|
||||||
@ -119,7 +119,7 @@ def checkChannelCapability(f, capability):
|
|||||||
else:
|
else:
|
||||||
self.log.warning('%r attempted %s without %s.',
|
self.log.warning('%r attempted %s without %s.',
|
||||||
msg.prefix, f.func_name, capability)
|
msg.prefix, f.func_name, capability)
|
||||||
irc.error(conf.replyNoCapability % chancap)
|
irc.errorNoCapability(chancap)
|
||||||
newf = types.FunctionType(newf.func_code, newf.func_globals,
|
newf = types.FunctionType(newf.func_code, newf.func_globals,
|
||||||
f.func_name, closure=newf.func_closure)
|
f.func_name, closure=newf.func_closure)
|
||||||
newf.__doc__ = f.__doc__
|
newf.__doc__ = f.__doc__
|
||||||
@ -209,7 +209,7 @@ class CapabilityCheckingPrivmsg(callbacks.Privmsg):
|
|||||||
else:
|
else:
|
||||||
self.log.warning('%r tried to call %s without %s.',
|
self.log.warning('%r tried to call %s without %s.',
|
||||||
msg.prefix, f.im_func.func_name, self.capability)
|
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:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user