2005-02-02 06:19:33 +01:00
|
|
|
###
|
|
|
|
# Copyright (c) 2004, Jeremiah Fincher
|
2021-10-17 09:54:06 +02:00
|
|
|
# Copyright (c) 2010-2021, Valentin Lorentz
|
2005-02-02 06:19:33 +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 time
|
|
|
|
|
|
|
|
import supybot.conf as conf
|
|
|
|
import supybot.ircmsgs as ircmsgs
|
|
|
|
import supybot.ircutils as ircutils
|
|
|
|
import supybot.callbacks as callbacks
|
2010-10-17 16:59:21 +02:00
|
|
|
from supybot.i18n import PluginInternationalization, internationalizeDocstring
|
|
|
|
_ = PluginInternationalization('NickCapture')
|
2005-02-02 06:19:33 +01:00
|
|
|
|
2005-02-09 08:04:04 +01:00
|
|
|
class NickCapture(callbacks.Plugin):
|
2011-08-07 12:02:06 +02:00
|
|
|
"""This plugin constantly tries to take whatever nick is configured as
|
2005-02-02 06:19:33 +01:00
|
|
|
supybot.nick. Just make sure that's set appropriately, and thus plugin
|
|
|
|
will do the rest."""
|
|
|
|
public = False
|
|
|
|
def __init__(self, irc):
|
|
|
|
self.__parent = super(NickCapture, self)
|
|
|
|
self.__parent.__init__(irc)
|
|
|
|
self.lastIson = 0
|
2015-05-15 19:24:24 +02:00
|
|
|
self.monitoring = []
|
|
|
|
|
|
|
|
def die(self):
|
|
|
|
for irc in self.monitoring:
|
|
|
|
nick = self._getNick(irc.network)
|
|
|
|
irc.unmonitor(nick)
|
2005-02-02 06:19:33 +01:00
|
|
|
|
2011-10-27 12:31:37 +02:00
|
|
|
def _getNick(self, network):
|
|
|
|
network_nick = conf.supybot.networks.get(network).nick()
|
|
|
|
if network_nick == '':
|
|
|
|
return conf.supybot.nick()
|
|
|
|
else:
|
|
|
|
return network_nick
|
2005-02-02 06:19:33 +01:00
|
|
|
|
|
|
|
def __call__(self, irc, msg):
|
|
|
|
if irc.afterConnect:
|
2011-10-27 12:31:37 +02:00
|
|
|
nick = self._getNick(irc.network)
|
2005-02-02 06:19:33 +01:00
|
|
|
if nick and not ircutils.strEqual(nick, irc.nick):
|
|
|
|
# We used to check this, but nicksToHostmasks is never cleared
|
|
|
|
# except on reconnects, which can cause trouble.
|
|
|
|
# if nick not in irc.state.nicksToHostmasks:
|
2015-05-15 19:24:24 +02:00
|
|
|
if 'monitor' in irc.state.supported:
|
|
|
|
if irc not in self.monitoring:
|
|
|
|
irc.monitor(nick)
|
|
|
|
self.monitoring.append(irc)
|
|
|
|
else:
|
|
|
|
self._ison(irc, nick)
|
2005-02-09 08:04:04 +01:00
|
|
|
self.__parent.__call__(irc, msg)
|
2005-02-02 06:19:33 +01:00
|
|
|
|
|
|
|
def _ison(self, irc, nick):
|
2015-05-15 19:24:24 +02:00
|
|
|
assert 'monitor' not in irc.state.supported
|
2005-02-02 06:19:33 +01:00
|
|
|
if self.registryValue('ison'):
|
|
|
|
now = time.time()
|
|
|
|
if now - self.lastIson > self.registryValue('ison.period'):
|
|
|
|
self.lastIson = now
|
|
|
|
self._sendIson(irc, nick)
|
|
|
|
|
|
|
|
def _sendIson(self, irc, nick):
|
|
|
|
self.log.info('Checking if %s ISON %s.', nick, irc.network)
|
|
|
|
irc.queueMsg(ircmsgs.ison(nick))
|
|
|
|
|
|
|
|
def _sendNick(self, irc, nick):
|
|
|
|
self.log.info('Attempting to switch to nick %s on %s.',
|
|
|
|
nick, irc.network)
|
|
|
|
irc.sendMsg(ircmsgs.nick(nick))
|
|
|
|
|
|
|
|
def doQuit(self, irc, msg):
|
2011-10-27 12:31:37 +02:00
|
|
|
nick = self._getNick(irc.network)
|
2005-02-02 06:19:33 +01:00
|
|
|
if ircutils.strEqual(msg.nick, nick):
|
|
|
|
self._sendNick(irc, nick)
|
|
|
|
|
|
|
|
def doNick(self, irc, msg):
|
2011-10-27 12:31:37 +02:00
|
|
|
nick = self._getNick(irc.network)
|
2005-02-02 06:19:33 +01:00
|
|
|
if ircutils.strEqual(msg.nick, nick):
|
|
|
|
self._sendNick(irc, nick)
|
|
|
|
|
|
|
|
def do303(self, irc, msg):
|
|
|
|
"""This is returned by the ISON command."""
|
|
|
|
if not msg.args[1]:
|
2011-10-27 12:31:37 +02:00
|
|
|
nick = self._getNick(irc.network)
|
2005-02-02 06:19:33 +01:00
|
|
|
if nick:
|
|
|
|
self._sendNick(irc, nick)
|
2015-05-15 19:24:24 +02:00
|
|
|
|
|
|
|
def do731(self, irc, msg):
|
|
|
|
"""This is sent by the MONITOR when a nick goes offline."""
|
|
|
|
nick = self._getNick(irc.network)
|
|
|
|
for target in msg.args[1].split(','):
|
|
|
|
if nick == target:
|
|
|
|
self._sendNick(irc, nick)
|
|
|
|
self.monitoring.remove(irc)
|
|
|
|
irc.unmonitor(nick)
|
|
|
|
break
|
2015-06-12 14:30:32 +02:00
|
|
|
|
|
|
|
def do437(self, irc, msg):
|
|
|
|
"""Nick/channel is temporarily unavailable"""
|
2019-08-04 18:11:28 +02:00
|
|
|
if irc.isChannel(msg.args[1]):
|
2015-06-12 14:30:32 +02:00
|
|
|
return
|
|
|
|
self.log.info('Nick %s is unavailable; attempting NickServ release '
|
|
|
|
'on %s.' % (msg.args[1], irc.network))
|
|
|
|
irc.sendMsg(ircmsgs.privmsg('NickServ', 'release %s' % msg.args[1]))
|
2010-10-26 09:32:12 +02:00
|
|
|
NickCapture = internationalizeDocstring(NickCapture)
|
2005-02-02 06:19:33 +01:00
|
|
|
|
|
|
|
Class = NickCapture
|
|
|
|
|
2006-02-11 16:52:51 +01:00
|
|
|
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:
|