Don't send JOIN and PART commands if channel is not set (#62334)

Currently, the irc module is sending JOIN and PART commands even if the channel
key is not set in the irc module. This causes the module to send JOIN and PART
commands to the #None channel. This module can send PRIVMSGs to either a
channel or a list of nicks, so sending JOIN and PART doesn't make sense in
cases where channel is undefined. The same goes for the TOPIC command, which is
used to set a topic for channels.

This patch ensures that the JOIN, PART and TOPIC commands are only sent if the
channel is defined.
pull/67442/head
Ronnie P. Thomas 5 years ago committed by GitHub
parent cc86748109
commit 807f4ea658
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,9 +17,9 @@ DOCUMENTATION = '''
---
module: irc
version_added: "1.2"
short_description: Send a message to an IRC channel
short_description: Send a message to an IRC channel or a nick
description:
- Send a message to an IRC channel. This is a very simplistic implementation.
- Send a message to an IRC channel or a nick. This is a very simplistic implementation.
options:
server:
description:
@ -204,24 +204,25 @@ def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=None, k
raise Exception('Timeout waiting for IRC server welcome response')
time.sleep(0.5)
if key:
irc.send(to_bytes('JOIN %s %s\r\n' % (channel, key)))
else:
irc.send(to_bytes('JOIN %s\r\n' % channel))
join = ''
start = time.time()
while 1:
join += to_native(irc.recv(1024))
if re.search(r'^:\S+ 366 %s %s :' % (nick, channel), join, flags=re.M | re.I):
break
elif time.time() - start > timeout:
raise Exception('Timeout waiting for IRC JOIN response')
time.sleep(0.5)
if topic is not None:
irc.send(to_bytes('TOPIC %s :%s\r\n' % (channel, topic)))
time.sleep(1)
if channel:
if key:
irc.send(to_bytes('JOIN %s %s\r\n' % (channel, key)))
else:
irc.send(to_bytes('JOIN %s\r\n' % channel))
join = ''
start = time.time()
while 1:
join += to_native(irc.recv(1024))
if re.search(r'^:\S+ 366 %s %s :' % (nick, channel), join, flags=re.M | re.I):
break
elif time.time() - start > timeout:
raise Exception('Timeout waiting for IRC JOIN response')
time.sleep(0.5)
if topic is not None:
irc.send(to_bytes('TOPIC %s :%s\r\n' % (channel, topic)))
time.sleep(1)
if nick_to:
for nick in nick_to:
@ -230,7 +231,8 @@ def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=None, k
irc.send(to_bytes('PRIVMSG %s :%s\r\n' % (channel, message)))
time.sleep(1)
if part:
irc.send(to_bytes('PART %s\r\n' % channel))
if channel:
irc.send(to_bytes('PART %s\r\n' % channel))
irc.send(to_bytes('QUIT\r\n'))
time.sleep(1)
irc.close()

Loading…
Cancel
Save