mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 11:09:23 +01:00
New way of handling channel keys.
This commit is contained in:
parent
58c631bd8f
commit
5af655391a
@ -119,7 +119,9 @@ class ChannelRelay(callbacks.Privmsg):
|
||||
source = self.registryValue('source')
|
||||
target = self.registryValue('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
|
||||
|
@ -68,7 +68,8 @@ class Cycler(callbacks.Privmsg):
|
||||
# XXX We should pull these keywords from the registry.
|
||||
self.log.info('Cycling %s: I\'m the only one left.', 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:
|
||||
self.log.info('Not cycling %s: it\'s +i or +k.', channel)
|
||||
|
||||
|
@ -227,7 +227,8 @@ class LogToIrc(callbacks.Privmsg):
|
||||
targets = self.registryValue('targets')
|
||||
for target in targets:
|
||||
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
|
||||
|
||||
|
||||
|
@ -166,8 +166,8 @@ class Protector(callbacks.Privmsg):
|
||||
protected = []
|
||||
for nick in kicked:
|
||||
if ircutils.strEqual(nick, irc.nick):
|
||||
irc.queueMsg(ircmsgs.join(channel))
|
||||
return # We can't revenge because we won't have ops on rejoin.
|
||||
return # Channel will handle the rejoin.
|
||||
for nick in kicked:
|
||||
hostmask = irc.state.nickToHostmask(nick)
|
||||
if self.isProtected(irc, channel, hostmask):
|
||||
self.log.info('%s was kicked from %s and is protected; '
|
||||
|
@ -120,13 +120,11 @@ class Relay(callbacks.Privmsg):
|
||||
callbacks.Privmsg.__call__(self, irc, msg)
|
||||
|
||||
def do376(self, irc, msg):
|
||||
L = []
|
||||
networkGroup = conf.supybot.networks.get(irc.network)
|
||||
for channel in self.registryValue('channels'):
|
||||
if self.registryValue('channels.joinOnAllNetworks', channel):
|
||||
if channel not in irc.state.channels:
|
||||
L.append(channel)
|
||||
if L:
|
||||
irc.queueMsg(ircmsgs.joins(L))
|
||||
irc.queueMsg(networkGroup.channels.join(channel))
|
||||
do377 = do422 = do376
|
||||
|
||||
def _getRealIrc(self, irc):
|
||||
@ -163,9 +161,10 @@ class Relay(callbacks.Privmsg):
|
||||
the message was sent in.
|
||||
"""
|
||||
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:
|
||||
otherIrc.queueMsg(ircmsgs.join(channel))
|
||||
networkGroup = conf.supybot.networks.get(otherIrc.network)
|
||||
otherIrc.queueMsg(networkGroup.channels.join(channel))
|
||||
irc.replySuccess()
|
||||
join = wrap(join, ['channel'])
|
||||
|
||||
|
@ -303,12 +303,13 @@ class Services(callbacks.Privmsg):
|
||||
s = msg.args[1].lower()
|
||||
channel = None
|
||||
m = self._chanRe.search(s)
|
||||
networkGroup = conf.supybot.networks.get(irc.network)
|
||||
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))
|
||||
irc.sendMsg(networkGroup.channels.join(channel))
|
||||
elif 'isn\'t registered' in s:
|
||||
# XXX We should notify the user that this happened as well.
|
||||
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)
|
||||
|
||||
def doNickservNotice(self, irc, msg):
|
||||
s = ircutils.stripFormatting(msg.args[1].lower())
|
||||
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:
|
||||
log = 'Received "Password Incorrect" from NickServ. ' \
|
||||
'Resetting password to empty.'
|
||||
@ -366,8 +368,8 @@ class Services(callbacks.Privmsg):
|
||||
self.identified = True
|
||||
for channel in irc.state.channels.keys():
|
||||
self.checkPrivileges(irc, channel)
|
||||
if self.channels:
|
||||
irc.queueMsg(ircmsgs.joins(self.channels))
|
||||
for channel in self.channels:
|
||||
irc.queueMsg(networkGroup.channels.join(channel))
|
||||
if self.waitingJoins:
|
||||
for m in self.waitingJoins:
|
||||
irc.sendMsg(m)
|
||||
@ -497,8 +499,9 @@ class Services(callbacks.Privmsg):
|
||||
def doInvite(self, irc, msg):
|
||||
if ircutils.strEqual(msg.nick, self.registryValue('ChanServ')):
|
||||
channel = msg.args[1]
|
||||
networkGroup = conf.supybot.networks.get(irc.network)
|
||||
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):
|
||||
"""takes no arguments
|
||||
|
49
src/Admin.py
49
src/Admin.py
@ -70,8 +70,9 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg):
|
||||
if irc.isChannel(target): # We don't care about nicks.
|
||||
t = time.time() + 30
|
||||
# Let's schedule a rejoin.
|
||||
networkGroup = conf.supybot.networks.get(irc.network)
|
||||
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
|
||||
# 437 when we try to join later.
|
||||
schedule.addEvent(rejoin, t)
|
||||
@ -133,7 +134,8 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg):
|
||||
if conf.supybot.alwaysJoinOnInvite() or \
|
||||
ircdb.checkCapability(msg.prefix, 'admin'):
|
||||
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)
|
||||
|
||||
def join(self, irc, msg, args, channel, key):
|
||||
@ -144,12 +146,15 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg):
|
||||
"""
|
||||
if not irc.isChannel(channel):
|
||||
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)
|
||||
if len(irc.state.channels) + 1 > maxchannels:
|
||||
irc.error('I\'m already too close to maximum number of '
|
||||
'channels for this network.', Raise=True)
|
||||
irc.queueMsg(ircmsgs.join(channel, key))
|
||||
irc.queueMsg(networkGroup.channels.join(channel))
|
||||
irc.noReply()
|
||||
self.joins[channel] = (irc, msg)
|
||||
join = wrap(join, ['validChannel', additional('something')])
|
||||
@ -225,36 +230,32 @@ class Admin(privmsgs.CapabilityCheckingPrivmsg):
|
||||
irc.reply(irc.nick)
|
||||
nick = wrap(nick, [additional('nick')])
|
||||
|
||||
def part(self, irc, msg, args, channels, reason):
|
||||
"""[<channel> ...] [<reason>]
|
||||
def part(self, irc, msg, args, channel, reason):
|
||||
"""[<channel>] [<reason>]
|
||||
|
||||
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
|
||||
current channel. If <reason> is specified, use it as the part
|
||||
message.
|
||||
"""
|
||||
if not channels:
|
||||
channels.append(msg.args[0])
|
||||
for chan in channels:
|
||||
if channel is None:
|
||||
if irc.isChannel(msg.args[0]):
|
||||
channel = msg.args[0]
|
||||
else:
|
||||
irc.error(Raise=True)
|
||||
try:
|
||||
network = conf.supybot.networks.get(irc.network)
|
||||
network.channels.removeChannel(chan)
|
||||
network.channels().remove(channel)
|
||||
except KeyError:
|
||||
pass # It might be in the network thingy.
|
||||
for chan in channels:
|
||||
if chan not in irc.state.channels:
|
||||
irc.error('I\'m not in %s.' % chan, Raise=True)
|
||||
irc.queueMsg(ircmsgs.parts(channels, reason or msg.nick))
|
||||
inAtLeastOneChannel = False
|
||||
for chan in channels:
|
||||
if msg.nick in irc.state.channels[chan].users:
|
||||
inAtLeastOneChannel = True
|
||||
if not inAtLeastOneChannel:
|
||||
irc.replySuccess()
|
||||
else:
|
||||
pass
|
||||
if channel not in irc.state.channels:
|
||||
irc.error('I\'m not in %s.' % channel, Raise=True)
|
||||
irc.queueMsg(ircmsgs.part(channel, reason or msg.nick))
|
||||
if msg.nick in irc.state.channels[channel].users:
|
||||
irc.noReply()
|
||||
part = wrap(part, [any('validChannel', continueOnError=True),
|
||||
additional('text','')])
|
||||
else:
|
||||
irc.replySuccess()
|
||||
part = wrap(part, [optional('validChannel'), additional('text')])
|
||||
|
||||
def addcapability(self, irc, msg, args, user, capability):
|
||||
"""<name|hostmask> <capability>
|
||||
|
@ -68,7 +68,8 @@ class Channel(callbacks.Privmsg):
|
||||
channel = msg.args[0]
|
||||
if msg.args[1] == irc.nick:
|
||||
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):
|
||||
"""[<channel>] <mode> [<arg> ...]
|
||||
@ -247,21 +248,18 @@ class Channel(callbacks.Privmsg):
|
||||
('haveOp', 'devoice someone'),
|
||||
any('nickInChannel')])
|
||||
|
||||
def cycle(self, irc, msg, args, channel, key):
|
||||
"""[<channel>] [<key>]
|
||||
def cycle(self, irc, msg, args, channel):
|
||||
"""[<channel>]
|
||||
|
||||
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
|
||||
the channel using that key. <channel> is only necessary if the message
|
||||
isn't sent in the channel itself.
|
||||
"cycle", or PART and then JOIN the channel. <channel> is only necessary
|
||||
if the message isn't sent in the channel itself.
|
||||
"""
|
||||
if not key:
|
||||
key = None
|
||||
irc.queueMsg(ircmsgs.part(channel))
|
||||
irc.queueMsg(ircmsgs.join(channel, key))
|
||||
irc.queueMsg(ircmsgs.part(channel, msg.nick))
|
||||
networkGroup = conf.supybot.networks.get(irc.network)
|
||||
irc.queueMsg(networkGroup.channels.join(channel))
|
||||
irc.noReply()
|
||||
cycle = wrap(cycle, [('checkChannelCapability','op'),
|
||||
additional('anything')])
|
||||
cycle = wrap(cycle, [('checkChannelCapability','op')])
|
||||
|
||||
def kick(self, irc, msg, args, channel, nick, reason):
|
||||
"""[<channel>] <nick> [<reason>]
|
||||
|
17
src/Owner.py
17
src/Owner.py
@ -357,20 +357,9 @@ class Owner(privmsgs.CapabilityCheckingPrivmsg):
|
||||
world.starting = False
|
||||
|
||||
def do376(self, irc, msg):
|
||||
channels = list(conf.supybot.networks.get(irc.network).channels())
|
||||
if not channels:
|
||||
return
|
||||
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))
|
||||
networkGroup = conf.supybot.networks.get(irc.network)
|
||||
for channel in networkGroup.channels():
|
||||
irc.queueMsg(networkGroup.channels.join(channel))
|
||||
do422 = do377 = do376
|
||||
|
||||
def doPrivmsg(self, irc, msg):
|
||||
|
38
src/conf.py
38
src/conf.py
@ -111,6 +111,7 @@ def registerPlugin(name, currentValue=None, public=True):
|
||||
group = registerGlobalValue(supybot.plugins, name,
|
||||
registry.Boolean(False, """Determines whether this plugin is loaded by
|
||||
default.""", showDefault=False))
|
||||
supybot.plugins().add(name)
|
||||
registerGlobalValue(group, 'public',
|
||||
registry.Boolean(public, """Determines whether this plugin is
|
||||
publicly visible."""))
|
||||
@ -234,16 +235,13 @@ class SpaceSeparatedSetOfChannels(registry.SpaceSeparatedListOf):
|
||||
sorted = True
|
||||
List = ircutils.IrcSet
|
||||
Value = ValidChannel
|
||||
def removeChannel(self, channel):
|
||||
removals = []
|
||||
for c in self.value:
|
||||
chan = c
|
||||
if ',' in c:
|
||||
(chan, _) = c.split(',')
|
||||
if chan == channel:
|
||||
removals.append(c)
|
||||
for removal in removals:
|
||||
self.value.remove(removal)
|
||||
def join(self, channel):
|
||||
import ircmsgs # Don't put this globally! It's recursive.
|
||||
key = self.key.get(channel)()
|
||||
if key:
|
||||
return ircmsgs.join(channel, key)
|
||||
else:
|
||||
return ircmsgs.join(channel)
|
||||
|
||||
def registerNetwork(name, password=''):
|
||||
network = registerGroup(supybot.networks, name)
|
||||
@ -257,6 +255,8 @@ def registerNetwork(name, password=''):
|
||||
completed.""" % name))
|
||||
registerGlobalValue(network, 'channels', SpaceSeparatedSetOfChannels([],
|
||||
"""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
|
||||
|
||||
# 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
|
||||
be the default for each of those commands."""))
|
||||
registerGlobalValue(supybot.commands.defaultPlugins, 'importantPlugins',
|
||||
registry.SpaceSeparatedSetOfStrings(['Admin', 'Channel', 'Config', 'Misc',
|
||||
'Owner', 'User'], """Determines what
|
||||
plugins automatically get precedence over all other plugins when selecting
|
||||
a default plugin for a command. By default, this includes the standard
|
||||
loaded plugins. You probably shouldn't change this if you don't know what
|
||||
you're doing; if you do know what you're doing, then also know that this
|
||||
set is case-sensitive."""))
|
||||
registry.SpaceSeparatedSetOfStrings(
|
||||
['Admin', 'Channel', 'Config', 'Misc', 'Owner', 'User'],
|
||||
"""Determines what plugins automatically get precedence over all other
|
||||
plugins when selecting a default plugin for a command. By default,
|
||||
this includes the standard loaded plugins. You probably shouldn't
|
||||
change this if you don't know what you're doing; if you do know what
|
||||
you're doing, then also know that this set is case-sensitive."""))
|
||||
|
||||
# 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
|
||||
[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',
|
||||
registry.Boolean(True, """Determines whether the bot will always load
|
||||
important plugins (Admin, Channel, Config, Misc, Owner, and User)
|
||||
|
Loading…
Reference in New Issue
Block a user