Limnoria/src/Channel.py

682 lines
28 KiB
Python
Raw Normal View History

2003-03-27 07:28:13 +01:00
#!/usr/bin/env python
###
# Copyright (c) 2002-2004, Jeremiah Fincher
2003-03-27 07:28:13 +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.
###
"""
2003-09-03 11:50:04 +02:00
Basic channel management commands. Many of these commands require their caller
to have the <channel>.op capability. This plugin is loaded by default.
2003-03-27 07:28:13 +01:00
"""
2003-11-25 18:33:58 +01:00
__revision__ = "$Id$"
2004-04-28 08:30:55 +02:00
__author__ = 'Jeremy Fincher (jemfinch) <jemfinch@users.sf.net>'
2003-11-25 18:33:58 +01:00
2004-07-24 07:18:26 +02:00
import supybot.fix as fix
2003-11-25 18:33:58 +01:00
2003-03-27 07:28:13 +01:00
import time
2004-01-01 21:17:55 +01:00
import getopt
from itertools import imap
2003-03-27 07:28:13 +01:00
2004-07-24 07:18:26 +02:00
import supybot.conf as conf
import supybot.ircdb as ircdb
import supybot.utils as utils
import supybot.ircmsgs as ircmsgs
import supybot.schedule as schedule
import supybot.ircutils as ircutils
import supybot.privmsgs as privmsgs
import supybot.registry as registry
import supybot.callbacks as callbacks
2003-03-27 07:28:13 +01:00
conf.registerPlugin('Channel')
conf.registerChannelValue(conf.supybot.plugins.Channel, 'alwaysRejoin',
2004-04-05 18:01:49 +02:00
registry.Boolean(True, """Determines whether the bot will always try to
rejoin a channel whenever it's kicked from the channel."""))
2003-10-21 08:03:57 +02:00
class Channel(callbacks.Privmsg):
def haveOps(self, irc, channel, what):
2004-07-31 09:45:19 +02:00
try:
if irc.nick in irc.state.channels[channel].ops:
return True
else:
irc.error('How can I %s? I\'m not opped in %s.' %
(what, channel))
return False
except KeyError:
irc.error('I don\'t seem to be in %s.' % channel)
def doKick(self, irc, msg):
channel = msg.args[0]
if msg.args[1] == irc.nick:
if self.registryValue('alwaysRejoin', channel):
irc.sendMsg(ircmsgs.join(channel)) # Fix for keys.
2004-07-23 03:01:29 +02:00
def mode(self, irc, msg, args, channel):
"""[<channel>] <mode> [<arg> ...]
Sets the mode in <channel> to <mode>, sending the arguments given.
2004-07-23 03:19:30 +02:00
<channel> is only necessary if the message isn't sent in the channel
itself.
2004-07-23 03:01:29 +02:00
"""
if not args:
raise callbacks.ArgumentError
if self.haveOps(irc, channel, 'change the mode'):
irc.queueMsg(ircmsgs.mode(channel, args))
2004-07-23 03:01:29 +02:00
mode = privmsgs.checkChannelCapability(mode, 'op')
2004-07-23 03:19:30 +02:00
def limit(self, irc, msg, args, channel):
"""[<channel>] <limit>
Sets the channel limit to <limit>. If <limit> is 0, removes the
channel limit. <channel> is only necessary if the message isn't sent
in the channel itself.
"""
2004-08-11 14:57:52 +02:00
limit = privmsgs.getArgs(args)
2004-07-23 03:19:30 +02:00
try:
limit = int(limit)
if limit < 0:
raise ValueError
except ValueError:
irc.error('%r is not a positive integer.' % limit)
return
if limit:
if self.haveOps(irc, channel, 'set the limit'):
irc.queueMsg(ircmsgs.mode(channel, ['+l', limit]))
2004-07-23 03:19:30 +02:00
else:
if self.haveOps(irc, channel, 'unset the limit'):
irc.queueMsg(ircmsgs.mode(channel, ['-l']))
2004-07-23 03:19:30 +02:00
limit = privmsgs.checkChannelCapability(limit, 'op')
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.
"""
if self.haveOps(irc, channel, 'moderate the channel'):
irc.queueMsg(ircmsgs.mode(channel, ['+m']))
moderate = privmsgs.checkChannelCapability(moderate, 'op')
2004-08-11 14:57:52 +02: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.
"""
if self.haveOps(irc, channel, 'unmoderate the channel'):
irc.queueMsg(ircmsgs.mode(channel, ['-m']))
unmoderate = privmsgs.checkChannelCapability(unmoderate, 'op')
def key(self, irc, msg, args, channel):
"""[<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.
"""
key = privmsgs.getArgs(args, required=0, optional=1)
if key:
if self.haveOps(irc, channel, 'set the keyword'):
irc.queueMsg(ircmsgs.mode(channel, ['+k', key]))
else:
if self.haveOps(irc, channel, 'unset the keyword'):
irc.queueMsg(ircmsgs.mode(channel, ['-k']))
key = privmsgs.checkChannelCapability(key, 'op')
2004-08-11 14:57:52 +02:00
2003-09-29 07:01:41 +02:00
def op(self, irc, msg, args, channel):
"""[<channel>] [<nick> ...]
2003-03-27 07:28:13 +01:00
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.
2003-03-27 07:28:13 +01:00
"""
if not args:
args = [msg.nick]
if self.haveOps(irc, channel, 'op you'):
irc.queueMsg(ircmsgs.ops(channel, args))
2003-09-29 07:01:41 +02:00
op = privmsgs.checkChannelCapability(op, 'op')
2003-03-27 07:28:13 +01:00
2003-09-29 07:01:41 +02:00
def halfop(self, irc, msg, args, channel):
2003-03-27 07:28:13 +01:00
"""[<channel>]
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.
2003-03-27 07:28:13 +01:00
"""
if not args:
args = [msg.nick]
if self.haveOps(irc, channel, 'halfop you'):
irc.queueMsg(ircmsgs.halfops(channel, args))
2003-09-29 07:01:41 +02:00
halfop = privmsgs.checkChannelCapability(halfop, 'halfop')
2003-03-27 07:28:13 +01:00
2003-09-29 07:01:41 +02:00
def voice(self, irc, msg, args, channel):
2003-03-27 07:28:13 +01:00
"""[<channel>]
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.
2003-03-27 07:28:13 +01:00
"""
if not args:
args = [msg.nick]
if self.haveOps(irc, channel, 'voice you'):
irc.queueMsg(ircmsgs.voices(channel, args))
2003-09-29 07:01:41 +02:00
voice = privmsgs.checkChannelCapability(voice, 'voice')
2003-12-03 21:27:42 +01:00
def deop(self, irc, msg, args, channel):
"""[<channel>] [<nick> ...]
2003-12-03 21:27:42 +01:00
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.
2003-12-03 21:27:42 +01:00
"""
if not args:
args.append(msg.nick)
2004-02-07 07:24:45 +01:00
if irc.nick in args:
irc.error('I cowardly refuse to deop myself. If you really want '
'me deopped, tell me to op you and then deop me '
'yourself.')
elif self.haveOps(irc, channel, 'deop someone'):
2003-12-03 21:27:42 +01:00
irc.queueMsg(ircmsgs.deops(channel, args))
deop = privmsgs.checkChannelCapability(deop, 'op')
2003-12-03 21:27:42 +01:00
def dehalfop(self, irc, msg, args, channel):
"""[<channel>] [<nick> ...]
2003-12-03 21:27:42 +01:00
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.
2003-12-03 21:27:42 +01:00
"""
if not args:
args.append(msg.nick)
2004-02-07 07:24:45 +01:00
if irc.nick in args:
irc.error('I cowardly refuse to dehalfop myself. If you really '
'want me dehalfopped, tell me to op you and then '
'dehalfop me yourself.')
elif self.haveOps(irc, channel, 'dehalfop someone'):
2003-12-03 21:27:42 +01:00
irc.queueMsg(ircmsgs.dehalfops(channel, args))
dehalfop = privmsgs.checkChannelCapability(dehalfop, 'op')
2003-12-03 21:27:42 +01:00
def devoice(self, irc, msg, args, channel):
"""[<channel>] [<nick> ...]
2003-12-03 21:27:42 +01:00
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.
2003-12-03 21:27:42 +01:00
"""
if not args:
args.append(msg.nick)
2004-02-07 07:24:45 +01:00
if irc.nick in args:
irc.error('I cowardly refuse to devoice myself. If you really '
'want me devoiced, tell me to op you and then devoice '
'me yourself.')
elif self.haveOps(irc, channel, 'devoice someone'):
2003-12-03 21:27:42 +01:00
irc.queueMsg(ircmsgs.devoices(channel, args))
devoice = privmsgs.checkChannelCapability(devoice, 'op')
2003-09-29 07:01:41 +02:00
def cycle(self, irc, msg, args, channel):
"""[<channel>] [<key>]
2003-03-27 07:28:13 +01:00
If you have the #channel,op capability, this will cause the bot to
"cycle", or PART and then JOIN the channel. If <key> is given, join
the channel using that key. <channel> is only necessary if the message
isn't sent in the channel itself.
2003-03-27 07:28:13 +01:00
"""
key = privmsgs.getArgs(args, required=0, optional=1)
if not key:
key = None
2003-09-29 07:01:41 +02:00
irc.queueMsg(ircmsgs.part(channel))
irc.queueMsg(ircmsgs.join(channel, key))
2003-09-29 07:01:41 +02:00
cycle = privmsgs.checkChannelCapability(cycle, 'op')
2003-03-27 07:28:13 +01:00
def kick(self, irc, msg, args, channel):
"""[<channel>] <nick> [<reason>]
Kicks <nick> from <channel> for <reason>. If <reason> isn't given,
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.
"""
if self.haveOps(irc, channel, 'kick someone'):
2003-12-03 21:52:05 +01:00
(nick, reason) = privmsgs.getArgs(args, optional=1)
if nick not in irc.state.channels[channel].users:
irc.error('%s isn\'t in %s.' % (nick, channel))
return
2003-12-03 21:52:05 +01:00
if not reason:
reason = msg.nick
irc.queueMsg(ircmsgs.kick(channel, nick, reason))
kick = privmsgs.checkChannelCapability(kick, 'op')
2003-03-27 07:28:13 +01:00
def kban(self, irc, msg, args):
2004-04-30 09:44:48 +02:00
"""[<channel>] [--{exact,nick,user,host}] <nick> [<seconds>] [<reason>]
2003-03-27 07:28:13 +01:00
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.
2004-01-01 21:17:55 +01:00
--exact bans only the exact hostmask; --nick bans just the nick;
--user bans just the user, and --host bans just the host. You can
2004-04-30 09:44:48 +02:00
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.
2003-03-27 07:28:13 +01:00
"""
channel = privmsgs.getChannel(msg, args)
2004-01-01 21:17:55 +01:00
(optlist, rest) = getopt.getopt(args, '', ['exact', 'nick',
'user', 'host'])
2004-04-30 09:44:48 +02:00
(bannedNick, length, reason) = privmsgs.getArgs(rest, optional=2)
# Check that they're not trying to make us kickban ourself.
2004-01-01 21:17:55 +01:00
if not ircutils.isNick(bannedNick):
self.log.warning('%r tried to kban a non nick: %r',
msg.prefix, bannedNick)
raise callbacks.ArgumentError
elif bannedNick == irc.nick:
self.log.warning('%r tried to make me kban myself.', msg.prefix)
irc.error('I cowardly refuse to kickban myself.')
return
2003-12-12 17:56:25 +01:00
try:
length = int(length or 0)
if length < 0:
irc.error('Ban length must be a non-negative integer.')
return
2003-12-12 17:56:25 +01:00
except ValueError:
2004-04-30 09:44:48 +02:00
if reason:
reason = ' '.join((length, reason))
length = 0
else:
irc.error('Ban length must be a non-negative integer.')
2004-04-30 09:44:48 +02:00
return
if not reason:
reason = msg.nick
try:
bannedHostmask = irc.state.nickToHostmask(bannedNick)
except KeyError:
irc.error('I haven\'t seen %s.' % bannedNick)
return
2003-03-27 07:28:13 +01:00
capability = ircdb.makeChannelCapability(channel, 'op')
2004-01-01 21:17:55 +01:00
if optlist:
(nick, user, host) = ircutils.splitHostmask(bannedHostmask)
self.log.debug('*** nick: %s' % nick)
self.log.debug('*** user: %s' % user)
self.log.debug('*** host: %s' % host)
2004-01-01 21:17:55 +01:00
bnick = '*'
buser = '*'
bhost = '*'
for (option, _) in optlist:
if option == '--nick':
bnick = nick
elif option == '--user':
buser = user
elif option == '--host':
bhost = host
elif option == '--exact':
(bnick, buser, bhost) = \
ircutils.splitHostmask(bannedHostmask)
banmask = ircutils.joinHostmask(bnick, buser, bhost)
else:
banmask = ircutils.banmask(bannedHostmask)
# Check (again) that they're not trying to make us kickban ourself.
if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
if ircutils.hostmaskPatternEqual(banmask, irc.prefix):
self.log.warning('%r tried to make me kban myself.',msg.prefix)
irc.error('I cowardly refuse to ban myself.')
return
else:
banmask = bannedHostmask
# Now, let's actually get to it. Check to make sure they have
2004-02-17 07:51:07 +01:00
# #channel,op and the bannee doesn't have #channel,op; or that the
# bannee and the banner are both the same person.
def doBan():
2004-04-30 09:44:48 +02:00
if bannedNick in irc.state.channels[channel].ops:
irc.queueMsg(ircmsgs.deop(channel, bannedNick))
irc.queueMsg(ircmsgs.ban(channel, banmask))
2004-04-30 09:44:48 +02:00
irc.queueMsg(ircmsgs.kick(channel, bannedNick, reason))
if length > 0:
def f():
irc.queueMsg(ircmsgs.unban(channel, banmask))
schedule.addEvent(f, time.time() + length)
if bannedNick == msg.nick:
if self.haveOps(irc, channel, 'kick or ban someone'):
doBan()
elif ircdb.checkCapability(msg.prefix, capability):
if ircdb.checkCapability(bannedHostmask, capability):
self.log.warning('%r tried to ban %r, but both have %s',
msg.prefix, bannedHostmask, capability)
irc.error('%s has %s too, you can\'t ban him/her/it.' %
(bannedNick, capability))
elif self.haveOps(irc, channel, 'kick or ban someone'):
doBan()
2003-03-27 07:28:13 +01:00
else:
self.log.warning('%r attempted kban without %s',
msg.prefix, capability)
2004-01-08 16:24:56 +01:00
irc.errorNoCapability(capability)
2003-03-27 07:28:13 +01:00
2003-10-15 06:46:19 +02:00
def unban(self, irc, msg, args, channel):
"""[<channel>] <hostmask>
Unbans <hostmask> on <channel>. Especially useful for unbanning
yourself when you get unexpectedly (or accidentally) banned from
the channel. <channel> is only necessary if the message isn't sent
in the channel itself.
"""
hostmask = privmsgs.getArgs(args)
if self.haveOps(irc, channel, 'unban someone'):
2003-10-15 06:46:19 +02:00
irc.queueMsg(ircmsgs.unban(channel, hostmask))
unban = privmsgs.checkChannelCapability(unban, 'op')
def invite(self, irc, msg, args, channel):
"""[<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.
"""
nick = privmsgs.getArgs(args)
if self.haveOps(irc, channel, 'invite someone'):
irc.queueMsg(ircmsgs.invite(nick, channel))
invite = privmsgs.checkChannelCapability(invite, 'op')
2003-10-15 06:46:19 +02:00
2003-09-29 07:01:41 +02:00
def lobotomize(self, irc, msg, args, channel):
2003-03-27 07:28:13 +01:00
"""[<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.
2003-03-27 07:28:13 +01:00
"""
c = ircdb.channels.getChannel(channel)
c.lobotomized = True
ircdb.channels.setChannel(channel, c)
irc.replySuccess()
2003-09-29 07:01:41 +02:00
lobotomize = privmsgs.checkChannelCapability(lobotomize, 'op')
2003-03-27 07:28:13 +01:00
2003-09-29 07:01:41 +02:00
def unlobotomize(self, irc, msg, args, channel):
2003-03-27 07:28:13 +01:00
"""[<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.
2003-03-27 07:28:13 +01:00
"""
c = ircdb.channels.getChannel(channel)
c.lobotomized = False
ircdb.channels.setChannel(channel, c)
irc.replySuccess()
2003-09-29 07:01:41 +02:00
unlobotomize = privmsgs.checkChannelCapability(unlobotomize, 'op')
2003-03-27 07:28:13 +01:00
def permban(self, irc, msg, args, channel):
2003-03-27 07:28:13 +01:00
"""[<channel>] <nick|hostmask>
If you have the #channel,op capability, this will effect a permanent
2004-06-19 02:42:52 +02:00
(persistent) ban from interacting with the bot on the given <hostmask>
(or the current hostmask associated with <nick>. <channel> is only
necessary if the message isn't sent in the channel itself.
2003-03-27 07:28:13 +01:00
"""
arg = privmsgs.getArgs(args)
if ircutils.isNick(arg):
banmask = ircutils.banmask(irc.state.nickToHostmask(arg))
elif ircutils.isUserHostmask(arg):
banmask = arg
else:
irc.error('That\'s not a valid nick or hostmask.')
2003-09-29 07:01:41 +02:00
return
c = ircdb.channels.getChannel(channel)
c.addBan(banmask)
ircdb.channels.setChannel(channel, c)
irc.replySuccess()
permban = privmsgs.checkChannelCapability(permban, 'op')
2003-03-27 07:28:13 +01:00
def unpermban(self, irc, msg, args, channel):
2003-03-27 07:28:13 +01:00
"""[<channel>] <hostmask>
If you have the #channel,op capability, this will remove the permanent
ban on <hostmask>. <channel> is only necessary if the message isn't
sent in the channel itself.
2003-03-27 07:28:13 +01:00
"""
banmask = privmsgs.getArgs(args)
2003-09-29 07:01:41 +02:00
c = ircdb.channels.getChannel(channel)
c.removeBan(banmask)
ircdb.channels.setChannel(channel, c)
#irc.queueMsg(ircmsgs.unban(channel, banmask))
irc.replySuccess()
unpermban = privmsgs.checkChannelCapability(unpermban, 'op')
2003-03-27 07:28:13 +01:00
def permbans(self, irc, msg, args, channel):
2004-07-01 19:55:29 +02:00
"""[<channel>]
If you have the #channel,op capability, this will show you the
current bans on #channel.
2004-07-01 19:55:29 +02:00
"""
c = ircdb.channels.getChannel(channel)
if c.bans:
irc.reply(utils.commaAndify(map(utils.dqrepr, c.bans)))
else:
irc.reply('There are currently no permanent bans on %s' % channel)
permbans = privmsgs.checkChannelCapability(permbans, 'op')
2004-07-01 19:55:29 +02:00
2003-11-09 15:11:15 +01:00
def ignore(self, irc, msg, args, channel):
2003-03-27 07:28:13 +01:00
"""[<channel>] <nick|hostmask>
If you have the #channel,op capability, this will set a permanent
(persistent) ignore on <hostmask> or the hostmask currently associated
with <nick>. <channel> is only necessary if the message isn't sent in
the channel itself.
2003-03-27 07:28:13 +01:00
"""
arg = privmsgs.getArgs(args)
if ircutils.isNick(arg):
banmask = ircutils.banmask(irc.state.nickToHostmask(arg))
elif ircutils.isUserHostmask(arg):
banmask = arg
else:
irc.error('That\'s not a valid nick or hostmask.')
2003-09-29 07:01:41 +02:00
return
c = ircdb.channels.getChannel(channel)
c.addIgnore(banmask)
ircdb.channels.setChannel(channel, c)
irc.replySuccess()
2003-11-09 15:11:15 +01:00
ignore = privmsgs.checkChannelCapability(ignore, 'op')
2003-03-27 07:28:13 +01:00
2003-11-09 15:11:15 +01:00
def unignore(self, irc, msg, args, channel):
2003-03-27 07:28:13 +01:00
"""[<channel>] <hostmask>
If you have the #channel,op capability, this will remove the permanent
ignore on <hostmask> in the channel. <channel> is only necessary if the
message isn't sent in the channel itself.
2003-03-27 07:28:13 +01:00
"""
banmask = privmsgs.getArgs(args)
2003-09-29 07:01:41 +02:00
c = ircdb.channels.getChannel(channel)
c.removeIgnore(banmask)
ircdb.channels.setChannel(channel, c)
irc.replySuccess()
2003-11-09 15:11:15 +01:00
unignore = privmsgs.checkChannelCapability(unignore, 'op')
2003-03-27 07:28:13 +01:00
2003-11-09 15:11:15 +01:00
def ignores(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.
"""
channelarg = privmsgs.getArgs(args, required=0, optional=1)
channel = channelarg or channel
c = ircdb.channels.getChannel(channel)
if len(c.ignores) == 0:
2003-12-04 08:18:10 +01:00
s = 'I\'m not currently ignoring any hostmasks in %r' % channel
irc.reply(s)
2003-12-04 08:18:10 +01:00
else:
L = sorted(c.ignores)
irc.reply(utils.commaAndify(imap(repr, L)))
2003-11-09 15:11:15 +01:00
ignores = privmsgs.checkChannelCapability(ignores, 'op')
2003-11-09 15:11:15 +01:00
def addcapability(self, irc, msg, args, channel):
2003-03-27 07:28:13 +01:00
"""[<channel>] <name|hostmask> <capability>
If you have the #channel,op capability, this will give 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.
2003-03-27 07:28:13 +01:00
"""
(name, capability) = privmsgs.getArgs(args, 2)
capability = ircdb.makeChannelCapability(channel, capability)
2003-09-29 07:01:41 +02:00
try:
id = ircdb.users.getUserId(name)
user = ircdb.users.getUser(id)
user.addCapability(capability)
ircdb.users.setUser(id, user)
irc.replySuccess()
2003-09-29 07:01:41 +02:00
except KeyError:
2004-01-08 16:47:38 +01:00
irc.errorNoUser()
2003-11-09 15:11:15 +01:00
addcapability = privmsgs.checkChannelCapability(addcapability,'op')
2003-03-27 07:28:13 +01:00
2003-11-09 15:11:15 +01:00
def removecapability(self, irc, msg, args, channel):
2003-03-27 07:28:13 +01:00
"""[<channel>] <name|hostmask> <capability>
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.
2003-03-27 07:28:13 +01:00
"""
(name, capability) = privmsgs.getArgs(args, 2)
capability = ircdb.makeChannelCapability(channel, capability)
2003-09-29 07:01:41 +02:00
try:
id = ircdb.users.getUserId(name)
2003-09-29 07:01:41 +02:00
except KeyError:
2004-01-08 16:47:38 +01:00
irc.errorNoUser()
2004-08-05 20:45:09 +02:00
return
user = ircdb.users.getUser(id)
try:
user.removeCapability(capability)
except KeyError:
irc.error('That user doesn\'t have the %s capability.'%capability)
return
ircdb.users.setUser(id, user)
irc.replySuccess()
2003-11-09 15:11:15 +01:00
removecapability = privmsgs.checkChannelCapability(removecapability, 'op')
2003-03-27 07:28:13 +01:00
2003-11-09 15:11:15 +01:00
def setdefaultcapability(self, irc, msg, args, channel):
2003-03-27 07:28:13 +01:00
"""[<channel>] <default response to unknown capabilities> <True|False>
If you have the #channel,op capability, this will set the default
response to non-power-related (that is, not {op, halfop, voice}
capabilities to be the value you give. <channel> is only necessary if
the message isn't sent in the channel itself.
2003-03-27 07:28:13 +01:00
"""
v = privmsgs.getArgs(args)
2003-09-29 07:01:41 +02:00
v = v.capitalize()
2003-10-04 14:57:44 +02:00
c = ircdb.channels.getChannel(channel)
2003-09-29 07:01:41 +02:00
if v == 'True':
c.setDefaultCapability(True)
elif v == 'False':
c.setDefaultCapability(False)
2003-03-27 07:28:13 +01:00
else:
2003-09-29 07:01:41 +02:00
s = 'The default value must be either True or False.'
irc.error(s)
2003-09-29 07:01:41 +02:00
return
ircdb.channels.setChannel(channel, c)
irc.replySuccess()
2003-11-09 15:11:15 +01:00
setdefaultcapability = \
privmsgs.checkChannelCapability(setdefaultcapability, 'op')
2003-09-29 07:01:41 +02:00
2003-11-09 15:11:15 +01:00
def setcapability(self, irc, msg, args, channel):
2003-04-02 13:08:34 +02:00
"""[<channel>] <capability>
2003-03-27 07:28:13 +01:00
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.
2003-03-27 07:28:13 +01:00
"""
2003-09-29 07:01:41 +02:00
capability = privmsgs.getArgs(args)
c = ircdb.channels.getChannel(channel)
c.addCapability(capability)
ircdb.channels.setChannel(channel, c)
irc.replySuccess()
2003-11-09 15:11:15 +01:00
setcapability = privmsgs.checkChannelCapability(setcapability, 'op')
2003-03-27 07:28:13 +01:00
2003-11-09 15:11:15 +01:00
def unsetcapability(self, irc, msg, args, channel):
2004-08-19 01:15:27 +02:00
"""[<channel>] <capability>
2003-03-27 07:28:13 +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.
2003-03-27 07:28:13 +01:00
"""
2003-09-29 07:01:41 +02:00
capability = privmsgs.getArgs(args)
c = ircdb.channels.getChannel(channel)
try:
c.removeCapability(capability)
ircdb.channels.setChannel(channel, c)
irc.replySuccess()
except KeyError:
irc.error('I do not know about that channel capability.')
2003-11-09 15:11:15 +01:00
unsetcapability = privmsgs.checkChannelCapability(unsetcapability, 'op')
2003-03-27 07:28:13 +01:00
2003-11-09 15:11:15 +01:00
def capabilities(self, irc, msg, args):
2003-04-02 13:08:34 +02:00
"""[<channel>]
Returns the capabilities present on the <channel>. <channel> is only
necessary if the message isn't sent in the channel itself.
2003-04-02 13:08:34 +02:00
"""
channel = privmsgs.getChannel(msg, args)
c = ircdb.channels.getChannel(channel)
L = sorted(c.capabilities)
irc.reply('[%s]' % '; '.join(L))
2003-04-02 13:08:34 +02:00
2003-12-03 02:28:31 +01:00
def lobotomies(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:
L.append(channel)
if L:
2003-12-04 08:18:10 +01:00
L.sort()
2003-12-03 02:28:31 +01:00
s = 'I\'m currently lobotomized in %s.' % utils.commaAndify(L)
irc.reply(s)
2003-12-03 02:28:31 +01:00
else:
irc.reply('I\'m not currently lobotomized in any channels.')
def nicks(self, irc, msg, args):
"""[<channel>]
Returns the nicks in <channel>. <channel> is only necessary if the
message isn't sent in the channel itself.
"""
channel = privmsgs.getChannel(msg, args)
L = list(irc.state.channels[channel].users)
utils.sortBy(str.lower, L)
irc.reply(utils.commaAndify(L))
2003-10-21 08:03:57 +02:00
Class = Channel
2003-03-27 07:28:13 +01:00
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78: