3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-11-30 14:49:28 +01:00

relay, clientbot: implement clientbot mode sync

Closes #287.
This commit is contained in:
James Lu 2016-09-25 19:28:15 -07:00
parent 13a42c17b2
commit 4222cc30a8
2 changed files with 34 additions and 8 deletions

View File

@ -667,7 +667,12 @@ def relayJoins(irc, channel, users, ts, burst=True):
# Fetch the known channel TS and all the prefix modes for each user. This ensures
# the different sides of the relay are merged properly.
ts = irc.channels[channel].ts
if irc.protoname == 'clientbot':
# Special hack for clientbot: just use the remote's modes so mode changes
# take precendence. protocols/clientbot does not track channel TS.
ts = remoteirc.channels[remotechan].ts
else:
ts = irc.channels[channel].ts
prefixes = getPrefixModes(irc, remoteirc, channel, user)
# proto.sjoin() takes its users as a list of (prefix mode characters, UID) pairs.
@ -1276,10 +1281,6 @@ def handle_mode(irc, numeric, command, args):
target = args['target']
modes = args['modes']
if irc.protoname == 'clientbot' and utils.isChannel(target):
# We don't sync cmodes with clientbot networks yet.
return
for name, remoteirc in world.networkobjects.copy().items():
if irc.name == name or not remoteirc.connected.is_set():
continue

View File

@ -181,6 +181,21 @@ class ClientbotWrapperProtocol(Protocol):
else:
self.irc.callHooks([source, 'CLIENTBOT_MESSAGE', {'target': target, 'is_notice': notice, 'text': text}])
def mode(self, source, channel, modes, ts=None):
"""Sends channel MODE changes."""
if utils.isChannel(channel):
extmodes = []
for modepair in extmodes:
# Ignore prefix modes for virtual internal clients.
if modepair[0] in self.irc.prefixmodes and self.irc.isInternalClient(modepair[0]):
log.debug('(%s) mode: skipping virtual client prefixmode change %s', self.irc.name, modepair)
continue
extmodes.append(modepair)
log.debug('(%s) mode: filtered modes for %s: %s', self.irc.name, channel, extmodes)
self.irc.send('MODE %s %s' % (channel, self.irc.joinModes(extmodes)))
# Don't update the state here: the IRCd sill respond with a MODE reply if successful.
def nick(self, source, newnick):
"""STUB: Sends NICK changes."""
if self.irc.pseudoclient and source == self.irc.pseudoclient.uid:
@ -252,7 +267,7 @@ class ClientbotWrapperProtocol(Protocol):
def _stub(self, *args):
"""Stub outgoing command function (does nothing)."""
return
kill = mode = topic = topicBurst = knock = numeric = _stub
kill = topic = topicBurst = knock = numeric = _stub
def updateClient(self, target, field, text):
"""Updates the known ident, host, or realname of a client."""
@ -497,9 +512,19 @@ class ClientbotWrapperProtocol(Protocol):
self.who_received.clear()
channel = self.irc.toLower(args[1])
self.irc.channels[channel].who_received = True
c = self.irc.channels[channel]
c.who_received = True
return {'channel': channel, 'users': users, 'modes': self.irc.channels[channel].modes,
modes = set(c.modes)
for user in users:
# Fill in prefix modes of everyone when doing mock SJOIN.
for mode in c.getPrefixModes(user):
modechar = self.irc.cmodes.get(mode)
log.debug('(%s) handle_315: adding mode %s +%s %s', self.irc.name, mode, modechar, user)
if modechar:
modes.add((modechar, user))
return {'channel': channel, 'users': users, 'modes': modes,
'parse_as': "JOIN"}
def handle_433(self, source, command, args):