From 41514bafdd75f739fcc61223dadd3dc5300b2636 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 1 Jul 2011 15:58:39 +0200 Subject: [PATCH] Core & Channel & Topic: Add the isGranted converter. Closes GH-39. --- plugins/Channel/plugin.py | 20 ++++++++++---------- plugins/Topic/plugin.py | 4 ++-- src/commands.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/plugins/Channel/plugin.py b/plugins/Channel/plugin.py index f483c800b..27bba391e 100644 --- a/plugins/Channel/plugin.py +++ b/plugins/Channel/plugin.py @@ -73,7 +73,7 @@ class Channel(callbacks.Plugin): itself. """ self._sendMsg(irc, ircmsgs.mode(channel, modes)) - mode = wrap(mode, ['op', ('haveOp', _('change the mode')), many('something')]) + mode = wrap(mode, ['op', ('isGranted', _('change the mode')), many('something')]) @internationalizeDocstring def limit(self, irc, msg, args, channel, limit): @@ -99,7 +99,7 @@ class Channel(callbacks.Plugin): message isn't sent in the channel itself. """ self._sendMsg(irc, ircmsgs.mode(channel, ['+m'])) - moderate = wrap(moderate, ['op', ('haveOp', _('moderate the channel'))]) + moderate = wrap(moderate, ['op', ('isGranted', _('moderate the channel'))]) @internationalizeDocstring def unmoderate(self, irc, msg, args, channel): @@ -110,7 +110,7 @@ class Channel(callbacks.Plugin): message isn't sent in the channel itself. """ self._sendMsg(irc, ircmsgs.mode(channel, ['-m'])) - unmoderate = wrap(unmoderate, ['op', ('haveOp', + unmoderate = wrap(unmoderate, ['op', ('isGranted', _('unmoderate the channel'))]) @internationalizeDocstring @@ -127,7 +127,7 @@ class Channel(callbacks.Plugin): self._sendMsg(irc, ircmsgs.mode(channel, ['+k', key])) else: self._sendMsg(irc, ircmsgs.mode(channel, ['-k'])) - key = wrap(key, ['op', ('haveOp', _('change the keyword')), + key = wrap(key, ['op', ('isGranted', _('change the keyword')), additional('somethingWithoutSpaces', '')]) @internationalizeDocstring @@ -187,7 +187,7 @@ class Channel(callbacks.Plugin): self._sendMsgs(irc, nicks, f) else: irc.errorNoCapability(capability) - voice = wrap(voice, ['channel', ('haveOp', _('voice someone')), + voice = wrap(voice, ['channel', ('isGranted', _('voice someone')), any('nickInChannel')]) @internationalizeDocstring @@ -247,7 +247,7 @@ class Channel(callbacks.Plugin): def f(L): return ircmsgs.devoices(channel, L) self._sendMsgs(irc, nicks, f) - devoice = wrap(devoice, ['voice', ('haveOp', 'devoice someone'), + devoice = wrap(devoice, ['voice', ('isGranted', 'devoice someone'), any('nickInChannel')]) @internationalizeDocstring @@ -283,7 +283,7 @@ class Channel(callbacks.Plugin): Raise=True) for nick in nicks: self._sendMsg(irc, ircmsgs.kick(channel, nick, reason)) - kick = wrap(kick, ['op', ('haveOp', _('kick someone')), + kick = wrap(kick, ['op', ('isGranted', _('kick someone')), commalist('nickInChannel'), additional('text')]) @internationalizeDocstring @@ -361,7 +361,7 @@ class Channel(callbacks.Plugin): kban = wrap(kban, ['op', getopts({'exact':'', 'nick':'', 'user':'', 'host':''}), - ('haveOp', _('kick or ban someone')), + ('isGranted', _('kick or ban someone')), 'nickInChannel', optional('expiry', 0), additional('text')]) @@ -392,7 +392,7 @@ class Channel(callbacks.Plugin): irc.error(_('No bans matching %s were found on %s.') % (msg.prefix, channel)) unban = wrap(unban, ['op', - ('haveOp', _('unban someone')), + ('isGranted', _('unban someone')), additional('hostmask')]) @internationalizeDocstring @@ -406,7 +406,7 @@ class Channel(callbacks.Plugin): nick = nick or msg.nick self._sendMsg(irc, ircmsgs.invite(nick, channel)) self.invites[(irc.getRealIrc(), ircutils.toLower(nick))] = irc - invite = wrap(invite, ['op', ('haveOp', _('invite someone')), + invite = wrap(invite, ['op', ('isGranted', _('invite someone')), additional('nick')]) def do341(self, irc, msg): diff --git a/plugins/Topic/plugin.py b/plugins/Topic/plugin.py index 757ed3625..d3bfa1862 100644 --- a/plugins/Topic/plugin.py +++ b/plugins/Topic/plugin.py @@ -479,7 +479,7 @@ class Topic(callbacks.Plugin): irc.errorNoCapability(capabilities, Raise=True) irc.queueMsg(ircmsgs.mode(channel, '+t')) irc.noReply() - lock = wrap(lock, ['channel', ('haveOp', _('lock the topic'))]) + lock = wrap(lock, ['channel', ('isGranted', _('lock the topic'))]) @internationalizeDocstring def unlock(self, irc, msg, args, channel): @@ -493,7 +493,7 @@ class Topic(callbacks.Plugin): irc.errorNoCapability(capabilities, Raise=True) irc.queueMsg(ircmsgs.mode(channel, '-t')) irc.noReply() - unlock = wrap(unlock, ['channel', ('haveOp', _('unlock the topic'))]) + unlock = wrap(unlock, ['channel', ('isGranted', _('unlock the topic'))]) @internationalizeDocstring def restore(self, irc, msg, args, channel): diff --git a/src/commands.py b/src/commands.py index 2a2b65edd..a24b890f0 100644 --- a/src/commands.py +++ b/src/commands.py @@ -252,6 +252,22 @@ def getNetworkIrc(irc, msg, args, state, errorIfNoMatch=False): else: state.args.append(irc) +def getHaveVoice(irc, msg, args, state, action=_('do that')): + if not state.channel: + getChannel(irc, msg, args, state) + if state.channel not in irc.state.channels: + state.error(_('I\'m not even in %s.') % state.channel, Raise=True) + if not irc.state.channels[state.channel].isVoice(irc.nick): + state.error(_('I need to be voiced to %s.') % action, Raise=True) + +def getHaveHalfop(irc, msg, args, state, action=_('do that')): + if not state.channel: + getChannel(irc, msg, args, state) + if state.channel not in irc.state.channels: + state.error(_('I\'m not even in %s.') % state.channel, Raise=True) + if not irc.state.channels[state.channel].isHalfop(irc.nick): + state.error(_('I need to be halfopped to %s.') % action, Raise=True) + def getHaveOp(irc, msg, args, state, action=_('do that')): if not state.channel: getChannel(irc, msg, args, state) @@ -260,6 +276,17 @@ def getHaveOp(irc, msg, args, state, action=_('do that')): if not irc.state.channels[state.channel].isOp(irc.nick): state.error(_('I need to be opped to %s.') % action, Raise=True) +def getIsGranted(irc, msg, args, state, action=_('do that')): + if not state.channel: + getChannel(irc, msg, args, state) + if state.channel not in irc.state.channels: + state.error(_('I\'m not even in %s.') % state.channel, Raise=True) + if not irc.state.channels[state.channel].isOp(irc.nick) and \ + not irc.state.channels[state.channel].isHalfop(irc.nick): + # isOp includes owners and protected users + state.error(_('I need to be at least halfopped to %s.') % action, + Raise=True) + def validChannel(irc, msg, args, state): if irc.isChannel(args[0]): state.args.append(args.pop(0)) @@ -591,6 +618,8 @@ wrappers = ircutils.IrcDict({ 'banmask': getBanmask, 'boolean': getBoolean, 'callerInGivenChannel': callerInGivenChannel, + 'isGranted': getIsGranted, # I know this name sucks, but I can't find + # something better 'capability': getSomethingNoSpaces, 'channel': getChannel, 'channelDb': getChannelDb, @@ -605,7 +634,9 @@ wrappers = ircutils.IrcDict({ 'float': getFloat, 'glob': getGlob, 'halfop': getHalfop, + 'haveHalfop': getHaveHalfop 'haveOp': getHaveOp, + 'haveVoice': getHaveVoice 'hostmask': getHostmask, 'httpUrl': getHttpUrl, 'id': getId,