2005-01-19 14:14:38 +01:00
|
|
|
###
|
2005-01-19 14:33:05 +01:00
|
|
|
# Copyright (c) 2002-2005, Jeremiah Fincher
|
2012-05-21 02:57:13 +02:00
|
|
|
# Copyright (c) 2009-2012, James McCoy
|
2005-01-19 14:14:38 +01:00
|
|
|
# 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.
|
|
|
|
###
|
|
|
|
|
|
|
|
import sys
|
2014-11-24 18:26:25 +01:00
|
|
|
import fnmatch
|
2015-02-28 03:45:37 +01:00
|
|
|
import time
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
import supybot.conf as conf
|
|
|
|
import supybot.ircdb as ircdb
|
|
|
|
import supybot.utils as utils
|
|
|
|
from supybot.commands import *
|
|
|
|
import supybot.ircmsgs as ircmsgs
|
|
|
|
import supybot.schedule as schedule
|
|
|
|
import supybot.ircutils as ircutils
|
|
|
|
import supybot.callbacks as callbacks
|
2010-10-16 10:17:51 +02:00
|
|
|
from supybot.i18n import PluginInternationalization, internationalizeDocstring
|
|
|
|
_ = PluginInternationalization('Channel')
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2005-02-09 08:04:04 +01:00
|
|
|
class Channel(callbacks.Plugin):
|
2014-11-30 08:18:44 +01:00
|
|
|
"""This plugin provides various commands for channel management, such
|
|
|
|
as setting modes and channel-wide bans/ignores/capabilities. This is
|
|
|
|
a core Supybot plugin that should not be removed!"""
|
2015-02-28 03:45:37 +01:00
|
|
|
|
2005-01-29 20:16:29 +01:00
|
|
|
def __init__(self, irc):
|
|
|
|
self.__parent = super(Channel, self)
|
|
|
|
self.__parent.__init__(irc)
|
2005-01-19 14:14:38 +01:00
|
|
|
self.invites = {}
|
|
|
|
|
|
|
|
def doKick(self, irc, msg):
|
|
|
|
channel = msg.args[0]
|
|
|
|
if msg.args[1] == irc.nick:
|
|
|
|
if self.registryValue('alwaysRejoin', channel):
|
2015-02-28 03:45:37 +01:00
|
|
|
delay = self.registryValue('rejoinDelay', channel)
|
2005-01-19 14:14:38 +01:00
|
|
|
networkGroup = conf.supybot.networks.get(irc.network)
|
2015-02-28 03:45:37 +01:00
|
|
|
if delay:
|
|
|
|
def f():
|
|
|
|
irc.sendMsg(networkGroup.channels.join(channel))
|
|
|
|
schedule.addEvent(f, time.time() + delay)
|
|
|
|
self.log.info('Kicked from %s by %s. Rejoining after %s '
|
|
|
|
'seconds.', channel, msg.prefix, delay)
|
|
|
|
else:
|
|
|
|
self.log.info('Kicked from %s by %s. Rejoining.',
|
|
|
|
channel, msg.prefix)
|
|
|
|
irc.sendMsg(networkGroup.channels.join(channel))
|
2013-05-21 17:19:21 +02:00
|
|
|
else:
|
2013-05-21 18:30:16 +02:00
|
|
|
self.log.info('Kicked from %s by %s. Not auto-rejoining.' %
|
|
|
|
(channel, msg.prefix))
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
def _sendMsg(self, irc, msg):
|
|
|
|
irc.queueMsg(msg)
|
|
|
|
irc.noReply()
|
|
|
|
|
2009-05-25 16:02:11 +02:00
|
|
|
def _sendMsgs(self, irc, nicks, f):
|
|
|
|
numModes = irc.state.supported.get('modes', 1)
|
|
|
|
for i in range(0, len(nicks), numModes):
|
|
|
|
irc.queueMsg(f(nicks[i:i + numModes]))
|
|
|
|
irc.noReply()
|
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def mode(self, irc, msg, args, channel, modes):
|
|
|
|
"""[<channel>] <mode> [<arg> ...]
|
|
|
|
|
|
|
|
Sets the mode in <channel> to <mode>, sending the arguments given.
|
|
|
|
<channel> is only necessary if the message isn't sent in the channel
|
|
|
|
itself.
|
|
|
|
"""
|
|
|
|
self._sendMsg(irc, ircmsgs.mode(channel, modes))
|
2013-05-17 17:36:11 +02:00
|
|
|
mode = wrap(mode, ['op', ('haveHalfop+', _('change the mode')), many('something')])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def limit(self, irc, msg, args, channel, limit):
|
|
|
|
"""[<channel>] [<limit>]
|
|
|
|
|
|
|
|
Sets the channel limit to <limit>. If <limit> is 0, or isn't given,
|
|
|
|
removes the channel limit. <channel> is only necessary if the message
|
|
|
|
isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
if limit:
|
|
|
|
self._sendMsg(irc, ircmsgs.mode(channel, ['+l', limit]))
|
|
|
|
else:
|
|
|
|
self._sendMsg(irc, ircmsgs.mode(channel, ['-l']))
|
2010-10-16 10:17:51 +02:00
|
|
|
limit = wrap(limit, ['op', ('haveOp', _('change the limit')),
|
2005-01-19 14:14:38 +01:00
|
|
|
additional('nonNegativeInt', 0)])
|
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def moderate(self, irc, msg, args, channel):
|
|
|
|
"""[<channel>]
|
|
|
|
|
|
|
|
Sets +m on <channel>, making it so only ops and voiced users can
|
|
|
|
send messages to the channel. <channel> is only necessary if the
|
|
|
|
message isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
self._sendMsg(irc, ircmsgs.mode(channel, ['+m']))
|
2013-05-17 17:36:11 +02:00
|
|
|
moderate = wrap(moderate, ['op', ('haveHalfop+', _('moderate the channel'))])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def unmoderate(self, irc, msg, args, channel):
|
|
|
|
"""[<channel>]
|
|
|
|
|
|
|
|
Sets -m on <channel>, making it so everyone can
|
|
|
|
send messages to the channel. <channel> is only necessary if the
|
|
|
|
message isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
self._sendMsg(irc, ircmsgs.mode(channel, ['-m']))
|
2013-05-17 17:36:11 +02:00
|
|
|
unmoderate = wrap(unmoderate, ['op', ('haveHalfop+',
|
2010-10-16 10:17:51 +02:00
|
|
|
_('unmoderate the channel'))])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def key(self, irc, msg, args, channel, key):
|
|
|
|
"""[<channel>] [<key>]
|
|
|
|
|
|
|
|
Sets the keyword in <channel> to <key>. If <key> is not given, removes
|
|
|
|
the keyword requirement to join <channel>. <channel> is only necessary
|
|
|
|
if the message isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
networkGroup = conf.supybot.networks.get(irc.network)
|
|
|
|
networkGroup.channels.key.get(channel).setValue(key)
|
|
|
|
if key:
|
|
|
|
self._sendMsg(irc, ircmsgs.mode(channel, ['+k', key]))
|
|
|
|
else:
|
|
|
|
self._sendMsg(irc, ircmsgs.mode(channel, ['-k']))
|
2013-05-17 17:36:11 +02:00
|
|
|
key = wrap(key, ['op', ('haveHalfop+', _('change the keyword')),
|
2005-01-19 14:14:38 +01:00
|
|
|
additional('somethingWithoutSpaces', '')])
|
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def op(self, irc, msg, args, channel, nicks):
|
|
|
|
"""[<channel>] [<nick> ...]
|
|
|
|
|
|
|
|
If you have the #channel,op capability, this will give all the <nick>s
|
|
|
|
you provide ops. If you don't provide any <nick>s, this will op you.
|
|
|
|
<channel> is only necessary if the message isn't sent in the channel
|
|
|
|
itself.
|
|
|
|
"""
|
|
|
|
if not nicks:
|
|
|
|
nicks = [msg.nick]
|
2009-05-25 16:02:11 +02:00
|
|
|
def f(L):
|
|
|
|
return ircmsgs.ops(channel, L)
|
|
|
|
self._sendMsgs(irc, nicks, f)
|
2010-10-16 10:17:51 +02:00
|
|
|
op = wrap(op, ['op', ('haveOp', _('op someone')), any('nickInChannel')])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def halfop(self, irc, msg, args, channel, nicks):
|
|
|
|
"""[<channel>] [<nick> ...]
|
|
|
|
|
|
|
|
If you have the #channel,halfop capability, this will give all the
|
|
|
|
<nick>s you provide halfops. If you don't provide any <nick>s, this
|
|
|
|
will give you halfops. <channel> is only necessary if the message isn't
|
|
|
|
sent in the channel itself.
|
|
|
|
"""
|
|
|
|
if not nicks:
|
|
|
|
nicks = [msg.nick]
|
2009-05-25 16:02:11 +02:00
|
|
|
def f(L):
|
|
|
|
return ircmsgs.halfops(channel, L)
|
|
|
|
self._sendMsgs(irc, nicks, f)
|
2010-10-16 10:17:51 +02:00
|
|
|
halfop = wrap(halfop, ['halfop', ('haveOp', _('halfop someone')),
|
2005-01-19 14:14:38 +01:00
|
|
|
any('nickInChannel')])
|
|
|
|
|
2012-05-21 02:57:13 +02:00
|
|
|
def _voice(self, irc, msg, args, channel, nicks, fn):
|
2005-01-19 14:14:38 +01:00
|
|
|
if nicks:
|
|
|
|
if len(nicks) == 1 and msg.nick in nicks:
|
|
|
|
capability = 'voice'
|
|
|
|
else:
|
|
|
|
capability = 'op'
|
|
|
|
else:
|
|
|
|
nicks = [msg.nick]
|
|
|
|
capability = 'voice'
|
|
|
|
capability = ircdb.makeChannelCapability(channel, capability)
|
|
|
|
if ircdb.checkCapability(msg.prefix, capability):
|
2009-05-25 16:02:11 +02:00
|
|
|
def f(L):
|
2012-05-21 02:57:13 +02:00
|
|
|
return fn(channel, L)
|
2009-05-25 16:02:11 +02:00
|
|
|
self._sendMsgs(irc, nicks, f)
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
|
|
|
irc.errorNoCapability(capability)
|
2012-05-21 02:57:13 +02:00
|
|
|
|
|
|
|
def voice(self, irc, msg, args, channel, nicks):
|
|
|
|
"""[<channel>] [<nick> ...]
|
|
|
|
|
|
|
|
If you have the #channel,voice capability, this will voice all the
|
|
|
|
<nick>s you provide. If you don't provide any <nick>s, this will
|
|
|
|
voice you. <channel> is only necessary if the message isn't sent in the
|
|
|
|
channel itself.
|
|
|
|
"""
|
|
|
|
self._voice(irc, msg, args, channel, nicks, ircmsgs.voices)
|
2013-05-17 17:36:11 +02:00
|
|
|
voice = wrap(voice, ['channel', ('haveHalfop+', _('voice someone')),
|
2005-01-19 14:14:38 +01:00
|
|
|
any('nickInChannel')])
|
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def deop(self, irc, msg, args, channel, nicks):
|
|
|
|
"""[<channel>] [<nick> ...]
|
|
|
|
|
|
|
|
If you have the #channel,op capability, this will remove operator
|
|
|
|
privileges from all the nicks given. If no nicks are given, removes
|
|
|
|
operator privileges from the person sending the message.
|
|
|
|
"""
|
|
|
|
if irc.nick in nicks:
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.error(_('I cowardly refuse to deop myself. If you really '
|
|
|
|
'want me deopped, tell me to op you and then deop me '
|
|
|
|
'yourself.'), Raise=True)
|
2005-01-19 14:14:38 +01:00
|
|
|
if not nicks:
|
|
|
|
nicks = [msg.nick]
|
2009-05-25 16:02:11 +02:00
|
|
|
def f(L):
|
|
|
|
return ircmsgs.deops(channel, L)
|
|
|
|
self._sendMsgs(irc, nicks, f)
|
2010-10-16 10:17:51 +02:00
|
|
|
deop = wrap(deop, ['op', ('haveOp', _('deop someone')),
|
2005-01-19 14:14:38 +01:00
|
|
|
any('nickInChannel')])
|
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def dehalfop(self, irc, msg, args, channel, nicks):
|
|
|
|
"""[<channel>] [<nick> ...]
|
|
|
|
|
|
|
|
If you have the #channel,op capability, this will remove half-operator
|
|
|
|
privileges from all the nicks given. If no nicks are given, removes
|
|
|
|
half-operator privileges from the person sending the message.
|
|
|
|
"""
|
|
|
|
if irc.nick in nicks:
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.error(_('I cowardly refuse to dehalfop myself. If you really '
|
2005-01-19 14:14:38 +01:00
|
|
|
'want me dehalfopped, tell me to op you and then '
|
2010-10-16 10:17:51 +02:00
|
|
|
'dehalfop me yourself.'), Raise=True)
|
2005-01-19 14:14:38 +01:00
|
|
|
if not nicks:
|
|
|
|
nicks = [msg.nick]
|
2009-05-25 16:02:11 +02:00
|
|
|
def f(L):
|
|
|
|
return ircmsgs.dehalfops(channel, L)
|
|
|
|
self._sendMsgs(irc, nicks, f)
|
2010-10-16 10:17:51 +02:00
|
|
|
dehalfop = wrap(dehalfop, ['halfop', ('haveOp', _('dehalfop someone')),
|
2005-01-19 14:14:38 +01:00
|
|
|
any('nickInChannel')])
|
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def devoice(self, irc, msg, args, channel, nicks):
|
|
|
|
"""[<channel>] [<nick> ...]
|
|
|
|
|
|
|
|
If you have the #channel,op capability, this will remove voice from all
|
|
|
|
the nicks given. If no nicks are given, removes voice from the person
|
|
|
|
sending the message.
|
|
|
|
"""
|
|
|
|
if irc.nick in nicks:
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.error(_('I cowardly refuse to devoice myself. If you really '
|
2005-01-19 14:14:38 +01:00
|
|
|
'want me devoiced, tell me to op you and then devoice '
|
2010-10-16 10:17:51 +02:00
|
|
|
'me yourself.'), Raise=True)
|
2012-05-21 02:57:13 +02:00
|
|
|
self._voice(irc, msg, args, channel, nicks, ircmsgs.devoices)
|
|
|
|
devoice = wrap(devoice, ['channel', ('haveOp', 'devoice someone'),
|
2005-01-19 14:14:38 +01:00
|
|
|
any('nickInChannel')])
|
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2015-02-28 03:27:58 +01:00
|
|
|
def cycle(self, irc, msg, args, channel, reason):
|
2005-01-19 14:14:38 +01:00
|
|
|
"""[<channel>]
|
|
|
|
|
|
|
|
If you have the #channel,op capability, this will cause the bot to
|
|
|
|
"cycle", or PART and then JOIN the channel. <channel> is only necessary
|
2015-02-28 03:27:58 +01:00
|
|
|
if the message isn't sent in the channel itself. If <reason> is not
|
|
|
|
specified, the default part message specified in
|
|
|
|
supybot.plugins.Channel.partMsg will be used. No part message will be
|
|
|
|
used if neither a cycle reason nor a default part message is given.
|
2005-01-19 14:14:38 +01:00
|
|
|
"""
|
2015-02-28 03:27:58 +01:00
|
|
|
reason = (reason or self.registryValue("partMsg", channel))
|
|
|
|
reason = ircutils.standardSubstitute(irc, msg, reason)
|
|
|
|
self._sendMsg(irc, ircmsgs.part(channel, reason))
|
2005-01-19 14:14:38 +01:00
|
|
|
networkGroup = conf.supybot.networks.get(irc.network)
|
|
|
|
self._sendMsg(irc, networkGroup.channels.join(channel))
|
2015-02-28 03:27:58 +01:00
|
|
|
cycle = wrap(cycle, ['op', additional('text')])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2009-07-21 00:08:21 +02:00
|
|
|
def kick(self, irc, msg, args, channel, nicks, reason):
|
|
|
|
"""[<channel>] <nick>[, <nick>, ...] [<reason>]
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2009-07-21 00:08:21 +02:00
|
|
|
Kicks <nick>(s) from <channel> for <reason>. If <reason> isn't given,
|
2005-01-19 14:14:38 +01:00
|
|
|
uses the nick of the person making the command as the reason.
|
|
|
|
<channel> is only necessary if the message isn't sent in the channel
|
|
|
|
itself.
|
|
|
|
"""
|
2009-07-21 00:08:21 +02:00
|
|
|
if utils.iter.any(lambda n: ircutils.strEqual(n, irc.nick), nicks):
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.error(_('I cowardly refuse to kick myself.'), Raise=True)
|
2005-01-19 14:14:38 +01:00
|
|
|
if not reason:
|
|
|
|
reason = msg.nick
|
2014-01-20 16:04:53 +01:00
|
|
|
kicklen = irc.state.supported.get('kicklen', sys.maxsize)
|
2005-01-19 14:14:38 +01:00
|
|
|
if len(reason) > kicklen:
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.error(_('The reason you gave is longer than the allowed '
|
|
|
|
'length for a KICK reason on this server.'),
|
2009-05-25 16:02:11 +02:00
|
|
|
Raise=True)
|
2009-07-21 00:08:21 +02:00
|
|
|
for nick in nicks:
|
|
|
|
self._sendMsg(irc, ircmsgs.kick(channel, nick, reason))
|
2013-05-17 17:36:11 +02:00
|
|
|
kick = wrap(kick, ['op', ('haveHalfop+', _('kick someone')),
|
2009-07-21 00:08:21 +02:00
|
|
|
commalist('nickInChannel'), additional('text')])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def kban(self, irc, msg, args,
|
|
|
|
channel, optlist, bannedNick, expiry, reason):
|
|
|
|
"""[<channel>] [--{exact,nick,user,host}] <nick> [<seconds>] [<reason>]
|
|
|
|
|
|
|
|
If you have the #channel,op capability, this will kickban <nick> for
|
|
|
|
as many seconds as you specify, or else (if you specify 0 seconds or
|
|
|
|
don't specify a number of seconds) it will ban the person indefinitely.
|
|
|
|
--exact bans only the exact hostmask; --nick bans just the nick;
|
|
|
|
--user bans just the user, and --host bans just the host. You can
|
|
|
|
combine these options as you choose. <reason> is a reason to give for
|
|
|
|
the kick.
|
|
|
|
<channel> is only necessary if the message isn't sent in the channel
|
|
|
|
itself.
|
|
|
|
"""
|
2012-10-06 19:58:19 +02:00
|
|
|
self._ban(irc, msg, args,
|
|
|
|
channel, optlist, bannedNick, expiry, reason, True)
|
|
|
|
kban = wrap(kban,
|
|
|
|
['op',
|
|
|
|
getopts({'exact':'', 'nick':'', 'user':'', 'host':''}),
|
2013-05-17 17:36:11 +02:00
|
|
|
('haveHalfop+', _('kick or ban someone')),
|
2012-10-06 19:58:19 +02:00
|
|
|
'nickInChannel',
|
|
|
|
optional('expiry', 0),
|
|
|
|
additional('text')])
|
|
|
|
|
|
|
|
@internationalizeDocstring
|
|
|
|
def iban(self, irc, msg, args,
|
|
|
|
channel, optlist, bannedNick, expiry):
|
2012-10-06 22:48:10 +02:00
|
|
|
"""[<channel>] [--{exact,nick,user,host}] <nick> [<seconds>]
|
2012-10-06 19:58:19 +02:00
|
|
|
|
|
|
|
If you have the #channel,op capability, this will ban <nick> for
|
2014-06-02 14:54:47 +02:00
|
|
|
as many seconds as you specify, otherwise (if you specify 0 seconds or
|
2012-10-06 19:58:19 +02:00
|
|
|
don't specify a number of seconds) it will ban the person indefinitely.
|
2014-06-02 14:54:47 +02:00
|
|
|
--exact can be used to specify an exact hostmask. You can combine the
|
|
|
|
exact, nick, user, and host options as you choose. <channel> is only
|
|
|
|
necessary if the message isn't sent in the channel itself.
|
2012-10-06 19:58:19 +02:00
|
|
|
"""
|
|
|
|
self._ban(irc, msg, args,
|
|
|
|
channel, optlist, bannedNick, expiry, None, False)
|
|
|
|
iban = wrap(iban,
|
|
|
|
['op',
|
|
|
|
getopts({'exact':'', 'nick':'', 'user':'', 'host':''}),
|
2013-05-17 17:36:11 +02:00
|
|
|
('haveHalfop+', _('ban someone')),
|
2012-10-06 19:58:19 +02:00
|
|
|
first('nick', 'hostmask'),
|
|
|
|
optional('expiry', 0)])
|
|
|
|
|
|
|
|
def _ban(self, irc, msg, args,
|
|
|
|
channel, optlist, target, expiry, reason, kick):
|
2005-01-19 14:14:38 +01:00
|
|
|
# Check that they're not trying to make us kickban ourself.
|
2012-10-06 19:58:19 +02:00
|
|
|
if irc.isNick(target):
|
|
|
|
bannedNick = target
|
|
|
|
try:
|
|
|
|
bannedHostmask = irc.state.nickToHostmask(target)
|
2012-12-02 18:50:41 +01:00
|
|
|
banmaskstyle = conf.supybot.protocols.irc.banmask
|
|
|
|
banmask = banmaskstyle.makeBanmask(bannedHostmask, [o[0] for o in optlist])
|
2012-10-06 19:58:19 +02:00
|
|
|
except KeyError:
|
2012-12-02 19:04:48 +01:00
|
|
|
if not conf.supybot.protocols.irc.strictRfc() and \
|
|
|
|
target.startswith('$'):
|
|
|
|
# Select the last part, or the whole target:
|
|
|
|
bannedNick = target.split(':')[-1]
|
|
|
|
banmask = bannedHostmask = target
|
|
|
|
else:
|
|
|
|
irc.error(format(_('I haven\'t seen %s.'), bannedNick), Raise=True)
|
2012-10-06 19:58:19 +02:00
|
|
|
else:
|
|
|
|
bannedNick = ircutils.nickFromHostmask(target)
|
2012-12-02 18:50:41 +01:00
|
|
|
banmask = bannedHostmask = target
|
2005-01-19 14:14:38 +01:00
|
|
|
if not irc.isNick(bannedNick):
|
2005-02-01 14:43:57 +01:00
|
|
|
self.log.warning('%q tried to kban a non nick: %q',
|
|
|
|
msg.prefix, bannedNick)
|
2005-01-19 14:14:38 +01:00
|
|
|
raise callbacks.ArgumentError
|
|
|
|
elif bannedNick == irc.nick:
|
2005-02-01 14:43:57 +01:00
|
|
|
self.log.warning('%q tried to make me kban myself.', msg.prefix)
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.error(_('I cowardly refuse to kickban myself.'))
|
2005-01-19 14:14:38 +01:00
|
|
|
return
|
|
|
|
if not reason:
|
|
|
|
reason = msg.nick
|
2011-10-29 15:23:39 +02:00
|
|
|
capability = ircdb.makeChannelCapability(channel, 'op')
|
2005-01-19 14:14:38 +01:00
|
|
|
# Check (again) that they're not trying to make us kickban ourself.
|
|
|
|
if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
|
2009-01-19 22:13:10 +01:00
|
|
|
if ircutils.hostmaskPatternEqual(bannedHostmask, irc.prefix):
|
2005-02-01 14:43:57 +01:00
|
|
|
self.log.warning('%q tried to make me kban myself.',msg.prefix)
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.error(_('I cowardly refuse to ban myself.'))
|
2005-01-19 14:14:38 +01:00
|
|
|
return
|
|
|
|
else:
|
2009-01-19 22:13:10 +01:00
|
|
|
self.log.warning('Using exact hostmask since banmask would '
|
|
|
|
'ban myself.')
|
2005-01-19 14:14:38 +01:00
|
|
|
banmask = bannedHostmask
|
|
|
|
# Now, let's actually get to it. Check to make sure they have
|
|
|
|
# #channel,op and the bannee doesn't have #channel,op; or that the
|
|
|
|
# bannee and the banner are both the same person.
|
|
|
|
def doBan():
|
|
|
|
if irc.state.channels[channel].isOp(bannedNick):
|
|
|
|
irc.queueMsg(ircmsgs.deop(channel, bannedNick))
|
|
|
|
irc.queueMsg(ircmsgs.ban(channel, banmask))
|
2012-10-06 19:58:19 +02:00
|
|
|
if kick:
|
|
|
|
irc.queueMsg(ircmsgs.kick(channel, bannedNick, reason))
|
2005-01-19 14:14:38 +01:00
|
|
|
if expiry > 0:
|
|
|
|
def f():
|
|
|
|
if channel in irc.state.channels and \
|
|
|
|
banmask in irc.state.channels[channel].bans:
|
|
|
|
irc.queueMsg(ircmsgs.unban(channel, banmask))
|
|
|
|
schedule.addEvent(f, expiry)
|
|
|
|
if bannedNick == msg.nick:
|
|
|
|
doBan()
|
2011-10-29 15:23:39 +02:00
|
|
|
elif ircdb.checkCapability(msg.prefix, capability):
|
|
|
|
if ircdb.checkCapability(bannedHostmask, capability) and \
|
|
|
|
not ircdb.checkCapability(msg.prefix, 'owner'):
|
2005-02-01 14:43:57 +01:00
|
|
|
self.log.warning('%s tried to ban %q, but both have %s',
|
2011-10-29 15:23:39 +02:00
|
|
|
msg.prefix, bannedHostmask, capability)
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.error(format(_('%s has %s too, you can\'t ban '
|
2014-04-11 23:56:42 +02:00
|
|
|
'them.'), bannedNick, capability))
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
|
|
|
doBan()
|
|
|
|
else:
|
2005-02-01 14:43:57 +01:00
|
|
|
self.log.warning('%q attempted kban without %s',
|
2011-10-29 15:23:39 +02:00
|
|
|
msg.prefix, capability)
|
|
|
|
irc.errorNoCapability(capability)
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def unban(self, irc, msg, args, channel, hostmask):
|
2012-12-23 17:28:36 +01:00
|
|
|
"""[<channel>] [<hostmask|--all>]
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
Unbans <hostmask> on <channel>. If <hostmask> is not given, unbans
|
|
|
|
any hostmask currently banned on <channel> that matches your current
|
2005-02-19 01:22:23 +01:00
|
|
|
hostmask. Especially useful for unbanning yourself when you get
|
2005-01-19 14:14:38 +01:00
|
|
|
unexpectedly (or accidentally) banned from the channel. <channel> is
|
|
|
|
only necessary if the message isn't sent in the channel itself.
|
|
|
|
"""
|
2012-12-23 17:28:36 +01:00
|
|
|
if hostmask == '--all':
|
|
|
|
bans = irc.state.channels[channel].bans
|
|
|
|
self._sendMsg(irc, ircmsgs.unbans(channel, bans))
|
|
|
|
elif hostmask:
|
2005-01-19 14:14:38 +01:00
|
|
|
self._sendMsg(irc, ircmsgs.unban(channel, hostmask))
|
|
|
|
else:
|
|
|
|
bans = []
|
|
|
|
for banmask in irc.state.channels[channel].bans:
|
|
|
|
if ircutils.hostmaskPatternEqual(banmask, msg.prefix):
|
|
|
|
bans.append(banmask)
|
|
|
|
if bans:
|
|
|
|
irc.queueMsg(ircmsgs.unbans(channel, bans))
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.replySuccess(format(_('All bans on %s matching %s '
|
|
|
|
'have been removed.'),
|
2005-02-19 01:22:23 +01:00
|
|
|
channel, msg.prefix))
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.error(_('No bans matching %s were found on %s.') %
|
2005-01-19 14:14:38 +01:00
|
|
|
(msg.prefix, channel))
|
2005-02-24 10:59:21 +01:00
|
|
|
unban = wrap(unban, ['op',
|
2013-05-17 17:36:11 +02:00
|
|
|
('haveHalfop+', _('unban someone')),
|
2012-12-23 17:28:36 +01:00
|
|
|
additional(
|
|
|
|
first('hostmask',
|
|
|
|
('literal', '--all')))])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2012-12-23 17:19:29 +01:00
|
|
|
@internationalizeDocstring
|
|
|
|
def listbans(self, irc, msg, args, channel):
|
|
|
|
"""[<channel>]
|
|
|
|
|
|
|
|
List all bans on the channel.
|
|
|
|
If <channel> is not given, it defaults to the current channel."""
|
|
|
|
irc.replies(irc.state.channels[channel].bans or [_('No bans.')])
|
|
|
|
listbans = wrap(listbans, ['channel'])
|
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def invite(self, irc, msg, args, channel, nick):
|
|
|
|
"""[<channel>] <nick>
|
|
|
|
|
|
|
|
If you have the #channel,op capability, this will invite <nick>
|
|
|
|
to join <channel>. <channel> is only necessary if the message isn't
|
|
|
|
sent in the channel itself.
|
|
|
|
"""
|
2005-03-09 11:36:54 +01:00
|
|
|
nick = nick or msg.nick
|
|
|
|
self._sendMsg(irc, ircmsgs.invite(nick, channel))
|
2005-01-19 14:14:38 +01:00
|
|
|
self.invites[(irc.getRealIrc(), ircutils.toLower(nick))] = irc
|
2013-05-17 17:36:11 +02:00
|
|
|
invite = wrap(invite, ['op', ('haveHalfop+', _('invite someone')),
|
2005-01-19 14:14:38 +01:00
|
|
|
additional('nick')])
|
|
|
|
|
|
|
|
def do341(self, irc, msg):
|
2011-07-15 23:01:41 +02:00
|
|
|
(foo, nick, channel) = msg.args
|
2005-01-19 14:14:38 +01:00
|
|
|
nick = ircutils.toLower(nick)
|
|
|
|
replyIrc = self.invites.pop((irc, nick), None)
|
|
|
|
if replyIrc is not None:
|
|
|
|
self.log.info('Inviting %s to %s by command of %s.',
|
|
|
|
nick, channel, replyIrc.msg.prefix)
|
|
|
|
replyIrc.replySuccess()
|
|
|
|
else:
|
|
|
|
self.log.info('Inviting %s to %s.', nick, channel)
|
|
|
|
|
|
|
|
def do443(self, irc, msg):
|
2011-07-15 23:01:41 +02:00
|
|
|
(foo, nick, channel, foo) = msg.args
|
2005-01-19 14:14:38 +01:00
|
|
|
nick = ircutils.toLower(nick)
|
|
|
|
replyIrc = self.invites.pop((irc, nick), None)
|
|
|
|
if replyIrc is not None:
|
2010-10-16 10:17:51 +02:00
|
|
|
replyIrc.error(format(_('%s is already in %s.'), nick, channel))
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
def do401(self, irc, msg):
|
|
|
|
nick = msg.args[1]
|
|
|
|
nick = ircutils.toLower(nick)
|
|
|
|
replyIrc = self.invites.pop((irc, nick), None)
|
|
|
|
if replyIrc is not None:
|
2010-10-16 10:17:51 +02:00
|
|
|
replyIrc.error(format(_('There is no %s on this network.'), nick))
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
def do504(self, irc, msg):
|
|
|
|
nick = msg.args[1]
|
|
|
|
nick = ircutils.toLower(nick)
|
|
|
|
replyIrc = self.invites.pop((irc, nick), None)
|
2011-07-09 14:05:28 +02:00
|
|
|
if replyIrc is not None:
|
2005-02-19 01:22:23 +01:00
|
|
|
replyIrc.error(format('There is no %s on this server.', nick))
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2005-02-24 13:49:25 +01:00
|
|
|
class lobotomy(callbacks.Commands):
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-24 13:49:25 +01:00
|
|
|
def add(self, irc, msg, args, channel):
|
|
|
|
"""[<channel>]
|
|
|
|
|
|
|
|
If you have the #channel,op capability, this will "lobotomize" the
|
|
|
|
bot, making it silent and unanswering to all requests made in the
|
|
|
|
channel. <channel> is only necessary if the message isn't sent in
|
|
|
|
the channel itself.
|
|
|
|
"""
|
|
|
|
c = ircdb.channels.getChannel(channel)
|
|
|
|
c.lobotomized = True
|
|
|
|
ircdb.channels.setChannel(channel, c)
|
|
|
|
irc.replySuccess()
|
|
|
|
add = wrap(add, ['op'])
|
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-24 13:49:25 +01:00
|
|
|
def remove(self, irc, msg, args, channel):
|
|
|
|
"""[<channel>]
|
|
|
|
|
|
|
|
If you have the #channel,op capability, this will unlobotomize the
|
|
|
|
bot, making it respond to requests made in the channel again.
|
|
|
|
<channel> is only necessary if the message isn't sent in the channel
|
|
|
|
itself.
|
|
|
|
"""
|
|
|
|
c = ircdb.channels.getChannel(channel)
|
|
|
|
c.lobotomized = False
|
|
|
|
ircdb.channels.setChannel(channel, c)
|
|
|
|
irc.replySuccess()
|
|
|
|
remove = wrap(remove, ['op'])
|
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-24 13:49:25 +01:00
|
|
|
def list(self, irc, msg, args):
|
|
|
|
"""takes no arguments
|
|
|
|
|
|
|
|
Returns the channels in which this bot is lobotomized.
|
|
|
|
"""
|
|
|
|
L = []
|
|
|
|
for (channel, c) in ircdb.channels.iteritems():
|
|
|
|
if c.lobotomized:
|
|
|
|
chancap = ircdb.makeChannelCapability(channel, 'op')
|
|
|
|
if ircdb.checkCapability(msg.prefix, 'admin') or \
|
|
|
|
ircdb.checkCapability(msg.prefix, chancap) or \
|
|
|
|
(channel in irc.state.channels and \
|
|
|
|
msg.nick in irc.state.channels[channel].users):
|
|
|
|
L.append(channel)
|
|
|
|
if L:
|
|
|
|
L.sort()
|
2010-10-16 10:17:51 +02:00
|
|
|
s = format(_('I\'m currently lobotomized in %L.'), L)
|
2005-02-24 13:49:25 +01:00
|
|
|
irc.reply(s)
|
|
|
|
else:
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.reply(_('I\'m not currently lobotomized in any channels '
|
|
|
|
'that you\'re in.'))
|
2005-02-24 13:49:25 +01:00
|
|
|
list = wrap(list)
|
|
|
|
|
|
|
|
class ban(callbacks.Commands):
|
2014-03-09 19:39:46 +01:00
|
|
|
def hostmask(self, irc, msg, args, channel, banmask):
|
|
|
|
"""[<channel>] <banmask>
|
|
|
|
|
|
|
|
Bans the <banmask> from the <channel>."""
|
|
|
|
irc.queueMsg(ircmsgs.ban(channel, banmask))
|
|
|
|
hostmask = wrap(hostmask, ['op', ('haveHalfop+', _('ban someone')), 'text'])
|
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-24 13:49:25 +01:00
|
|
|
def add(self, irc, msg, args, channel, banmask, expires):
|
|
|
|
"""[<channel>] <nick|hostmask> [<expires>]
|
|
|
|
|
|
|
|
If you have the #channel,op capability, this will effect a
|
|
|
|
persistent ban from interacting with the bot on the given
|
2011-07-22 01:34:31 +02:00
|
|
|
<hostmask> (or the current hostmask associated with <nick>). Other
|
2005-02-24 13:49:25 +01:00
|
|
|
plugins may enforce this ban by actually banning users with
|
|
|
|
matching hostmasks when they join. <expires> is an optional
|
|
|
|
argument specifying when (in "seconds from now") the ban should
|
|
|
|
expire; if none is given, the ban will never automatically expire.
|
|
|
|
<channel> is only necessary if the message isn't sent in the
|
|
|
|
channel itself.
|
|
|
|
"""
|
|
|
|
c = ircdb.channels.getChannel(channel)
|
|
|
|
c.addBan(banmask, expires)
|
|
|
|
ircdb.channels.setChannel(channel, c)
|
|
|
|
irc.replySuccess()
|
2012-10-06 19:58:44 +02:00
|
|
|
add = wrap(add, ['op', first('hostmask', 'banmask'), additional('expiry', 0)])
|
2005-02-24 13:49:25 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-24 13:49:25 +01:00
|
|
|
def remove(self, irc, msg, args, channel, banmask):
|
|
|
|
"""[<channel>] <hostmask>
|
|
|
|
|
|
|
|
If you have the #channel,op capability, this will remove the
|
|
|
|
persistent ban on <hostmask>. <channel> is only necessary if the
|
|
|
|
message isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
c = ircdb.channels.getChannel(channel)
|
2005-06-01 15:24:06 +02:00
|
|
|
try:
|
|
|
|
c.removeBan(banmask)
|
|
|
|
ircdb.channels.setChannel(channel, c)
|
|
|
|
irc.replySuccess()
|
|
|
|
except KeyError:
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.error(_('There are no persistent bans for that hostmask.'))
|
2005-02-24 13:49:25 +01:00
|
|
|
remove = wrap(remove, ['op', 'hostmask'])
|
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2014-11-24 18:26:25 +01:00
|
|
|
def list(self, irc, msg, args, channel, mask):
|
|
|
|
"""[<channel>] [<mask>]
|
2005-02-24 13:49:25 +01:00
|
|
|
|
|
|
|
If you have the #channel,op capability, this will show you the
|
2014-11-24 18:29:25 +01:00
|
|
|
current persistent bans on the <channel> that match the given
|
|
|
|
mask, if any (returns all of them otherwise).
|
|
|
|
Note that you can use * as a wildcard on masks and \* to match
|
|
|
|
actual * in masks
|
2005-02-24 13:49:25 +01:00
|
|
|
"""
|
2014-11-24 18:26:25 +01:00
|
|
|
all_bans = ircdb.channels.getChannel(channel).bans
|
|
|
|
if mask:
|
|
|
|
mask = mask.replace(r'\*', '[*]')
|
|
|
|
filtered_bans = fnmatch.filter(all_bans, mask)
|
|
|
|
else:
|
|
|
|
filtered_bans = all_bans
|
|
|
|
if filtered_bans:
|
2006-04-27 02:29:14 +02:00
|
|
|
bans = []
|
2014-11-24 18:26:25 +01:00
|
|
|
for ban in filtered_bans:
|
|
|
|
if all_bans[ban]:
|
2010-10-16 10:17:51 +02:00
|
|
|
bans.append(format(_('%q (expires %t)'),
|
2014-11-24 18:26:25 +01:00
|
|
|
ban, all_bans[ban]))
|
2006-04-27 02:29:14 +02:00
|
|
|
else:
|
2010-10-16 10:17:51 +02:00
|
|
|
bans.append(format(_('%q (never expires)'),
|
2014-11-24 18:26:25 +01:00
|
|
|
ban, all_bans[ban]))
|
2006-04-27 02:29:14 +02:00
|
|
|
irc.reply(format('%L', bans))
|
2005-02-24 13:49:25 +01:00
|
|
|
else:
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.reply(format(_('There are no persistent bans on %s.'),
|
2005-02-24 13:49:25 +01:00
|
|
|
channel))
|
2014-11-24 18:26:25 +01:00
|
|
|
list = wrap(list, ['op', optional('somethingWithoutSpaces')])
|
2005-02-24 13:49:25 +01:00
|
|
|
|
|
|
|
class ignore(callbacks.Commands):
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-24 13:49:25 +01:00
|
|
|
def add(self, irc, msg, args, channel, banmask, expires):
|
|
|
|
"""[<channel>] <nick|hostmask> [<expires>]
|
|
|
|
|
|
|
|
If you have the #channel,op capability, this will set a persistent
|
|
|
|
ignore on <hostmask> or the hostmask currently
|
|
|
|
associated with <nick>. <expires> is an optional argument
|
|
|
|
specifying when (in "seconds from now") the ignore will expire; if
|
|
|
|
it isn't given, the ignore will never automatically expire.
|
|
|
|
<channel> is only necessary if the message isn't sent in the
|
|
|
|
channel itself.
|
|
|
|
"""
|
|
|
|
c = ircdb.channels.getChannel(channel)
|
|
|
|
c.addIgnore(banmask, expires)
|
|
|
|
ircdb.channels.setChannel(channel, c)
|
|
|
|
irc.replySuccess()
|
2009-01-19 22:13:02 +01:00
|
|
|
add = wrap(add, ['op', 'banmask', additional('expiry', 0)])
|
2005-02-24 13:49:25 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-24 13:49:25 +01:00
|
|
|
def remove(self, irc, msg, args, channel, banmask):
|
|
|
|
"""[<channel>] <hostmask>
|
|
|
|
|
|
|
|
If you have the #channel,op capability, this will remove the
|
|
|
|
persistent ignore on <hostmask> in the channel. <channel> is only
|
|
|
|
necessary if the message isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
c = ircdb.channels.getChannel(channel)
|
2005-06-01 15:24:06 +02:00
|
|
|
try:
|
|
|
|
c.removeIgnore(banmask)
|
|
|
|
ircdb.channels.setChannel(channel, c)
|
|
|
|
irc.replySuccess()
|
|
|
|
except KeyError:
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.error(_('There are no ignores for that hostmask.'))
|
2005-02-24 13:49:25 +01:00
|
|
|
remove = wrap(remove, ['op', 'hostmask'])
|
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-24 13:49:25 +01:00
|
|
|
def list(self, irc, msg, args, channel):
|
|
|
|
"""[<channel>]
|
|
|
|
|
|
|
|
Lists the hostmasks that the bot is ignoring on the given channel.
|
|
|
|
<channel> is only necessary if the message isn't sent in the
|
|
|
|
channel itself.
|
|
|
|
"""
|
|
|
|
# XXX Add the expirations.
|
|
|
|
c = ircdb.channels.getChannel(channel)
|
|
|
|
if len(c.ignores) == 0:
|
2010-10-16 10:17:51 +02:00
|
|
|
s = format(_('I\'m not currently ignoring any hostmasks in '
|
|
|
|
'%q'), channel)
|
2005-02-24 13:49:25 +01:00
|
|
|
irc.reply(s)
|
|
|
|
else:
|
|
|
|
L = sorted(c.ignores)
|
2014-01-21 10:57:38 +01:00
|
|
|
irc.reply(utils.str.commaAndify(list(map(repr, L))))
|
2005-02-24 13:49:25 +01:00
|
|
|
list = wrap(list, ['op'])
|
|
|
|
|
|
|
|
class capability(callbacks.Commands):
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-24 13:49:25 +01:00
|
|
|
def add(self, irc, msg, args, channel, user, capabilities):
|
|
|
|
"""[<channel>] <nick|username> <capability> [<capability> ...]
|
|
|
|
|
2012-02-11 15:18:32 +01:00
|
|
|
If you have the #channel,op capability, this will give the
|
|
|
|
<username> (or the user to whom <nick> maps)
|
2005-02-24 13:49:25 +01:00
|
|
|
the capability <capability> in the channel. <channel> is only
|
|
|
|
necessary if the message isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
for c in capabilities.split():
|
|
|
|
c = ircdb.makeChannelCapability(channel, c)
|
|
|
|
user.addCapability(c)
|
|
|
|
ircdb.users.setUser(user)
|
|
|
|
irc.replySuccess()
|
|
|
|
add = wrap(add, ['op', 'otherUser', 'capability'])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-24 13:49:25 +01:00
|
|
|
def remove(self, irc, msg, args, channel, user, capabilities):
|
|
|
|
"""[<channel>] <name|hostmask> <capability> [<capability> ...]
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2005-02-24 13:49:25 +01:00
|
|
|
If you have the #channel,op capability, this will take from the
|
|
|
|
user currently identified as <name> (or the user to whom <hostmask>
|
|
|
|
maps) the capability <capability> in the channel. <channel> is only
|
|
|
|
necessary if the message isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
fail = []
|
|
|
|
for c in capabilities.split():
|
|
|
|
cap = ircdb.makeChannelCapability(channel, c)
|
|
|
|
try:
|
|
|
|
user.removeCapability(cap)
|
|
|
|
except KeyError:
|
|
|
|
fail.append(c)
|
|
|
|
ircdb.users.setUser(user)
|
|
|
|
if fail:
|
|
|
|
s = 'capability'
|
|
|
|
if len(fail) > 1:
|
|
|
|
s = utils.str.pluralize(s)
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.error(format(_('That user didn\'t have the %L %s.'), fail,
|
|
|
|
s), Raise=True)
|
2005-02-24 13:49:25 +01:00
|
|
|
irc.replySuccess()
|
|
|
|
remove = wrap(remove, ['op', 'otherUser', 'capability'])
|
|
|
|
|
|
|
|
# XXX This needs to be fix0red to be like Owner.defaultcapability. Or
|
|
|
|
# something else. This is a horrible interface.
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-24 13:49:25 +01:00
|
|
|
def setdefault(self, irc, msg, args, channel, v):
|
|
|
|
"""[<channel>] {True|False}
|
|
|
|
|
|
|
|
If you have the #channel,op capability, this will set the default
|
2011-07-22 01:34:31 +02:00
|
|
|
response to non-power-related (that is, not {op, halfop, voice})
|
2005-02-24 13:49:25 +01:00
|
|
|
capabilities to be the value you give. <channel> is only necessary
|
|
|
|
if the message isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
c = ircdb.channels.getChannel(channel)
|
|
|
|
if v:
|
|
|
|
c.setDefaultCapability(True)
|
|
|
|
else:
|
|
|
|
c.setDefaultCapability(False)
|
|
|
|
ircdb.channels.setChannel(channel, c)
|
|
|
|
irc.replySuccess()
|
|
|
|
setdefault = wrap(setdefault, ['op', 'boolean'])
|
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-24 13:49:25 +01:00
|
|
|
def set(self, irc, msg, args, channel, capabilities):
|
|
|
|
"""[<channel>] <capability> [<capability> ...]
|
|
|
|
|
|
|
|
If you have the #channel,op capability, this will add the channel
|
|
|
|
capability <capability> for all users in the channel. <channel> is
|
|
|
|
only necessary if the message isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
chan = ircdb.channels.getChannel(channel)
|
|
|
|
for c in capabilities:
|
|
|
|
chan.addCapability(c)
|
|
|
|
ircdb.channels.setChannel(channel, chan)
|
|
|
|
irc.replySuccess()
|
|
|
|
set = wrap(set, ['op', many('capability')])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-24 13:49:25 +01:00
|
|
|
def unset(self, irc, msg, args, channel, capabilities):
|
|
|
|
"""[<channel>] <capability> [<capability> ...]
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2005-02-24 13:49:25 +01:00
|
|
|
If you have the #channel,op capability, this will unset the channel
|
|
|
|
capability <capability> so each user's specific capability or the
|
|
|
|
channel default capability will take precedence. <channel> is only
|
|
|
|
necessary if the message isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
chan = ircdb.channels.getChannel(channel)
|
|
|
|
fail = []
|
|
|
|
for c in capabilities:
|
|
|
|
try:
|
|
|
|
chan.removeCapability(c)
|
|
|
|
except KeyError:
|
|
|
|
fail.append(c)
|
|
|
|
ircdb.channels.setChannel(channel, chan)
|
|
|
|
if fail:
|
2010-10-16 10:17:51 +02:00
|
|
|
s = _('capability')
|
2005-02-24 13:49:25 +01:00
|
|
|
if len(fail) > 1:
|
|
|
|
s = utils.str.pluralize(s)
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.error(format(_('I do not know about the %L %s.'), fail, s),
|
2005-02-24 13:49:25 +01:00
|
|
|
Raise=True)
|
|
|
|
irc.replySuccess()
|
|
|
|
unset = wrap(unset, ['op', many('capability')])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-02-24 13:49:25 +01:00
|
|
|
def list(self, irc, msg, args, channel):
|
|
|
|
"""[<channel>]
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2005-02-24 13:49:25 +01:00
|
|
|
Returns the capabilities present on the <channel>. <channel> is
|
|
|
|
only necessary if the message isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
c = ircdb.channels.getChannel(channel)
|
|
|
|
L = sorted(c.capabilities)
|
|
|
|
irc.reply(' '.join(L))
|
|
|
|
list = wrap(list, ['channel'])
|
2005-02-19 01:22:23 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def disable(self, irc, msg, args, channel, plugin, command):
|
|
|
|
"""[<channel>] [<plugin>] [<command>]
|
|
|
|
|
2005-02-19 01:22:23 +01:00
|
|
|
If you have the #channel,op capability, this will disable the <command>
|
|
|
|
in <channel>. If <plugin> is provided, <command> will be disabled only
|
|
|
|
for that plugin. If only <plugin> is provided, all commands in the
|
|
|
|
given plugin will be disabled. <channel> is only necessary if the
|
2005-01-19 14:14:38 +01:00
|
|
|
message isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
chan = ircdb.channels.getChannel(channel)
|
|
|
|
failMsg = ''
|
|
|
|
if plugin:
|
|
|
|
s = '-%s' % plugin.name()
|
|
|
|
if command:
|
|
|
|
if plugin.isCommand(command):
|
|
|
|
s = '-%s.%s' % (plugin.name(), command)
|
|
|
|
else:
|
2010-10-16 10:17:51 +02:00
|
|
|
failMsg = format(_('The %s plugin does not have a command '
|
|
|
|
'called %s.'), plugin.name(), command)
|
2005-01-19 14:14:38 +01:00
|
|
|
elif command:
|
|
|
|
# findCallbackForCommand
|
Start accelerating the 2to3 step (remove fix_apply, fix_buffer, fix_callable, fix_exec, fix_execfile, fix_exitfunc, fix_filter, fix_funcattrs, fix_future, fix_getcwdu, and fix_has_key).
2014-01-20 14:49:47 +01:00
|
|
|
if list(filter(None, irc.findCallbacksForArgs([command]))):
|
2005-01-19 14:14:38 +01:00
|
|
|
s = '-%s' % command
|
|
|
|
else:
|
2010-10-16 10:17:51 +02:00
|
|
|
failMsg = format(_('No plugin or command named %s could be '
|
|
|
|
'found.'), command)
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
|
|
|
raise callbacks.ArgumentError
|
|
|
|
if failMsg:
|
|
|
|
irc.error(failMsg)
|
|
|
|
else:
|
|
|
|
chan.addCapability(s)
|
|
|
|
ircdb.channels.setChannel(channel, chan)
|
|
|
|
irc.replySuccess()
|
2005-02-24 10:59:21 +01:00
|
|
|
disable = wrap(disable, ['op',
|
|
|
|
optional(('plugin', False)),
|
|
|
|
additional('commandName')])
|
2005-02-19 01:22:23 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def enable(self, irc, msg, args, channel, plugin, command):
|
|
|
|
"""[<channel>] [<plugin>] [<command>]
|
|
|
|
|
2005-02-19 01:22:23 +01:00
|
|
|
If you have the #channel,op capability, this will enable the <command>
|
|
|
|
in <channel> if it has been disabled. If <plugin> is provided,
|
|
|
|
<command> will be enabled only for that plugin. If only <plugin> is
|
|
|
|
provided, all commands in the given plugin will be enabled. <channel>
|
2005-01-19 14:14:38 +01:00
|
|
|
is only necessary if the message isn't sent in the channel itself.
|
|
|
|
"""
|
|
|
|
chan = ircdb.channels.getChannel(channel)
|
|
|
|
failMsg = ''
|
|
|
|
if plugin:
|
|
|
|
s = '-%s' % plugin.name()
|
|
|
|
if command:
|
|
|
|
if plugin.isCommand(command):
|
|
|
|
s = '-%s.%s' % (plugin.name(), command)
|
|
|
|
else:
|
2010-10-16 10:17:51 +02:00
|
|
|
failMsg = format(_('The %s plugin does not have a command '
|
|
|
|
'called %s.'), plugin.name(), command)
|
2005-01-19 14:14:38 +01:00
|
|
|
elif command:
|
|
|
|
# findCallbackForCommand
|
Start accelerating the 2to3 step (remove fix_apply, fix_buffer, fix_callable, fix_exec, fix_execfile, fix_exitfunc, fix_filter, fix_funcattrs, fix_future, fix_getcwdu, and fix_has_key).
2014-01-20 14:49:47 +01:00
|
|
|
if list(filter(None, irc.findCallbacksForArgs([command]))):
|
2005-01-19 14:14:38 +01:00
|
|
|
s = '-%s' % command
|
|
|
|
else:
|
2010-10-16 10:17:51 +02:00
|
|
|
failMsg = format(_('No plugin or command named %s could be '
|
|
|
|
'found.'), command)
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
|
|
|
raise callbacks.ArgumentError
|
|
|
|
if failMsg:
|
|
|
|
irc.error(failMsg)
|
|
|
|
else:
|
|
|
|
fail = []
|
|
|
|
try:
|
|
|
|
chan.removeCapability(s)
|
|
|
|
except KeyError:
|
|
|
|
fail.append(s)
|
|
|
|
ircdb.channels.setChannel(channel, chan)
|
|
|
|
if fail:
|
2010-10-16 10:17:51 +02:00
|
|
|
irc.error(format(_('%s was not disabled.'), s[1:]))
|
2005-01-19 14:14:38 +01:00
|
|
|
else:
|
|
|
|
irc.replySuccess()
|
2005-02-24 10:59:21 +01:00
|
|
|
enable = wrap(enable, ['op',
|
|
|
|
optional(('plugin', False)),
|
|
|
|
additional('commandName')])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2010-06-13 08:36:18 +02:00
|
|
|
def nicks(self, irc, msg, args, channel, optlist):
|
|
|
|
"""[<channel>] [--count]
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
Returns the nicks in <channel>. <channel> is only necessary if the
|
2010-06-13 08:36:18 +02:00
|
|
|
message isn't sent in the channel itself. Returns only the number of
|
|
|
|
nicks if --count option is provided.
|
2005-01-19 14:14:38 +01:00
|
|
|
"""
|
2009-05-25 06:30:13 +02:00
|
|
|
# Make sure we don't elicit information about private channels to
|
|
|
|
# people or channels that shouldn't know
|
2014-10-09 16:12:09 +02:00
|
|
|
capability = ircdb.makeChannelCapability(channel, 'op')
|
2014-10-09 16:20:25 +02:00
|
|
|
hostmask = irc.state.nickToHostmask(msg.nick)
|
2009-05-25 06:30:13 +02:00
|
|
|
if 's' in irc.state.channels[channel].modes and \
|
|
|
|
msg.args[0] != channel and \
|
2014-10-09 16:12:09 +02:00
|
|
|
not ircdb.checkCapability(hostmask, capability) and \
|
2009-05-25 06:30:13 +02:00
|
|
|
(ircutils.isChannel(msg.args[0]) or \
|
|
|
|
msg.nick not in irc.state.channels[channel].users):
|
2011-10-27 11:56:13 +02:00
|
|
|
irc.error(_('You don\'t have access to that information.'),
|
|
|
|
Raise=True)
|
2005-01-19 14:14:38 +01:00
|
|
|
L = list(irc.state.channels[channel].users)
|
2010-06-13 08:36:18 +02:00
|
|
|
keys = [option for (option, arg) in optlist]
|
|
|
|
if 'count' not in keys:
|
|
|
|
utils.sortBy(str.lower, L)
|
2015-02-02 02:52:00 +01:00
|
|
|
private = self.registryValue("nicksInPrivate", channel)
|
|
|
|
irc.reply(utils.str.commaAndify(L), private=private)
|
2010-06-13 08:36:18 +02:00
|
|
|
else:
|
|
|
|
irc.reply(str(len(L)))
|
|
|
|
nicks = wrap(nicks, ['inChannel',
|
|
|
|
getopts({'count':''})])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def alertOps(self, irc, channel, s, frm=None):
|
|
|
|
"""Internal message for notifying all the #channel,ops in a channel of
|
|
|
|
a given situation."""
|
|
|
|
capability = ircdb.makeChannelCapability(channel, 'op')
|
2010-10-16 10:17:51 +02:00
|
|
|
s = format(_('Alert to all %s ops: %s'), channel, s)
|
2005-01-19 14:14:38 +01:00
|
|
|
if frm is not None:
|
2010-10-16 10:17:51 +02:00
|
|
|
s += format(_(' (from %s)'), frm)
|
2005-01-19 14:14:38 +01:00
|
|
|
for nick in irc.state.channels[channel].users:
|
|
|
|
hostmask = irc.state.nickToHostmask(nick)
|
|
|
|
if ircdb.checkCapability(hostmask, capability):
|
|
|
|
irc.reply(s, to=nick, private=True)
|
2014-05-09 21:37:17 +02:00
|
|
|
irc.replySuccess()
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2010-10-16 10:17:51 +02:00
|
|
|
@internationalizeDocstring
|
2005-01-19 14:14:38 +01:00
|
|
|
def alert(self, irc, msg, args, channel, text):
|
|
|
|
"""[<channel>] <text>
|
|
|
|
|
|
|
|
Sends <text> to all the users in <channel> who have the <channel>,op
|
|
|
|
capability.
|
|
|
|
"""
|
|
|
|
self.alertOps(irc, channel, text, frm=msg.nick)
|
2009-06-30 17:06:17 +02:00
|
|
|
alert = wrap(alert, ['inChannel', 'text'])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
2015-02-28 03:11:10 +01:00
|
|
|
@internationalizeDocstring
|
|
|
|
def part(self, irc, msg, args, channel, reason):
|
|
|
|
"""[<channel>] [<reason>]
|
|
|
|
|
|
|
|
Tells the bot to part the list of channels you give it. <channel> is
|
|
|
|
only necessary if you want the bot to part a channel other than the
|
|
|
|
current channel. If <reason> is specified, use it as the part
|
|
|
|
message. Otherwise, the default part message specified in
|
|
|
|
supybot.plugins.Channel.partMsg will be used. No part message will be
|
|
|
|
used if no default is configured.
|
|
|
|
"""
|
|
|
|
if channel is None:
|
|
|
|
if irc.isChannel(msg.args[0]):
|
|
|
|
channel = msg.args[0]
|
|
|
|
else:
|
|
|
|
irc.error(Raise=True)
|
|
|
|
capability = ircdb.makeChannelCapability(channel, 'op')
|
|
|
|
hostmask = irc.state.nickToHostmask(msg.nick)
|
2015-03-06 18:50:59 +01:00
|
|
|
if not ircdb.checkCapabilities(hostmask, [capability, 'admin']):
|
2015-02-28 03:11:10 +01:00
|
|
|
irc.errorNoCapability(capability, Raise=True)
|
|
|
|
try:
|
|
|
|
network = conf.supybot.networks.get(irc.network)
|
|
|
|
network.channels().remove(channel)
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
if channel not in irc.state.channels:
|
|
|
|
irc.error(_('I\'m not in %s.') % channel, Raise=True)
|
|
|
|
reason = (reason or self.registryValue("partMsg", channel))
|
|
|
|
reason = ircutils.standardSubstitute(irc, msg, reason)
|
|
|
|
irc.queueMsg(ircmsgs.part(channel, reason))
|
|
|
|
if msg.nick in irc.state.channels[channel].users:
|
|
|
|
irc.noReply()
|
|
|
|
else:
|
|
|
|
irc.replySuccess()
|
|
|
|
part = wrap(part, [optional('validChannel'), additional('text')])
|
2005-01-19 14:14:38 +01:00
|
|
|
|
|
|
|
Class = Channel
|
|
|
|
|
2006-02-11 16:52:51 +01:00
|
|
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|