From ed62c9efb18432cc99151c09b1b32755d2b77c8c Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 17 May 2013 17:36:11 +0200 Subject: [PATCH] commands.py: Rename 'isGranted' to 'haveHalfop+' and add 'haveVoice+'. --- plugins/Channel/plugin.py | 20 ++++++++++---------- plugins/Topic/plugin.py | 4 ++-- src/commands.py | 36 +++++++++++++++++++++++++----------- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/plugins/Channel/plugin.py b/plugins/Channel/plugin.py index 47e3e9528..0c411ede7 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', ('isGranted', _('change the mode')), many('something')]) + mode = wrap(mode, ['op', ('haveHalfop+', _('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', ('isGranted', _('moderate the channel'))]) + moderate = wrap(moderate, ['op', ('haveHalfop+', _('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', ('isGranted', + unmoderate = wrap(unmoderate, ['op', ('haveHalfop+', _('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', ('isGranted', _('change the keyword')), + key = wrap(key, ['op', ('haveHalfop+', _('change the keyword')), additional('somethingWithoutSpaces', '')]) @internationalizeDocstring @@ -189,7 +189,7 @@ class Channel(callbacks.Plugin): channel itself. """ self._voice(irc, msg, args, channel, nicks, ircmsgs.voices) - voice = wrap(voice, ['channel', ('isGranted', _('voice someone')), + voice = wrap(voice, ['channel', ('haveHalfop+', _('voice someone')), any('nickInChannel')]) @internationalizeDocstring @@ -281,7 +281,7 @@ class Channel(callbacks.Plugin): Raise=True) for nick in nicks: self._sendMsg(irc, ircmsgs.kick(channel, nick, reason)) - kick = wrap(kick, ['op', ('isGranted', _('kick someone')), + kick = wrap(kick, ['op', ('haveHalfop+', _('kick someone')), commalist('nickInChannel'), additional('text')]) @internationalizeDocstring @@ -304,7 +304,7 @@ class Channel(callbacks.Plugin): kban = wrap(kban, ['op', getopts({'exact':'', 'nick':'', 'user':'', 'host':''}), - ('isGranted', _('kick or ban someone')), + ('haveHalfop+', _('kick or ban someone')), 'nickInChannel', optional('expiry', 0), additional('text')]) @@ -328,7 +328,7 @@ class Channel(callbacks.Plugin): iban = wrap(iban, ['op', getopts({'exact':'', 'nick':'', 'user':'', 'host':''}), - ('isGranted', _('ban someone')), + ('haveHalfop+', _('ban someone')), first('nick', 'hostmask'), optional('expiry', 0)]) @@ -434,7 +434,7 @@ class Channel(callbacks.Plugin): irc.error(_('No bans matching %s were found on %s.') % (msg.prefix, channel)) unban = wrap(unban, ['op', - ('isGranted', _('unban someone')), + ('haveHalfop+', _('unban someone')), additional( first('hostmask', ('literal', '--all')))]) @@ -459,7 +459,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', ('isGranted', _('invite someone')), + invite = wrap(invite, ['op', ('haveHalfop+', _('invite someone')), additional('nick')]) def do341(self, irc, msg): diff --git a/plugins/Topic/plugin.py b/plugins/Topic/plugin.py index b380a21b5..0ef60eb92 100644 --- a/plugins/Topic/plugin.py +++ b/plugins/Topic/plugin.py @@ -481,7 +481,7 @@ class Topic(callbacks.Plugin): irc.errorNoCapability(capabilities, Raise=True) irc.queueMsg(ircmsgs.mode(channel, '+t')) irc.noReply() - lock = wrap(lock, ['channel', ('isGranted', _('lock the topic'))]) + lock = wrap(lock, ['channel', ('haveHalfop+', _('lock the topic'))]) @internationalizeDocstring def unlock(self, irc, msg, args, channel): @@ -495,7 +495,7 @@ class Topic(callbacks.Plugin): irc.errorNoCapability(capabilities, Raise=True) irc.queueMsg(ircmsgs.mode(channel, '-t')) irc.noReply() - unlock = wrap(unlock, ['channel', ('isGranted', _('unlock the topic'))]) + unlock = wrap(unlock, ['channel', ('haveHalfop+', _('unlock the topic'))]) @internationalizeDocstring def restore(self, irc, msg, args, channel): diff --git a/src/commands.py b/src/commands.py index c50735b16..cce5f5a00 100644 --- a/src/commands.py +++ b/src/commands.py @@ -325,6 +325,18 @@ def getHaveVoice(irc, msg, args, state, action=_('do that')): if not irc.state.channels[state.channel].isVoice(irc.nick): state.error(_('I need to be voiced to %s.') % action, Raise=True) +def getHaveVoicePlus(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) and \ + not irc.state.channels[state.channel].isVoice(irc.nick): + # isOp includes owners and protected users + state.error(_('I need to be at least voiced to %s.') % action, + Raise=True) + def getHaveHalfop(irc, msg, args, state, action=_('do that')): if not state.channel: getChannel(irc, msg, args, state) @@ -333,15 +345,7 @@ def getHaveHalfop(irc, msg, args, state, action=_('do that')): 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) - 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): - state.error(_('I need to be opped to %s.') % action, Raise=True) - -def getIsGranted(irc, msg, args, state, action=_('do that')): +def getHaveHalfopPlus(irc, msg, args, state, action=_('do that')): if not state.channel: getChannel(irc, msg, args, state) if state.channel not in irc.state.channels: @@ -352,6 +356,14 @@ def getIsGranted(irc, msg, args, state, action=_('do that')): state.error(_('I need to be at least halfopped to %s.') % action, Raise=True) +def getHaveOp(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): + state.error(_('I need to be opped to %s.') % action, Raise=True) + def validChannel(irc, msg, args, state): if irc.isChannel(args[0]): state.args.append(args.pop(0)) @@ -700,8 +712,7 @@ wrappers = ircutils.IrcDict({ 'banmask': getBanmask, 'boolean': getBoolean, 'callerInGivenChannel': callerInGivenChannel, - 'isGranted': getIsGranted, # I know this name sucks, but I can't find - # something better + 'isGranted': getHaveHalfopPlus, # Backward compatibility 'capability': getSomethingNoSpaces, 'channel': getChannel, 'channelOrGlobal': getChannelOrGlobal, @@ -718,8 +729,11 @@ wrappers = ircutils.IrcDict({ 'glob': getGlob, 'halfop': getHalfop, 'haveHalfop': getHaveHalfop, + 'haveHalfop+': getHaveHalfopPlus, 'haveOp': getHaveOp, + 'haveOp+': getHaveOp, # We don't handle modes greater than op. 'haveVoice': getHaveVoice, + 'haveVoice+': getHaveVoicePlus, 'hostmask': getHostmask, 'httpUrl': getHttpUrl, 'id': getId,