commit 54417a9ed2aa9348a9aa04f37c9347ea8593e5a1 Author: James Booth Date: Sun Sep 1 16:44:19 2013 +0100 Initial commit diff --git a/ChatStart.rb b/ChatStart.rb new file mode 100644 index 0000000..3d77270 --- /dev/null +++ b/ChatStart.rb @@ -0,0 +1,14 @@ +module ChatStart + + @@contacts = [ + "\"Prof 2\"", + "prof3@panesar" + ] + + def self.prof_on_connect() + @@contacts.each { | contact | + Prof::send_line("/msg " + contact) + } + Prof::send_line("/win 1") + end +end diff --git a/RubyTest.rb b/RubyTest.rb new file mode 100644 index 0000000..0444af4 --- /dev/null +++ b/RubyTest.rb @@ -0,0 +1,53 @@ +module RubyTest + + def self.prof_init(version, status) + Prof::cons_show("RubyTest: init, " + version + ", " + status) + Prof::register_command("/ruby", 0, 1, "/ruby", "RubyTest", "RubyTest", cmd_ruby) + Prof::register_timed(timer_test, 10) + end + + def self.prof_on_start() + Prof::cons_show("RubyTest: on_start") + end + + def self.prof_on_connect(account_name, fulljid) + Prof::cons_show("RubyTest: on_connect, " + account_name + ", " + fulljid) + end + + def self.prof_on_message_received(jid, message) + Prof::cons_show("RubyTest: on_message_received, " + jid + ", " + message) + Prof::cons_alert + return message + "[RUBY]" + end + + def self.prof_on_message_send(jid, message) + Prof::cons_show("RubyTest: on_message_send, " + jid + ", " + message) + Prof::cons_alert + return message + "[RUBY]" + end + + def self.cmd_ruby() + return Proc.new { | msg | + if msg + Prof::cons_show("RubyTest: /ruby command called, arg = " + msg) + else + Prof::cons_show("RubyTest: /ruby command called with no arg") + end + Prof::cons_alert + Prof::notify("RubyTest: notify", 2000, "Plugins") + Prof::send_line("/help") + Prof::cons_show("RubyTest: sent \"/help\" command") + } + end + + def self.timer_test() + return Proc.new { + Prof::cons_show("RubyTest: timer fired.") + recipient = Prof::get_current_recipient + if recipient + Prof::cons_show(" current recipient = " + recipient) + end + Prof::cons_alert + } + end +end diff --git a/ascii.py b/ascii.py new file mode 100644 index 0000000..e37ed10 --- /dev/null +++ b/ascii.py @@ -0,0 +1,12 @@ +import prof +import subprocess + +def prof_init(version, status): + prof.register_command("/ascii", 1, 1, "/ascii", "ASCIIfy a message", "ASCIIfy a message.", cmd_ascii) + +def cmd_ascii(text): + recipient = prof.get_current_recipient() + if recipient: + proc = subprocess.Popen(['figlet', '--', text], stdout=subprocess.PIPE) + ascii_out = proc.communicate()[0].decode('utf-8') + prof.send_line(u'\u000A' + ascii_out) diff --git a/browser.py b/browser.py new file mode 100644 index 0000000..5dab73d --- /dev/null +++ b/browser.py @@ -0,0 +1,60 @@ +import prof +import os +import webbrowser +import re + +lastlink = {} + +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) + +def prof_on_message_received(jid, message): + global lastlink + links = re.findall(r'(https?://\S+)', message) + if (len(links) > 0): + lastlink[jid] = links[len(links)-1] + +def cmd_browser(url): + global lastlink + link = None + + # use arg if supplied + if (url != None): + link = url + else: + jid = prof.get_current_recipient(); + + # check if in chat window + if (jid != None): + + # check for link from recipient + if jid in lastlink.keys(): + link = lastlink[jid] + else: + prof.cons_show("No links found from " + jid); + + # not in chat window + else: + prof.cons_show("You must supply a URL to the /browser command") + + # open the browser if link found + if (link != None): + prof.cons_show("Opening " + link + " in browser") + open_browser(link) + +def open_browser(url): + savout = os.dup(1) + saverr = os.dup(2) + os.close(1) + os.close(2) + os.open(os.devnull, os.O_RDWR) + try: + webbrowser.open(url, new=2) + finally: + os.dup2(savout, 1) + os.dup2(saverr, 2) diff --git a/connect.py b/connect.py new file mode 100644 index 0000000..2741cb9 --- /dev/null +++ b/connect.py @@ -0,0 +1,9 @@ +import prof + +user = "prof1@panesar" + +def prof_on_start(): + global user + prof.cons_show("") + prof.cons_show("Enter password for " + user) + prof.send_line("/connect " + user) diff --git a/cricket-score.py b/cricket-score.py new file mode 100644 index 0000000..125af83 --- /dev/null +++ b/cricket-score.py @@ -0,0 +1,97 @@ +import prof +import urllib2 +import json + +#score_url = "http://api.scorescard.com/?type=score&teamone=Australia&teamtwo=England" +score_url = None + +summary = None + +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() + +def cmd_cricket(): + global score_url + global summary + new_summary = None + + result_json = retrieve_scores_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 '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'}) + f = urllib2.urlopen(req) + response = f.read() + f.close() + return json.loads(response); diff --git a/platform-info.py b/platform-info.py new file mode 100644 index 0000000..8132c39 --- /dev/null +++ b/platform-info.py @@ -0,0 +1,9 @@ +import prof +import platform + +def prof_init(version, status): + prof.register_command("/platform", 0, 0, "/platform", "Output system information.", "Output system information", cmd_platform) + +def cmd_platform(): + result_summary = platform.platform() + prof.cons_show(result_summary) diff --git a/python-test.py b/python-test.py new file mode 100644 index 0000000..97fd979 --- /dev/null +++ b/python-test.py @@ -0,0 +1,40 @@ +import prof + +def prof_init(version, status): + prof.cons_show("python-test: init, " + version + ", " + status) + prof.register_command("/python", 0, 1, "/python", "python-test", "python-test", cmd_python) + prof.register_timed(timer_test, 10) + +def prof_on_start(): + prof.cons_show("python-test: on_start") + +def prof_on_connect(account_name, fulljid): + prof.cons_show("python-test: on_connect, " + account_name + ", " + fulljid) + +def prof_on_message_received(jid, message): + prof.cons_show("python-test: on_message_received, " + jid + ", " + message) + prof.cons_alert() + return message + "[PYTHON]" + +def prof_on_message_send(jid, message): + prof.cons_show("python-test: on_message_send, " + jid + ", " + message) + prof.cons_alert() + return message + "[PYTHON]" + +def cmd_python(msg): + if msg: + prof.cons_show("python-test: /python command called, arg = " + msg) + else: + prof.cons_show("python-test: /python command called with no arg") + prof.cons_alert() + prof.notify("python-test: notify", 2000, "Plugins") + prof.send_line("/vercheck") + prof.cons_show("python-test: sent \"/vercheck\" command") + +def timer_test(): + prof.cons_show("python-test: timer fired.") + recipient = prof.get_current_recipient() + if recipient: + prof.cons_show(" current recipient = " + recipient) + prof.cons_alert() + diff --git a/test-c-plugin/Makefile b/test-c-plugin/Makefile new file mode 100644 index 0000000..66ae3e6 --- /dev/null +++ b/test-c-plugin/Makefile @@ -0,0 +1,11 @@ +all: test-c-plugin.so + +%.so:%.o + $(CC) -shared -fpic -lprofanity -o $@ $^ + +%.o:%.c + $(CC) $(INCLUDE) -D_GNU_SOURCE -D_BSD_SOURCE -fpic -O3 -std=c99 \ + -Wall -Wextra -lprofanity -pedantic -c -o $@ $< + +clean: + $(RM) test-c-plugin.so diff --git a/test-c-plugin/test-c-plugin.c b/test-c-plugin/test-c-plugin.c new file mode 100644 index 0000000..852fcb3 --- /dev/null +++ b/test-c-plugin/test-c-plugin.c @@ -0,0 +1,91 @@ +#include +#include +#include +#include + +#include + +void +cmd_c(char **args) +{ + if (args[0] != NULL) { + char *start = "c-test: /c command called, arg = "; + char buf[strlen(start) + strlen(args[0]) + 1]; + sprintf(buf, "%s%s", start, args[0]); + prof_cons_show(buf); + } else { + prof_cons_show("c-test: /c command called with no arg"); + } + prof_cons_alert(); + prof_notify("c-test: notify", 2000, "Plugins"); + prof_send_line("/about"); + prof_cons_show("c-test: sent \"/about\" command"); +} + +void +timer_test(void) +{ + prof_cons_show("c-test: timer fired."); + char *recipient = prof_get_current_recipient(); + if (recipient != NULL) { + char *start = " current recipient = "; + char buf[strlen(start) + strlen(recipient) + 1]; + sprintf(buf, "%s%s", start, recipient); + prof_cons_show(buf); + } + prof_cons_alert(); +} + +void +prof_init(const char * const version, const char * const status) +{ + char *start = "c-test: init. "; + char buf[strlen(start) + strlen(version) + 2 + strlen(status) + 1]; + sprintf(buf, "%s%s, %s", start, version, status); + prof_cons_show(buf); + prof_register_command("/c", 0, 1, "/c", "c test", "c test", cmd_c); + prof_register_timed(timer_test, 10); +} + +void +prof_on_start(void) +{ + prof_cons_show("c-test: on_start"); +} + +void +prof_on_connect(const char * const account_name, const char * const fulljid) +{ + char *start = "c-test: on_connect, "; + char buf[strlen(start) + strlen(account_name) + 2 + strlen(fulljid) + 1]; + sprintf(buf, "%s%s, %s", start, account_name, fulljid); + prof_cons_show(buf); +} + +char * +prof_on_message_received(const char * const jid, const char *message) +{ + char *start = "c-test: on_message_received, "; + char buf[strlen(start) + strlen(jid) + 2 + strlen(message) + 1]; + sprintf(buf, "%s%s, %s", start, jid, message); + prof_cons_show(buf); + prof_cons_alert(); + char *result = malloc(strlen(message) + 4); + sprintf(result, "%s%s", message, "[C]"); + + return result; +} + +char * +prof_on_message_send(const char * const jid, const char *message) +{ + char *start = "c-test: on_message_send, "; + char buf[strlen(start) + strlen(jid) + 2 + strlen(message) + 1]; + sprintf(buf, "%s%s, %s", start, jid, message); + prof_cons_show(buf); + prof_cons_alert(); + char *result = malloc(strlen(message) + 4); + sprintf(result, "%s%s", message, "[C]"); + + return result; +} diff --git a/whoami.py b/whoami.py new file mode 100644 index 0000000..9d1b8aa --- /dev/null +++ b/whoami.py @@ -0,0 +1,9 @@ +import prof +import getpass + +def prof_init(version, status): + prof.register_command("/whoami", 0, 0, "/whoami", "Call shell whoami command.", "Call shell whoami command.", cmd_whoami) + +def cmd_whoami(): + me = getpass.getuser() + prof.cons_show(me)