From e02efb4cf2eca650e8dccd0af7604569063bec33 Mon Sep 17 00:00:00 2001 From: "Leo R. Lundgren" Date: Wed, 5 Mar 2014 04:39:08 +0100 Subject: [PATCH 1/2] Make irc module accept the nick being shortened by the server. This can happen if the server has a NICKLEN setting which is less than the length of the specified nick. With this patch we now grab that nick and use it moving forward, instead of failing because we didn't get back the one we specified, in the connection response. --- notification/irc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/notification/irc b/notification/irc index 11bdc4a95ec..5fa05c41488 100644 --- a/notification/irc +++ b/notification/irc @@ -39,7 +39,7 @@ options: default: 6667 nick: description: - - Nickname + - Nickname. May be shortened, depending on server's NICKLEN setting. required: false default: ansible msg: @@ -122,7 +122,11 @@ def send_msg(channel, msg, server='localhost', port='6667', start = time.time() while 1: motd += irc.recv(1024) - if re.search('^:\S+ 00[1-4] %s :' % nick, motd, flags=re.M): + # The server might send back a shorter nick than we specified (due to NICKLEN), + # so grab that and use it from now on (assuming we find the 00[1-4] response). + match = re.search('^:\S+ 00[1-4] (?P\S+) :', motd, flags=re.M) + if match: + nick = match.group('nick') break elif time.time() - start > timeout: raise Exception('Timeout waiting for IRC server welcome response') From 7d7fd7b9a4cb1cd4aef35411f2fc1e50afb4212b Mon Sep 17 00:00:00 2001 From: "Leo R. Lundgren" Date: Wed, 5 Mar 2014 05:12:21 +0100 Subject: [PATCH 2/2] Fix whitespace (tabs -> spaces). --- notification/irc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notification/irc b/notification/irc index 5fa05c41488..e3d5e65d66a 100644 --- a/notification/irc +++ b/notification/irc @@ -122,8 +122,8 @@ def send_msg(channel, msg, server='localhost', port='6667', start = time.time() while 1: motd += irc.recv(1024) - # The server might send back a shorter nick than we specified (due to NICKLEN), - # so grab that and use it from now on (assuming we find the 00[1-4] response). + # The server might send back a shorter nick than we specified (due to NICKLEN), + # so grab that and use it from now on (assuming we find the 00[1-4] response). match = re.search('^:\S+ 00[1-4] (?P\S+) :', motd, flags=re.M) if match: nick = match.group('nick')