From 98003318cdfc922aa3c21ad3c63c5e927a66ad20 Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 20 May 2016 20:57:27 -0700 Subject: [PATCH] coreplugin: support bot and hidechans umodes Closes #214. --- coreplugin.py | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/coreplugin.py b/coreplugin.py index 3dd1dfc..976f8d7 100644 --- a/coreplugin.py +++ b/coreplugin.py @@ -85,27 +85,30 @@ def handle_whois(irc, source, command, args): # 311: sends nick!user@host information f(server, 311, source, "%s %s %s * :%s" % (nick, user.ident, user.host, user.realname)) - # 319: RPL_WHOISCHANNELS, shows public channel list of target - public_chans = [] - for chan in user.channels: - c = irc.channels[chan] - # Here, we'll want to hide secret/private channels from non-opers - # who are not in them. + # 319: RPL_WHOISCHANNELS; Show public channels of the target, respecting + # hidechans umodes for non-oper callers. + isHideChans = (irc.umodes.get('hidechans'), None) in user.modes + if (not isHideChans) or (isHideChans and sourceisOper): + public_chans = [] + for chan in user.channels: + c = irc.channels[chan] + # Here, we'll want to hide secret/private channels from non-opers + # who are not in them. - if ((irc.cmodes.get('secret'), None) in c.modes or \ - (irc.cmodes.get('private'), None) in c.modes) \ - and not (sourceisOper or source in c.users): - continue + if ((irc.cmodes.get('secret'), None) in c.modes or \ + (irc.cmodes.get('private'), None) in c.modes) \ + and not (sourceisOper or source in c.users): + continue - # Show prefix modes like a regular IRCd does. - for prefixmode in c.getPrefixModes(target): - modechar = irc.cmodes[prefixmode] - chan = irc.prefixmodes[modechar] + chan + # Show prefix modes like a regular IRCd does. + for prefixmode in c.getPrefixModes(target): + modechar = irc.cmodes[prefixmode] + chan = irc.prefixmodes[modechar] + chan - public_chans.append(chan) + public_chans.append(chan) - if public_chans: # Only send the line if the person is in any visible channels... - f(server, 319, source, '%s :%s' % (nick, ' '.join(public_chans))) + if public_chans: # Only send the line if the person is in any visible channels... + f(server, 319, source, '%s :%s' % (nick, ' '.join(public_chans))) # 312: sends the server the target is on, and its server description. f(server, 312, source, "%s %s :%s" % (nick, irc.servers[server].name, @@ -146,6 +149,10 @@ def handle_whois(irc, source, command, args): # <- 317 GL GL 15 1437632859 :seconds idle, signon time f(server, 317, source, "%s 0 %s :seconds idle, signon time" % (nick, user.ts)) + if (irc.umodes.get('bot'), None) in user.modes: + # Show botmode info in WHOIS. + f(server, 335, source, "%s :is a bot" % nick) + # Call custom WHOIS handlers via the PYLINK_CUSTOM_WHOIS hook. irc.callHooks([source, 'PYLINK_CUSTOM_WHOIS', {'target': target, 'server': server}])