Added op, halfop, and voice converters, and converted Channel to use them.

This commit is contained in:
Jeremy Fincher 2005-02-24 09:59:21 +00:00
parent 1e56f0df7e
commit 4648360a04
2 changed files with 48 additions and 61 deletions

View File

@ -64,9 +64,7 @@ class Channel(callbacks.Plugin):
""" """
self._sendMsg(irc, ircmsgs.mode(channel, modes)) self._sendMsg(irc, ircmsgs.mode(channel, modes))
mode = wrap(mode, mode = wrap(mode,
[('checkChannelCapability', 'op'), ['op', ('haveOp', 'change the mode'), many('something')])
('haveOp', 'change the mode'),
many('something')])
def limit(self, irc, msg, args, channel, limit): def limit(self, irc, msg, args, channel, limit):
"""[<channel>] [<limit>] """[<channel>] [<limit>]
@ -79,8 +77,7 @@ class Channel(callbacks.Plugin):
self._sendMsg(irc, ircmsgs.mode(channel, ['+l', limit])) self._sendMsg(irc, ircmsgs.mode(channel, ['+l', limit]))
else: else:
self._sendMsg(irc, ircmsgs.mode(channel, ['-l'])) self._sendMsg(irc, ircmsgs.mode(channel, ['-l']))
limit = wrap(limit, [('checkChannelCapability', 'op'), limit = wrap(limit, ['op', ('haveOp', 'change the limit'),
('haveOp', 'change the limit'),
additional('nonNegativeInt', 0)]) additional('nonNegativeInt', 0)])
def moderate(self, irc, msg, args, channel): def moderate(self, irc, msg, args, channel):
@ -91,8 +88,7 @@ class Channel(callbacks.Plugin):
message isn't sent in the channel itself. message isn't sent in the channel itself.
""" """
self._sendMsg(irc, ircmsgs.mode(channel, ['+m'])) self._sendMsg(irc, ircmsgs.mode(channel, ['+m']))
moderate = wrap(moderate, [('checkChannelCapability', 'op'), moderate = wrap(moderate, ['op', ('haveOp', 'moderate the channel')])
('haveOp', 'moderate the channel')])
def unmoderate(self, irc, msg, args, channel): def unmoderate(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
@ -102,8 +98,7 @@ class Channel(callbacks.Plugin):
message isn't sent in the channel itself. message isn't sent in the channel itself.
""" """
self._sendMsg(irc, ircmsgs.mode(channel, ['-m'])) self._sendMsg(irc, ircmsgs.mode(channel, ['-m']))
unmoderate = wrap(unmoderate, [('checkChannelCapability', 'op'), unmoderate = wrap(unmoderate, ['op', ('haveOp', 'unmoderate the channel')])
('haveOp', 'unmoderate the channel')])
def key(self, irc, msg, args, channel, key): def key(self, irc, msg, args, channel, key):
"""[<channel>] [<key>] """[<channel>] [<key>]
@ -118,8 +113,7 @@ class Channel(callbacks.Plugin):
self._sendMsg(irc, ircmsgs.mode(channel, ['+k', key])) self._sendMsg(irc, ircmsgs.mode(channel, ['+k', key]))
else: else:
self._sendMsg(irc, ircmsgs.mode(channel, ['-k'])) self._sendMsg(irc, ircmsgs.mode(channel, ['-k']))
key = wrap(key, [('checkChannelCapability', 'op'), key = wrap(key, ['op', ('haveOp', 'change the keyword'),
('haveOp', 'change the keyword'),
additional('somethingWithoutSpaces', '')]) additional('somethingWithoutSpaces', '')])
def op(self, irc, msg, args, channel, nicks): def op(self, irc, msg, args, channel, nicks):
@ -133,9 +127,7 @@ class Channel(callbacks.Plugin):
if not nicks: if not nicks:
nicks = [msg.nick] nicks = [msg.nick]
self._sendMsg(irc, ircmsgs.ops(channel, nicks)) self._sendMsg(irc, ircmsgs.ops(channel, nicks))
op = wrap(op, [('checkChannelCapability', 'op'), op = wrap(op, ['op', ('haveOp', 'op someone'), any('nickInChannel')])
('haveOp', 'op someone'),
any('nickInChannel')])
def halfop(self, irc, msg, args, channel, nicks): def halfop(self, irc, msg, args, channel, nicks):
"""[<channel>] [<nick> ...] """[<channel>] [<nick> ...]
@ -148,8 +140,7 @@ class Channel(callbacks.Plugin):
if not nicks: if not nicks:
nicks = [msg.nick] nicks = [msg.nick]
self._sendMsg(irc, ircmsgs.halfops(channel, nicks)) self._sendMsg(irc, ircmsgs.halfops(channel, nicks))
halfop = wrap(halfop, [('checkChannelCapability', 'halfop'), halfop = wrap(halfop, ['halfop', ('haveOp', 'halfop someone'),
('haveOp', 'halfop someone'),
any('nickInChannel')]) any('nickInChannel')])
def voice(self, irc, msg, args, channel, nicks): def voice(self, irc, msg, args, channel, nicks):
@ -190,8 +181,7 @@ class Channel(callbacks.Plugin):
if not nicks: if not nicks:
nicks = [msg.nick] nicks = [msg.nick]
self._sendMsg(irc, ircmsgs.deops(channel, nicks)) self._sendMsg(irc, ircmsgs.deops(channel, nicks))
deop = wrap(deop, [('checkChannelCapability', 'op'), deop = wrap(deop, ['op', ('haveOp', 'deop someone'),
('haveOp', 'deop someone'),
any('nickInChannel')]) any('nickInChannel')])
def dehalfop(self, irc, msg, args, channel, nicks): def dehalfop(self, irc, msg, args, channel, nicks):
@ -208,8 +198,7 @@ class Channel(callbacks.Plugin):
if not nicks: if not nicks:
nicks = [msg.nick] nicks = [msg.nick]
self._sendMsg(irc, ircmsgs.dehalfops(channel, nicks)) self._sendMsg(irc, ircmsgs.dehalfops(channel, nicks))
dehalfop = wrap(dehalfop, [('checkChannelCapability', 'halfop'), dehalfop = wrap(dehalfop, ['halfop', ('haveOp', 'dehalfop someone'),
('haveOp', 'dehalfop someone'),
any('nickInChannel')]) any('nickInChannel')])
# XXX We should respect the MODES part of an 005 here. Helper function # XXX We should respect the MODES part of an 005 here. Helper function
@ -228,8 +217,7 @@ class Channel(callbacks.Plugin):
if not nicks: if not nicks:
nicks = [msg.nick] nicks = [msg.nick]
self._sendMsg(irc, ircmsgs.devoices(channel, nicks)) self._sendMsg(irc, ircmsgs.devoices(channel, nicks))
devoice = wrap(devoice, [('checkChannelCapability', 'voice'), devoice = wrap(devoice, ['voice', ('haveOp', 'devoice someone'),
('haveOp', 'devoice someone'),
any('nickInChannel')]) any('nickInChannel')])
def cycle(self, irc, msg, args, channel): def cycle(self, irc, msg, args, channel):
@ -242,7 +230,7 @@ class Channel(callbacks.Plugin):
self._sendMsg(irc, ircmsgs.part(channel, msg.nick)) self._sendMsg(irc, ircmsgs.part(channel, msg.nick))
networkGroup = conf.supybot.networks.get(irc.network) networkGroup = conf.supybot.networks.get(irc.network)
self._sendMsg(irc, networkGroup.channels.join(channel)) self._sendMsg(irc, networkGroup.channels.join(channel))
cycle = wrap(cycle, [('checkChannelCapability','op')]) cycle = wrap(cycle, ['op'])
def kick(self, irc, msg, args, channel, nick, reason): def kick(self, irc, msg, args, channel, nick, reason):
"""[<channel>] <nick> [<reason>] """[<channel>] <nick> [<reason>]
@ -262,10 +250,8 @@ class Channel(callbacks.Plugin):
'length for a KICK reason on this server.') 'length for a KICK reason on this server.')
return return
self._sendMsg(irc, ircmsgs.kick(channel, nick, reason)) self._sendMsg(irc, ircmsgs.kick(channel, nick, reason))
kick = wrap(kick, [('checkChannelCapability', 'op'), kick = wrap(kick, ['op', ('haveOp', 'kick someone'),
('haveOp', 'kick someone'), 'nickInChannel', additional('text')])
'nickInChannel',
additional('text')])
def kban(self, irc, msg, args, def kban(self, irc, msg, args,
channel, optlist, bannedNick, expiry, reason): channel, optlist, bannedNick, expiry, reason):
@ -360,7 +346,7 @@ class Channel(callbacks.Plugin):
irc.errorNoCapability(capability) irc.errorNoCapability(capability)
exact,nick,user,host exact,nick,user,host
kban = wrap(kban, kban = wrap(kban,
[('checkChannelCapability', 'op'), ['op',
getopts({'exact':'', 'nick':'', 'user':'', 'host':''}), getopts({'exact':'', 'nick':'', 'user':'', 'host':''}),
('haveOp', 'kick or ban someone'), ('haveOp', 'kick or ban someone'),
'nickInChannel', 'nickInChannel',
@ -391,7 +377,7 @@ class Channel(callbacks.Plugin):
else: else:
irc.error('No bans matching %s were found on %s.' % irc.error('No bans matching %s were found on %s.' %
(msg.prefix, channel)) (msg.prefix, channel))
unban = wrap(unban, [('checkChannelCapability', 'op'), unban = wrap(unban, ['op',
('haveOp', 'unban someone'), ('haveOp', 'unban someone'),
additional('hostmask')]) additional('hostmask')])
@ -404,8 +390,7 @@ class Channel(callbacks.Plugin):
""" """
self._sendMsg(irc, ircmsgs.invite(nick or msg.nick, channel)) self._sendMsg(irc, ircmsgs.invite(nick or msg.nick, channel))
self.invites[(irc.getRealIrc(), ircutils.toLower(nick))] = irc self.invites[(irc.getRealIrc(), ircutils.toLower(nick))] = irc
invite = wrap(invite, [('checkChannelCapability', 'op'), invite = wrap(invite, ['op', ('haveOp', 'invite someone'),
('haveOp', 'invite someone'),
additional('nick')]) additional('nick')])
def do341(self, irc, msg): def do341(self, irc, msg):
@ -452,7 +437,7 @@ class Channel(callbacks.Plugin):
c.lobotomized = True c.lobotomized = True
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
lobotomize = wrap(lobotomize, [('checkChannelCapability', 'op')]) lobotomize = wrap(lobotomize, ['op'])
def unlobotomize(self, irc, msg, args, channel): def unlobotomize(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
@ -466,7 +451,7 @@ class Channel(callbacks.Plugin):
c.lobotomized = False c.lobotomized = False
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
unlobotomize = wrap(unlobotomize, [('checkChannelCapability', 'op')]) unlobotomize = wrap(unlobotomize, ['op'])
def permban(self, irc, msg, args, channel, banmask, expires): def permban(self, irc, msg, args, channel, banmask, expires):
"""[<channel>] <nick|hostmask> [<expires>] """[<channel>] <nick|hostmask> [<expires>]
@ -484,9 +469,7 @@ class Channel(callbacks.Plugin):
c.addBan(banmask, expires) c.addBan(banmask, expires)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
permban = wrap(permban, [('checkChannelCapability', 'op'), permban = wrap(permban, ['op', 'hostmask', additional('expiry', 0)])
'hostmask',
additional('expiry', 0)])
def unpermban(self, irc, msg, args, channel, banmask): def unpermban(self, irc, msg, args, channel, banmask):
"""[<channel>] <hostmask> """[<channel>] <hostmask>
@ -499,7 +482,7 @@ class Channel(callbacks.Plugin):
c.removeBan(banmask) c.removeBan(banmask)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
unpermban = wrap(unpermban, [('checkChannelCapability', 'op'), 'hostmask']) unpermban = wrap(unpermban, ['op', 'hostmask'])
def permbans(self, irc, msg, args, channel): def permbans(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
@ -513,7 +496,7 @@ class Channel(callbacks.Plugin):
irc.reply(format('%L', map(utils.str.dqrepr, c.bans))) irc.reply(format('%L', map(utils.str.dqrepr, c.bans)))
else: else:
irc.reply('There are currently no permanent bans on %s' % channel) irc.reply('There are currently no permanent bans on %s' % channel)
permbans = wrap(permbans, [('checkChannelCapability', 'op')]) permbans = wrap(permbans, ['op'])
def ignore(self, irc, msg, args, channel, banmask, expires): def ignore(self, irc, msg, args, channel, banmask, expires):
"""[<channel>] <nick|hostmask> [<expires>] """[<channel>] <nick|hostmask> [<expires>]
@ -529,8 +512,7 @@ class Channel(callbacks.Plugin):
c.addIgnore(banmask, expires) c.addIgnore(banmask, expires)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
ignore = wrap(ignore, [('checkChannelCapability', 'op'), ignore = wrap(ignore, ['op', 'hostmask', additional('expiry', 0)])
'hostmask', additional('expiry', 0)])
def unignore(self, irc, msg, args, channel, banmask): def unignore(self, irc, msg, args, channel, banmask):
"""[<channel>] <hostmask> """[<channel>] <hostmask>
@ -543,7 +525,7 @@ class Channel(callbacks.Plugin):
c.removeIgnore(banmask) c.removeIgnore(banmask)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
unignore = wrap(unignore, [('checkChannelCapability', 'op'), 'hostmask']) unignore = wrap(unignore, ['op', 'hostmask'])
def ignores(self, irc, msg, args, channel): def ignores(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
@ -561,7 +543,7 @@ class Channel(callbacks.Plugin):
else: else:
L = sorted(c.ignores) L = sorted(c.ignores)
irc.reply(utils.str.commaAndify(map(repr, L))) irc.reply(utils.str.commaAndify(map(repr, L)))
ignores = wrap(ignores, [('checkChannelCapability', 'op')]) ignores = wrap(ignores, ['op'])
def addcapability(self, irc, msg, args, channel, user, capabilities): def addcapability(self, irc, msg, args, channel, user, capabilities):
"""[<channel>] <nick|username> <capability> [<capability> ...] """[<channel>] <nick|username> <capability> [<capability> ...]
@ -576,8 +558,7 @@ class Channel(callbacks.Plugin):
user.addCapability(c) user.addCapability(c)
ircdb.users.setUser(user) ircdb.users.setUser(user)
irc.replySuccess() irc.replySuccess()
addcapability = wrap(addcapability, [('checkChannelCapability', 'op'), addcapability = wrap(addcapability, ['op', 'otherUser', 'capability'])
'otherUser', 'capability'])
def removecapability(self, irc, msg, args, channel, user, capabilities): def removecapability(self, irc, msg, args, channel, user, capabilities):
"""[<channel>] <name|hostmask> <capability> [<capability> ...] """[<channel>] <name|hostmask> <capability> [<capability> ...]
@ -602,9 +583,7 @@ class Channel(callbacks.Plugin):
irc.error(format('That user didn\'t have the %L %s.', fail, s), irc.error(format('That user didn\'t have the %L %s.', fail, s),
Raise=True) Raise=True)
irc.replySuccess() irc.replySuccess()
removecapability = wrap(removecapability, removecapability = wrap(removecapability,['op', 'otherUser', 'capability'])
[('checkChannelCapability', 'op'),
'otherUser', 'capability'])
# XXX This needs to be fix0red to be like Owner.defaultcapability. Or # XXX This needs to be fix0red to be like Owner.defaultcapability. Or
# something else. This is a horrible interface. # something else. This is a horrible interface.
@ -623,8 +602,7 @@ class Channel(callbacks.Plugin):
c.setDefaultCapability(False) c.setDefaultCapability(False)
ircdb.channels.setChannel(channel, c) ircdb.channels.setChannel(channel, c)
irc.replySuccess() irc.replySuccess()
setdefaultcapability = wrap(setdefaultcapability, setdefaultcapability = wrap(setdefaultcapability, ['op', 'boolean'])
[('checkChannelCapability', 'op'), 'boolean'])
def setcapability(self, irc, msg, args, channel, capabilities): def setcapability(self, irc, msg, args, channel, capabilities):
"""[<channel>] <capability> [<capability> ...] """[<channel>] <capability> [<capability> ...]
@ -638,8 +616,7 @@ class Channel(callbacks.Plugin):
chan.addCapability(c) chan.addCapability(c)
ircdb.channels.setChannel(channel, chan) ircdb.channels.setChannel(channel, chan)
irc.replySuccess() irc.replySuccess()
setcapability = wrap(setcapability, setcapability = wrap(setcapability, ['op', many('capability')])
[('checkChannelCapability', 'op'), many('capability')])
def unsetcapability(self, irc, msg, args, channel, capabilities): def unsetcapability(self, irc, msg, args, channel, capabilities):
"""[<channel>] <capability> [<capability> ...] """[<channel>] <capability> [<capability> ...]
@ -664,9 +641,7 @@ class Channel(callbacks.Plugin):
irc.error(format('I do not know about the %L %s.', fail, s), irc.error(format('I do not know about the %L %s.', fail, s),
Raise=True) Raise=True)
irc.replySuccess() irc.replySuccess()
unsetcapability = wrap(unsetcapability, unsetcapability = wrap(unsetcapability, ['op', many('capability')])
[('checkChannelCapability', 'op'),
many('capability')])
def capabilities(self, irc, msg, args, channel): def capabilities(self, irc, msg, args, channel):
"""[<channel>] """[<channel>]
@ -713,9 +688,9 @@ class Channel(callbacks.Plugin):
chan.addCapability(s) chan.addCapability(s)
ircdb.channels.setChannel(channel, chan) ircdb.channels.setChannel(channel, chan)
irc.replySuccess() irc.replySuccess()
disable = wrap(disable, [('checkChannelCapability', 'op'), disable = wrap(disable, ['op',
optional(('plugin', False)), optional(('plugin', False)),
additional('commandName')]) additional('commandName')])
def enable(self, irc, msg, args, channel, plugin, command): def enable(self, irc, msg, args, channel, plugin, command):
"""[<channel>] [<plugin>] [<command>] """[<channel>] [<plugin>] [<command>]
@ -758,9 +733,9 @@ class Channel(callbacks.Plugin):
irc.error(format('%s was not disabled.', s[1:])) irc.error(format('%s was not disabled.', s[1:]))
else: else:
irc.replySuccess() irc.replySuccess()
enable = wrap(enable, [('checkChannelCapability', 'op'), enable = wrap(enable, ['op',
optional(('plugin', False)), optional(('plugin', False)),
additional('commandName')]) additional('commandName')])
def lobotomies(self, irc, msg, args): def lobotomies(self, irc, msg, args):
"""takes no arguments """takes no arguments
@ -808,7 +783,7 @@ class Channel(callbacks.Plugin):
capability. capability.
""" """
self.alertOps(irc, channel, text, frm=msg.nick) self.alertOps(irc, channel, text, frm=msg.nick)
alert = wrap(alert, [('checkChannelCapability', 'op'), 'text']) alert = wrap(alert, ['op', 'text'])
Class = Channel Class = Channel

View File

@ -422,6 +422,15 @@ def checkChannelCapability(irc, msg, args, state, cap):
if not ircdb.checkCapability(msg.prefix, cap): if not ircdb.checkCapability(msg.prefix, cap):
irc.errorNoCapability(cap, Raise=True) irc.errorNoCapability(cap, Raise=True)
def getOp(irc, msg, args, state):
checkChannelCapability(irc, msg, args, state, 'op')
def getHalfop(irc, msg, args, state):
checkChannelCapability(irc, msg, args, state, 'halfop')
def getVoice(irc, msg, args, state):
checkChannelCapability(irc, msg, args, state, 'voice')
def getLowered(irc, msg, args, state): def getLowered(irc, msg, args, state):
state.args.append(ircutils.toLower(args.pop(0))) state.args.append(ircutils.toLower(args.pop(0)))
@ -610,6 +619,9 @@ wrappers = ircutils.IrcDict({
'admin': admin, 'admin': admin,
'checkCapability': checkCapability, 'checkCapability': checkCapability,
'checkChannelCapability': checkChannelCapability, 'checkChannelCapability': checkChannelCapability,
'op': getOp,
'halfop': getHalfop,
'voice': getVoice,
}) })
def addConverter(name, wrapper): def addConverter(name, wrapper):