3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-27 21:19:31 +01:00

ServiceBot: handle autojoin additions even if bots haven't spawned yet

This commit is contained in:
James Lu 2016-09-24 12:33:57 -07:00
parent 1c60ad7251
commit 438838f81d
3 changed files with 23 additions and 12 deletions

View File

@ -104,7 +104,6 @@ def handle_kick(irc, source, command, args):
sbot = irc.isServiceBot(kicked)
if sbot:
sbot.join(irc, channel)
irc.callHooks([irc.sid, 'PYLINK_SERVICE_JOIN', {'channel': channel, 'users': [kicked]}])
utils.add_hook(handle_kick, 'KICK')
def handle_commands(irc, source, command, args):

View File

@ -78,8 +78,7 @@ def main(irc=None):
netname, channel = entry.split('#', 1)
channel = '#' + channel
log.debug('automode: auto-joining %s on %s', channel, netname)
if netname in world.networkobjects:
modebot.join(world.networkobjects[netname], channel)
modebot.join(netname, channel)
def die(sourceirc):
"""Saves the Automode database and quit."""

View File

@ -239,25 +239,38 @@ class ServiceBot():
"""
Joins the given service bot to the given channel(s).
"""
try:
u = self.uids[irc.name]
except KeyError:
log.debug('(%s/%s) Skipping join(), UID not initialized yet', irc.name, self.name)
return
if type(irc) == str:
netname = irc
else:
netname = irc.name
# Ensure type safety: pluralize strings if only one channel was given, then convert to set.
if type(channels) == str:
channels = [channels]
channels = set(channels)
if autojoin:
log.debug('(%s/%s) Adding channels %s to autojoin', netname, self.name, channels)
self.extra_channels[netname] |= channels
# If the network was given as a string, look up the Irc object here.
try:
irc = world.networkobjects[netname]
except KeyError:
log.debug('(%s/%s) Skipping join(), IRC object not initialized yet', irc, self.name)
return
try:
u = self.uids[irc.name]
except KeyError:
log.debug('(%s/%s) Skipping join(), UID not initialized yet', irc.name, self.name)
return
# Specify modes to join the services bot with.
joinmodes = irc.serverdata.get("%s_joinmodes" % self.name) or conf.conf.get(self.name, {}).get('joinmodes') or ''
joinmodes = ''.join([m for m in joinmodes if m in irc.prefixmodes])
if autojoin:
log.debug('(%s/%s) Adding channels %s to autojoin', irc.name, self.name, channels)
self.extra_channels[irc.name] |= channels
for chan in channels:
if isChannel(chan):
if u in irc.channels[chan].users: