mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-30 14:49:28 +01:00
relay/clientbot: rework KICK handling to send the right thing at the right times
Some of the logic was inverted so that the Clientbot would try to kick invalid things like GLolol/ovd, and send clientbot KICK payloads when it's supposed to forward an actual kick. This also fixes KICKs from servers not being relayed by clientbot.
This commit is contained in:
parent
05972e500c
commit
a905f74800
@ -63,6 +63,9 @@ def cb_relay_core(irc, source, command, args):
|
||||
# Get the original client that the relay client source was meant for.
|
||||
try:
|
||||
origuser = relay.getOrigUser(irc, source) or args['userdata'].remote
|
||||
except (AttributeError, KeyError):
|
||||
try:
|
||||
origuser = (irc.servers[source].remote, '')
|
||||
except (AttributeError, KeyError):
|
||||
return
|
||||
netname = origuser[0]
|
||||
|
@ -38,16 +38,6 @@ class ClientbotWrapperProtocol(Protocol):
|
||||
return nick
|
||||
return uid
|
||||
|
||||
def _formatText(self, source, text):
|
||||
"""
|
||||
Formats text with the given sender as a prefix.
|
||||
"""
|
||||
if self.irc.pseudoclient and source == self.irc.pseudoclient.uid:
|
||||
return text
|
||||
else:
|
||||
# TODO: configurable formatting
|
||||
return '<%s> %s' % (self.irc.getFriendlyName(source), text)
|
||||
|
||||
def connect(self):
|
||||
"""Initializes a connection to a server."""
|
||||
ts = self.irc.start_ts
|
||||
@ -139,14 +129,19 @@ class ClientbotWrapperProtocol(Protocol):
|
||||
def kick(self, source, channel, target, reason=''):
|
||||
"""Sends channel kicks."""
|
||||
|
||||
log.debug('(%s) kick: checking if target %s (nick: %s) is an internal client? %s',
|
||||
self.irc.name, target, self.irc.getFriendlyName(target),
|
||||
self.irc.isInternalClient(target))
|
||||
if self.irc.isInternalClient(target):
|
||||
# Target was one of our virtual clients. Just remove them from the state.
|
||||
self.handle_part(target, 'KICK', [channel, reason])
|
||||
|
||||
# Send a KICK hook for message formatting.
|
||||
self.irc.callHooks([source, 'CLIENTBOT_KICK', {'channel': channel, 'target': target, 'text': reason}])
|
||||
return
|
||||
|
||||
# TODO: handle kick failures and send rejoin hooks for the target
|
||||
reason = self._formatText(source, reason)
|
||||
self.irc.send('KICK %s %s :%s' % (channel, self._expandPUID(target), reason))
|
||||
self.irc.send('KICK %s %s :<%s> %s' % (channel, self._expandPUID(target),
|
||||
self.irc.getFriendlyName(source), reason))
|
||||
|
||||
# Don't update our state here: wait for the IRCd to send an acknowledgement instead.
|
||||
# There is essentially a 3 second wait to do this, as we send NAMES with a delay
|
||||
@ -163,11 +158,6 @@ class ClientbotWrapperProtocol(Protocol):
|
||||
log.debug('(%s) kick: adding %s to kick queue for channel %s', self.irc.name, target, channel)
|
||||
self.kick_queue[channel][0].add(target)
|
||||
|
||||
if not self.irc.isInternalClient(target):
|
||||
# Send a clientbot_kick hook only if the target is an external client. Kicks between
|
||||
# users on fully-linked relay networks would otherwise have no message attached to them.
|
||||
self.irc.callHooks([source, 'CLIENTBOT_KICK', {'channel': channel, 'target': target, 'text': reason}])
|
||||
|
||||
def message(self, source, target, text, notice=False):
|
||||
"""Sends messages to the target."""
|
||||
command = 'NOTICE' if notice else 'PRIVMSG'
|
||||
|
Loading…
Reference in New Issue
Block a user