Core & Channel & Topic: Add the isGranted converter. Closes GH-39.

This commit is contained in:
Valentin Lorentz 2011-07-01 15:58:39 +02:00
parent d4693ebb69
commit 41514bafdd
3 changed files with 43 additions and 12 deletions

View File

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

View File

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

View File

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