
    Vh+                         d dl mZmZmZ eZdZdZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlmZmZ d dlmZ 	 	 	 d
dZd Zed	k(  r e        yy)    )absolute_importdivisionprint_functiona  
module: irc
short_description: Send a message to an IRC channel or a nick
description:
  - Send a message to an IRC channel or a nick. This is a very simplistic implementation.
extends_documentation_fragment:
  - community.general.attributes
attributes:
  check_mode:
    support: full
  diff_mode:
    support: none
options:
  server:
    type: str
    description:
      - IRC server name/address.
    default: localhost
  port:
    type: int
    description:
      - IRC server port number.
    default: 6667
  nick:
    type: str
    description:
      - Nickname to send the message from. May be shortened, depending on server's NICKLEN setting.
    default: ansible
  msg:
    type: str
    description:
      - The message body.
    required: true
  topic:
    type: str
    description:
      - Set the channel topic.
  color:
    type: str
    description:
      - Text color for the message.
    default: "none"
    choices:
      - none
      - white
      - black
      - blue
      - green
      - red
      - brown
      - purple
      - orange
      - yellow
      - light_green
      - teal
      - light_cyan
      - light_blue
      - pink
      - gray
      - light_gray
    aliases: [colour]
  channel:
    type: str
    description:
      - Channel name. One of nick_to or channel needs to be set. When both are set, the message will be sent to both of them.
  nick_to:
    type: list
    elements: str
    description:
      - A list of nicknames to send the message to. One of nick_to or channel needs to be set. When both are defined, the
        message will be sent to both of them.
  key:
    type: str
    description:
      - Channel key.
  passwd:
    type: str
    description:
      - Server password.
  timeout:
    type: int
    description:
      - Timeout to use while waiting for successful registration and join messages, this is to prevent an endless loop.
    default: 30
  use_tls:
    description:
      - Designates whether TLS/SSL should be used when connecting to the IRC server.
      - O(use_tls) is available since community.general 8.1.0, before the option was exlusively called O(use_ssl). The latter
        is now an alias of O(use_tls).
      - B(Note:) for security reasons, you should always set O(use_tls=true) and O(validate_certs=true) whenever possible.
      - The default of this option changed to V(true) in community.general 10.0.0.
    type: bool
    default: true
    aliases:
      - use_ssl
  part:
    description:
      - Designates whether user should part from channel after sending message or not. Useful for when using a mock bot and
        not wanting join/parts between messages.
    type: bool
    default: true
  style:
    type: str
    description:
      - Text style for the message. Note italic does not work on some clients.
    choices: ["bold", "underline", "reverse", "italic", "none"]
    default: none
  validate_certs:
    description:
      - If set to V(false), the SSL certificates will not be validated.
      - This should always be set to V(true). Using V(false) is unsafe and should only be done if the network between between
        Ansible and the IRC server is known to be safe.
      - B(Note:) for security reasons, you should always set O(use_tls=true) and O(validate_certs=true) whenever possible.
      - The default of this option changed to V(true) in community.general 10.0.0.
    type: bool
    default: true
    version_added: 8.1.0

# informational: requirements for nodes
requirements: [socket]
author:
  - "Jan-Piet Mens (@jpmens)"
  - "Matt Martz (@sivel)"
a  
- name: Send a message to an IRC channel from nick ansible
  community.general.irc:
    server: irc.example.net
    use_tls: true
    validate_certs: true
    channel: '#t1'
    msg: Hello world

- name: Send a message to an IRC channel
  local_action:
    module: irc
    port: 6669
    server: irc.example.net
    use_tls: true
    validate_certs: true
    channel: '#t1'
    msg: 'All finished at {{ ansible_date_time.iso8601 }}'
    color: red
    nick: ansibleIRC

- name: Send a message to an IRC channel
  local_action:
    module: irc
    port: 6669
    server: irc.example.net
    use_tls: true
    validate_certs: true
    channel: '#t1'
    nick_to:
      - nick1
      - nick2
    msg: 'All finished at {{ ansible_date_time.iso8601 }}'
    color: red
    nick: ansibleIRC
N)	to_nativeto_bytes)AnsibleModulec                    |g n|}i dddddddd	d
dddddddddddddddddddddd d!}d"d#d$d%d&}	 ||   }	 ||   }d(|z   }||z   | z   }t        j                  t        j                  t        j                        }|r|r	 t	        j
                         }n^t        t        d*d      $t	        j                  t        j                        }nt	        j                         }t        j                  |_        |j                  |      }|j                  |t        |      f       |	r|j                  t!        d+|	z               |j                  t!        d,|z               |j                  t!        d-|d.|d.|d/             d'}t#        j"                         }	 |t%        |j'                  d1            z  }t)        j*                  d2|t(        j,                  3      }|r|j/                  d4      }n;t#        j"                         |z
  |
kD  rt        d5      t#        j0                  d6       |r'|r"|j                  t!        d7|d.|d8             n|j                  t!        d9|z               d'}t#        j"                         }	 |t%        |j'                  d1            z  }t)        j*                  d:|d.|d;|t(        j,                  t(        j2                  z  3      rn;t#        j"                         |z
  |
kD  rt        d<      t#        j0                  d6       |6|j                  t!        d=|d;|d8             t#        j0                  d0       |r(|D ]#  }|j                  t!        d>|d;|d8             % |r!|j                  t!        d>|d;|d8             t#        j0                  d0       |rN|r|j                  t!        d?|z               |j                  t!        d@             t#        j0                  d0       |j5                          y# t         $ r d'}Y w xY w# t         $ r d'}Y w xY w# t        $ r t        d)      w xY w)Azsend message to IRCNwhite00black01blue02green03red04brown05purple06orange07yellow08light_green09teal10
light_cyan11
light_blue12pink13gray14
light_gray15)bold	underlinereverseitalic z9Need at least Python 2.7.9 for SSL certificate validationPROTOCOL_TLSz	PASS %s
z	NICK %s
zUSER  z :ansible IRC
   i   z^:\S+ 00[1-4] (?P<nick>\S+) :)flagsnickz/Timeout waiting for IRC server welcome responseg      ?zJOIN z
z	JOIN %s
z
^:\S+ 366 z :z%Timeout waiting for IRC JOIN responsezTOPIC zPRIVMSG z	PART %s
zQUIT
)	ExceptionsocketAF_INETSOCK_STREAMsslcreate_default_contextAttributeErrorgetattr
SSLContextr4   	CERT_NONEverify_modewrap_socketconnectintsendr   timer   recvresearchMgroupsleepIclose)msgserverportchannelnick_tokeytopicr8   colorpasswdtimeoutuse_tlsvalidate_certspartstylecolornumbersstylechoices	styletextcolornumber	colortextmessageirccontextmotdstartmatchjoins                              i/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/modules/irc.pysend_msgrl      s9    ObG 	 		
 	t 	 	$ 	$ 	$ 	t 	 	d 	d 	 	  	d!L( 	L '	"5)[(	 )#c)G
--(:(:
;C]446 sND1=..)9)9:..*"%--G!!#&KKT#$-&012HHXmd*+,HHX$dKLMDIIKE
	#((4.)) 		:DM;;v&DYY[5 7*MNN

3  HHX'3?@AHHXmg567		Ichhtn--Dyyw?RTTTVTXTX[Yu$w. GHHJJsO  HHXGUCDEJJqM 	GDHHXdGDEF	G'7CDEJJqMHHXmg567*%&

1IIK[  	  	 " ] [\\]s0   P& 
P8 Q
 &P54P58QQ
Qc                  z   t        t        t        d      t        dd      t        d      t        ddd	
      t        d      t        ddgg d      t        dg d      t        d      t        d      t               t        d      t        dd      t        dd      t        dddg      t        dd            dddgg      } | j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d   }| j                  d    }| j                  d   }| j                  d!   }|r|s| j                  d"#       | j                  d$   }	| j                  d%   }
| j                  d&   }| j                  d'   }| j                  d(   }| j                  d)   }| j                  d*   }	 t	        ||||||	||||
|||||       | j                  d|||-       y # t
        $ r;}| j                  d+t        |      z  t        j                         ,       Y d }~Ud }~ww xY w).N	localhost)defaultrF   i  )typero   ansibleFliststr)requiredrp   elementsT)rt   nonecolour)r
   r   r   r   r   r   r   r   r   r   r   r    r"   r$   r&   r(   rv   )ro   aliaseschoices)r/   r0   r.   r1   rv   )ro   ry   )no_log   booluse_ssl)rp   ro   rx   )rR   rS   r8   rU   rQ   rX   r^   rT   rV   rW   rY   rZ   r]   r[   r\   rT   rU   )argument_specsupports_check_moderequired_one_ofrR   rS   r8   rQ   rX   rW   z/When topic is specified, a channel is required.)rQ   rV   rY   rZ   r[   r]   r^   r\   zunable to send to IRC: %s)rQ   	exception)changedrT   r8   rQ   )
r   dictparams	fail_jsonrl   r9   r   	traceback
format_exc	exit_json)modulerR   rS   r8   rU   rQ   rX   rT   rW   rV   rY   rZ   r[   r]   r^   r\   es                    rk   mainr   2  s<   ,5$/i(%fuEd#vz DZ [ v/ab%(D!&t$eR0640fdYKHVT:)
, !#Y/01F6 ]]8$F== D== DmmI&G
--
CMM'"EmmI&GMM'"EWNO
--
C]]8$FmmI&GmmI&G== DMM'"E]]#34NkfdGWc5$vW^`giwy}  @E  	F UG$    k89Q<GS\SgSgSijjks   G6 6	H:?1H55H:__main__)rn   6667NNNNrq   rv   Fr{   FTTN)
__future__r   r   r   rp   __metaclass__DOCUMENTATIONEXAMPLESrJ   r:   r=   rH   r   +ansible.module_utils.common.text.convertersr   r   ansible.module_utils.basicr   rl   r   __name__     rk   <module>r      si    A @{z#R 
  
   K 4 `dcg"ol4n zF r   