mirror of
https://github.com/jlu5/PyLink.git
synced 2024-11-01 09:19:23 +01:00
relay: support relaying channel mode changes as text
Closes #389. This adds a new internal hook RELAY_RAW_MODE, which is called once on every relayed network but with the mode list from the source network.
This commit is contained in:
parent
92dae6db5e
commit
d2466dd33c
@ -1415,6 +1415,7 @@ def handle_mode(irc, numeric, command, args):
|
||||
def _handle_mode_loop(irc, remoteirc, numeric, command, args):
|
||||
target = args['target']
|
||||
modes = args['modes']
|
||||
|
||||
if utils.isChannel(target):
|
||||
# Use the old state of the channel to check for CLAIM access.
|
||||
oldchan = args.get('channeldata')
|
||||
@ -1422,16 +1423,32 @@ def handle_mode(irc, numeric, command, args):
|
||||
if check_claim(irc, target, numeric, chanobj=oldchan):
|
||||
remotechan = get_remote_channel(irc, remoteirc, target)
|
||||
supported_modes = get_supported_cmodes(irc, remoteirc, target, modes)
|
||||
if supported_modes:
|
||||
|
||||
# Check if the sender is a user with a relay client; otherwise relay the mode
|
||||
# from the corresponding server.
|
||||
u = get_remote_user(irc, remoteirc, numeric, spawn_if_missing=False)
|
||||
if u:
|
||||
remoteirc.mode(u, remotechan, supported_modes)
|
||||
else:
|
||||
rsid = get_remote_sid(remoteirc, irc)
|
||||
rsid = rsid or remoteirc.sid
|
||||
remoteirc.mode(rsid, remotechan, supported_modes)
|
||||
remotesender = get_remote_user(irc, remoteirc, numeric, spawn_if_missing=False) or \
|
||||
get_remote_sid(remoteirc, irc) or remoteirc.sid
|
||||
|
||||
friendly_modes = []
|
||||
for modepair in modes:
|
||||
if modepair[0][-1] in irc.prefixmodes:
|
||||
orig_user = get_orig_user(irc, modepair[1])
|
||||
if orig_user and orig_user[0] == remoteirc.name:
|
||||
# Don't display prefix mode changes for someone on the target clientbot
|
||||
# link; this will either be relayed via modesync or ignored.
|
||||
continue
|
||||
|
||||
# Convert UIDs to nicks when relaying this to clientbot.
|
||||
modepair = (modepair[0], irc.get_friendly_name(modepair[1]))
|
||||
friendly_modes.append(modepair)
|
||||
|
||||
if friendly_modes:
|
||||
# Call hooks, this is used for clientbot relay.
|
||||
remoteirc.call_hooks([remotesender, 'RELAY_RAW_MODE', {'channel': target, 'modes': friendly_modes}])
|
||||
|
||||
if supported_modes:
|
||||
remoteirc.mode(remotesender, remotechan, supported_modes)
|
||||
|
||||
else: # Mode change blocked by CLAIM.
|
||||
reversed_modes = irc.reverse_modes(target, modes, oldobj=oldchan)
|
||||
|
||||
|
@ -17,6 +17,7 @@ default_styles = {'MESSAGE': '\x02[$netname]\x02 <$colored_sender> $text',
|
||||
'NOTICE': '\x02[$netname]\x02 - Notice from $colored_sender: $text',
|
||||
'SQUIT': '\x02[$netname]\x02 - Netsplit lost users: $colored_nicks',
|
||||
'SJOIN': '\x02[$netname]\x02 - Netjoin gained users: $colored_nicks',
|
||||
'MODE': '\x02[$netname]\x02 - $colored_sender$sender_identhost sets mode $modes on $channel',
|
||||
'PM': 'PM from $sender on $netname: $text',
|
||||
'PNOTICE': '<$sender> $text',
|
||||
}
|
||||
@ -141,6 +142,10 @@ def cb_relay_core(irc, source, command, args):
|
||||
if args.get("target") in irc.users:
|
||||
args["target_nick"] = irc.get_friendly_name(args['target'])
|
||||
|
||||
# Join up modes from their list form
|
||||
if args.get('modes'):
|
||||
args['modes'] = irc.join_modes(args['modes'])
|
||||
|
||||
args.update({'netname': netname, 'sender': sourcename, 'sender_identhost': identhost,
|
||||
'colored_sender': color_text(sourcename), 'colored_netname': color_text(netname)})
|
||||
if 'channel' in args:
|
||||
@ -185,6 +190,7 @@ utils.add_hook(cb_relay_core, 'CLIENTBOT_QUIT')
|
||||
utils.add_hook(cb_relay_core, 'CLIENTBOT_NICK')
|
||||
utils.add_hook(cb_relay_core, 'CLIENTBOT_SJOIN')
|
||||
utils.add_hook(cb_relay_core, 'CLIENTBOT_SQUIT')
|
||||
utils.add_hook(cb_relay_core, 'RELAY_RAW_MODE')
|
||||
|
||||
@utils.add_cmd
|
||||
def rpm(irc, source, args):
|
||||
|
Loading…
Reference in New Issue
Block a user