3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-01-23 18:54:05 +01:00

relay/clientbot: implement kick, join, part relaying

This commit is contained in:
James Lu 2016-07-23 12:25:52 -07:00
parent fdaed4f700
commit 3e91118644
3 changed files with 30 additions and 12 deletions

View File

@ -1137,14 +1137,18 @@ def handle_kick(irc, source, command, args):
# common channels with the target relay network.
rsid = getRemoteSid(remoteirc, irc)
log.debug('(%s) relay.handle_kick: Kicking %s from channel %s via %s on behalf of %s/%s', irc.name, real_target, remotechan, rsid, kicker, irc.name)
try:
if kicker in irc.servers:
kname = irc.servers[kicker].name
else:
kname = irc.users.get(kicker).nick
text = "(%s/%s) %s" % (kname, irc.name, args['text'])
except AttributeError:
text = "(<unknown kicker>@%s) %s" % (irc.name, args['text'])
if irc.protoname == 'clientbot':
# Special case for clientbot: no kick prefixes are needed.
text = args['text']
else:
try:
if kicker in irc.servers:
kname = irc.servers[kicker].name
else:
kname = irc.users.get(kicker).nick
text = "(%s/%s) %s" % (kname, irc.name, args['text'])
except AttributeError:
text = "(<unknown kicker>@%s) %s" % (irc.name, args['text'])
remoteirc.proto.kick(rsid, remotechan, real_target, text)
# If the target isn't on any channels, quit them.

View File

@ -5,7 +5,10 @@ from pylinkirc import utils, conf, world
from pylinkirc.log import log
default_styles = {'MESSAGE': '\x02[$colored_netname]\x02 <$colored_nick> $text',
}
'KICK': '\x02[$colored_netname]\x02 -$colored_nick$identhost has kicked $target_nick from $channel ($text)',
'PART': '\x02[$colored_netname]\x02 -$colored_nick$identhost has left $channel ($text)',
'JOIN': '\x02[$colored_netname]\x02 -$colored_nick$identhost has joined $channel',
}
def color_text(s):
"""
@ -45,18 +48,29 @@ def cb_relay_core(irc, source, command, args):
return
if source in irc.users:
identhost = irc.getHostmask(source).split('!')[-1]
try:
identhost = irc.getHostmask(source).split('!')[-1]
except KeyError: # User got removed due to quit
identhost = '%s@%s' % (args['olduser'].ident, args['olduser'].host)
# This is specifically spaced so that ident@host is only shown for users that have
# one, and not servers.
identhost = ' (%s)' % identhost
else:
identhost = ''
if args.get("target") in irc.users:
target_nick = irc.getFriendlyName(args['target'])
else:
target_nick = ''
args.update({'netname': netname, 'nick': sourcename, 'identhost': identhost,
'colored_nick': color_text(sourcename), 'colored_netname': color_text(netname)})
'colored_nick': color_text(sourcename), 'colored_netname': color_text(netname),
'target_nick': target_nick})
text = text_template.substitute(args)
irc.proto.message(irc.pseudoclient.uid, target, text)
utils.add_hook(cb_relay_core, 'CLIENTBOT_MESSAGE')
utils.add_hook(cb_relay_core, 'CLIENTBOT_KICK')
utils.add_hook(cb_relay_core, 'CLIENTBOT_PART')
utils.add_hook(cb_relay_core, 'CLIENTBOT_JOIN')

View File

@ -152,7 +152,7 @@ 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 irc.isInternalClient(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}])