2003-03-12 07:26:59 +01:00
|
|
|
###
|
2004-08-23 15:14:06 +02:00
|
|
|
# Copyright (c) 2002-2004, Jeremiah Fincher
|
2003-03-12 07:26:59 +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-03-25 07:35:53 +01:00
|
|
|
"""
|
2003-08-30 06:28:09 +02:00
|
|
|
Services: Handles management of nicks with NickServ, and ops with ChanServ.
|
2003-03-25 07:35:53 +01:00
|
|
|
"""
|
2003-03-12 07:26:59 +01:00
|
|
|
|
2004-09-01 08:06:54 +02:00
|
|
|
import supybot
|
|
|
|
|
2003-11-25 09:23:47 +01:00
|
|
|
__revision__ = "$Id$"
|
2004-09-01 08:06:54 +02:00
|
|
|
__author__ = supybot.authors.jemfinch
|
2003-11-25 09:23:47 +01:00
|
|
|
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.plugins as plugins
|
2003-03-12 07:26:59 +01:00
|
|
|
|
|
|
|
import re
|
2003-08-20 18:26:23 +02:00
|
|
|
import time
|
2003-03-12 07:26:59 +01:00
|
|
|
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.conf as conf
|
2004-08-19 18:51:18 +02:00
|
|
|
import supybot.utils as utils
|
2004-11-20 00:54:14 +01:00
|
|
|
from supybot.commands import *
|
2004-07-24 07:18:26 +02:00
|
|
|
import supybot.ircmsgs as ircmsgs
|
|
|
|
import supybot.ircutils as ircutils
|
|
|
|
import supybot.registry as registry
|
|
|
|
import supybot.schedule as schedule
|
|
|
|
import supybot.callbacks as callbacks
|
2003-03-12 07:26:59 +01:00
|
|
|
|
2004-01-28 20:05:16 +01:00
|
|
|
def configure(advanced):
|
2004-09-18 03:56:55 +02:00
|
|
|
from supybot.questions import expect, anything, something, yn, getpass
|
2004-01-28 20:05:16 +01:00
|
|
|
conf.registerPlugin('Services', True)
|
2003-11-22 04:50:45 +01:00
|
|
|
nick = something('What is your registered nick?')
|
|
|
|
password = something('What is your password for that nick?')
|
2004-01-31 23:24:43 +01:00
|
|
|
chanserv = something('What is your ChanServ named?', default='ChanServ')
|
|
|
|
nickserv = something('What is your NickServ named?', default='NickServ')
|
2004-08-29 22:49:03 +02:00
|
|
|
conf.supybot.plugins.Services.nicks.setValue([nick])
|
2004-01-28 20:05:16 +01:00
|
|
|
conf.supybot.plugins.Services.NickServ.setValue(nickserv)
|
2004-08-29 22:33:07 +02:00
|
|
|
registerNick(nick, password)
|
2004-01-28 20:05:16 +01:00
|
|
|
conf.supybot.plugins.Services.ChanServ.setValue(chanserv)
|
|
|
|
|
|
|
|
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.'
|
2004-02-09 17:32:00 +01:00
|
|
|
registry.String.setValue(self, v)
|
2004-06-04 08:14:29 +02:00
|
|
|
|
2004-08-29 22:33:07 +02:00
|
|
|
def registerNick(nick, password=''):
|
|
|
|
p = conf.supybot.plugins.Services.Nickserv.get('password')
|
|
|
|
v = p.register(nick, registry.String(password, '', private=True))
|
|
|
|
if password:
|
|
|
|
v.setValue(password)
|
|
|
|
|
2004-01-28 20:05:16 +01:00
|
|
|
conf.registerPlugin('Services')
|
|
|
|
# Not really ChannelValues: but we can have values for each network. We
|
|
|
|
# should probably document that this is possible.
|
2004-08-19 18:51:18 +02:00
|
|
|
|
|
|
|
class ValidNickSet(conf.ValidNicks):
|
|
|
|
List = ircutils.IrcSet
|
2004-08-29 22:33:07 +02:00
|
|
|
|
2004-10-03 10:58:26 +02:00
|
|
|
|
2004-08-19 18:51:18 +02:00
|
|
|
conf.registerGlobalValue(conf.supybot.plugins.Services, 'nicks',
|
|
|
|
ValidNickSet([], """Determines what nicks the bot will use with
|
2004-01-28 20:05:16 +01:00
|
|
|
services."""))
|
2004-10-03 10:58:26 +02:00
|
|
|
|
|
|
|
class Networks(registry.SpaceSeparatedSetOfStrings):
|
|
|
|
List = ircutils.IrcSet
|
|
|
|
|
|
|
|
conf.registerGlobalValue(conf.supybot.plugins.Services, 'disabledNetworks',
|
|
|
|
Networks(['QuakeNet'], """Determines what networks this plugin will be
|
|
|
|
disabled on."""))
|
|
|
|
|
2004-08-20 08:38:43 +02:00
|
|
|
conf.registerGlobalValue(conf.supybot.plugins.Services,
|
|
|
|
'noJoinsUntilIdentified',
|
|
|
|
registry.Boolean(False, """Determines whether the bot will not join any
|
|
|
|
channels until it is identified. This may be useful, for instances, if
|
|
|
|
you have a vhost that isn't set until you're identified, or if you're
|
|
|
|
joining +r channels that won't allow you to join unless you identify."""))
|
2004-04-13 02:58:56 +02:00
|
|
|
conf.registerGlobalValue(conf.supybot.plugins.Services, 'NickServ',
|
2004-01-28 20:05:16 +01:00
|
|
|
ValidNickOrEmptyString('', """Determines what nick the 'NickServ' service
|
|
|
|
has."""))
|
2004-08-19 18:51:18 +02:00
|
|
|
conf.registerGroup(conf.supybot.plugins.Services.NickServ, 'password',
|
2004-04-13 02:58:56 +02:00
|
|
|
registry.String('', """Determines what password the bot will use with
|
|
|
|
NickServ.""", private=True))
|
|
|
|
conf.registerGlobalValue(conf.supybot.plugins.Services, 'ChanServ',
|
2004-01-28 20:05:16 +01:00
|
|
|
ValidNickOrEmptyString('', """Determines what nick the 'ChanServ' service
|
|
|
|
has."""))
|
2004-04-13 02:58:56 +02:00
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Services.ChanServ, 'password',
|
|
|
|
registry.String('', """Determines what password the bot will use with
|
|
|
|
ChanServ.""", private=True))
|
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Services.ChanServ, 'op',
|
|
|
|
registry.Boolean(False, """Determines whether the bot will request to get
|
|
|
|
opped by the ChanServ when it joins the channel."""))
|
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Services.ChanServ, 'halfop',
|
|
|
|
registry.Boolean(False, """Determines whether the bot will request to get
|
|
|
|
half-opped by the ChanServ when it joins the channel."""))
|
|
|
|
conf.registerChannelValue(conf.supybot.plugins.Services.ChanServ, 'voice',
|
|
|
|
registry.Boolean(False, """Determines whether the bot will request to get
|
|
|
|
voiced by the ChanServ when it joins the channel."""))
|
2004-01-28 20:05:16 +01:00
|
|
|
|
2004-07-21 21:36:35 +02:00
|
|
|
|
2004-11-20 00:54:14 +01:00
|
|
|
class Services(callbacks.Privmsg):
|
2004-08-21 09:27:35 +02:00
|
|
|
"""This plugin handles dealing with Services on networks that provide them.
|
2004-08-23 18:15:41 +02:00
|
|
|
Basically, you should use the "password" command to tell the bot a nick to
|
|
|
|
identify with and what password to use to identify with that nick. You can
|
|
|
|
use the password command multiple times if your bot has multiple nicks
|
|
|
|
registered. Also, be sure to configure the NickServ and ChanServ
|
|
|
|
configuration variables to match the NickServ and ChanServ nicks on your
|
|
|
|
network. Other commands such as identify, getops, etc. should not be
|
|
|
|
necessary if the bot is properly configured."""
|
2003-03-12 07:26:59 +01:00
|
|
|
def __init__(self):
|
2004-09-06 10:10:49 +02:00
|
|
|
self.__parent = super(Services, self)
|
|
|
|
self.__parent.__init__()
|
2004-08-19 18:51:18 +02:00
|
|
|
for nick in self.registryValue('nicks'):
|
2004-08-29 22:33:07 +02:00
|
|
|
registerNick(nick)
|
2003-12-09 05:57:34 +01:00
|
|
|
self.reset()
|
|
|
|
|
|
|
|
def reset(self):
|
2004-02-10 04:48:56 +01:00
|
|
|
self.channels = []
|
2003-12-12 13:29:22 +01:00
|
|
|
self.sentGhost = False
|
|
|
|
self.identified = False
|
2004-08-20 08:38:43 +02:00
|
|
|
self.waitingJoins = []
|
|
|
|
|
|
|
|
def outFilter(self, irc, msg):
|
|
|
|
if msg.command == 'JOIN':
|
|
|
|
if not self.identified:
|
|
|
|
if self.registryValue('noJoinsUntilIdentified'):
|
|
|
|
self.log.info('Holding JOIN to %s until identified.',
|
|
|
|
msg.args[0])
|
|
|
|
self.waitingJoins.append(msg)
|
|
|
|
return None
|
|
|
|
return msg
|
2003-08-20 18:26:23 +02:00
|
|
|
|
2004-08-19 18:51:18 +02:00
|
|
|
def _getNick(self):
|
|
|
|
return conf.supybot.nick()
|
|
|
|
|
|
|
|
## def _getNickServ(self, network):
|
|
|
|
## return self.registryValue('NickServ', network)
|
|
|
|
|
|
|
|
def _getNickServPassword(self, nick):
|
|
|
|
# This should later be nick-specific.
|
|
|
|
assert nick in self.registryValue('nicks')
|
|
|
|
return self.registryValue('NickServ.password.%s' % nick)
|
|
|
|
|
|
|
|
def _setNickServPassword(self, nick, password):
|
|
|
|
# This also should be nick-specific.
|
|
|
|
assert nick in self.registryValue('nicks')
|
|
|
|
self.setRegistryValue('NickServ.password.%s' % nick, password)
|
|
|
|
|
|
|
|
def _doIdentify(self, irc, nick=None):
|
|
|
|
if nick is None:
|
|
|
|
nick = self._getNick()
|
|
|
|
if nick not in self.registryValue('nicks'):
|
|
|
|
return
|
2004-04-13 02:58:56 +02:00
|
|
|
nickserv = self.registryValue('NickServ')
|
2004-08-19 18:51:18 +02:00
|
|
|
password = self._getNickServPassword(nick)
|
2004-08-17 10:29:08 +02:00
|
|
|
if not nickserv or not password:
|
|
|
|
s = 'Tried to identify without a NickServ or password set.'
|
|
|
|
self.log.warning(s)
|
|
|
|
return
|
2004-08-31 19:23:33 +02:00
|
|
|
assert ircutils.strEqual(irc.nick, nick), \
|
|
|
|
'Identifying with not normal nick.'
|
2003-12-07 00:49:22 +01:00
|
|
|
self.log.info('Sending identify (current nick: %s)' % irc.nick)
|
2004-01-28 20:05:16 +01:00
|
|
|
identify = 'IDENTIFY %s' % password
|
2003-12-07 00:49:22 +01:00
|
|
|
# It's important that this next statement is irc.sendMsg, not
|
|
|
|
# irc.queueMsg. We want this message to get through before any
|
|
|
|
# JOIN messages also being sent on 376.
|
2004-01-28 20:05:16 +01:00
|
|
|
irc.sendMsg(ircmsgs.privmsg(nickserv, identify))
|
2003-12-07 00:49:22 +01:00
|
|
|
|
2004-08-19 18:51:18 +02:00
|
|
|
def _doGhost(self, irc, nick=None):
|
|
|
|
if nick is None:
|
|
|
|
nick = self._getNick()
|
|
|
|
if nick not in self.registryValue('nicks'):
|
|
|
|
return
|
2004-04-13 02:58:56 +02:00
|
|
|
nickserv = self.registryValue('NickServ')
|
2004-08-19 18:51:18 +02:00
|
|
|
password = self._getNickServPassword(nick)
|
2004-08-17 10:29:08 +02:00
|
|
|
if not nickserv or not password:
|
|
|
|
s = 'Tried to ghost without a NickServ or password set.'
|
|
|
|
self.log.warning(s)
|
2004-01-28 20:05:16 +01:00
|
|
|
return
|
2003-12-07 00:49:22 +01:00
|
|
|
if self.sentGhost:
|
|
|
|
self.log.warning('Refusing to send GHOST twice.')
|
2004-08-19 18:51:18 +02:00
|
|
|
elif not password:
|
|
|
|
self.log.warning('Not ghosting: no password set.')
|
|
|
|
return
|
2003-12-07 00:49:22 +01:00
|
|
|
else:
|
2004-08-17 10:29:08 +02:00
|
|
|
self.log.info('Sending ghost (current nick: %s; ghosting: %s)',
|
|
|
|
irc.nick, nick)
|
2004-01-28 20:05:16 +01:00
|
|
|
ghost = 'GHOST %s %s' % (nick, password)
|
|
|
|
# Ditto about the sendMsg (see _doIdentify).
|
|
|
|
irc.sendMsg(ircmsgs.privmsg(nickserv, ghost))
|
2003-12-07 00:49:22 +01:00
|
|
|
self.sentGhost = True
|
|
|
|
|
2004-04-16 09:40:18 +02:00
|
|
|
def __call__(self, irc, msg):
|
2004-10-03 10:58:26 +02:00
|
|
|
disabled = self.registryValue('disabledNetworks')
|
|
|
|
if irc.network in disabled or \
|
|
|
|
irc.state.supported.get('NETWORK', '') in disabled:
|
2004-10-04 12:01:23 +02:00
|
|
|
self.log.verbose('Ignoring message from %s, %s is disabled.',
|
|
|
|
irc, irc.network)
|
2004-10-03 10:58:26 +02:00
|
|
|
return
|
2004-09-06 10:10:49 +02:00
|
|
|
self.__parent.__call__(irc, msg)
|
2004-08-19 18:51:18 +02:00
|
|
|
nick = self._getNick()
|
|
|
|
if nick not in self.registryValue('nicks'):
|
|
|
|
return
|
2004-08-17 10:29:08 +02:00
|
|
|
nickserv = self.registryValue('NickServ')
|
2004-08-19 18:51:18 +02:00
|
|
|
password = self._getNickServPassword(nick)
|
2004-08-31 21:19:31 +02:00
|
|
|
if nick and nickserv and password and \
|
|
|
|
not ircutils.strEqual(nick, irc.nick):
|
2004-04-16 09:40:18 +02:00
|
|
|
if irc.afterConnect and not self.sentGhost:
|
2004-08-17 10:29:08 +02:00
|
|
|
if nick in irc.state.nicksToHostmasks:
|
|
|
|
self._doGhost(irc)
|
|
|
|
else:
|
|
|
|
irc.sendMsg(ircmsgs.nick(nick)) # 433 is handled elsewhere.
|
2004-07-21 21:36:35 +02:00
|
|
|
|
2003-12-07 00:49:22 +01:00
|
|
|
def do001(self, irc, msg):
|
|
|
|
# New connection, make sure sentGhost is False.
|
|
|
|
self.sentGhost = False
|
|
|
|
|
2003-09-07 11:49:43 +02:00
|
|
|
def do376(self, irc, msg):
|
2004-08-19 18:51:18 +02:00
|
|
|
nick = self._getNick()
|
|
|
|
if nick not in self.registryValue('nicks'):
|
|
|
|
return
|
2004-04-13 02:58:56 +02:00
|
|
|
nickserv = self.registryValue('NickServ')
|
2004-08-21 09:27:35 +02:00
|
|
|
if not nickserv:
|
|
|
|
self.log.warning('NickServ is unset, cannot identify.')
|
|
|
|
return
|
2004-08-19 18:51:18 +02:00
|
|
|
password = self._getNickServPassword(nick)
|
2004-08-21 09:27:35 +02:00
|
|
|
if not password:
|
|
|
|
self.log.warning('Password for %s is unset, cannot identify.',nick)
|
2004-08-17 10:29:08 +02:00
|
|
|
return
|
|
|
|
if not nick:
|
|
|
|
self.log.warning('Cannot identify without a nick being set. '
|
|
|
|
'Set supybot.plugins.Services.nick.')
|
|
|
|
return
|
2004-08-31 19:23:33 +02:00
|
|
|
if ircutils.strEqual(irc.nick, nick):
|
2004-08-17 10:29:08 +02:00
|
|
|
self._doIdentify(irc)
|
|
|
|
else:
|
|
|
|
self._doGhost(irc)
|
2003-12-07 00:49:22 +01:00
|
|
|
do422 = do377 = do376
|
|
|
|
|
|
|
|
def do433(self, irc, msg):
|
2004-08-19 18:51:18 +02:00
|
|
|
nick = self._getNick()
|
|
|
|
if nick not in self.registryValue('nicks'):
|
|
|
|
return
|
|
|
|
if nick and irc.afterConnect:
|
|
|
|
password = self._getNickServPassword(nick)
|
2004-08-17 10:29:08 +02:00
|
|
|
if not password:
|
|
|
|
return
|
2004-04-16 09:40:18 +02:00
|
|
|
self._doGhost(irc)
|
2003-09-07 11:49:43 +02:00
|
|
|
|
2004-02-10 04:48:56 +01:00
|
|
|
def do515(self, irc, msg):
|
|
|
|
# Can't join this channel, it's +r (we must be identified).
|
|
|
|
self.channels.append(msg.args[1])
|
|
|
|
|
2003-12-09 05:57:34 +01:00
|
|
|
def doNick(self, irc, msg):
|
2004-08-19 18:51:18 +02:00
|
|
|
nick = self._getNick()
|
2004-08-31 19:23:33 +02:00
|
|
|
if ircutils.strEqual(msg.args[0], irc.nick) and \
|
|
|
|
ircutils.strEqual(irc.nick, nick):
|
2004-01-28 20:05:16 +01:00
|
|
|
self._doIdentify(irc)
|
2004-08-17 10:29:08 +02:00
|
|
|
elif ircutils.strEqual(msg.nick, nick):
|
|
|
|
irc.sendMsg(ircmsgs.nick(nick))
|
|
|
|
|
2004-04-16 09:40:18 +02:00
|
|
|
def _ghosted(self, s):
|
2004-08-19 18:51:18 +02:00
|
|
|
nick = self._getNick()
|
2004-04-16 09:40:18 +02:00
|
|
|
lowered = s.lower()
|
|
|
|
return bool('killed' in lowered and (nick in s or 'ghost' in lowered))
|
2004-07-21 21:36:35 +02:00
|
|
|
|
2003-03-12 07:26:59 +01:00
|
|
|
def doNotice(self, irc, msg):
|
2004-01-28 20:05:16 +01:00
|
|
|
if irc.afterConnect:
|
2004-04-13 02:58:56 +02:00
|
|
|
nickserv = self.registryValue('NickServ')
|
2004-08-25 06:06:59 +02:00
|
|
|
chanserv = self.registryValue('ChanServ')
|
|
|
|
if nickserv and ircutils.strEqual(msg.nick, nickserv):
|
|
|
|
self.doNickservNotice(irc, msg)
|
|
|
|
elif chanserv and ircutils.strEqual(msg.nick, chanserv):
|
|
|
|
self.doChanservNotice(irc, msg)
|
|
|
|
|
|
|
|
_chanRe = re.compile('\x02(.*?)\x02')
|
|
|
|
def doChanservNotice(self, irc, msg):
|
|
|
|
s = msg.args[1].lower()
|
|
|
|
channel = None
|
|
|
|
m = self._chanRe.search(s)
|
2004-12-07 01:29:20 +01:00
|
|
|
networkGroup = conf.supybot.networks.get(irc.network)
|
2004-08-25 06:06:59 +02:00
|
|
|
if m is not None:
|
|
|
|
channel = m.group(1)
|
|
|
|
if 'all bans' in s or 'unbanned from' in s:
|
|
|
|
# All bans removed (freenode)
|
|
|
|
# You have been unbanned from (oftc)
|
2004-12-07 01:29:20 +01:00
|
|
|
irc.sendMsg(networkGroup.channels.join(channel))
|
2004-08-25 06:06:59 +02:00
|
|
|
elif 'isn\'t registered' in s:
|
2004-12-16 10:50:42 +01:00
|
|
|
self.log.warning('Received "%s isn\'t registered" from ChanServ',
|
|
|
|
channel)
|
2004-08-27 08:20:42 +02:00
|
|
|
elif 'this channel has been registered' in s:
|
|
|
|
self.log.debug('Got "Registered channel" from ChanServ.')
|
2004-08-27 09:14:08 +02:00
|
|
|
elif 'already opped' in s:
|
2004-08-29 17:56:43 +02:00
|
|
|
# This shouldn't happen, Services.op should refuse to run if
|
|
|
|
# we already have ops.
|
2004-08-27 09:14:08 +02:00
|
|
|
self.log.debug('Got "Already opped" from ChanServ.')
|
2004-08-29 17:56:43 +02:00
|
|
|
elif 'access level' in s and 'is required' in s:
|
2004-12-16 10:50:42 +01:00
|
|
|
self.log.warning('Got "Access level required" from ChanServ.')
|
2004-08-31 19:23:33 +02:00
|
|
|
elif 'inviting' in s:
|
|
|
|
self.log.debug('Got "Inviting to channel" from ChanServ.')
|
2004-08-25 06:06:59 +02:00
|
|
|
else:
|
|
|
|
self.log.warning('Got unexpected notice from ChanServ: %r.', msg)
|
|
|
|
|
|
|
|
def doNickservNotice(self, irc, msg):
|
|
|
|
nick = self._getNick()
|
2004-12-07 01:29:20 +01:00
|
|
|
s = ircutils.stripFormatting(msg.args[1].lower())
|
|
|
|
networkGroup = conf.supybot.networks.get(irc.network)
|
2004-08-25 06:06:59 +02:00
|
|
|
if 'incorrect' in s or 'denied' in s:
|
|
|
|
log = 'Received "Password Incorrect" from NickServ. ' \
|
|
|
|
'Resetting password to empty.'
|
|
|
|
self.log.warning(log)
|
|
|
|
self.sentGhost = False
|
|
|
|
self._setNickServPassword(nick, '')
|
|
|
|
elif self._ghosted(s):
|
|
|
|
self.log.info('Received "GHOST succeeded" from NickServ.')
|
|
|
|
self.sentGhost = False
|
|
|
|
self.identified = False
|
|
|
|
irc.queueMsg(ircmsgs.nick(nick))
|
|
|
|
elif 'currently' in s and 'isn\'t' in s or 'is not' in s:
|
|
|
|
# The nick isn't online, let's change our nick to it.
|
|
|
|
self.sentGhost = False
|
|
|
|
irc.queueMsg(ircmsgs.nick(nick))
|
2004-08-27 06:28:36 +02:00
|
|
|
elif ('owned by someone else' in s) or \
|
|
|
|
('nickname is registered and protected' in s) or \
|
|
|
|
('nick belongs to another user' in s):
|
2004-08-27 07:04:25 +02:00
|
|
|
# freenode, arstechnica, chatjunkies
|
2004-08-27 06:28:36 +02:00
|
|
|
# oftc, zirc.org
|
|
|
|
# sorcery
|
|
|
|
self.log.info('Received "Registered nick" from NickServ.')
|
|
|
|
elif '/msg' in s and 'id' in s and 'password' in s:
|
2004-08-25 06:06:59 +02:00
|
|
|
# Usage info for identify command; ignore.
|
|
|
|
self.log.debug('Got usage info for identify command.')
|
2004-08-27 06:28:36 +02:00
|
|
|
elif ('please choose a different nick' in s): # oftc, part 3
|
|
|
|
# This is a catch-all for redundant messages from nickserv.
|
|
|
|
pass
|
|
|
|
elif ('now recognized' in s) or \
|
|
|
|
('now identified' in s):
|
|
|
|
# freenode, oftc, arstechnica, zirc, ....
|
|
|
|
# sorcery
|
2004-08-25 06:06:59 +02:00
|
|
|
self.log.info('Received "Password accepted" from NickServ.')
|
|
|
|
self.identified = True
|
|
|
|
for channel in irc.state.channels.keys():
|
|
|
|
self.checkPrivileges(irc, channel)
|
2004-12-07 01:29:20 +01:00
|
|
|
for channel in self.channels:
|
|
|
|
irc.queueMsg(networkGroup.channels.join(channel))
|
2004-08-25 06:06:59 +02:00
|
|
|
if self.waitingJoins:
|
|
|
|
for m in self.waitingJoins:
|
|
|
|
irc.sendMsg(m)
|
|
|
|
self.waitingJoins = []
|
2004-08-27 06:28:36 +02:00
|
|
|
elif 'not yet authenticated' in s:
|
|
|
|
# zirc.org has this, it requires an auth code.
|
|
|
|
email = s.split()[-1]
|
|
|
|
self.log.warning('Received "Nick not yet authenticated" from '
|
|
|
|
'NickServ. Check email at %s and send the auth '
|
|
|
|
'command to NickServ.', email)
|
2004-08-25 06:06:59 +02:00
|
|
|
else:
|
2004-10-24 00:07:50 +02:00
|
|
|
self.log.debug('Unexpected notice from NickServ: %s.',
|
|
|
|
utils.quoted(s))
|
2003-08-20 18:26:23 +02:00
|
|
|
|
2004-04-13 02:58:56 +02:00
|
|
|
def checkPrivileges(self, irc, channel):
|
|
|
|
chanserv = self.registryValue('ChanServ')
|
|
|
|
if chanserv and self.registryValue('ChanServ.op', channel):
|
|
|
|
if irc.nick not in irc.state.channels[channel].ops:
|
2004-07-27 07:17:31 +02:00
|
|
|
self.log.info('Requesting op from %s in %s.', chanserv, channel)
|
2004-04-13 02:58:56 +02:00
|
|
|
irc.sendMsg(ircmsgs.privmsg(chanserv, 'op %s' % channel))
|
|
|
|
if chanserv and self.registryValue('ChanServ.halfop', channel):
|
|
|
|
if irc.nick not in irc.state.channels[channel].halfops:
|
2004-07-27 07:17:31 +02:00
|
|
|
self.log.info('Requesting halfop from %s in %s.',
|
2004-04-14 17:47:10 +02:00
|
|
|
chanserv, channel)
|
2004-04-13 02:58:56 +02:00
|
|
|
irc.sendMsg(ircmsgs.privmsg(chanserv, 'halfop %s' % channel))
|
|
|
|
if chanserv and self.registryValue('ChanServ.voice', channel):
|
|
|
|
if irc.nick not in irc.state.channels[channel].voices:
|
2004-07-27 07:17:31 +02:00
|
|
|
self.log.info('Requesting voice from %s in %s.',
|
2004-04-14 17:47:10 +02:00
|
|
|
chanserv, channel)
|
2004-04-13 02:58:56 +02:00
|
|
|
irc.sendMsg(ircmsgs.privmsg(chanserv, 'voice %s' % channel))
|
2004-07-21 21:36:35 +02:00
|
|
|
|
2004-07-27 07:17:31 +02:00
|
|
|
def doMode(self, irc, msg):
|
|
|
|
chanserv = self.registryValue('ChanServ')
|
2004-08-31 19:23:33 +02:00
|
|
|
if ircutils.strEqual(msg.nick, chanserv):
|
2004-07-27 07:17:31 +02:00
|
|
|
channel = msg.args[0]
|
|
|
|
if len(msg.args) == 3:
|
2004-08-31 19:23:33 +02:00
|
|
|
if ircutils.strEqual(msg.args[2], irc.nick):
|
2004-07-27 07:17:31 +02:00
|
|
|
mode = msg.args[1]
|
|
|
|
info = self.log.info
|
|
|
|
if mode == '+o':
|
|
|
|
info('Received op from ChanServ in %s.', channel)
|
|
|
|
elif mode == '+h':
|
|
|
|
info('Received halfop from ChanServ in %s.', channel)
|
|
|
|
elif mode == '+v':
|
|
|
|
info('Received voice from ChanServ in %s.', channel)
|
|
|
|
|
2004-04-13 02:58:56 +02:00
|
|
|
def do366(self, irc, msg): # End of /NAMES list; finished joining a channel
|
|
|
|
if self.identified:
|
|
|
|
channel = msg.args[1] # nick is msg.args[0].
|
|
|
|
self.checkPrivileges(irc, channel)
|
|
|
|
|
2004-09-13 19:51:34 +02:00
|
|
|
def _chanservCommand(self, irc, channel, command, log=False):
|
2004-08-25 06:06:59 +02:00
|
|
|
chanserv = self.registryValue('ChanServ')
|
|
|
|
if chanserv:
|
2004-08-31 19:23:33 +02:00
|
|
|
msg = ircmsgs.privmsg(chanserv,
|
|
|
|
' '.join([command, channel, irc.nick]))
|
|
|
|
irc.sendMsg(msg)
|
2004-08-25 06:06:59 +02:00
|
|
|
else:
|
2004-09-13 19:51:34 +02:00
|
|
|
if log:
|
|
|
|
self.log.warning('Unable to send %s command to ChanServ, '
|
|
|
|
'you must set '
|
|
|
|
'supybot.plugins.Services.ChanServ before '
|
|
|
|
'I can send commands to ChanServ.', command)
|
|
|
|
else:
|
|
|
|
irc.error('You must set supybot.plugins.Services.ChanServ '
|
|
|
|
'before I\'m able to do get voiced.', Raise=True)
|
2004-08-25 06:06:59 +02:00
|
|
|
|
2004-11-20 00:54:14 +01:00
|
|
|
def op(self, irc, msg, args, channel):
|
2003-08-20 18:26:23 +02:00
|
|
|
"""[<channel>]
|
|
|
|
|
2004-08-24 16:11:12 +02:00
|
|
|
Attempts to get opped by ChanServ in <channel>. <channel> is only
|
|
|
|
necessary if the message isn't sent in the channel itself.
|
2003-08-20 18:26:23 +02:00
|
|
|
"""
|
2004-11-20 00:54:14 +01:00
|
|
|
if irc.nick in irc.state.channels[channel].ops:
|
|
|
|
irc.error('I\'m already opped in %s.' % channel)
|
|
|
|
else:
|
|
|
|
self._chanservCommand(irc, channel, 'op')
|
|
|
|
op = wrap(op, [('checkChannelCapability', 'op'), 'inChannel'])
|
2004-08-24 16:11:12 +02:00
|
|
|
|
2004-11-20 00:54:14 +01:00
|
|
|
def voice(self, irc, msg, args, channel):
|
2004-08-24 16:11:12 +02:00
|
|
|
"""[<channel>]
|
|
|
|
|
|
|
|
Attempts to get voiced by ChanServ in <channel>. <channel> is only
|
|
|
|
necessary if the message isn't sent in the channel itself.
|
|
|
|
"""
|
2004-11-20 00:54:14 +01:00
|
|
|
if irc.nick in irc.state.channels[channel].voices:
|
|
|
|
irc.error('I\'m already voiced in %s.' % channel)
|
|
|
|
else:
|
|
|
|
self._chanservCommand(irc, channel, 'voice')
|
|
|
|
voice = wrap(voice, [('checkChannelCapability', 'op'), 'inChannel'])
|
2003-08-20 18:26:23 +02:00
|
|
|
|
2004-08-25 06:06:59 +02:00
|
|
|
def do474(self, irc, msg):
|
|
|
|
channel = msg.args[1]
|
|
|
|
self.log.info('Banned from %s, attempting ChanServ unban.', channel)
|
2004-09-13 19:51:34 +02:00
|
|
|
self._chanservCommand(irc, channel, 'unban', log=True)
|
2004-08-25 06:06:59 +02:00
|
|
|
# Success log in doChanservNotice.
|
|
|
|
|
2004-11-20 00:54:14 +01:00
|
|
|
def unban(self, irc, msg, args, channel):
|
2004-08-25 06:06:59 +02:00
|
|
|
"""[<channel>]
|
|
|
|
|
|
|
|
Attempts to get unbanned by ChanServ in <channel>. <channel> is only
|
|
|
|
necessary if the message isn't sent in the channel itself, but chances
|
|
|
|
are, if you need this command, you're not sending it in the channel
|
|
|
|
itself.
|
|
|
|
"""
|
2004-11-20 00:54:14 +01:00
|
|
|
self._chanservCommand(irc, channel, 'unban')
|
|
|
|
irc.replySuccess()
|
|
|
|
unban = wrap(unban, [('checkChannelCapability', 'op')])
|
2004-08-25 06:06:59 +02:00
|
|
|
|
|
|
|
def do473(self, irc, msg):
|
|
|
|
channel = msg.args[1]
|
|
|
|
self.log.info('%s is +i, attempting ChanServ invite.', channel)
|
2004-09-13 19:51:34 +02:00
|
|
|
self._chanservCommand(irc, channel, 'invite', log=True)
|
|
|
|
|
2004-11-20 00:54:14 +01:00
|
|
|
def invite(self, irc, msg, args, channel):
|
2004-08-25 06:06:59 +02:00
|
|
|
"""[<channel>]
|
|
|
|
|
|
|
|
Attempts to get invited by ChanServ to <channel>. <channel> is only
|
|
|
|
necessary if the message isn't sent in the channel itself, but chances
|
|
|
|
are, if you need this command, you're not sending it in the channel
|
|
|
|
itself.
|
|
|
|
"""
|
2004-11-20 00:54:14 +01:00
|
|
|
self._chanservCommand(irc, channel, 'invite')
|
|
|
|
irc.replySuccess()
|
|
|
|
invite = wrap(invite, [('checkChannelCapability', 'op'), 'inChannel'])
|
2004-08-25 06:06:59 +02:00
|
|
|
|
|
|
|
def doInvite(self, irc, msg):
|
2004-08-31 19:23:33 +02:00
|
|
|
if ircutils.strEqual(msg.nick, self.registryValue('ChanServ')):
|
2004-08-25 06:06:59 +02:00
|
|
|
channel = msg.args[1]
|
2004-12-07 01:29:20 +01:00
|
|
|
networkGroup = conf.supybot.networks.get(irc.network)
|
2004-08-25 06:06:59 +02:00
|
|
|
self.log.info('Joining %s, invited by ChanServ.' % channel)
|
2004-12-07 01:29:20 +01:00
|
|
|
irc.queueMsg(networkGroup.channels.join(channel))
|
2004-08-25 06:06:59 +02:00
|
|
|
|
2003-12-07 00:49:22 +01:00
|
|
|
def identify(self, irc, msg, args):
|
|
|
|
"""takes no arguments
|
|
|
|
|
2004-11-20 00:54:14 +01:00
|
|
|
Identifies with NickServ using the current nick.
|
2003-12-07 00:49:22 +01:00
|
|
|
"""
|
2004-04-13 02:58:56 +02:00
|
|
|
if self.registryValue('NickServ'):
|
2004-08-19 18:51:18 +02:00
|
|
|
if irc.nick in self.registryValue('nicks'):
|
|
|
|
self._doIdentify(irc, irc.nick)
|
2004-02-10 04:29:02 +01:00
|
|
|
irc.replySuccess()
|
2004-08-30 23:46:04 +02:00
|
|
|
else:
|
|
|
|
irc.error('I don\'t have a configured password for '
|
|
|
|
'my current nick.')
|
2003-12-07 00:49:22 +01:00
|
|
|
else:
|
2004-01-28 20:05:16 +01:00
|
|
|
irc.error('You must set supybot.plugins.Services.NickServ before '
|
|
|
|
'I\'m able to do identify.')
|
2004-11-21 14:18:58 +01:00
|
|
|
identify = wrap(identify, [('checkCapability', 'admin')])
|
2003-12-07 00:49:22 +01:00
|
|
|
|
2004-11-20 00:54:14 +01:00
|
|
|
def ghost(self, irc, msg, args, nick):
|
2004-08-19 18:51:18 +02:00
|
|
|
"""[<nick>]
|
2004-02-10 04:29:02 +01:00
|
|
|
|
2004-08-19 18:51:18 +02:00
|
|
|
Ghosts the bot's given nick and takes it. If no nick is given,
|
|
|
|
ghosts the bot's configured nick and takes it.
|
2004-02-10 04:29:02 +01:00
|
|
|
"""
|
2004-04-13 02:58:56 +02:00
|
|
|
if self.registryValue('NickServ'):
|
2004-08-19 18:51:18 +02:00
|
|
|
if not nick:
|
|
|
|
nick = self._getNick()
|
2004-08-31 19:23:33 +02:00
|
|
|
if ircutils.strEqual(nick, irc.nick):
|
2004-02-10 04:29:02 +01:00
|
|
|
irc.error('I cowardly refuse to ghost myself.')
|
|
|
|
else:
|
2004-08-19 18:51:18 +02:00
|
|
|
self._doGhost(irc, nick=nick)
|
2004-02-10 04:29:02 +01:00
|
|
|
irc.replySuccess()
|
|
|
|
else:
|
|
|
|
irc.error('You must set supybot.plugins.Services.NickServ before '
|
|
|
|
'I\'m able to ghost a nick.')
|
2004-11-20 00:54:14 +01:00
|
|
|
ghost = wrap(ghost, [('checkCapability', 'admin'), additional('nick')])
|
2004-02-10 04:29:02 +01:00
|
|
|
|
2004-11-20 00:54:14 +01:00
|
|
|
def password(self, irc, msg, args, nick, password):
|
2004-08-19 18:51:18 +02:00
|
|
|
"""<nick> [<password>]
|
|
|
|
|
|
|
|
Sets the NickServ password for <nick> to <password>. If <password> is
|
|
|
|
not given, removes <nick> from the configured nicks.
|
|
|
|
"""
|
|
|
|
if not password:
|
|
|
|
try:
|
|
|
|
self.registryValue('nicks').remove(nick)
|
|
|
|
irc.replySuccess()
|
|
|
|
except KeyError:
|
|
|
|
irc.error('That nick was not configured with a password.')
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
self.registryValue('nicks').add(nick)
|
2004-08-29 22:33:07 +02:00
|
|
|
registerNick(nick, password)
|
2004-08-19 18:51:18 +02:00
|
|
|
irc.replySuccess()
|
2004-11-20 00:54:14 +01:00
|
|
|
password = wrap(password, [('checkCapability', 'admin'),
|
|
|
|
'private', 'nick', 'text'])
|
2004-08-19 18:51:18 +02:00
|
|
|
|
|
|
|
def nicks(self, irc, msg, args):
|
|
|
|
"""takes no arguments
|
|
|
|
|
|
|
|
Returns the nicks that this plugin is configured to identify and ghost
|
2004-11-20 00:54:14 +01:00
|
|
|
with.
|
|
|
|
"""
|
2004-08-19 18:51:18 +02:00
|
|
|
L = list(self.registryValue('nicks'))
|
|
|
|
if L:
|
|
|
|
utils.sortBy(ircutils.toLower, L)
|
|
|
|
irc.reply(utils.commaAndify(L))
|
|
|
|
else:
|
|
|
|
irc.reply('I\'m not currently configured for any nicks.')
|
2004-11-20 00:54:14 +01:00
|
|
|
nicks = wrap(nicks, [('checkCapability', 'admin')])
|
2003-03-12 07:26:59 +01:00
|
|
|
|
|
|
|
|
2003-08-30 06:28:09 +02:00
|
|
|
Class = Services
|
2003-03-28 04:10:22 +01:00
|
|
|
|
2003-03-24 09:41:19 +01:00
|
|
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|