You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.7 KiB
58 lines
1.7 KiB
from .base import Command, Content
|
|
from ...exceptions import InvalidInput
|
|
|
|
|
|
def dialog(message, height=15, title="Message", width=100, **kwargs):
|
|
statement = list()
|
|
statement.append("dialog --clear")
|
|
statement.append('--backtitle "%s"' % title)
|
|
statement.append('--msgbox "%s" %s %s;' % (message, height, width))
|
|
statement.append("clear;")
|
|
|
|
return Command(" ".join(statement), **kwargs)
|
|
|
|
|
|
def echo(message, **kwargs):
|
|
return Command('echo "%s"' % message, **kwargs)
|
|
|
|
|
|
def explain(message, heading=None, **kwargs):
|
|
return Content("explain", message=message, heading=heading, **kwargs)
|
|
|
|
|
|
def screenshot(image, caption=None, height=None, width=None, **kwargs):
|
|
return Content("screenshot", caption=caption, height=height, image=image, width=width, **kwargs)
|
|
|
|
|
|
def slack(message, url=None, **kwargs):
|
|
if url is None:
|
|
raise InvalidInput("Slack command requires a url parameter.")
|
|
|
|
statement = list()
|
|
statement.append("curl -X POST -H 'Content-type: application/json' --data")
|
|
statement.append('\'{"text": "%s"}\'' % message)
|
|
statement.append(url)
|
|
|
|
return Command(statement, **kwargs)
|
|
|
|
|
|
def twist(message, title="Notice", url=None, **kwargs):
|
|
if url is None:
|
|
raise InvalidInput("Twist command requires a url parameter.")
|
|
|
|
statement = list()
|
|
statement.append("curl -X POST -H 'Content-type: application/json' --data")
|
|
statement.append('\'{"content": "%s", "title": "%s"}\'' % (message, title))
|
|
statement.append(url)
|
|
|
|
return Command(" ".join(statement), **kwargs)
|
|
|
|
|
|
MESSAGE_MAPPINGS = {
|
|
'dialog': dialog,
|
|
'echo': echo,
|
|
'explain': explain,
|
|
'screenshot': screenshot,
|
|
'slack': slack,
|
|
'twist': twist,
|
|
}
|
|
|