3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-01-24 03:04: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,6 +1137,10 @@ def handle_kick(irc, source, command, args):
# common channels with the target relay network. # common channels with the target relay network.
rsid = getRemoteSid(remoteirc, irc) 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) 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)
if irc.protoname == 'clientbot':
# Special case for clientbot: no kick prefixes are needed.
text = args['text']
else:
try: try:
if kicker in irc.servers: if kicker in irc.servers:
kname = irc.servers[kicker].name kname = irc.servers[kicker].name

View File

@ -5,6 +5,9 @@ from pylinkirc import utils, conf, world
from pylinkirc.log import log from pylinkirc.log import log
default_styles = {'MESSAGE': '\x02[$colored_netname]\x02 <$colored_nick> $text', 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): def color_text(s):
@ -45,18 +48,29 @@ def cb_relay_core(irc, source, command, args):
return return
if source in irc.users: if source in irc.users:
try:
identhost = irc.getHostmask(source).split('!')[-1] 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 # This is specifically spaced so that ident@host is only shown for users that have
# one, and not servers. # one, and not servers.
identhost = ' (%s)' % identhost identhost = ' (%s)' % identhost
else: else:
identhost = '' 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, 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) text = text_template.substitute(args)
irc.proto.message(irc.pseudoclient.uid, target, text) irc.proto.message(irc.pseudoclient.uid, target, text)
utils.add_hook(cb_relay_core, 'CLIENTBOT_MESSAGE') 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) 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 irc.isInternalClient(target): if not self.irc.isInternalClient(target):
# Send a clientbot_kick hook only if the target is an external client. Kicks between # 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. # 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}]) self.irc.callHooks([source, 'CLIENTBOT_KICK', {'channel': channel, 'target': target, 'text': reason}])