New way of handling channel keys.

This commit is contained in:
Jeremy Fincher 2004-12-07 00:29:20 +00:00
parent 58c631bd8f
commit 5af655391a
10 changed files with 83 additions and 87 deletions

View File

@ -119,7 +119,9 @@ class ChannelRelay(callbacks.Privmsg):
source = self.registryValue('source') source = self.registryValue('source')
target = self.registryValue('target') target = self.registryValue('target')
if source and target: if source and target:
irc.queueMsg(ircmsgs.joins([source, target])) networkGroup = conf.supybot.networks.get(irc.network)
irc.queueMsg(networkGroup.channels.join(target))
irc.queueMsg(networkGroup.channels.join(source))
Class = ChannelRelay Class = ChannelRelay

View File

@ -68,7 +68,8 @@ class Cycler(callbacks.Privmsg):
# XXX We should pull these keywords from the registry. # XXX We should pull these keywords from the registry.
self.log.info('Cycling %s: I\'m the only one left.', channel) self.log.info('Cycling %s: I\'m the only one left.', channel)
irc.queueMsg(ircmsgs.part(channel)) irc.queueMsg(ircmsgs.part(channel))
irc.queueMsg(ircmsgs.join(channel)) networkGroup = conf.supybot.networks.get(irc.network)
irc.queueMsg(networkGroup.channels.join(channel))
else: else:
self.log.info('Not cycling %s: it\'s +i or +k.', channel) self.log.info('Not cycling %s: it\'s +i or +k.', channel)

View File

@ -227,7 +227,8 @@ class LogToIrc(callbacks.Privmsg):
targets = self.registryValue('targets') targets = self.registryValue('targets')
for target in targets: for target in targets:
if ircutils.isChannel(target): if ircutils.isChannel(target):
irc.queueMsg(ircmsgs.join(target)) networkGroup = conf.supybot.networks.get(irc.network)
irc.queueMsg(networkGroup.channels.join(target))
do377 = do422 = do376 do377 = do422 = do376

View File

@ -166,8 +166,8 @@ class Protector(callbacks.Privmsg):
protected = [] protected = []
for nick in kicked: for nick in kicked:
if ircutils.strEqual(nick, irc.nick): if ircutils.strEqual(nick, irc.nick):
irc.queueMsg(ircmsgs.join(channel)) return # Channel will handle the rejoin.
return # We can't revenge because we won't have ops on rejoin. for nick in kicked:
hostmask = irc.state.nickToHostmask(nick) hostmask = irc.state.nickToHostmask(nick)
if self.isProtected(irc, channel, hostmask): if self.isProtected(irc, channel, hostmask):
self.log.info('%s was kicked from %s and is protected; ' self.log.info('%s was kicked from %s and is protected; '

View File

@ -120,13 +120,11 @@ class Relay(callbacks.Privmsg):
callbacks.Privmsg.__call__(self, irc, msg) callbacks.Privmsg.__call__(self, irc, msg)
def do376(self, irc, msg): def do376(self, irc, msg):
L = [] networkGroup = conf.supybot.networks.get(irc.network)
for channel in self.registryValue('channels'): for channel in self.registryValue('channels'):
if self.registryValue('channels.joinOnAllNetworks', channel): if self.registryValue('channels.joinOnAllNetworks', channel):
if channel not in irc.state.channels: if channel not in irc.state.channels:
L.append(channel) irc.queueMsg(networkGroup.channels.join(channel))
if L:
irc.queueMsg(ircmsgs.joins(L))
do377 = do422 = do376 do377 = do422 = do376
def _getRealIrc(self, irc): def _getRealIrc(self, irc):
@ -163,9 +161,10 @@ class Relay(callbacks.Privmsg):
the message was sent in. the message was sent in.
""" """
self.registryValue('channels').add(channel) self.registryValue('channels').add(channel)
for otherIrc in world.ircs: # Should we abstract this? for otherIrc in world.ircs:
if channel not in otherIrc.state.channels: if channel not in otherIrc.state.channels:
otherIrc.queueMsg(ircmsgs.join(channel)) networkGroup = conf.supybot.networks.get(otherIrc.network)
otherIrc.queueMsg(networkGroup.channels.join(channel))
irc.replySuccess() irc.replySuccess()
join = wrap(join, ['channel']) join = wrap(join, ['channel'])

View File

@ -303,12 +303,13 @@ class Services(callbacks.Privmsg):
s = msg.args[1].lower() s = msg.args[1].lower()
channel = None channel = None
m = self._chanRe.search(s) m = self._chanRe.search(s)
networkGroup = conf.supybot.networks.get(irc.network)
if m is not None: if m is not None:
channel = m.group(1) channel = m.group(1)
if 'all bans' in s or 'unbanned from' in s: if 'all bans' in s or 'unbanned from' in s:
# All bans removed (freenode) # All bans removed (freenode)
# You have been unbanned from (oftc) # You have been unbanned from (oftc)
irc.sendMsg(ircmsgs.join(channel)) irc.sendMsg(networkGroup.channels.join(channel))
elif 'isn\'t registered' in s: elif 'isn\'t registered' in s:
# XXX We should notify the user that this happened as well. # XXX We should notify the user that this happened as well.
self.log.info('Received "%s isn\'t registered" from ChanServ', self.log.info('Received "%s isn\'t registered" from ChanServ',
@ -328,8 +329,9 @@ class Services(callbacks.Privmsg):
self.log.warning('Got unexpected notice from ChanServ: %r.', msg) self.log.warning('Got unexpected notice from ChanServ: %r.', msg)
def doNickservNotice(self, irc, msg): def doNickservNotice(self, irc, msg):
s = ircutils.stripFormatting(msg.args[1].lower())
nick = self._getNick() nick = self._getNick()
s = ircutils.stripFormatting(msg.args[1].lower())
networkGroup = conf.supybot.networks.get(irc.network)
if 'incorrect' in s or 'denied' in s: if 'incorrect' in s or 'denied' in s:
log = 'Received "Password Incorrect" from NickServ. ' \ log = 'Received "Password Incorrect" from NickServ. ' \
'Resetting password to empty.' 'Resetting password to empty.'
@ -366,8 +368,8 @@ class Services(callbacks.Privmsg):
self.identified = True self.identified = True
for channel in irc.state.channels.keys(): for channel in irc.state.channels.keys():
self.checkPrivileges(irc, channel) self.checkPrivileges(irc, channel)
if self.channels: for channel in self.channels:
irc.queueMsg(ircmsgs.joins(self.channels)) irc.queueMsg(networkGroup.channels.join(channel))
if self.waitingJoins: if self.waitingJoins:
for m in self.waitingJoins: for m in self.waitingJoins:
irc.sendMsg(m) irc.sendMsg(m)
@ -497,8 +499,9 @@ class Services(callbacks.Privmsg):
def doInvite(self, irc, msg): def doInvite(self, irc, msg):
if ircutils.strEqual(msg.nick, self.registryValue('ChanServ')): if ircutils.strEqual(msg.nick, self.registryValue('ChanServ')):
channel = msg.args[1] channel = msg.args[1]
networkGroup = conf.supybot.networks.get(irc.network)
self.log.info('Joining %s, invited by ChanServ.' % channel) self.log.info('Joining %s, invited by ChanServ.' % channel)
irc.queueMsg(ircmsgs.join(channel)) irc.queueMsg(networkGroup.channels.join(channel))
def identify(self, irc, msg, args): def identify(self, irc, msg, args):
"""takes no arguments """takes no arguments

View File

@ -70,8 +70,9 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg):
if irc.isChannel(target): # We don't care about nicks. if irc.isChannel(target): # We don't care about nicks.
t = time.time() + 30 t = time.time() + 30
# Let's schedule a rejoin. # Let's schedule a rejoin.
networkGroup = conf.supybot.networks.get(irc.network)
def rejoin(): def rejoin():
irc.queueMsg(ircmsgs.join(target)) irc.queueMsg(networkGroup.channels.join(target))
# We don't need to schedule something because we'll get another # We don't need to schedule something because we'll get another
# 437 when we try to join later. # 437 when we try to join later.
schedule.addEvent(rejoin, t) schedule.addEvent(rejoin, t)
@ -133,7 +134,8 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg):
if conf.supybot.alwaysJoinOnInvite() or \ if conf.supybot.alwaysJoinOnInvite() or \
ircdb.checkCapability(msg.prefix, 'admin'): ircdb.checkCapability(msg.prefix, 'admin'):
self.log.info('Invited to %s by %s.', channel, msg.prefix) self.log.info('Invited to %s by %s.', channel, msg.prefix)
irc.queueMsg(ircmsgs.join(channel)) networkGroup = conf.supybot.networks.get(irc.network)
irc.queueMsg(networkGroup.channels.join(channel))
conf.supybot.networks.get(irc.network).channels().add(channel) conf.supybot.networks.get(irc.network).channels().add(channel)
def join(self, irc, msg, args, channel, key): def join(self, irc, msg, args, channel, key):
@ -144,12 +146,15 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg):
""" """
if not irc.isChannel(channel): if not irc.isChannel(channel):
irc.errorInvalid('channel', channel, Raise=True) irc.errorInvalid('channel', channel, Raise=True)
conf.supybot.networks.get(irc.network).channels().add(channel) networkGroup = conf.supybot.networks.get(irc.network)
networkGroup.channels().add(channel)
if key:
networkGroup.channels.key.get(channel).setValue(key)
maxchannels = irc.state.supported.get('maxchannels', sys.maxint) maxchannels = irc.state.supported.get('maxchannels', sys.maxint)
if len(irc.state.channels) + 1 > maxchannels: if len(irc.state.channels) + 1 > maxchannels:
irc.error('I\'m already too close to maximum number of ' irc.error('I\'m already too close to maximum number of '
'channels for this network.', Raise=True) 'channels for this network.', Raise=True)
irc.queueMsg(ircmsgs.join(channel, key)) irc.queueMsg(networkGroup.channels.join(channel))
irc.noReply() irc.noReply()
self.joins[channel] = (irc, msg) self.joins[channel] = (irc, msg)
join = wrap(join, ['validChannel', additional('something')]) join = wrap(join, ['validChannel', additional('something')])
@ -225,36 +230,32 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg):
irc.reply(irc.nick) irc.reply(irc.nick)
nick = wrap(nick, [additional('nick')]) nick = wrap(nick, [additional('nick')])
def part(self, irc, msg, args, channels, reason): def part(self, irc, msg, args, channel, reason):
"""[<channel> ...] [<reason>] """[<channel>] [<reason>]
Tells the bot to part the list of channels you give it. <channel> is Tells the bot to part the list of channels you give it. <channel> is
only necessary if you want the bot to part a channel other than the only necessary if you want the bot to part a channel other than the
current channel. If <reason> is specified, use it as the part current channel. If <reason> is specified, use it as the part
message. message.
""" """
if not channels: if channel is None:
channels.append(msg.args[0]) if irc.isChannel(msg.args[0]):
for chan in channels: channel = msg.args[0]
try: else:
network = conf.supybot.networks.get(irc.network) irc.error(Raise=True)
network.channels.removeChannel(chan) try:
except KeyError: network = conf.supybot.networks.get(irc.network)
pass # It might be in the network thingy. network.channels().remove(channel)
for chan in channels: except KeyError:
if chan not in irc.state.channels: pass
irc.error('I\'m not in %s.' % chan, Raise=True) if channel not in irc.state.channels:
irc.queueMsg(ircmsgs.parts(channels, reason or msg.nick)) irc.error('I\'m not in %s.' % channel, Raise=True)
inAtLeastOneChannel = False irc.queueMsg(ircmsgs.part(channel, reason or msg.nick))
for chan in channels: if msg.nick in irc.state.channels[channel].users:
if msg.nick in irc.state.channels[chan].users:
inAtLeastOneChannel = True
if not inAtLeastOneChannel:
irc.replySuccess()
else:
irc.noReply() irc.noReply()
part = wrap(part, [any('validChannel', continueOnError=True), else:
additional('text','')]) irc.replySuccess()
part = wrap(part, [optional('validChannel'), additional('text')])
def addcapability(self, irc, msg, args, user, capability): def addcapability(self, irc, msg, args, user, capability):
"""<name|hostmask> <capability> """<name|hostmask> <capability>

View File

@ -68,7 +68,8 @@ class Channel(callbacks.Privmsg):
channel = msg.args[0] channel = msg.args[0]
if msg.args[1] == irc.nick: if msg.args[1] == irc.nick:
if self.registryValue('alwaysRejoin', channel): if self.registryValue('alwaysRejoin', channel):
irc.sendMsg(ircmsgs.join(channel)) # Fix for keys. networkGroup = conf.supybot.networks.get(irc.network)
irc.sendMsg(networkGroup.channels.join(channel))
def mode(self, irc, msg, args, channel, modes): def mode(self, irc, msg, args, channel, modes):
"""[<channel>] <mode> [<arg> ...] """[<channel>] <mode> [<arg> ...]
@ -247,21 +248,18 @@ class Channel(callbacks.Privmsg):
('haveOp', 'devoice someone'), ('haveOp', 'devoice someone'),
any('nickInChannel')]) any('nickInChannel')])
def cycle(self, irc, msg, args, channel, key): def cycle(self, irc, msg, args, channel):
"""[<channel>] [<key>] """[<channel>]
If you have the #channel,op capability, this will cause the bot to If you have the #channel,op capability, this will cause the bot to
"cycle", or PART and then JOIN the channel. If <key> is given, join "cycle", or PART and then JOIN the channel. <channel> is only necessary
the channel using that key. <channel> is only necessary if the message if the message isn't sent in the channel itself.
isn't sent in the channel itself.
""" """
if not key: irc.queueMsg(ircmsgs.part(channel, msg.nick))
key = None networkGroup = conf.supybot.networks.get(irc.network)
irc.queueMsg(ircmsgs.part(channel)) irc.queueMsg(networkGroup.channels.join(channel))
irc.queueMsg(ircmsgs.join(channel, key))
irc.noReply() irc.noReply()
cycle = wrap(cycle, [('checkChannelCapability','op'), cycle = wrap(cycle, [('checkChannelCapability','op')])
additional('anything')])
def kick(self, irc, msg, args, channel, nick, reason): def kick(self, irc, msg, args, channel, nick, reason):
"""[<channel>] <nick> [<reason>] """[<channel>] <nick> [<reason>]

View File

@ -357,20 +357,9 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
world.starting = False world.starting = False
def do376(self, irc, msg): def do376(self, irc, msg):
channels = list(conf.supybot.networks.get(irc.network).channels()) networkGroup = conf.supybot.networks.get(irc.network)
if not channels: for channel in networkGroup.channels():
return irc.queueMsg(networkGroup.channels.join(channel))
utils.sortBy(lambda s: ',' not in s, channels)
keys = []
chans = []
for channel in channels:
if ',' in channel:
(channel, key) = channel.split(',', 1)
chans.append(channel)
keys.append(key)
else:
chans.append(channel)
irc.queueMsg(ircmsgs.joins(chans, keys))
do422 = do377 = do376 do422 = do377 = do376
def doPrivmsg(self, irc, msg): def doPrivmsg(self, irc, msg):

View File

@ -111,6 +111,7 @@ def registerPlugin(name, currentValue=None, public=True):
group = registerGlobalValue(supybot.plugins, name, group = registerGlobalValue(supybot.plugins, name,
registry.Boolean(False, """Determines whether this plugin is loaded by registry.Boolean(False, """Determines whether this plugin is loaded by
default.""", showDefault=False)) default.""", showDefault=False))
supybot.plugins().add(name)
registerGlobalValue(group, 'public', registerGlobalValue(group, 'public',
registry.Boolean(public, """Determines whether this plugin is registry.Boolean(public, """Determines whether this plugin is
publicly visible.""")) publicly visible."""))
@ -234,16 +235,13 @@ class SpaceSeparatedSetOfChannels(registry.SpaceSeparatedListOf):
sorted = True sorted = True
List = ircutils.IrcSet List = ircutils.IrcSet
Value = ValidChannel Value = ValidChannel
def removeChannel(self, channel): def join(self, channel):
removals = [] import ircmsgs # Don't put this globally! It's recursive.
for c in self.value: key = self.key.get(channel)()
chan = c if key:
if ',' in c: return ircmsgs.join(channel, key)
(chan, _) = c.split(',') else:
if chan == channel: return ircmsgs.join(channel)
removals.append(c)
for removal in removals:
self.value.remove(removal)
def registerNetwork(name, password=''): def registerNetwork(name, password=''):
network = registerGroup(supybot.networks, name) network = registerGroup(supybot.networks, name)
@ -257,6 +255,8 @@ def registerNetwork(name, password=''):
completed.""" % name)) completed.""" % name))
registerGlobalValue(network, 'channels', SpaceSeparatedSetOfChannels([], registerGlobalValue(network, 'channels', SpaceSeparatedSetOfChannels([],
"""Determines what channels the bot will join only on %s.""" % name)) """Determines what channels the bot will join only on %s.""" % name))
registerChannelValue(network.channels, 'key', registry.String('',
"""Determines what key (if any) will be used to join the channel."""))
return network return network
# Let's fill our networks. # Let's fill our networks.
@ -567,13 +567,13 @@ registerGroup(supybot.commands, 'defaultPlugins',
what commands have default plugins set, and which plugins are set to what commands have default plugins set, and which plugins are set to
be the default for each of those commands.""")) be the default for each of those commands."""))
registerGlobalValue(supybot.commands.defaultPlugins, 'importantPlugins', registerGlobalValue(supybot.commands.defaultPlugins, 'importantPlugins',
registry.SpaceSeparatedSetOfStrings(['Admin', 'Channel', 'Config', 'Misc', registry.SpaceSeparatedSetOfStrings(
'Owner', 'User'], """Determines what ['Admin', 'Channel', 'Config', 'Misc', 'Owner', 'User'],
plugins automatically get precedence over all other plugins when selecting """Determines what plugins automatically get precedence over all other
a default plugin for a command. By default, this includes the standard plugins when selecting a default plugin for a command. By default,
loaded plugins. You probably shouldn't change this if you don't know what this includes the standard loaded plugins. You probably shouldn't
you're doing; if you do know what you're doing, then also know that this change this if you don't know what you're doing; if you do know what
set is case-sensitive.""")) you're doing, then also know that this set is case-sensitive."""))
# supybot.commands.disabled moved to callbacks for canonicalName. # supybot.commands.disabled moved to callbacks for canonicalName.
@ -712,7 +712,9 @@ registerGlobalValue(supybot.directories, 'plugins',
a new one. E.g. you can say: bot: 'config supybot.directories.plugins a new one. E.g. you can say: bot: 'config supybot.directories.plugins
[config supybot.directories.plugins], newPluginDirectory'.""")) [config supybot.directories.plugins], newPluginDirectory'."""))
registerGroup(supybot, 'plugins', orderAlphabetically=True) registerGlobalValue(supybot, 'plugins',
registry.SpaceSeparatedSetOfStrings([], """Determines what plugins will
be loaded.""", orderAlphabetically=True))
registerGlobalValue(supybot.plugins, 'alwaysLoadImportant', registerGlobalValue(supybot.plugins, 'alwaysLoadImportant',
registry.Boolean(True, """Determines whether the bot will always load registry.Boolean(True, """Determines whether the bot will always load
important plugins (Admin, Channel, Config, Misc, Owner, and User) important plugins (Admin, Channel, Config, Misc, Owner, and User)