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

View File

@ -187,28 +187,6 @@ class Servers(registry.SpaceSeparatedListOfStrings):
def __str__(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):
List = ircutils.IrcSet
Value = ValidChannel
@ -221,7 +199,31 @@ class SpaceSeparatedSetOfChannels(registry.SpaceSeparatedListOf):
if chan == channel:
removals.append(c)
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',
SpaceSeparatedSetOfChannels(['#supybot'], """Determines what channels the