mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Added style= and more colors.
This commit is contained in:
parent
ae72b7c12c
commit
c277a8b191
1 changed files with 46 additions and 8 deletions
|
@ -56,9 +56,11 @@ options:
|
||||||
color:
|
color:
|
||||||
description:
|
description:
|
||||||
- Text color for the message. ("none" is a valid option in 1.6 or later, in 1.6 and prior, the default color is black, not "none").
|
- Text color for the message. ("none" is a valid option in 1.6 or later, in 1.6 and prior, the default color is black, not "none").
|
||||||
|
Added 11 more colors in version 2.0.
|
||||||
required: false
|
required: false
|
||||||
default: "none"
|
default: "none"
|
||||||
choices: [ "none", "yellow", "red", "green", "blue", "black" ]
|
choices: [ "none", "white", "black", "blue", "green", "red", "brown", "purple", "orange", "yellow", "light_green", "teal", "light_cyan",
|
||||||
|
"light_blue", "pink", "gray", "light_gray"]
|
||||||
channel:
|
channel:
|
||||||
description:
|
description:
|
||||||
- Channel name
|
- Channel name
|
||||||
|
@ -95,6 +97,13 @@ options:
|
||||||
Useful for when using a faux bot and not wanting join/parts between messages.
|
Useful for when using a faux bot and not wanting join/parts between messages.
|
||||||
default: True
|
default: True
|
||||||
version_added: "2.0"
|
version_added: "2.0"
|
||||||
|
style:
|
||||||
|
description:
|
||||||
|
- Text style for the message. Note italic does not work on some clients
|
||||||
|
default: None
|
||||||
|
required: False
|
||||||
|
choices: [ "bold", "underline", "reverse", "italic" ]
|
||||||
|
version_added: "2.0"
|
||||||
|
|
||||||
# informational: requirements for nodes
|
# informational: requirements for nodes
|
||||||
requirements: [ socket ]
|
requirements: [ socket ]
|
||||||
|
@ -134,24 +143,47 @@ from time import sleep
|
||||||
|
|
||||||
|
|
||||||
def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=[], key=None, topic=None,
|
def send_msg(msg, server='localhost', port='6667', channel=None, nick_to=[], key=None, topic=None,
|
||||||
nick="ansible", color='none', passwd=False, timeout=30, use_ssl=False, part=True):
|
nick="ansible", color='none', passwd=False, timeout=30, use_ssl=False, part=True, style=None):
|
||||||
'''send message to IRC'''
|
'''send message to IRC'''
|
||||||
|
|
||||||
colornumbers = {
|
colornumbers = {
|
||||||
|
'white': "00",
|
||||||
'black': "01",
|
'black': "01",
|
||||||
|
'blue': "02",
|
||||||
|
'green': "03",
|
||||||
'red': "04",
|
'red': "04",
|
||||||
'green': "09",
|
'brown': "05",
|
||||||
|
'purple': "06",
|
||||||
|
'orange': "07",
|
||||||
'yellow': "08",
|
'yellow': "08",
|
||||||
'blue': "12",
|
'light_green': "09",
|
||||||
|
'teal': "10",
|
||||||
|
'light_cyan': "11",
|
||||||
|
'light_blue': "12",
|
||||||
|
'pink': "13",
|
||||||
|
'gray': "14",
|
||||||
|
'light_gray': "15",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stylechoices = {
|
||||||
|
'bold': "\x02",
|
||||||
|
'underline': "\x1F",
|
||||||
|
'reverse': "\x16",
|
||||||
|
'italic': "\x1D",
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
styletext = stylechoices[style]
|
||||||
|
except:
|
||||||
|
styletext = ""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
colornumber = colornumbers[color]
|
colornumber = colornumbers[color]
|
||||||
colortext = "\x03" + colornumber
|
colortext = "\x03" + colornumber
|
||||||
except:
|
except:
|
||||||
colortext = ""
|
colortext = ""
|
||||||
|
|
||||||
message = colortext + msg
|
message = styletext + colortext + msg
|
||||||
|
|
||||||
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
if use_ssl:
|
if use_ssl:
|
||||||
|
@ -219,8 +251,13 @@ def main():
|
||||||
nick=dict(default='ansible'),
|
nick=dict(default='ansible'),
|
||||||
nick_to=dict(required=False, type='list'),
|
nick_to=dict(required=False, type='list'),
|
||||||
msg=dict(required=True),
|
msg=dict(required=True),
|
||||||
color=dict(default="none", choices=["yellow", "red", "green",
|
color=dict(default="none", aliases=['colour'], choices=["white", "black", "blue",
|
||||||
"blue", "black", "none"]),
|
"green", "red", "brown",
|
||||||
|
"purple", "orange", "yellow",
|
||||||
|
"light_green", "teal", "light_cyan",
|
||||||
|
"light_blue", "pink", "gray",
|
||||||
|
"light_gray", "none"]),
|
||||||
|
style=dict(default="none", choices=["underline", "reverse", "bold", "italic", "none"]),
|
||||||
channel=dict(required=False),
|
channel=dict(required=False),
|
||||||
key=dict(),
|
key=dict(),
|
||||||
topic=dict(),
|
topic=dict(),
|
||||||
|
@ -248,9 +285,10 @@ def main():
|
||||||
timeout = module.params["timeout"]
|
timeout = module.params["timeout"]
|
||||||
use_ssl = module.params["use_ssl"]
|
use_ssl = module.params["use_ssl"]
|
||||||
part = module.params["part"]
|
part = module.params["part"]
|
||||||
|
style = module.params["style"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
send_msg(msg, server, port, channel, nick_to, key, topic, nick, color, passwd, timeout, use_ssl, part)
|
send_msg(msg, server, port, channel, nick_to, key, topic, nick, color, passwd, timeout, use_ssl, part, style)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
module.fail_json(msg="unable to send to IRC: %s" % e)
|
module.fail_json(msg="unable to send to IRC: %s" % e)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue