Added cycleToGetOps configuration variable.

This commit is contained in:
Jeremy Fincher 2004-01-30 19:00:04 +00:00
parent 43d0619796
commit 88ba40baad

View File

@ -58,6 +58,13 @@ def configure(advanced):
onStart.append('enforcer start %s' % chanserv) onStart.append('enforcer start %s' % chanserv)
conf.supybot.plugins.Enforcer.takeRevenge.setValue(revenge) conf.supybot.plugins.Enforcer.takeRevenge.setValue(revenge)
class ValidNickOrEmptyString(registry.String):
def setValue(self, v):
if v and not ircutils.isNick(v):
raise registry.InvalidRegistryValue, \
'Value must be a valid nick or the empty string.'
self.value = v
conf.registerPlugin('Enforcer') conf.registerPlugin('Enforcer')
conf.registerChannelValue(conf.supybot.plugins.Enforcer, 'autoOp', conf.registerChannelValue(conf.supybot.plugins.Enforcer, 'autoOp',
registry.Boolean(False, """Determines whether the bot will automatically op registry.Boolean(False, """Determines whether the bot will automatically op
@ -74,28 +81,19 @@ conf.registerChannelValue(conf.supybot.plugins.Enforcer, 'takeRevenge',
registry.Boolean(False, """Determines whether the bot will take revenge on 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 people who do things it doesn't like (somewhat like 'bitch mode' in other
IRC bots).""")) IRC bots)."""))
conf.registerChannelValue(conf.supybot.plugins.Enforcer, 'cycleToGetOps',
registry.Boolean(True, """Determines whether the bot will cycle the channel
if it doesn't have ops and there's no one else in the channel."""))
# This is a network value, not a channel value.
conf.registerChannelValue(conf.supybot.plugins.Enforcer, 'ChanServ',
ValidNickOrEmptyString('', """Determines what nick the bot will consider to
be the ChanServ on the network. ChanServ (on networks that support it) is
obviously beyond our abilities to enforce, and so we would ignore all
messages from it."""))
_chanCap = ircdb.makeChannelCapability _chanCap = ircdb.makeChannelCapability
class Enforcer(callbacks.Privmsg): class Enforcer(callbacks.Privmsg):
started = False
def start(self, irc, msg, args):
"""[<CHANSERV>]
Starts the Enforcer plugin. <chanserv> is the nick for the chanserv
aspect of Services (it defaults to ChanServ).
"""
self.topics = {}
chanserv = privmsgs.getArgs(args, required=0, optional=1)
self.chanserv = ircutils.IrcString(chanserv or 'ChanServ')
self.started = True
for channel in irc.state.channels:
irc.queueMsg(ircmsgs.topic(channel))
irc.replySuccess()
start = privmsgs.checkCapability(start, 'admin')
def doJoin(self, irc, msg): def doJoin(self, irc, msg):
if not self.started:
self.log.warning('Enforcer not started.')
return
channel = msg.args[0] channel = msg.args[0]
c = ircdb.channels.getChannel(channel) c = ircdb.channels.getChannel(channel)
if c.checkBan(msg.prefix): if c.checkBan(msg.prefix):
@ -112,9 +110,6 @@ class Enforcer(callbacks.Privmsg):
irc.queueMsg(ircmsgs.voice(channel, msg.nick)) irc.queueMsg(ircmsgs.voice(channel, msg.nick))
def doTopic(self, irc, msg): def doTopic(self, irc, msg):
if not self.started:
self.log.info('Enforcer not started.')
return
channel = msg.args[0] channel = msg.args[0]
topic = msg.args[1] topic = msg.args[1]
if msg.nick != irc.nick and \ if msg.nick != irc.nick and \
@ -131,9 +126,6 @@ class Enforcer(callbacks.Privmsg):
def do332(self, irc, msg): def do332(self, irc, msg):
# This command gets sent right after joining a channel. # This command gets sent right after joining a channel.
if not self.started:
self.log.info('Enforcer not started.')
return
(channel, topic) = msg.args[1:] (channel, topic) = msg.args[1:]
self.topics[channel] = topic self.topics[channel] = topic
@ -146,9 +138,6 @@ class Enforcer(callbacks.Privmsg):
irc.queueMsg(ircmsgs.kick(channel,ircutils.nickFromHostmask(hostmask))) irc.queueMsg(ircmsgs.kick(channel,ircutils.nickFromHostmask(hostmask)))
def doKick(self, irc, msg): def doKick(self, irc, msg):
if not self.started:
self.log.info('Enforcer not started.')
return
channel = msg.args[0] channel = msg.args[0]
kicked = msg.args[1].split(',') kicked = msg.args[1].split(',')
deop = False deop = False
@ -171,9 +160,6 @@ class Enforcer(callbacks.Privmsg):
irc.queueMsg(ircmsgs.deop(channel, msg.nick)) irc.queueMsg(ircmsgs.deop(channel, msg.nick))
def doMode(self, irc, msg): def doMode(self, irc, msg):
if not self.started:
self.log.info('Enforcer not started.')
return
channel = msg.args[0] channel = msg.args[0]
if not ircutils.isChannel(channel) or msg.nick == self.chanserv: if not ircutils.isChannel(channel) or msg.nick == self.chanserv:
return return
@ -222,7 +208,7 @@ class Enforcer(callbacks.Privmsg):
else: else:
irc.queueMsg(ircmsgs.deop(channel, msg.nick)) irc.queueMsg(ircmsgs.deop(channel, msg.nick))
elif mode == '+b': elif mode == '+b':
# To be safe, only #channel.ops are allowed to ban. # To be safe, only #channel,ops are allowed to ban.
if not ircdb.checkCapability(msg.prefix, if not ircdb.checkCapability(msg.prefix,
_chanCap(channel, 'op')): _chanCap(channel, 'op')):
irc.queueMsg(ircmsgs.unban(channel, value)) irc.queueMsg(ircmsgs.unban(channel, value))
@ -231,11 +217,31 @@ class Enforcer(callbacks.Privmsg):
else: else:
irc.queueMsg(ircmsgs.deop(channel, msg.nick)) irc.queueMsg(ircmsgs.deop(channel, msg.nick))
def _cycle(self, irc, channel):
if self.registryValue('cycleToGetOps', channel):
if 'i' not in irc.state.channels[channel].modes:
# What about keywords?
self.log.info('Cycling %s: I\'m the only one left.', channel)
irc.queueMsg(ircmsgs.part(channel))
irc.queueMsg(ircmsgs.join(channel))
else:
self.log.warning('Not cycling %s: it\'s +i', channel)
def doPart(self, irc, msg):
channel = msg.args[0]
if len(irc.state.channels[channel].users) == 1:
self._cycle(irc, channel)
def doQuit(self, irc, msg):
for (channel, c) in irc.state.channels.iteritems():
if len(c.users) == 1:
self._cycle(irc, channel)
def __call__(self, irc, msg): def __call__(self, irc, msg):
if self.started: chanserv = self.registryValue('ChanServ', irc.network)
if ircutils.isUserHostmask(msg.prefix) and \ if chanserv and ircutils.isUserHostmask(msg.prefix):
not msg.nick == self.chanserv: if msg.nick != chanserv:
return callbacks.Privmsg.__call__(self, irc, msg) callbacks.Privmsg.__call__(self, irc, msg)
Class = Enforcer Class = Enforcer