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
@ -64,7 +64,10 @@ def cb_relay_core(irc, source, command, args):
|
|||||||
try:
|
try:
|
||||||
origuser = relay.getOrigUser(irc, source) or args['userdata'].remote
|
origuser = relay.getOrigUser(irc, source) or args['userdata'].remote
|
||||||
except (AttributeError, KeyError):
|
except (AttributeError, KeyError):
|
||||||
return
|
try:
|
||||||
|
origuser = (irc.servers[source].remote, '')
|
||||||
|
except (AttributeError, KeyError):
|
||||||
|
return
|
||||||
netname = origuser[0]
|
netname = origuser[0]
|
||||||
try: # Try to get the full network name
|
try: # Try to get the full network name
|
||||||
netname = conf.conf['servers'][netname]['netname']
|
netname = conf.conf['servers'][netname]['netname']
|
||||||
|
@ -38,16 +38,6 @@ class ClientbotWrapperProtocol(Protocol):
|
|||||||
return nick
|
return nick
|
||||||
return uid
|
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):
|
def connect(self):
|
||||||
"""Initializes a connection to a server."""
|
"""Initializes a connection to a server."""
|
||||||
ts = self.irc.start_ts
|
ts = self.irc.start_ts
|
||||||
@ -139,14 +129,19 @@ class ClientbotWrapperProtocol(Protocol):
|
|||||||
def kick(self, source, channel, target, reason=''):
|
def kick(self, source, channel, target, reason=''):
|
||||||
"""Sends channel kicks."""
|
"""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):
|
if self.irc.isInternalClient(target):
|
||||||
# Target was one of our virtual clients. Just remove them from the state.
|
# Target was one of our virtual clients. Just remove them from the state.
|
||||||
self.handle_part(target, 'KICK', [channel, reason])
|
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
|
return
|
||||||
|
|
||||||
# TODO: handle kick failures and send rejoin hooks for the target
|
self.irc.send('KICK %s %s :<%s> %s' % (channel, self._expandPUID(target),
|
||||||
reason = self._formatText(source, reason)
|
self.irc.getFriendlyName(source), reason))
|
||||||
self.irc.send('KICK %s %s :%s' % (channel, self._expandPUID(target), reason))
|
|
||||||
|
|
||||||
# Don't update our state here: wait for the IRCd to send an acknowledgement instead.
|
# 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
|
# 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)
|
log.debug('(%s) kick: adding %s to kick queue for channel %s', self.irc.name, target, channel)
|
||||||
self.kick_queue[channel][0].add(target)
|
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):
|
def message(self, source, target, text, notice=False):
|
||||||
"""Sends messages to the target."""
|
"""Sends messages to the target."""
|
||||||
command = 'NOTICE' if notice else 'PRIVMSG'
|
command = 'NOTICE' if notice else 'PRIVMSG'
|
||||||
|
Loading…
Reference in New Issue
Block a user