From f4c51cde0067ae471b5eb7f7103ee3ab816818b4 Mon Sep 17 00:00:00 2001 From: James Lu Date: Tue, 5 Sep 2017 18:36:37 -0700 Subject: [PATCH 1/3] automode: don't send empty mode lines if no users match the ACL --- plugins/automode.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/plugins/automode.py b/plugins/automode.py index 7b55700..d0ebe48 100644 --- a/plugins/automode.py +++ b/plugins/automode.py @@ -106,18 +106,19 @@ def match(irc, channel, uids=None): log.debug("(%s) automode: Filtered mode list of %s to %s (protocol:%s)", irc.name, modes, outgoing_modes, irc.protoname) - # If the Automode bot is missing, send the mode through the PyLink server. - if modebot_uid not in irc.users: - modebot_uid = irc.sid + if outgoing_modes: + # If the Automode bot is missing, send the mode through the PyLink server. + if modebot_uid not in irc.users: + modebot_uid = irc.sid - log.debug("(%s) automode: sending modes from modebot_uid %s", - irc.name, modebot_uid) + log.debug("(%s) automode: sending modes from modebot_uid %s", + irc.name, modebot_uid) - irc.proto.mode(modebot_uid, channel, outgoing_modes) + irc.proto.mode(modebot_uid, channel, outgoing_modes) - # Create a hook payload to support plugins like relay. - irc.callHooks([modebot_uid, 'AUTOMODE_MODE', - {'target': channel, 'modes': outgoing_modes, 'parse_as': 'MODE'}]) + # Create a hook payload to support plugins like relay. + irc.callHooks([modebot_uid, 'AUTOMODE_MODE', + {'target': channel, 'modes': outgoing_modes, 'parse_as': 'MODE'}]) def handle_join(irc, source, command, args): """ From 8420587318d683c9bb0422983c3955ff18f60791 Mon Sep 17 00:00:00 2001 From: James Lu Date: Tue, 5 Sep 2017 18:49:34 -0700 Subject: [PATCH 2/3] clientbot: warn when an outgoing message is blocked Closes #497. (backported from commit 5112fcd7d105388b324e2fce6b18d022f84b8ab8) --- protocols/clientbot.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/protocols/clientbot.py b/protocols/clientbot.py index c16f3a3..c12fe3a 100644 --- a/protocols/clientbot.py +++ b/protocols/clientbot.py @@ -958,5 +958,26 @@ class ClientbotWrapperProtocol(Protocol): self.quit(source, args[0]) return {'text': args[0]} + def handle_404(self, source, command, args): + """ + Handles ERR_CANNOTSENDTOCHAN and other similar numerics. + """ + # <- :some.server 404 james #test :Cannot send to channel + if len(args) >= 2 and utils.isChannel(args[1]): + channel = args[1] + f = log.warning + + # Don't sent the warning multiple times to prevent flood if the target + # is a log chan. + if hasattr(self.irc.channels[channel], '_clientbot_cannot_send_warned'): + f = log.debug + f('(%s) Failed to send message to %s: %s', self.irc.name, channel, args[-1]) + + self.irc.channels[channel]._clientbot_cannot_send_warned = True + + # 408: ERR_NOCOLORSONCHAN on Bahamut, ERR_NOCTRLSONCHAN on Hybrid + handle_408 = handle_404 + # 492: ERR_NOCTCP on Hybrid + handle_492 = handle_404 Class = ClientbotWrapperProtocol From 7188081511b687a18faa09c9d3cd020010431df9 Mon Sep 17 00:00:00 2001 From: James Lu Date: Tue, 5 Sep 2017 18:55:19 -0700 Subject: [PATCH 3/3] networks: throw a proper error in 'remote' if the remote network isn't connected --- plugins/networks.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/networks.py b/plugins/networks.py index 6700be6..3bad211 100644 --- a/plugins/networks.py +++ b/plugins/networks.py @@ -89,7 +89,7 @@ def remote(irc, source, args): try: remoteirc = world.networkobjects[netname] except KeyError: # Unknown network. - irc.error('No such network "%s" (case sensitive).' % netname) + irc.error('No such network %r (case sensitive).' % netname) REMOTE_IN_USE.clear() return @@ -97,6 +97,10 @@ def remote(irc, source, args): irc.error('Unknown service %r.' % args.service) REMOTE_IN_USE.clear() return + elif not remoteirc.connected.is_set(): + irc.error('Network %r is not connected.' % netname) + REMOTE_IN_USE.clear() + return # Force remoteirc.called_in to something private in order to prevent # accidental information leakage from replies.