2003-04-08 10:40:50 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
###
|
|
|
|
# Copyright (c) 2002, Jeremiah Fincher
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions are met:
|
|
|
|
#
|
|
|
|
# * Redistributions of source code must retain the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer.
|
|
|
|
# * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
# this list of conditions, and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# * Neither the name of the author of this software nor the name of
|
|
|
|
# contributors to this software may be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written consent.
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
# POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
###
|
|
|
|
|
|
|
|
"""
|
2003-09-03 20:45:29 +02:00
|
|
|
Enforcer: Enforces capabilities on a channel, watching MODEs, KICKs,
|
2003-04-08 10:40:50 +02:00
|
|
|
JOINs, etc. to make sure they match the channel's config.
|
|
|
|
"""
|
|
|
|
|
2003-11-25 09:23:47 +01:00
|
|
|
__revision__ = "$Id$"
|
|
|
|
|
2003-10-05 14:56:56 +02:00
|
|
|
import plugins
|
2003-04-08 10:40:50 +02:00
|
|
|
|
|
|
|
import conf
|
|
|
|
import ircdb
|
|
|
|
import ircmsgs
|
2003-10-29 01:04:30 +01:00
|
|
|
import plugins
|
2003-04-08 10:40:50 +02:00
|
|
|
import ircutils
|
2004-01-30 06:01:46 +01:00
|
|
|
import privmsgs
|
|
|
|
import registry
|
2003-08-29 16:02:14 +02:00
|
|
|
import callbacks
|
2003-04-08 10:40:50 +02:00
|
|
|
|
2004-01-30 00:58:27 +01:00
|
|
|
def configure(advanced):
|
2003-09-11 14:32:39 +02:00
|
|
|
from questions import expect, anything, something, yn
|
2004-01-28 23:19:25 +01:00
|
|
|
conf.registerPlugin('Enforcer', True)
|
2003-09-03 22:41:28 +02:00
|
|
|
chanserv = something('What\'s the name of ChanServ on your network?')
|
|
|
|
if yn('Do you want the bot to take revenge on rule breakers?') == 'y':
|
|
|
|
revenge = True
|
|
|
|
else:
|
|
|
|
revenge = False
|
2003-11-17 15:46:10 +01:00
|
|
|
onStart.append('enforcer start %s' % chanserv)
|
2004-01-28 23:19:25 +01:00
|
|
|
conf.supybot.plugins.Enforcer.takeRevenge.setValue(revenge)
|
2003-09-03 22:41:28 +02:00
|
|
|
|
2004-01-27 16:36:49 +01:00
|
|
|
conf.registerPlugin('Enforcer')
|
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Enforcer, 'autoOp',
|
|
|
|
registry.Boolean(False, """Determines whether the bot will automatically op
|
2004-01-30 17:33:21 +01:00
|
|
|
people with the <channel>,op capability when they join the channel."""))
|
2004-01-27 16:36:49 +01:00
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Enforcer, 'autoHalfop',
|
|
|
|
registry.Boolean(False, """Determines whether the bot will automatically
|
2004-01-30 17:33:21 +01:00
|
|
|
halfop people with the <channel>,halfop capability when they join the
|
2004-01-27 16:36:49 +01:00
|
|
|
channel."""))
|
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Enforcer, 'autoVoice',
|
|
|
|
registry.Boolean(False, """Determines whether the bot will automatically
|
2004-01-30 17:33:21 +01:00
|
|
|
voice people with the <channel>,voice capability when they join the
|
2004-01-27 16:36:49 +01:00
|
|
|
channel."""))
|
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Enforcer, 'takeRevenge',
|
|
|
|
registry.Boolean(False, """Determines whether the bot will take revenge on
|
|
|
|
people who do things it doesn't like (somewhat like 'bitch mode' in other
|
|
|
|
IRC bots)."""))
|
2003-04-08 10:40:50 +02:00
|
|
|
_chanCap = ircdb.makeChannelCapability
|
2004-01-27 16:36:49 +01:00
|
|
|
class Enforcer(callbacks.Privmsg):
|
2003-09-03 20:45:29 +02:00
|
|
|
started = False
|
2003-10-21 08:36:38 +02:00
|
|
|
def start(self, irc, msg, args):
|
2003-11-17 15:37:43 +01:00
|
|
|
"""[<CHANSERV>]
|
2003-09-06 20:29:44 +02:00
|
|
|
|
|
|
|
Starts the Enforcer plugin. <chanserv> is the nick for the chanserv
|
2003-11-17 15:37:43 +01:00
|
|
|
aspect of Services (it defaults to ChanServ).
|
2003-09-06 20:29:44 +02:00
|
|
|
"""
|
2003-04-08 10:40:50 +02:00
|
|
|
self.topics = {}
|
2003-11-21 16:32:14 +01:00
|
|
|
chanserv = privmsgs.getArgs(args, required=0, optional=1)
|
2003-11-25 09:28:41 +01:00
|
|
|
self.chanserv = ircutils.IrcString(chanserv or 'ChanServ')
|
2003-04-08 10:40:50 +02:00
|
|
|
self.started = True
|
2003-09-06 04:03:44 +02:00
|
|
|
for channel in irc.state.channels:
|
|
|
|
irc.queueMsg(ircmsgs.topic(channel))
|
2004-01-08 04:12:14 +01:00
|
|
|
irc.replySuccess()
|
2003-10-21 08:36:38 +02:00
|
|
|
start = privmsgs.checkCapability(start, 'admin')
|
2003-04-08 10:40:50 +02:00
|
|
|
|
|
|
|
def doJoin(self, irc, msg):
|
2003-09-03 20:45:29 +02:00
|
|
|
if not self.started:
|
2003-11-26 19:21:12 +01:00
|
|
|
self.log.warning('Enforcer not started.')
|
2003-09-03 20:45:29 +02:00
|
|
|
return
|
2003-04-08 10:40:50 +02:00
|
|
|
channel = msg.args[0]
|
|
|
|
c = ircdb.channels.getChannel(channel)
|
|
|
|
if c.checkBan(msg.prefix):
|
|
|
|
irc.queueMsg(ircmsgs.ban(channel, ircutils.banmask(msg.prefix)))
|
|
|
|
irc.queueMsg(ircmsgs.kick(channel, msg.nick))
|
|
|
|
elif ircdb.checkCapability(msg.prefix, _chanCap(channel, 'op')):
|
2004-01-27 16:36:49 +01:00
|
|
|
if self.registryValue('autoOp', channel):
|
2003-10-29 01:04:30 +01:00
|
|
|
irc.queueMsg(ircmsgs.op(channel, msg.nick))
|
2003-04-08 10:40:50 +02:00
|
|
|
elif ircdb.checkCapability(msg.prefix, _chanCap(channel, 'halfop')):
|
2004-01-27 16:36:49 +01:00
|
|
|
if self.registryValue('autoHalfop', channel):
|
2003-10-29 01:04:30 +01:00
|
|
|
irc.queueMsg(ircmsgs.halfop(channel, msg.nick))
|
2003-04-08 10:40:50 +02:00
|
|
|
elif ircdb.checkCapability(msg.prefix, _chanCap(channel, 'voice')):
|
2004-01-27 16:36:49 +01:00
|
|
|
if self.registryValue('autoVoice', channel):
|
2003-10-29 01:04:30 +01:00
|
|
|
irc.queueMsg(ircmsgs.voice(channel, msg.nick))
|
2003-04-08 10:40:50 +02:00
|
|
|
|
|
|
|
def doTopic(self, irc, msg):
|
2003-09-03 20:45:29 +02:00
|
|
|
if not self.started:
|
2003-11-26 19:21:12 +01:00
|
|
|
self.log.info('Enforcer not started.')
|
2003-09-03 20:45:29 +02:00
|
|
|
return
|
2003-04-08 10:40:50 +02:00
|
|
|
channel = msg.args[0]
|
|
|
|
topic = msg.args[1]
|
|
|
|
if msg.nick != irc.nick and \
|
|
|
|
not ircdb.checkCapabilities(msg.prefix,
|
|
|
|
(_chanCap(channel, 'op'),
|
|
|
|
_chanCap(channel, 'topic'))):
|
|
|
|
irc.queueMsg(ircmsgs.topic(channel, self.topics[channel]))
|
2004-01-27 16:36:49 +01:00
|
|
|
if self.registryValue('takeRevenge', channel):
|
2003-04-08 10:40:50 +02:00
|
|
|
irc.queueMsg(ircmsgs.kick(channel, msg.nick,
|
2004-01-18 08:58:26 +01:00
|
|
|
conf.supybot.replies.noCapability() %
|
2004-01-09 00:03:48 +01:00
|
|
|
_chanCap(channel, 'topic')))
|
2003-04-08 10:40:50 +02:00
|
|
|
else:
|
|
|
|
self.topics[channel] = msg.args[1]
|
|
|
|
|
|
|
|
def do332(self, irc, msg):
|
|
|
|
# This command gets sent right after joining a channel.
|
2003-09-06 03:15:32 +02:00
|
|
|
if not self.started:
|
2003-11-26 19:21:12 +01:00
|
|
|
self.log.info('Enforcer not started.')
|
2003-09-06 03:15:32 +02:00
|
|
|
return
|
2003-04-08 10:40:50 +02:00
|
|
|
(channel, topic) = msg.args[1:]
|
|
|
|
self.topics[channel] = topic
|
|
|
|
|
|
|
|
def _isProtected(self, channel, hostmask):
|
|
|
|
capabilities = [_chanCap(channel, 'op'),_chanCap(channel, 'protected')]
|
|
|
|
return ircdb.checkCapabilities(hostmask, capabilities)
|
|
|
|
|
|
|
|
def _revenge(self, irc, channel, hostmask):
|
|
|
|
irc.queueMsg(ircmsgs.ban(channel, ircutils.banmask(hostmask)))
|
|
|
|
irc.queueMsg(ircmsgs.kick(channel,ircutils.nickFromHostmask(hostmask)))
|
|
|
|
|
|
|
|
def doKick(self, irc, msg):
|
2003-09-03 20:45:29 +02:00
|
|
|
if not self.started:
|
2003-11-26 19:21:12 +01:00
|
|
|
self.log.info('Enforcer not started.')
|
2003-09-03 20:45:29 +02:00
|
|
|
return
|
2003-04-08 10:40:50 +02:00
|
|
|
channel = msg.args[0]
|
|
|
|
kicked = msg.args[1].split(',')
|
|
|
|
deop = False
|
2004-01-09 00:03:48 +01:00
|
|
|
if msg.nick != irc.nick and \
|
2003-04-08 10:40:50 +02:00
|
|
|
not ircdb.checkCapability(msg.prefix, _chanCap(channel, 'op')):
|
|
|
|
for nick in kicked:
|
|
|
|
hostmask = irc.state.nickToHostmask(nick)
|
2003-09-11 12:27:49 +02:00
|
|
|
if nick == irc.nick:
|
|
|
|
# Must be a sendMsg so he joins the channel before MODEing.
|
|
|
|
irc.sendMsg(ircmsgs.join(channel))
|
|
|
|
deop = True
|
2003-04-08 10:40:50 +02:00
|
|
|
if self._isProtected(channel, hostmask):
|
|
|
|
deop = True
|
|
|
|
irc.queueMsg(ircmsgs.invite(channel, msg.args[1]))
|
|
|
|
if deop:
|
|
|
|
deop = False
|
2004-01-27 16:36:49 +01:00
|
|
|
if self.registryValue('takeRevenge', channel):
|
2003-04-08 10:40:50 +02:00
|
|
|
self._revenge(irc, channel, msg.prefix)
|
|
|
|
else:
|
|
|
|
irc.queueMsg(ircmsgs.deop(channel, msg.nick))
|
|
|
|
|
|
|
|
def doMode(self, irc, msg):
|
2003-09-03 20:45:29 +02:00
|
|
|
if not self.started:
|
2003-11-26 19:21:12 +01:00
|
|
|
self.log.info('Enforcer not started.')
|
2003-09-03 20:45:29 +02:00
|
|
|
return
|
2003-04-08 10:40:50 +02:00
|
|
|
channel = msg.args[0]
|
2003-10-06 07:57:03 +02:00
|
|
|
if not ircutils.isChannel(channel) or msg.nick == self.chanserv:
|
2003-04-08 10:40:50 +02:00
|
|
|
return
|
2004-01-09 00:03:48 +01:00
|
|
|
if msg.nick != irc.nick and \
|
2003-04-08 10:40:50 +02:00
|
|
|
not ircdb.checkCapability(msg.prefix, _chanCap(channel, 'op')):
|
|
|
|
for (mode, value) in ircutils.separateModes(msg.args[1:]):
|
|
|
|
if value == msg.nick:
|
|
|
|
continue
|
|
|
|
elif mode == '+o' and value != irc.nick:
|
|
|
|
hostmask = irc.state.nickToHostmask(value)
|
|
|
|
if ircdb.checkCapability(channel,
|
|
|
|
ircdb.makeAntiCapability('op')):
|
|
|
|
irc.queueMsg(ircmsgs.deop(channel, value))
|
|
|
|
elif mode == '+h' and value != irc.nick:
|
|
|
|
hostmask = irc.state.nickToHostmask(value)
|
|
|
|
if ircdb.checkCapability(channel,
|
|
|
|
ircdb.makeAntiCapability('halfop')):
|
|
|
|
irc.queueMsg(ircmsgs.dehalfop(channel, value))
|
|
|
|
elif mode == '+v' and value != irc.nick:
|
|
|
|
hostmask = irc.state.nickToHostmask(value)
|
|
|
|
if ircdb.checkCapability(channel,
|
|
|
|
ircdb.makeAntiCapability('voice')):
|
|
|
|
irc.queueMsg(ircmsgs.devoice(channel, value))
|
|
|
|
elif mode == '-o':
|
|
|
|
hostmask = irc.state.nickToHostmask(value)
|
|
|
|
if self._isProtected(channel, hostmask):
|
|
|
|
irc.queueMsg(ircmsgs.op(channel, value))
|
2004-01-27 16:36:49 +01:00
|
|
|
if self.registryValue('takeRevenge', channel):
|
2003-04-08 10:40:50 +02:00
|
|
|
self._revenge(irc, channel, msg.prefix)
|
|
|
|
else:
|
|
|
|
irc.queueMsg(ircmsgs.deop(channel, msg.nick))
|
|
|
|
elif mode == '-h':
|
|
|
|
hostmask = irc.state.nickToHostmask(value)
|
|
|
|
if self._isProtected(channel, hostmask):
|
|
|
|
irc.queueMsg(ircmsgs.halfop(channel, value))
|
2004-01-27 16:36:49 +01:00
|
|
|
if self.registryValue('takeRevenge', channel):
|
2003-04-08 10:40:50 +02:00
|
|
|
self._revenge(irc, channel, msg.prefix)
|
|
|
|
else:
|
|
|
|
irc.queueMsg(ircmsgs.deop(channel, msg.nick))
|
|
|
|
elif mode == '-v':
|
|
|
|
hostmask = irc.state.nickToHostmask(value)
|
|
|
|
if self._isProtected(channel, hostmask):
|
|
|
|
irc.queueMsg(ircmsgs.voice(channel, value))
|
2004-01-27 16:36:49 +01:00
|
|
|
if self.registryValue('takeRevenge', channel):
|
2003-04-08 10:40:50 +02:00
|
|
|
self._revenge(irc, channel, msg.prefix)
|
|
|
|
else:
|
|
|
|
irc.queueMsg(ircmsgs.deop(channel, msg.nick))
|
|
|
|
elif mode == '+b':
|
|
|
|
# To be safe, only #channel.ops are allowed to ban.
|
|
|
|
if not ircdb.checkCapability(msg.prefix,
|
|
|
|
_chanCap(channel, 'op')):
|
|
|
|
irc.queueMsg(ircmsgs.unban(channel, value))
|
2004-01-27 16:36:49 +01:00
|
|
|
if self.registryValue('takeRevenge', channel):
|
2003-04-08 10:40:50 +02:00
|
|
|
self._revenge(irc, channel, msg.prefix)
|
|
|
|
else:
|
|
|
|
irc.queueMsg(ircmsgs.deop(channel, msg.nick))
|
|
|
|
|
|
|
|
def __call__(self, irc, msg):
|
2003-09-22 04:46:36 +02:00
|
|
|
if self.started:
|
2003-10-06 15:00:22 +02:00
|
|
|
if ircutils.isUserHostmask(msg.prefix) and \
|
2003-11-25 09:28:41 +01:00
|
|
|
not msg.nick == self.chanserv:
|
2003-09-22 04:46:36 +02:00
|
|
|
return callbacks.Privmsg.__call__(self, irc, msg)
|
2003-04-08 10:40:50 +02:00
|
|
|
|
|
|
|
|
2003-09-03 20:45:29 +02:00
|
|
|
Class = Enforcer
|
2003-04-08 10:40:50 +02:00
|
|
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|