Add pre chat a room message blocking

This commit is contained in:
James Booth
2017-01-22 16:00:58 +00:00
parent 9fb6ea1cf3
commit 4f9f513c08
2 changed files with 138 additions and 3 deletions

View File

@@ -2,9 +2,13 @@
#include <sys/types.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <profapi.h>
static char *chat_msg_hook = NULL;
static char *room_msg_hook = NULL;
void
cmd_enc(char **args)
{
@@ -71,6 +75,18 @@ cmd_enc(char **args)
} else if (args[0] && (strcmp(args[0], "room_show_themed") == 0)) {
prof_room_show_themed(args[1], "enc_c", "room_msg", NULL, "C", args[2]);
} else if (args[0] && (strcmp(args[0], "chat_msg") == 0)) {
if (chat_msg_hook) {
free(chat_msg_hook);
}
chat_msg_hook = strdup(args[1]);
} else if (args[0] && (strcmp(args[0], "room_msg") == 0)) {
if (room_msg_hook) {
free(room_msg_hook);
}
room_msg_hook = strdup(args[1]);
} else {
prof_cons_bad_cmd_usage("/enc_c");
}
@@ -95,6 +111,12 @@ prof_init(const char * const version, const char * const status, const char *con
"/enc_c room_ch reset <roomjid>",
"/enc_c room_show <roomjid> <message>",
"/enc_c room_show_themed <roomjid> <message>",
"/enc_c chat_msg none",
"/enc_c chat_msg modify",
"/enc_c chat_msg block",
"/enc_c room_msg none",
"/enc_c room_msg modify",
"/enc_c room_msg block",
NULL
};
char *description = "Various enc things";
@@ -114,13 +136,32 @@ prof_init(const char * const version, const char * const status, const char *con
{ "room_ch reset <roomjid>", "Reset char for room" },
{ "room_show <roomjid> <message>", "Show chat room message" },
{ "room_show_themed <roomjid> <message>", "Show themed chat room message" },
{ "chat_msg none", "Preserve chat messages" },
{ "chat_msg modify", "Modify chat messages" },
{ "chat_msg block", "Block chat messages" },
{ "room_msg none", "Preserve chat room messages" },
{ "room_msg modify", "Modify chat room messages" },
{ "room_msg block", "Block chat room messages" },
{ NULL, NULL }
};
char *examples[] = { NULL };
prof_register_command("/enc_c", 2, 5, synopsis, description, args, examples, cmd_enc);
char *cmd_ac[] = { "end", "chat_title", "chat_ch", "chat_show", "chat_show_themed", "room_title", "room_ch", "room_show", "room_show_themed", NULL };
char *cmd_ac[] = {
"end",
"chat_title",
"chat_ch",
"chat_show",
"chat_show_themed",
"room_title",
"room_ch",
"room_show",
"room_show_themed",
"chat_msg",
"room_msg",
NULL
};
prof_completer_add("/enc_c", cmd_ac);
char *chat_title_ac[] = { "set", "reset", NULL };
@@ -140,4 +181,40 @@ prof_init(const char * const version, const char * const status, const char *con
char *room_ch_ac[] = { "set", "reset", NULL };
prof_completer_add("/enc_c room_ch", room_ch_ac);
char *chat_msg_ac[] = { "none", "modify", "block", NULL };
prof_completer_add("/enc_c chat_msg", chat_msg_ac);
char *room_msg_ac[] = { "none", "modify", "block", NULL };
prof_completer_add("/enc_c room_msg", room_msg_ac);
}
char*
prof_pre_chat_message_send(const char * const barejid, const char *message)
{
if (chat_msg_hook && (strcmp(chat_msg_hook, "modify") == 0)) {
char buf[strlen("[c modified] ") + strlen(message) + 1];
sprintf(buf, "%s%s", "[c modified] ", message);
return strdup(buf);
} else if (chat_msg_hook && (strcmp(chat_msg_hook, "block") == 0)) {
prof_chat_show_themed(barejid, NULL, NULL, "bold_red", "!", "C plugin blocked message");
return NULL;
} else {
return strdup(message);
}
}
char*
prof_pre_room_message_send(const char * const roomjid, const char *message)
{
if (room_msg_hook && (strcmp(room_msg_hook, "modify") == 0)) {
char buf[strlen("[c modified] ") + strlen(message) + 1];
sprintf(buf, "%s%s", "[c modified] ", message);
return strdup(buf);
} else if (room_msg_hook && (strcmp(room_msg_hook, "block") == 0)) {
prof_room_show_themed(roomjid, NULL, NULL, "bold_red", "!", "C plugin blocked message");
return NULL;
} else {
return strdup(message);
}
}

View File

@@ -1,6 +1,12 @@
import prof
chat_msg_hook = None
room_msg_hook = None
def _cmd_enc(arg1=None, arg2=None, arg3=None, arg4=None, arg5=None):
global chat_msg_hook
global room_msg_hook
if arg1 == "end":
prof.encryption_reset(arg2)
@@ -46,6 +52,12 @@ def _cmd_enc(arg1=None, arg2=None, arg3=None, arg4=None, arg5=None):
elif arg1 == "room_show_themed":
prof.room_show_themed(arg2, "enc_py", "room_msg", None, "P", arg3)
elif arg1 == "chat_msg":
chat_msg_hook = arg2
elif arg1 == "room_msg":
room_msg_hook = arg2
else:
prof.cons_bad_cmd_usage("/enc_py")
@@ -67,6 +79,12 @@ def prof_init(version, status, account_name, fulljid):
"/enc_py room_ch reset <roomjid>",
"/enc_py room_show <roomjid> <message>",
"/enc_py room_show_themed <roomjid> <message>"
"/enc_py chat_msg none",
"/enc_py chat_msg modify",
"/enc_py chat_msg block",
"/enc_py room_msg none",
"/enc_py room_msg modify",
"/enc_py room_msg block"
]
description = "Various enc things"
args = [
@@ -84,16 +102,56 @@ def prof_init(version, status, account_name, fulljid):
[ "room_ch set <roomjid> <ch>", "Set char for room" ],
[ "room_ch reset <roomjid>", "Reset char for room" ],
[ "room_show <roomjid> <message>", "Show chat room message" ],
[ "room_show_themed <roomjid> <message>", "Show themed chat room message" ]
[ "room_show_themed <roomjid> <message>", "Show themed chat room message" ],
[ "chat_msg none", "Preserve chat messages" ],
[ "chat_msg modify", "Modify chat messages" ],
[ "chat_msg block", "Block chat messages" ],
[ "room_msg none", "Preserve chat room messages" ],
[ "room_msg modify", "Modify chat room messages" ],
[ "room_msg block", "Block chat room messages" ]
]
examples = []
prof.register_command("/enc_py", 2, 5, synopsis, description, args, examples, _cmd_enc)
prof.completer_add("/enc_py", [ "end", "chat_title", "chat_ch", "chat_show", "chat_show_themed", "room_title", "room_ch", "room_show", "room_show_themed" ])
prof.completer_add("/enc_py", [
"end",
"chat_title",
"chat_ch",
"chat_show",
"chat_show_themed",
"room_title",
"room_ch",
"room_show",
"room_show_themed",
"chat_msg",
"room_msg"
])
prof.completer_add("/enc_py chat_title", [ "set", "reset" ])
prof.completer_add("/enc_py chat_ch", [ "set", "reset" ])
prof.completer_add("/enc_py chat_ch set", [ "in", "out" ])
prof.completer_add("/enc_py chat_ch reset", [ "in", "out" ])
prof.completer_add("/enc_py room_title", [ "set", "reset" ])
prof.completer_add("/enc_py room_ch", [ "set", "reset" ])
prof.completer_add("/enc_py chat_msg", [ "none", "modify", "block" ])
prof.completer_add("/enc_py room_msg", [ "none", "modify", "block" ])
def prof_pre_chat_message_send(barejid, message):
if chat_msg_hook == "modify":
return "[py modified] " + message
elif chat_msg_hook == "block":
prof.chat_show_themed(barejid, None, None, "bold_red", "!", "Python plugin blocked message")
return None
else:
prof.log_info("none")
return message
def prof_pre_room_message_send(roomjid, message):
if room_msg_hook == "modify":
return "[py modified] " + message
elif room_msg_hook == "block":
prof.room_show_themed(roomjid, None, None, "bold_red", "!", "Python plugin blocked message")
return None
else:
return message