Initial commit
This commit is contained in:
14
ChatStart.rb
Normal file
14
ChatStart.rb
Normal file
@@ -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
|
||||||
53
RubyTest.rb
Normal file
53
RubyTest.rb
Normal file
@@ -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
|
||||||
12
ascii.py
Normal file
12
ascii.py
Normal file
@@ -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)
|
||||||
60
browser.py
Normal file
60
browser.py
Normal file
@@ -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)
|
||||||
9
connect.py
Normal file
9
connect.py
Normal file
@@ -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)
|
||||||
97
cricket-score.py
Normal file
97
cricket-score.py
Normal file
@@ -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);
|
||||||
9
platform-info.py
Normal file
9
platform-info.py
Normal file
@@ -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)
|
||||||
40
python-test.py
Normal file
40
python-test.py
Normal file
@@ -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()
|
||||||
|
|
||||||
11
test-c-plugin/Makefile
Normal file
11
test-c-plugin/Makefile
Normal file
@@ -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
|
||||||
91
test-c-plugin/test-c-plugin.c
Normal file
91
test-c-plugin/test-c-plugin.c
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <profapi.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user