Updated Python plugin for API changes

This commit is contained in:
James Booth
2016-02-23 21:24:50 +00:00
parent 9e7f472b23
commit 0557eff53b
8 changed files with 99 additions and 132 deletions

View File

@@ -9,4 +9,13 @@ def _cmd_ascii(text):
prof.send_line(u'\u000A' + ascii_out)
def prof_init(version, status):
prof.register_command("/ascii", 1, 1, "/ascii", "ASCIIfy a message", "ASCIIfy a message.", _cmd_ascii)
synopsis = [ "/ascii <message>" ]
description = "ASCIIfy a message."
args = [
[ "<message>", "The message to be ASCIIfied" ]
]
examples = [
"/ascii \"Hello there\""
]
prof.register_command("/ascii", 1, 1, synopsis, description, args, examples, _cmd_ascii)

View File

@@ -57,12 +57,19 @@ def _open_browser(url):
def prof_init(version, status):
prof.register_command("/browser", 0, 1,
"/browser [url]",
"View a URL in the browser.",
"View a URL in the browser, if no argument is supplied, " +
"the last received URL will be used.",
_cmd_browser)
synopsis = [
"/browser",
"/browser <url>"
]
description = "View a URL in the systems default browser. If no argument is supplied, the last URL in the current chat or room will be used."
args = [
[ "<url>", "URL to open in the browser" ]
]
examples = [
"/browser http://www.profanity.im"
]
prof.register_command("/browser", 0, 1, synopsis, description, args, examples, _cmd_browser)
def prof_post_chat_message_display(jid, message):

View File

@@ -32,4 +32,15 @@ def _cmd_chatterbot(state):
prof.cons_show("ChatterBot is stopped - /chatterbot enable to activate.")
def prof_init(version, status):
prof.register_command("/chatterbot", 0, 1, "/chatterbot [enable|disable]", "ChatterBot", "ChatterBot", _cmd_chatterbot)
synopsis = [
"/chatterbot",
"/chatterbot enable|disable"
]
description = "ChatterBot"
args = [
[ "enable", "Enable chatterbot" ],
[ "disable", "Disable chatterbot" ]
]
examples = []
prof.register_command("/chatterbot", 0, 1, synopsis, description, args, examples, _cmd_chatterbot)

View File

@@ -1,101 +0,0 @@
import prof
import urllib2
import json
_score_url = "http://api.scorescard.com/?type=score&teamone=England&teamtwo=Sri%20Lanka"
_summary = None
def _cmd_cricket():
global _score_url
global _summary
new_summary = None
result_json = _retrieve_scores_json()
if (result_json):
if 'ms' in result_json.keys():
new_summary = result_json['ms']
prof.cons_show("")
prof.cons_show("Cricket score:")
if 't1FI' in result_json.keys():
prof.cons_show(" " + result_json['t1FI'])
if 't2FI' in result_json.keys():
prof.cons_show(" " + result_json['t2FI'])
if 't1SI' in result_json.keys():
prof.cons_show(" " + result_json['t1SI'])
if 't2SI' in result_json.keys():
prof.cons_show(" " + result_json['t2SI'])
_summary = new_summary
prof.cons_show("")
prof.cons_show(" " + _summary)
prof.cons_alert()
def _get_scores():
global _score_url
global _summary
notify = None
new_summary = None
change = False
result_json = _retrieve_scores_json()
if (result_json):
if 'ms' in result_json.keys():
new_summary = result_json['ms']
if new_summary != _summary:
change = True
if change:
prof.cons_show("")
prof.cons_show("Cricket score:")
if 't1FI' in result_json.keys():
notify = result_json['t1FI']
prof.cons_show(" " + result_json['t1FI'])
if 't2FI' in result_json.keys():
notify += "\n" + result_json['t2FI']
prof.cons_show(" " + result_json['t2FI'])
if 't1SI' in result_json.keys():
notify += "\n" + result_json['t1SI']
prof.cons_show(" " + result_json['t1SI'])
if 't2SI' in result_json.keys():
notify += "\n" + result_json['t2SI']
prof.cons_show(" " + result_json['t2SI'])
_summary = new_summary
notify += "\n\n" + _summary
prof.cons_show("")
prof.cons_show(" " + _summary)
prof.cons_alert()
prof.notify(notify, 5000, "Cricket score")
def _retrieve_scores_json():
req = urllib2.Request(_score_url, None, {'Content-Type': 'application/json'})
try:
f = urllib2.urlopen(req)
except:
prof.log_info("cricket-score.py: Error getting scores.")
return None
else:
response = f.read()
f.close()
return json.loads(response)
def prof_init(version, status):
if _score_url:
prof.register_timed(_get_scores, 60)
prof.register_command("/cricket", 0, 0,
"/cricket",
"Get latest cricket score.",
"Get latest cricket score.",
_cmd_cricket)
def prof_on_start():
if _score_url:
_get_scores()

View File

@@ -243,27 +243,27 @@ def _prof_callback():
for name in changes_list.get_in_state(STATE_QUEUED):
if not prof.win_exists(win_tag):
prof.win_create(win_tag, _handle_input)
prof.win_show_cyan(win_tag, name + " " + STATE_QUEUED)
prof.win_show_themed(win_tag, None, None, "cyan", name + " " + STATE_QUEUED)
for name in changes_list.get_in_state(STATE_RUNNING):
if not prof.win_exists(win_tag):
prof.win_create(win_tag, _handle_input)
prof.win_show_cyan(win_tag, name + " " + STATE_RUNNING)
prof.win_show_themed(win_tag, None, None, "cyan", name + " " + STATE_RUNNING)
for name, build_number in changes_list.get_in_state(STATE_SUCCESS):
if not prof.win_exists(win_tag):
prof.win_create(win_tag, _handle_input)
prof.win_show_green(win_tag, name + " #" + str(build_number) + " " + STATE_SUCCESS)
prof.win_show_themed(win_tag, None, None, "green", name + " #" + str(build_number) + " " + STATE_SUCCESS)
if enable_notify:
prof.notify(name + " " + STATE_SUCCESS, 5000, "Jenkins")
for name, build_number in changes_list.get_in_state(STATE_UNSTABLE):
if not prof.win_exists(win_tag):
prof.win_create(win_tag, _handle_input)
prof.win_show_yellow(win_tag, name + " #" + str(build_number) + " " + STATE_UNSTABLE)
prof.win_show_themed(win_tag, None, None, "yellow", name + " #" + str(build_number) + " " + STATE_UNSTABLE)
if enable_notify:
prof.notify(name + " " + STATE_UNSTABLE, 5000, "Jenkins")
for name, build_number in changes_list.get_in_state(STATE_FAILURE):
if not prof.win_exists(win_tag):
prof.win_create(win_tag, _handle_input)
prof.win_show_red(win_tag, name + " #" + str(build_number) + " " + STATE_FAILURE)
prof.win_show_themed(win_tag, None, None, "red", name + " #" + str(build_number) + " " + STATE_FAILURE)
if enable_notify:
prof.notify(name + " " + STATE_FAILURE, 5000, "Jenkins")
@@ -275,15 +275,15 @@ def _handle_input(win, line):
def _list_jobs(jobs):
for name, build_number, state in jobs:
if state == STATE_SUCCESS:
prof.win_show_green(win_tag, " " + name + " #" + str(build_number) + " " + STATE_SUCCESS)
prof.win_show_themed(win_tag, None, None, "green", " " + name + " #" + str(build_number) + " " + STATE_SUCCESS)
elif state == STATE_UNSTABLE:
prof.win_show_yellow(win_tag, " " + name + " #" + str(build_number) + " " + STATE_UNSTABLE)
prof.win_show_themed(win_tag, None, None, "yellow", " " + name + " #" + str(build_number) + " " + STATE_UNSTABLE)
elif state == STATE_FAILURE:
prof.win_show_red(win_tag, " " + name + " #" + str(build_number) + " " + STATE_FAILURE)
prof.win_show_themed(win_tag, None, None, "red", " " + name + " #" + str(build_number) + " " + STATE_FAILURE)
elif state == STATE_NOBUILDS:
prof.win_show(win_tag, " " + name + ", no builds")
else:
prof.win_show_cyan(win_tag, " " + name + " " + state)
prof.win_show_themed(win_tag, None, None, "cyan", " " + name + " " + state)
def _build_job(job):
try:
@@ -476,15 +476,36 @@ def prof_init(version, status):
"off"
]
);
prof.register_command(
"/jenkins",
0,
2,
"/jenkins",
"Do jenkins stuff.",
"Do jenkins stuff.",
_cmd_jenkins
)
synopsis = [
"/jenkins jobs|failing|passing|unstable",
"/jenkins build <job>",
"/jenkins open <job>",
"/jenkins log <job>",
"/jenkins remind on|off",
"/jenkins notify on|off",
"/jenkins settings"
]
description = "Monitor, run and view Jenkins jobs."
args = [
[ "jobs", "List all jobs" ],
[ "failing", "List all failing jobs" ],
[ "passing", "List all passing jobs" ],
[ "unstable", "List all unstable jobs" ],
[ "build <job>", "Trigger build for job" ],
[ "open <job>", "Open job in browser" ],
[ "log <job>", "Show the latest build log for job" ],
[ "remind on|off", "Enable/disable reminder notifications" ],
[ "notify on|off", "Enable/disable build notifications" ],
[ "settings", "Show current settings" ]
]
examples = [
"/kenkins failing",
"/kenkins build stabber-build",
"/kenkins remind off"
]
prof.register_command("/jenkins", 0, 2, synopsis, description, args, examples, _cmd_jenkins)
def prof_on_start():
prof.win_create(win_tag, _handle_input)

View File

@@ -6,4 +6,11 @@ def _cmd_platform():
prof.cons_show(result_summary)
def prof_init(version, status):
prof.register_command("/platform", 0, 0, "/platform", "Output system information.", "Output system information", _cmd_platform)
synopsis = [
"/platform"
]
description = "Output system information to the console window."
args = []
examples = []
prof.register_command("/platform", 0, 0, synopsis, description, args, examples, _cmd_platform)

12
say.py
View File

@@ -38,6 +38,14 @@ def _cmd_say(arg=None):
prof.cons_show("Usage: /say on|off")
def prof_init(version, status):
prof.register_command("/say", 1, 1, "/say on|pff", "Enable or disable say.", "Enable or disable say.",
_cmd_say)
synopsis = [
"/say on|off"
]
description = "Read all messages out loud"
args = [
[ "on|off", "Enable/disable say" ]
]
examples = []
prof.register_command("/say", 1, 1, synopsis, description, args, examples, _cmd_say)
prof.register_ac("/say", [ "on", "off" ])

View File

@@ -3,7 +3,12 @@ import getpass
def _cmd_whoami():
me = getpass.getuser()
prof.cons_show(me)
prof.cons_show_themed("whoami", "result", "bold_yellow", me)
def prof_init(version, status):
prof.register_command("/whoami", 0, 0, "/whoami", "Call shell whoami command.", "Call shell whoami command.", _cmd_whoami)
synopsis = [ "/whoami" ]
description = "Calls the system whoami command"
args = []
examples = []
prof.register_command("/whoami", 0, 0, synopsis, description, args, examples, _cmd_whoami)