@ -17,9 +17,9 @@ DOCUMENTATION = '''
- - -
- - -
module : irc
module : irc
version_added : " 1.2 "
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 :
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 :
options :
server :
server :
description :
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 ' )
raise Exception ( ' Timeout waiting for IRC server welcome response ' )
time . sleep ( 0.5 )
time . sleep ( 0.5 )
if key :
if channel :
irc . send ( to_bytes ( ' JOIN %s %s \r \n ' % ( channel , key ) ) )
if key :
else :
irc . send ( to_bytes ( ' JOIN %s %s \r \n ' % ( channel , key ) ) )
irc . send ( to_bytes ( ' JOIN %s \r \n ' % channel ) )
else :
irc . send ( to_bytes ( ' JOIN %s \r \n ' % channel ) )
join = ' '
start = time . time ( )
join = ' '
while 1 :
start = time . time ( )
join + = to_native ( irc . recv ( 1024 ) )
while 1 :
if re . search ( r ' ^: \ S+ 366 %s %s : ' % ( nick , channel ) , join , flags = re . M | re . I ) :
join + = to_native ( irc . recv ( 1024 ) )
break
if re . search ( r ' ^: \ S+ 366 %s %s : ' % ( nick , channel ) , join , flags = re . M | re . I ) :
elif time . time ( ) - start > timeout :
break
raise Exception ( ' Timeout waiting for IRC JOIN response ' )
elif time . time ( ) - start > timeout :
time . sleep ( 0.5 )
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 ) ) )
if topic is not None :
time . sleep ( 1 )
irc . send ( to_bytes ( ' TOPIC %s : %s \r \n ' % ( channel , topic ) ) )
time . sleep ( 1 )
if nick_to :
if nick_to :
for nick in 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 ) ) )
irc . send ( to_bytes ( ' PRIVMSG %s : %s \r \n ' % ( channel , message ) ) )
time . sleep ( 1 )
time . sleep ( 1 )
if part :
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 ' ) )
irc . send ( to_bytes ( ' QUIT \r \n ' ) )
time . sleep ( 1 )
time . sleep ( 1 )
irc . close ( )
irc . close ( )