Added network-specific channels.

This commit is contained in:
Jeremy Fincher 2004-07-30 21:07:28 +00:00
parent fb0a5dd51f
commit 7328bd50ba
2 changed files with 38 additions and 33 deletions

View File

@ -66,7 +66,9 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg):
self.pendingNickChanges = {} self.pendingNickChanges = {}
def do376(self, irc, msg): def do376(self, irc, msg):
channels = list(conf.supybot.channels()) channels = ircutils.IrcSet(conf.supybot.channels())
channels |= conf.supybot.networks.get(irc.network).channels()
channels = list(channels)
if not channels: if not channels:
return return
utils.sortBy(lambda s: ',' not in s, channels) utils.sortBy(lambda s: ',' not in s, channels)
@ -269,17 +271,18 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg):
reason = ' '.join(args) reason = ' '.join(args)
for chan in channels: for chan in channels:
if chan not in irc.state.channels: if chan not in irc.state.channels:
irc.error('I\'m not currently in %s' % chan) irc.error('I\'m not currently in %s.' % chan)
return return
for chan in channels: for chan in channels:
L = [] try:
for channelWithPass in conf.supybot.channels(): conf.supybot.channels.removeChannel(chan)
channel = channelWithPass.split(',')[0] except KeyError:
if ircutils.strEqual(chan, channel): pass # It might be in the network thingy.
L.append(channelWithPass) try:
# This is necessary so the set doesn't change size while iterating. networkGroup = conf.supybot.networks.get(irc.network)
for channel in L: networkGroup.channels.removeChannel(chan)
conf.supybot.channels().remove(channel) except KeyError:
pass # It might be in the non-network thingy.
irc.queueMsg(ircmsgs.parts(channels, reason or msg.nick)) irc.queueMsg(ircmsgs.parts(channels, reason or msg.nick))
inAtLeastOneChannel = False inAtLeastOneChannel = False
for chan in channels: for chan in channels:

View File

@ -187,28 +187,6 @@ class Servers(registry.SpaceSeparatedListOfStrings):
def __str__(self): def __str__(self):
return ' '.join(registry.SpaceSeparatedListOfStrings.__call__(self)) return ' '.join(registry.SpaceSeparatedListOfStrings.__call__(self))
def registerNetwork(name, password='', servers=()):
name = intern(name)
network = registerGroup(supybot.networks, name)
registerGlobalValue(network, 'password', registry.String(password,
"""Determines what password will be used on %s. Yes, we know that
technically passwords are server-specific and not network-specific,
but this is the best we can do right now.""" % name))
registerGlobalValue(network, 'servers', Servers(servers,
"""Determines what servers the bot will connect to for %s. Each will
be tried in order, wrapping back to the first when the cycle is
completed.""" % name))
return network
# Let's fill our networks.
for (name, s) in registry._cache.iteritems():
if name.startswith('supybot.networks.'):
parts = name.split('.')
name = parts[2]
if name != 'default':
registerNetwork(name)
class SpaceSeparatedSetOfChannels(registry.SpaceSeparatedListOf): class SpaceSeparatedSetOfChannels(registry.SpaceSeparatedListOf):
List = ircutils.IrcSet List = ircutils.IrcSet
Value = ValidChannel Value = ValidChannel
@ -221,7 +199,31 @@ class SpaceSeparatedSetOfChannels(registry.SpaceSeparatedListOf):
if chan == channel: if chan == channel:
removals.append(c) removals.append(c)
for removal in removals: for removal in removals:
self.value.remove(discard) self.value.remove(removal)
def registerNetwork(name, password='', servers=()):
name = intern(name)
network = registerGroup(supybot.networks, name)
registerGlobalValue(network, 'password', registry.String(password,
"""Determines what password will be used on %s. Yes, we know that
technically passwords are server-specific and not network-specific,
but this is the best we can do right now.""" % name))
registerGlobalValue(network, 'servers', Servers(servers,
"""Determines what servers the bot will connect to for %s. Each will
be tried in order, wrapping back to the first when the cycle is
completed.""" % name))
registerGlobalValue(network, 'channels', SpaceSeparatedSetOfChannels([],
"""Determines what channels the bot will join only on %s.""" % name))
return network
# Let's fill our networks.
for (name, s) in registry._cache.iteritems():
if name.startswith('supybot.networks.'):
parts = name.split('.')
name = parts[2]
if name != 'default':
registerNetwork(name)
registerGlobalValue(supybot, 'channels', registerGlobalValue(supybot, 'channels',
SpaceSeparatedSetOfChannels(['#supybot'], """Determines what channels the SpaceSeparatedSetOfChannels(['#supybot'], """Determines what channels the