mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-02 15:44:06 +01:00
Fixed several latent bugs, made much more robust.
This commit is contained in:
parent
b91a1b8941
commit
8727e620ad
@ -87,46 +87,70 @@ class Services(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
self.nick = ircutils.IrcString(self.nick)
|
self.nick = ircutils.IrcString(self.nick)
|
||||||
self.nickserv = ircutils.IrcString(nickserv or 'NickServ')
|
self.nickserv = ircutils.IrcString(nickserv or 'NickServ')
|
||||||
self.chanserv = ircutils.IrcString(chanserv or 'ChanServ')
|
self.chanserv = ircutils.IrcString(chanserv or 'ChanServ')
|
||||||
|
self._ghosted = re.compile('(Ghost|%s).*killed' % self.nick, re.I)
|
||||||
self.sentGhost = False
|
self.sentGhost = False
|
||||||
self._ghosted = re.compile('%s.*killed' % self.nick)
|
self.log.info('Services started.')
|
||||||
irc.reply(msg, conf.replySuccess)
|
irc.reply(msg, conf.replySuccess)
|
||||||
|
|
||||||
def do376(self, irc, msg):
|
def _doIdentify(self, irc):
|
||||||
if self.nickserv:
|
assert self.nickserv, 'Nickserv must not be empty.'
|
||||||
assert self.nick, 'Services: Nick must not be empty.'
|
self.log.info('Sending identify (current nick: %s)' % irc.nick)
|
||||||
identify = 'IDENTIFY %s' % self.password
|
identify = 'IDENTIFY %s' % self.password
|
||||||
# It's important that this next statement is irc.sendMsg, not
|
# It's important that this next statement is irc.sendMsg, not
|
||||||
# irc.queueMsg. We want this message to get through before any
|
# irc.queueMsg. We want this message to get through before any
|
||||||
# JOIN messages also being sent on 376.
|
# JOIN messages also being sent on 376.
|
||||||
irc.sendMsg(ircmsgs.privmsg(self.nickserv, identify))
|
irc.sendMsg(ircmsgs.privmsg(self.nickserv, identify))
|
||||||
do377 = do376
|
|
||||||
do422 = do376
|
def _doGhost(self, irc):
|
||||||
|
assert self.nickserv, 'Nickserv must not be empty.'
|
||||||
|
if self.sentGhost:
|
||||||
|
self.log.warning('Refusing to send GHOST twice.')
|
||||||
|
else:
|
||||||
|
self.log.info('Sending ghost (current nick: %s)', irc.nick)
|
||||||
|
ghost = 'GHOST %s %s' % (self.nick, self.password)
|
||||||
|
# Ditto about the sendMsg.
|
||||||
|
irc.sendMsg(ircmsgs.privmsg(self.nickserv, ghost))
|
||||||
|
self.sentGhost = True
|
||||||
|
|
||||||
|
def do001(self, irc, msg):
|
||||||
|
# New connection, make sure sentGhost is False.
|
||||||
|
self.sentGhost = False
|
||||||
|
|
||||||
|
def do376(self, irc, msg):
|
||||||
|
if self.nickserv: # Check to see if we're started.
|
||||||
|
assert self.nick, 'Services: Nick must not be empty.'
|
||||||
|
if irc.nick == self.nick:
|
||||||
|
self._doIdentify(irc)
|
||||||
|
else:
|
||||||
|
self._doGhost(irc)
|
||||||
|
self._doIdentify(irc)
|
||||||
|
else:
|
||||||
|
self.log.warning('do376 called without plugin being started.')
|
||||||
|
do422 = do377 = do376
|
||||||
|
|
||||||
|
def do433(self, irc, msg):
|
||||||
|
if self.nickserv:
|
||||||
|
self._doGhost(irc)
|
||||||
|
else:
|
||||||
|
self.log.warning('do433 called without plugin being started.')
|
||||||
|
|
||||||
def doNotice(self, irc, msg):
|
def doNotice(self, irc, msg):
|
||||||
if self.nickserv:
|
if self.nickserv and msg.nick == self.nickserv:
|
||||||
if msg.nick == self.nickserv:
|
self.log.debug('Notice received from NickServ: %r', msg)
|
||||||
s = msg.args[1]
|
s = msg.args[1]
|
||||||
|
if self._ghosted.search(msg.args[1]):
|
||||||
|
self.log.info('Received "GHOST succeeded" from NickServ')
|
||||||
|
self.sentGhost = False
|
||||||
|
irc.queueMsg(ircmsgs.nick(self.nick))
|
||||||
if ('registered' in s or 'protected' in s) and \
|
if ('registered' in s or 'protected' in s) and \
|
||||||
('not' not in s and 'isn\'t' not in s):
|
('not' not in s and 'isn\'t' not in s):
|
||||||
# NickServ told us the nick is registered.
|
self.log.info('Received "Registered Nick" from NickServ')
|
||||||
identify = 'IDENTIFY %s' % self.password
|
if self.nick == irc.nick:
|
||||||
irc.queueMsg(ircmsgs.privmsg(self.nickserv, identify))
|
self._doIdentify(irc)
|
||||||
elif 'recognized' in msg.args[1]:
|
else:
|
||||||
self.sentGhost = False
|
irc.sendMsg(ircmsgs.nick(self.nick))
|
||||||
elif self._ghosted.search(msg.args[1]):
|
elif msg.nick == self.nickserv:
|
||||||
# NickServ told us the nick has been ghost-killed.
|
self.log.warning('Received NOTICE without plugin being started.')
|
||||||
irc.queueMsg(ircmsgs.nick(self.nick))
|
|
||||||
|
|
||||||
def __call__(self, irc, msg):
|
|
||||||
callbacks.Privmsg.__call__(self, irc, msg)
|
|
||||||
if self.nickserv:
|
|
||||||
if irc.nick != self.nick and not self.sentGhost:
|
|
||||||
ghost = 'GHOST %s %s' % (self.nick, self.password)
|
|
||||||
irc.queueMsg(ircmsgs.privmsg(self.nickserv, ghost))
|
|
||||||
self.sentGhost = True
|
|
||||||
def flipSentGhost():
|
|
||||||
self.sentGhost = False
|
|
||||||
schedule.addEvent(flipSentGhost, time.time() + 300)
|
|
||||||
|
|
||||||
def getops(self, irc, msg, args):
|
def getops(self, irc, msg, args):
|
||||||
"""[<channel>]
|
"""[<channel>]
|
||||||
@ -137,6 +161,18 @@ class Services(privmsgs.CapabilityCheckingPrivmsg):
|
|||||||
channel = privmsgs.getChannel(msg, args)
|
channel = privmsgs.getChannel(msg, args)
|
||||||
irc.sendMsg(ircmsgs.privmsg(self.chanserv, 'op %s' % channel))
|
irc.sendMsg(ircmsgs.privmsg(self.chanserv, 'op %s' % channel))
|
||||||
|
|
||||||
|
def identify(self, irc, msg, args):
|
||||||
|
"""takes no arguments
|
||||||
|
|
||||||
|
Identifies with NickServ.
|
||||||
|
"""
|
||||||
|
if self.nickserv:
|
||||||
|
self._doIdentify(irc)
|
||||||
|
irc.reply(msg, conf.replySuccess)
|
||||||
|
else:
|
||||||
|
s = 'This plugin must first be started via the start command.'
|
||||||
|
irc.error(msg, s)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Class = Services
|
Class = Services
|
||||||
|
Loading…
Reference in New Issue
Block a user