Added the unban and invite commands, as well as a better framework for detecting when a channel can't be joined and handling it.

This commit is contained in:
Jeremy Fincher 2004-08-25 04:06:59 +00:00
parent 24e09136b6
commit 92b0d6da1f

View File

@ -141,7 +141,9 @@ class Services(privmsgs.CapabilityCheckingPrivmsg):
def _registerNick(self, nick, password=''):
p = self.registryValue('NickServ.password', value=False)
p.register(nick, registry.String(password, '', private=True))
v = p.register(nick, registry.String(password, '', private=True))
if password:
v.setValue(password)
def _getNick(self):
return conf.supybot.nick()
@ -271,11 +273,32 @@ class Services(privmsgs.CapabilityCheckingPrivmsg):
def doNotice(self, irc, msg):
if irc.afterConnect:
nickserv = self.registryValue('NickServ')
if not nickserv or msg.nick != nickserv:
return
nick = self._getNick()
self.log.debug('Notice received from NickServ: %r.', msg)
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)
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)
irc.sendMsg(ircmsgs.join(channel))
elif 'isn\'t registered' in s:
self.log.info('Received "%s isn\'t registered" from ChanServ',
channel)
else:
self.log.warning('Got unexpected notice from ChanServ: %r.', msg)
def doNickservNotice(self, irc, msg):
s = ircutils.stripFormatting(msg.args[1].lower())
nick = self._getNick()
if 'incorrect' in s or 'denied' in s:
log = 'Received "Password Incorrect" from NickServ. ' \
'Resetting password to empty.'
@ -350,6 +373,14 @@ class Services(privmsgs.CapabilityCheckingPrivmsg):
channel = msg.args[1] # nick is msg.args[0].
self.checkPrivileges(irc, channel)
def _chanservCommand(self, irc, channel, command):
chanserv = self.registryValue('ChanServ')
if chanserv:
irc.sendMsg(ircmsgs.privmsg(chanserv, '%s %s' % (command, channel)))
return True
else:
return False
def op(self, irc, msg, args):
"""[<channel>]
@ -361,10 +392,7 @@ class Services(privmsgs.CapabilityCheckingPrivmsg):
if irc.nick in irc.state.channels[channel].ops:
irc.error('I\'m already opped in %s.' % channel)
else:
chanserv = self.registryValue('ChanServ')
if chanserv:
irc.sendMsg(ircmsgs.privmsg(chanserv, 'op %s' % channel))
else:
if not self._chanservCommand(irc, channel, 'op'):
irc.error('You must set supybot.plugins.Services.ChanServ '
'before I\'m able to do get opped.')
except KeyError:
@ -381,15 +409,68 @@ class Services(privmsgs.CapabilityCheckingPrivmsg):
if irc.nick in irc.state.channels[channel].voices:
irc.error('I\'m already voiced in %s.' % channel)
else:
chanserv = self.registryValue('ChanServ')
if chanserv:
irc.sendMsg(ircmsgs.privmsg(chanserv,'voice %s' % channel))
if self._chanservCommand(irc, channel, 'voice'):
irc.error('You must set supybot.plugins.Services.ChanServ '
'before I\'m able to do get voiced.')
except KeyError:
irc.error('I\'m not in %s.' % channel)
def do474(self, irc, msg):
channel = msg.args[1]
self.log.info('Banned from %s, attempting ChanServ unban.', channel)
if not self._chanservCommand(irc, channel, 'unban'):
self.log.info('Unable to send unban command, '
'ChanServ is not configured.')
# Success log in doChanservNotice.
def unban(self, irc, msg, args):
"""[<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.
"""
channel = privmsgs.getChannel(msg, args)
try:
if self._chanservCommand(irc, channel, 'unban'):
irc.replySuccess()
else:
irc.error('You must set supybot.plugins.Services.ChanServ '
'before I\'m able to do get voiced.')
except KeyError:
irc.error('I\'m not in %s.' % channel)
def do473(self, irc, msg):
channel = msg.args[1]
self.log.info('%s is +i, attempting ChanServ invite.', channel)
if not self._chanservCommand(irc, channel, 'invite'):
self.log.info('Unable to send invite command, '
'ChanServ is not configured.')
def invite(self, irc, msg, args):
"""[<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.
"""
channel = privmsgs.getChannel(msg, args)
try:
if self._chanservCommand(irc, channel, 'invite'):
irc.replySuccess()
else:
irc.error('You must set supybot.plugins.Services.ChanServ '
'before I\'m able to do get voiced.')
except KeyError:
irc.error('I\'m not in %s.' % channel)
def doInvite(self, irc, msg):
if msg.nick == self.registryValue('ChanServ'):
channel = msg.args[1]
self.log.info('Joining %s, invited by ChanServ.' % channel)
irc.queueMsg(ircmsgs.join(channel))
def identify(self, irc, msg, args):
"""takes no arguments