Slight refactoring.

This commit is contained in:
Jeremy Fincher 2004-03-25 12:14:01 +00:00
parent 154577832c
commit 4837707e65

View File

@ -144,6 +144,19 @@ class Enforcer(callbacks.Privmsg):
capabilities = [_chanCap(channel, 'op'),_chanCap(channel, 'protected')] capabilities = [_chanCap(channel, 'op'),_chanCap(channel, 'protected')]
return ircdb.checkCapabilities(hostmask, capabilities) return ircdb.checkCapabilities(hostmask, capabilities)
def _isPowerful(self, irc, msg):
if msg.nick == irc.nick:
return True # It's me.
if not ircutils.isUserHostmask(msg.prefix):
return True # It's a server.
chanserv = self.registryValue('ChanServ')
if ircutils.nickEqual(msg.nick, chanserv):
return True # It's ChanServ.
capability = _chanCap(msg.args[0], 'op')
if ircdb.checkCapability(msg.prefix, capability):
return True # It's a chanop.
return False # Default.
def _revenge(self, irc, channel, hostmask): def _revenge(self, irc, channel, hostmask):
irc.queueMsg(ircmsgs.ban(channel, ircutils.banmask(hostmask))) irc.queueMsg(ircmsgs.ban(channel, ircutils.banmask(hostmask)))
irc.queueMsg(ircmsgs.kick(channel,ircutils.nickFromHostmask(hostmask))) irc.queueMsg(ircmsgs.kick(channel,ircutils.nickFromHostmask(hostmask)))
@ -152,8 +165,7 @@ class Enforcer(callbacks.Privmsg):
channel = msg.args[0] channel = msg.args[0]
kicked = msg.args[1].split(',') kicked = msg.args[1].split(',')
deop = False deop = False
if msg.nick != irc.nick and \ if not self._isPowerful(irc, msg):
not ircdb.checkCapability(msg.prefix, _chanCap(channel, 'op')):
for nick in kicked: for nick in kicked:
hostmask = irc.state.nickToHostmask(nick) hostmask = irc.state.nickToHostmask(nick)
if nick == irc.nick: if nick == irc.nick:
@ -162,7 +174,7 @@ class Enforcer(callbacks.Privmsg):
deop = True deop = True
if self._isProtected(channel, hostmask): if self._isProtected(channel, hostmask):
deop = True deop = True
irc.queueMsg(ircmsgs.invite(channel, msg.args[1])) irc.queueMsg(ircmsgs.invite(msg.args[1], channel))
if deop: if deop:
deop = False deop = False
if self.registryValue('takeRevenge', channel): if self.registryValue('takeRevenge', channel):
@ -173,62 +185,56 @@ class Enforcer(callbacks.Privmsg):
def doMode(self, irc, msg): def doMode(self, irc, msg):
channel = msg.args[0] channel = msg.args[0]
chanserv = self.registryValue('ChanServ', channel) chanserv = self.registryValue('ChanServ', channel)
if not ircutils.isChannel(channel) or \ if not ircutils.isChannel(channel) or self._isPowerful(irc, msg):
(chanserv and msg.nick == chanserv):
return return
if msg.nick != irc.nick and \ for (mode, value) in ircutils.separateModes(msg.args[1:]):
not ircdb.checkCapability(msg.prefix, _chanCap(channel, 'op')): if value == msg.nick:
for (mode, value) in ircutils.separateModes(msg.args[1:]): continue
if value == msg.nick: elif mode == '+o' and value != irc.nick:
continue hostmask = irc.state.nickToHostmask(value)
elif mode == '+o' and value != irc.nick: if ircdb.checkCapability(channel,
hostmask = irc.state.nickToHostmask(value) ircdb.makeAntiCapability('op')):
if ircdb.checkCapability(channel, irc.queueMsg(ircmsgs.deop(channel, value))
ircdb.makeAntiCapability('op')): elif mode == '+h' and value != irc.nick:
irc.queueMsg(ircmsgs.deop(channel, value)) hostmask = irc.state.nickToHostmask(value)
elif mode == '+h' and value != irc.nick: if ircdb.checkCapability(channel,
hostmask = irc.state.nickToHostmask(value) ircdb.makeAntiCapability('halfop')):
if ircdb.checkCapability(channel, irc.queueMsg(ircmsgs.dehalfop(channel, value))
ircdb.makeAntiCapability('halfop')): elif mode == '+v' and value != irc.nick:
irc.queueMsg(ircmsgs.dehalfop(channel, value)) hostmask = irc.state.nickToHostmask(value)
elif mode == '+v' and value != irc.nick: if ircdb.checkCapability(channel,
hostmask = irc.state.nickToHostmask(value) ircdb.makeAntiCapability('voice')):
if ircdb.checkCapability(channel, irc.queueMsg(ircmsgs.devoice(channel, value))
ircdb.makeAntiCapability('voice')): elif mode == '-o':
irc.queueMsg(ircmsgs.devoice(channel, value)) hostmask = irc.state.nickToHostmask(value)
elif mode == '-o': if self._isProtected(channel, hostmask):
hostmask = irc.state.nickToHostmask(value) irc.queueMsg(ircmsgs.op(channel, value))
if self._isProtected(channel, hostmask): if self.registryValue('takeRevenge', channel):
irc.queueMsg(ircmsgs.op(channel, value)) self._revenge(irc, channel, msg.prefix)
if self.registryValue('takeRevenge', channel): else:
self._revenge(irc, channel, msg.prefix) irc.queueMsg(ircmsgs.deop(channel, msg.nick))
else: elif mode == '-h':
irc.queueMsg(ircmsgs.deop(channel, msg.nick)) hostmask = irc.state.nickToHostmask(value)
elif mode == '-h': if self._isProtected(channel, hostmask):
hostmask = irc.state.nickToHostmask(value) irc.queueMsg(ircmsgs.halfop(channel, value))
if self._isProtected(channel, hostmask): if self.registryValue('takeRevenge', channel):
irc.queueMsg(ircmsgs.halfop(channel, value)) self._revenge(irc, channel, msg.prefix)
if self.registryValue('takeRevenge', channel): else:
self._revenge(irc, channel, msg.prefix) irc.queueMsg(ircmsgs.deop(channel, msg.nick))
else: elif mode == '-v':
irc.queueMsg(ircmsgs.deop(channel, msg.nick)) hostmask = irc.state.nickToHostmask(value)
elif mode == '-v': if self._isProtected(channel, hostmask):
hostmask = irc.state.nickToHostmask(value) irc.queueMsg(ircmsgs.voice(channel, value))
if self._isProtected(channel, hostmask): if self.registryValue('takeRevenge', channel):
irc.queueMsg(ircmsgs.voice(channel, value)) self._revenge(irc, channel, msg.prefix)
if self.registryValue('takeRevenge', channel): else:
self._revenge(irc, channel, msg.prefix) irc.queueMsg(ircmsgs.deop(channel, msg.nick))
else: elif mode == '+b':
irc.queueMsg(ircmsgs.deop(channel, msg.nick)) irc.queueMsg(ircmsgs.unban(channel, value))
elif mode == '+b': if self.registryValue('takeRevenge', channel):
# To be safe, only #channel,ops are allowed to ban. self._revenge(irc, channel, msg.prefix)
if not ircdb.checkCapability(msg.prefix, else:
_chanCap(channel, 'op')): irc.queueMsg(ircmsgs.deop(channel, msg.nick))
irc.queueMsg(ircmsgs.unban(channel, value))
if self.registryValue('takeRevenge', channel):
self._revenge(irc, channel, msg.prefix)
else:
irc.queueMsg(ircmsgs.deop(channel, msg.nick))
def _cycle(self, irc, channel): def _cycle(self, irc, channel):
if self.registryValue('cycleToGetOps', channel): if self.registryValue('cycleToGetOps', channel):