From 3e911186442dea7428ef53272d56a4b3e62f0d5c Mon Sep 17 00:00:00 2001 From: James Lu Date: Sat, 23 Jul 2016 12:25:52 -0700 Subject: [PATCH] relay/clientbot: implement kick, join, part relaying --- plugins/relay.py | 20 ++++++++++++-------- plugins/relay_clientbot.py | 20 +++++++++++++++++--- protocols/clientbot.py | 2 +- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/plugins/relay.py b/plugins/relay.py index 2397f53..39080ec 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -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 = "(@%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 = "(@%s) %s" % (irc.name, args['text']) remoteirc.proto.kick(rsid, remotechan, real_target, text) # If the target isn't on any channels, quit them. diff --git a/plugins/relay_clientbot.py b/plugins/relay_clientbot.py index 5a9e45c..cee6d36 100644 --- a/plugins/relay_clientbot.py +++ b/plugins/relay_clientbot.py @@ -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') diff --git a/protocols/clientbot.py b/protocols/clientbot.py index ea5abf5..0f73ce0 100644 --- a/protocols/clientbot.py +++ b/protocols/clientbot.py @@ -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}])