Fixed all plugins (excl lua) to work with new hooks

This commit is contained in:
James Booth
2014-10-30 00:20:19 +00:00
parent b9f69dcda6
commit 35e274a2ba
7 changed files with 229 additions and 140 deletions

View File

@@ -53,7 +53,7 @@ def prof_init(version, status):
"the last received URL will be used.", "the last received URL will be used.",
_cmd_browser) _cmd_browser)
def prof_on_message_received(jid, message): def prof_post_chat_message_display(jid, message):
global _lastlink global _lastlink
links = re.findall(r'(https?://\S+)', message) links = re.findall(r'(https?://\S+)', message)
if (len(links) > 0): if (len(links) > 0):

View File

@@ -8,5 +8,11 @@ def _emote(input_str):
result = result.replace(":(", u'\u2639') result = result.replace(":(", u'\u2639')
return result return result
def prof_before_message_displayed(message): def prof_pre_chat_message_display(jid, message):
return _emote(message)
def prof_pre_room_message_display(room, nick, message):
return _emote(message)
def prof_pre_priv_message_display(room, nick, message):
return _emote(message) return _emote(message)

View File

@@ -12,7 +12,7 @@ all: pid.so
%.o:%.c %.o:%.c
$(CC) $(INCLUDE) -D_GNU_SOURCE -D_BSD_SOURCE -fpic -O3 -std=c99 \ $(CC) $(INCLUDE) -D_GNU_SOURCE -D_BSD_SOURCE -fpic -O3 -std=c99 \
-Wall -Wextra -pedantic -c -o $@ $< -Wextra -pedantic -c -o $@ $<
clean: clean:
$(RM) pid.so $(RM) pid.so

10
say.py
View File

@@ -1,26 +1,26 @@
import prof import prof
import os import os
on_message = False on_message = True
def prof_on_message_received(jid, message): def prof_post_chat_message_display(jid, message):
if on_message: if on_message:
os.system("say \"" + jid + " says " + message + "\" 2>/dev/null") os.system("say \"" + jid + " says " + message + "\" 2>/dev/null")
return message return message
def prof_on_room_message_received(room, nick, message): def prof_post_room_message_display(room, nick, message):
if on_message: if on_message:
os.system("say \"" + nick + " says " + message + " in " + room + "\" 2>/dev/null") os.system("say \"" + nick + " says " + message + " in " + room + "\" 2>/dev/null")
return message return message
def prof_on_private_message_received(room, nick, message): def prof_post_priv_message_display(room, nick, message):
if on_message: if on_message:
os.system("say \"" + nick + " says " + message + "\" 2>/dev/null") os.system("say \"" + nick + " says " + message + "\" 2>/dev/null")
return message return message
def _cmd_say(msg=None): def _cmd_say(msg=None):
if msg: if msg:
os.system("say \"" + msg + "\" &2>/dev/null") os.system("say \"" + msg + "\" 2>/dev/null")
def prof_init(version, status): def prof_init(version, status):
prof.register_command("/say", 0, 1, "/say message", "Say something.", "Say something.", prof.register_command("/say", 0, 1, "/say message", "Say something.", "Say something.",

View File

@@ -19,7 +19,7 @@ def _cmd_python(msg):
prof.cons_show("python-test: /python command called with no arg") prof.cons_show("python-test: /python command called with no arg")
def _cmd_ac(arg1=None, arg2=None): def _cmd_ac(arg1=None, arg2=None):
prof.cons_show("python-test: /py_complete called"); prof.cons_show("python-test: /py_complete called")
def _cmd_upper(line): def _cmd_upper(line):
win_tag = "Python Plugin" win_tag = "Python Plugin"

View File

@@ -12,7 +12,7 @@ all: test-c-plugin.so
%.o:%.c %.o:%.c
$(CC) $(INCLUDE) -D_GNU_SOURCE -D_BSD_SOURCE -fpic -O3 -std=c99 \ $(CC) $(INCLUDE) -D_GNU_SOURCE -D_BSD_SOURCE -fpic -O3 -std=c99 \
-Wall -Wextra -pedantic -c -o $@ $< -pedantic -c -o $@ $<
clean: clean:
$(RM) test-c-plugin.so $(RM) test-c-plugin.so

View File

@@ -2,28 +2,12 @@
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <ctype.h>
#include <profapi.h> #include <profapi.h>
static PROF_WIN_TAG echo_win = "Reverse Echo"; static PROF_WIN_TAG echo_win = "Reverse Echo";
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 void
timer_test(void) timer_test(void)
{ {
@@ -38,38 +22,80 @@ timer_test(void)
prof_cons_alert(); prof_cons_alert();
} }
void char*
handle_reverse(PROF_WIN_TAG win, char *line) convert_to_upper(char *str) {
{ char *newstr = strdup(str);
int len = strlen(line); char *p = newstr;
char buf[len];
int i = len; while (*p != '\0') {
int pos = 0; *p = toupper(*p);
for (i = len-1; i >= 0; i--) { p++;
buf[pos] = line[i];
pos++;
} }
buf[pos] = '\0';
prof_win_show(win, buf); return newstr;
prof_win_show_red(win, "Red");
prof_win_show_yellow(win, "Yellow");
prof_win_show_green(win, "Green");
prof_win_show_cyan(win, "Cyan");
} }
void void
cmd_reverse(char **args) handle_upper(PROF_WIN_TAG win, char *line)
{
char *upper = convert_to_upper(line);
prof_win_show(win, upper);
char buf[strlen(upper) + 8];
sprintf(buf, "%s %s", upper, "red");
prof_win_show_red(win, buf);
sprintf(buf, "%s %s", upper, "yellow");
prof_win_show_yellow(win, buf);
sprintf(buf, "%s %s", upper, "green");
prof_win_show_green(win, buf);
sprintf(buf, "%s %s", upper, "cyan");
prof_win_show_cyan(win, buf);
free(upper);
}
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");
}
}
void
cmd_ac(char **args) {
prof_cons_show("c-test: /c_complete called");
}
void
cmd_upper(char **args)
{ {
if (!prof_win_exists(echo_win)) { if (!prof_win_exists(echo_win)) {
prof_win_create(echo_win, handle_reverse); prof_win_create(echo_win, handle_upper);
} }
prof_win_focus(echo_win); prof_win_focus(echo_win);
if (args[0] != NULL) { if (args[0] != NULL) {
handle_reverse(echo_win, args[0]); handle_upper(echo_win, args[0]);
} }
} }
void
cmd_notification(char **args) {
prof_notify("c-test: notify", 2000, "Plugins");
}
void
cmd_verchecker(char **args) {
prof_send_line("/vercheck");
prof_cons_show("c-test: sent \"/vercheck\" command");
}
void void
prof_init(const char * const version, const char * const status) prof_init(const char * const version, const char * const status)
{ {
@@ -77,34 +103,40 @@ prof_init(const char * const version, const char * const status)
char buf[strlen(start) + strlen(version) + 2 + strlen(status) + 1]; char buf[strlen(start) + strlen(version) + 2 + strlen(status) + 1];
sprintf(buf, "%s%s, %s", start, version, status); sprintf(buf, "%s%s, %s", start, version, status);
prof_cons_show(buf); prof_cons_show(buf);
prof_register_command("/c", 0, 1, "/c [arg]", "c test", "c test", cmd_c);
prof_register_command("/c", 0, 1, "/c", "c test", "c test", cmd_c); prof_register_command("/c_upper", 1, 1, "/c_upper", "c test", "c test", cmd_upper);
prof_register_command("/c_notify", 0, 0, "/c_notify", "c test", "c test", cmd_notification);
prof_register_command("/reverse", 0, 1, "/reverse", "Reverse input string", "Reverse input string", cmd_reverse); prof_register_command("/c_vercheck", 0, 0, "/c_vercheck", "c test", "c test", cmd_verchecker);
char *arg1_ac[] = { "aaaa", "bbbb", "bcbcbc", NULL };
char *arg_ac[] = { "one", "two", "three", NULL }; char *arg2_ac1[] = { "one", "two", "three", "four", NULL };
prof_register_ac("/ccomplete", arg_ac); char *arg1_ac2[] = { "james", "jim", "jane", "bob", NULL };
char *arg_one_ac[] = { "james", "bob", "jenny", "steven", NULL }; prof_register_ac("/c_complete", arg1_ac);
prof_register_ac("/ccomplete one", arg_one_ac); prof_register_ac("/c_complete aaaa", arg2_ac1);
prof_register_command("/ccomplete", 0, 2, "/ccomplete", "C completion", "C completion", cmd_reverse); prof_register_ac("/c_complete bcbcbc", arg1_ac2);
prof_register_command("/c_complete", 0, 2, "/c_complete [arg1] [arg2]", "c test", "c test", cmd_ac);
prof_register_timed(timer_test, 10); prof_register_timed(timer_test, 30);
} }
void void
prof_on_start(void) prof_on_start(void)
{ {
prof_cons_show("c-test: on_start"); prof_cons_show("c-test: prof_on_start");
prof_log_debug("c-test: logged debug"); prof_log_debug("c-test: logged debug");
prof_log_info("c-test: logged info"); prof_log_info("c-test: logged info");
prof_log_warning("c-test: logged warning"); prof_log_warning("c-test: logged warning");
prof_log_error("c-test: logged error"); prof_log_error("c-test: logged error");
} }
void
prof_on_shutdown(void)
{
prof_log_info("c-test: prof_on_shutdown");
}
void void
prof_on_connect(const char * const account_name, const char * const fulljid) prof_on_connect(const char * const account_name, const char * const fulljid)
{ {
char *start = "c-test: on_connect, "; char *start = "c-test: prof_on_connect, ";
char buf[strlen(start) + strlen(account_name) + 2 + strlen(fulljid) + 1]; char buf[strlen(start) + strlen(account_name) + 2 + strlen(fulljid) + 1];
sprintf(buf, "%s%s, %s", start, account_name, fulljid); sprintf(buf, "%s%s, %s", start, account_name, fulljid);
prof_cons_show(buf); prof_cons_show(buf);
@@ -113,7 +145,7 @@ prof_on_connect(const char * const account_name, const char * const fulljid)
void void
prof_on_disconnect(const char * const account_name, const char * const fulljid) prof_on_disconnect(const char * const account_name, const char * const fulljid)
{ {
char *start = "c-test: on_disconnect, "; char *start = "c-test: prof_on_disconnect, ";
char buf[strlen(start) + strlen(account_name) + 2 + strlen(fulljid) + 1]; char buf[strlen(start) + strlen(account_name) + 2 + strlen(fulljid) + 1];
sprintf(buf, "%s%s, %s", start, account_name, fulljid); sprintf(buf, "%s%s, %s", start, account_name, fulljid);
prof_cons_show(buf); prof_cons_show(buf);
@@ -121,94 +153,145 @@ prof_on_disconnect(const char * const account_name, const char * const fulljid)
} }
char * char *
prof_on_message_received(const char * const jid, const char *message) prof_pre_chat_message_display(const char * const jid, const char *message)
{ {
char *start = "c-test: on_message_received, "; char *start = "c-test: prof_pre_chat_message_display, ";
char buf[strlen(start) + strlen(jid) + 2 + strlen(message) + 1]; char buf[strlen(start) + strlen(jid) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s", start, jid, message); sprintf(buf, "%s%s, %s", start, jid, message);
prof_cons_show(buf); prof_cons_show(buf);
prof_cons_alert(); prof_cons_alert();
char *result = malloc(strlen(message) + 4); char *result = malloc(strlen(message) + 29);
sprintf(result, "%s%s", message, "[C]"); sprintf(result, "%s%s", message, "[C_pre_chat_message_display]");
return result;
}
char *
prof_on_room_message_received(const char * const room, const char * const nick,
const char *message)
{
char *start = "c-test: on_room_message_received, ";
char buf[strlen(start) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", start, room, nick, 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_private_message_received(const char * const room, const char * const nick,
const char *message)
{
char *start = "c-test: on_private_message_received, ";
char buf[strlen(start) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", start, room, nick, 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;
}
char *
prof_on_private_message_send(const char * const room, const char * const nick,
const char *message)
{
char *start = "c-test: on_private_message_send, ";
char buf[strlen(start) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", start, room, nick, 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_room_message_send(const char * const room, const char *message)
{
char *start = "c-test: on_room_message_send, ";
char buf[strlen(start) + strlen(room) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s", start, room, message);
prof_cons_show(buf);
prof_cons_alert();
char *result = malloc(strlen(message) + 4);
sprintf(result, "%s%s", message, "[C]");
return result; return result;
} }
void void
prof_on_shutdown(void) prof_post_chat_message_display(const char * const jid, const char *message)
{ {
prof_log_info("c-test: on_shutdown"); char *start = "c-test: prof_post_chat_message_display, ";
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 *
prof_pre_chat_message_send(const char * const jid, const char *message)
{
char *start = "c-test: prof_pre_chat_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) + 26);
sprintf(result, "%s%s", message, "[C_pre_chat_message_send]");
return result;
}
void
prof_post_chat_message_send(const char * const jid, const char *message)
{
char *start = "c-test: prof_post_chat_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 *
prof_pre_room_message_display(const char * const room, const char * const nick, const char *message)
{
char *start = "c-test: prof_pre_room_message_display, ";
char buf[strlen(start) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", start, room, nick, message);
prof_cons_show(buf);
prof_cons_alert();
char *result = malloc(strlen(message) + 29);
sprintf(result, "%s%s", message, "[C_pre_room_message_display]");
return result;
}
void
prof_post_room_message_display(const char * const room, const char * const nick, const char *message)
{
char *start = "c-test: prof_post_room_message_display, ";
char buf[strlen(start) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", start, room, nick, message);
prof_cons_show(buf);
prof_cons_alert();
}
char *
prof_pre_room_message_send(const char * const room, const char *message)
{
char *start = "c-test: prof_pre_room_message_display, ";
char buf[strlen(start) + strlen(room) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s", start, room, message);
prof_cons_show(buf);
prof_cons_alert();
char *result = malloc(strlen(message) + 26);
sprintf(result, "%s%s", message, "[C_pre_room_message_send]");
return result;
}
void
prof_post_room_message_send(const char * const room, const char *message)
{
char *start = "c-test: prof_post_room_message_display, ";
char buf[strlen(start) + strlen(room) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s", start, room, message);
prof_cons_show(buf);
prof_cons_alert();
}
char *
prof_pre_priv_message_display(const char * const room, const char * const nick, const char *message)
{
char *start = "c-test: prof_pre_priv_message_display, ";
char buf[strlen(start) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", start, room, nick, message);
prof_cons_show(buf);
prof_cons_alert();
char *result = malloc(strlen(message) + 29);
sprintf(result, "%s%s", message, "[C_pre_priv_message_display]");
return result;
}
void
prof_post_priv_message_display(const char * const room, const char * const nick, const char *message)
{
char *start = "c-test: prof_post_priv_message_display, ";
char buf[strlen(start) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", start, room, nick, message);
prof_cons_show(buf);
prof_cons_alert();
}
char *
prof_pre_priv_message_send(const char * const room, const char * const nick, const char *message)
{
char *start = "c-test: prof_pre_priv_message_send, ";
char buf[strlen(start) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", start, room, nick, message);
prof_cons_show(buf);
prof_cons_alert();
char *result = malloc(strlen(message) + 26);
sprintf(result, "%s%s", message, "[C_pre_priv_message_send]");
return result;
}
void
prof_post_priv_message_send(const char * const room, const char * const nick, const char *message)
{
char *start = "c-test: prof_post_priv_message_send, ";
char buf[strlen(start) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", start, room, nick, message);
prof_cons_show(buf);
prof_cons_alert();
}