plugins/Services: Only send GHOST once every 60 seconds to prevent spinning when the services are down. Bug 1491034

This commit is contained in:
James Vega 2006-07-14 15:36:11 +00:00
parent 0af94ef179
commit 1be3d7f159

View File

@ -28,6 +28,7 @@
### ###
import re import re
import time
import config import config
@ -39,6 +40,8 @@ import supybot.ircutils as ircutils
import supybot.schedule as schedule import supybot.schedule as schedule
import supybot.callbacks as callbacks import supybot.callbacks as callbacks
ghostDelay = 60
class Services(callbacks.Plugin): class Services(callbacks.Plugin):
"""This plugin handles dealing with Services on networks that provide them. """This plugin handles dealing with Services on networks that provide them.
Basically, you should use the "password" command to tell the bot a nick to Basically, you should use the "password" command to tell the bot a nick to
@ -57,7 +60,7 @@ class Services(callbacks.Plugin):
def reset(self): def reset(self):
self.channels = [] self.channels = []
self.sentGhost = False self.sentGhost = None
self.identified = False self.identified = False
self.waitingJoins = [] self.waitingJoins = []
@ -118,8 +121,9 @@ class Services(callbacks.Plugin):
s = 'Tried to ghost without a NickServ or password set.' s = 'Tried to ghost without a NickServ or password set.'
self.log.warning(s) self.log.warning(s)
return return
if self.sentGhost: if self.sentGhost and time.time() < (self.sentGhost + ghostDelay):
self.log.warning('Refusing to send GHOST twice.') self.log.warning('Refusing to send GHOST more than once every '
'%s seconds.' % ghostDelay)
elif not password: elif not password:
self.log.warning('Not ghosting: no password set.') self.log.warning('Not ghosting: no password set.')
return return
@ -129,7 +133,7 @@ class Services(callbacks.Plugin):
ghost = 'GHOST %s %s' % (nick, password) ghost = 'GHOST %s %s' % (nick, password)
# Ditto about the sendMsg (see _doIdentify). # Ditto about the sendMsg (see _doIdentify).
irc.sendMsg(ircmsgs.privmsg(nickserv, ghost)) irc.sendMsg(ircmsgs.privmsg(nickserv, ghost))
self.sentGhost = True self.sentGhost = time.time()
def __call__(self, irc, msg): def __call__(self, irc, msg):
disabled = self.registryValue('disabledNetworks') disabled = self.registryValue('disabledNetworks')
@ -144,7 +148,8 @@ class Services(callbacks.Plugin):
password = self._getNickServPassword(nick) password = self._getNickServPassword(nick)
if nick and nickserv and password and \ if nick and nickserv and password and \
not ircutils.strEqual(nick, irc.nick): not ircutils.strEqual(nick, irc.nick):
if irc.afterConnect and not self.sentGhost: if irc.afterConnect and self.sentGhost is None or \
(self.sentGhost + ghostDelay) < time.time():
if nick in irc.state.nicksToHostmasks: if nick in irc.state.nicksToHostmasks:
self._doGhost(irc) self._doGhost(irc)
else: else:
@ -152,7 +157,7 @@ class Services(callbacks.Plugin):
def do001(self, irc, msg): def do001(self, irc, msg):
# New connection, make sure sentGhost is False. # New connection, make sure sentGhost is False.
self.sentGhost = False self.sentGhost = None
def do376(self, irc, msg): def do376(self, irc, msg):
nick = self._getNick() nick = self._getNick()
@ -252,11 +257,11 @@ class Services(callbacks.Plugin):
log = 'Received "Password Incorrect" from NickServ %s. ' \ log = 'Received "Password Incorrect" from NickServ %s. ' \
'Resetting password to empty.' % on 'Resetting password to empty.' % on
self.log.warning(log) self.log.warning(log)
self.sentGhost = False self.sentGhost = time.time()
self._setNickServPassword(nick, '') self._setNickServPassword(nick, '')
elif self._ghosted(s): elif self._ghosted(s):
self.log.info('Received "GHOST succeeded" from NickServ %s.', on) self.log.info('Received "GHOST succeeded" from NickServ %s.', on)
self.sentGhost = False self.sentGhost = None
self.identified = False self.identified = False
irc.queueMsg(ircmsgs.nick(nick)) irc.queueMsg(ircmsgs.nick(nick))
elif 'is not registered' in s: elif 'is not registered' in s:
@ -264,7 +269,7 @@ class Services(callbacks.Plugin):
on) on)
elif 'currently' in s and 'isn\'t' in s or 'is not' in s: 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. # The nick isn't online, let's change our nick to it.
self.sentGhost = False self.sentGhost = None
irc.queueMsg(ircmsgs.nick(nick)) irc.queueMsg(ircmsgs.nick(nick))
elif ('owned by someone else' in s) or \ elif ('owned by someone else' in s) or \
('nickname is registered and protected' in s) or \ ('nickname is registered and protected' in s) or \