mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added on_message_send hook
This commit is contained in:
parent
17013d1a05
commit
d6ad5735cb
@ -20,6 +20,12 @@ module RubyTest
|
|||||||
return message + "[RUBY]"
|
return message + "[RUBY]"
|
||||||
end
|
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()
|
def self.cmd_ruby()
|
||||||
return Proc.new { | msg |
|
return Proc.new { | msg |
|
||||||
if msg
|
if msg
|
||||||
|
@ -16,6 +16,11 @@ def prof_on_message_received(jid, message):
|
|||||||
prof.cons_alert()
|
prof.cons_alert()
|
||||||
return message + "[PYTHON]"
|
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):
|
def cmd_python(msg):
|
||||||
if msg:
|
if msg:
|
||||||
prof.cons_show("python-test: /python command called, arg = " + msg)
|
prof.cons_show("python-test: /python command called, arg = " + msg)
|
||||||
|
@ -31,4 +31,12 @@ prof_on_message_received (const char * const jid, const char *message)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
prof_on_message_send (const char * const jid, const char *message)
|
||||||
|
{
|
||||||
|
fprintf (stderr, "called %s with args=<%s, %s>\n", __func__, jid, message);
|
||||||
|
char *result = malloc(strlen(message) + 4);
|
||||||
|
sprintf(result, "%s%s", message, "[C]");
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@ -1166,16 +1166,27 @@ cmd_execute_default(const char * const inp)
|
|||||||
if (status != JABBER_CONNECTED) {
|
if (status != JABBER_CONNECTED) {
|
||||||
ui_current_print_line("You are not currently connected.");
|
ui_current_print_line("You are not currently connected.");
|
||||||
} else {
|
} else {
|
||||||
message_send(inp, recipient);
|
const char * recipient_jid = NULL;
|
||||||
|
if (roster_barejid_from_name(recipient) != NULL) {
|
||||||
|
recipient_jid = roster_barejid_from_name(recipient);
|
||||||
|
} else {
|
||||||
|
recipient_jid = recipient;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *new_message = plugins_on_message_send(recipient_jid, inp);
|
||||||
|
|
||||||
|
message_send(new_message, recipient);
|
||||||
|
|
||||||
if (prefs_get_boolean(PREF_CHLOG)) {
|
if (prefs_get_boolean(PREF_CHLOG)) {
|
||||||
const char *jid = jabber_get_fulljid();
|
const char *jid = jabber_get_fulljid();
|
||||||
Jid *jidp = jid_create(jid);
|
Jid *jidp = jid_create(jid);
|
||||||
chat_log_chat(jidp->barejid, recipient, inp, PROF_OUT_LOG, NULL);
|
chat_log_chat(jidp->barejid, recipient, new_message, PROF_OUT_LOG, NULL);
|
||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
}
|
}
|
||||||
|
|
||||||
ui_outgoing_msg("me", recipient, inp);
|
ui_outgoing_msg("me", recipient, new_message);
|
||||||
|
|
||||||
|
free(new_message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -2201,16 +2212,20 @@ _cmd_msg(gchar **args, struct cmd_help_t help)
|
|||||||
usr_jid = usr;
|
usr_jid = usr;
|
||||||
}
|
}
|
||||||
if (msg != NULL) {
|
if (msg != NULL) {
|
||||||
message_send(msg, usr_jid);
|
char *new_message = plugins_on_message_send(usr_jid, msg);
|
||||||
ui_outgoing_msg("me", usr_jid, msg);
|
|
||||||
|
message_send(new_message, usr_jid);
|
||||||
|
ui_outgoing_msg("me", usr_jid, new_message);
|
||||||
|
|
||||||
if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) {
|
if (((win_type == WIN_CHAT) || (win_type == WIN_CONSOLE)) && prefs_get_boolean(PREF_CHLOG)) {
|
||||||
const char *jid = jabber_get_fulljid();
|
const char *jid = jabber_get_fulljid();
|
||||||
Jid *jidp = jid_create(jid);
|
Jid *jidp = jid_create(jid);
|
||||||
chat_log_chat(jidp->barejid, usr_jid, msg, PROF_OUT_LOG, NULL);
|
chat_log_chat(jidp->barejid, usr_jid, new_message, PROF_OUT_LOG, NULL);
|
||||||
jid_destroy(jidp);
|
jid_destroy(jidp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(new_message);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
} else {
|
} else {
|
||||||
const char * jid = NULL;
|
const char * jid = NULL;
|
||||||
|
@ -39,6 +39,7 @@ c_plugin_create(const char * const filename)
|
|||||||
plugin->on_start_func = c_on_start_hook;
|
plugin->on_start_func = c_on_start_hook;
|
||||||
plugin->on_connect_func = c_on_connect_hook;
|
plugin->on_connect_func = c_on_connect_hook;
|
||||||
plugin->on_message_received_func = c_on_message_received_hook;
|
plugin->on_message_received_func = c_on_message_received_hook;
|
||||||
|
plugin->on_message_send_func = c_on_message_send_hook;
|
||||||
|
|
||||||
g_string_free(path, TRUE);
|
g_string_free(path, TRUE);
|
||||||
|
|
||||||
@ -110,6 +111,21 @@ c_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const cha
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
c_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *message)
|
||||||
|
{
|
||||||
|
void * f = NULL;
|
||||||
|
char* (*func)(const char * const __jid, const char * __message);
|
||||||
|
assert (plugin && plugin->module);
|
||||||
|
|
||||||
|
if (NULL == (f = dlsym (plugin->module, "prof_on_message_send")))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
func = (char* (*)(const char * const, const char *)) f;
|
||||||
|
return func (jid, message);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
c_close_library (ProfPlugin * plugin)
|
c_close_library (ProfPlugin * plugin)
|
||||||
{
|
{
|
||||||
|
@ -9,6 +9,7 @@ void c_init_hook(ProfPlugin *plugin, const char * const version, const char * co
|
|||||||
void c_on_start_hook (ProfPlugin *plugin);
|
void c_on_start_hook (ProfPlugin *plugin);
|
||||||
void c_on_connect_hook (ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
|
void c_on_connect_hook (ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
|
||||||
char * c_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
char * c_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||||
|
char * c_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||||
void c_close_library (ProfPlugin * plugin);
|
void c_close_library (ProfPlugin * plugin);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -133,6 +133,27 @@ plugins_on_message_received(const char * const jid, const char *message)
|
|||||||
return curr_message;
|
return curr_message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
plugins_on_message_send(const char * const jid, const char *message)
|
||||||
|
{
|
||||||
|
GSList *curr = plugins;
|
||||||
|
char *new_message = NULL;
|
||||||
|
char *curr_message = strdup(message);
|
||||||
|
|
||||||
|
while (curr != NULL) {
|
||||||
|
ProfPlugin *plugin = curr->data;
|
||||||
|
new_message = plugin->on_message_send_func(plugin, jid, curr_message);
|
||||||
|
if (new_message != NULL) {
|
||||||
|
free(curr_message);
|
||||||
|
curr_message = strdup(new_message);
|
||||||
|
free(new_message);
|
||||||
|
}
|
||||||
|
curr = g_slist_next(curr);
|
||||||
|
}
|
||||||
|
|
||||||
|
return curr_message;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
plugins_shutdown(void)
|
plugins_shutdown(void)
|
||||||
{
|
{
|
||||||
|
@ -40,12 +40,15 @@ typedef struct prof_plugin_t {
|
|||||||
const char * const account_name, const char * const fulljid);
|
const char * const account_name, const char * const fulljid);
|
||||||
char* (*on_message_received_func)(struct prof_plugin_t* plugin,
|
char* (*on_message_received_func)(struct prof_plugin_t* plugin,
|
||||||
const char * const jid, const char * const message);
|
const char * const jid, const char * const message);
|
||||||
|
char* (*on_message_send_func)(struct prof_plugin_t* plugin,
|
||||||
|
const char * const jid, const char * const message);
|
||||||
} ProfPlugin;
|
} ProfPlugin;
|
||||||
|
|
||||||
void plugins_init(void);
|
void plugins_init(void);
|
||||||
void plugins_on_start(void);
|
void plugins_on_start(void);
|
||||||
void plugins_on_connect(const char * const account_name, const char * const fulljid);
|
void plugins_on_connect(const char * const account_name, const char * const fulljid);
|
||||||
char * plugins_on_message_received(const char * const jid, const char *message);
|
char * plugins_on_message_received(const char * const jid, const char *message);
|
||||||
|
char * plugins_on_message_send(const char * const jid, const char *message);
|
||||||
void plugins_shutdown(void);
|
void plugins_shutdown(void);
|
||||||
gboolean plugins_run_command(const char * const cmd);
|
gboolean plugins_run_command(const char * const cmd);
|
||||||
void plugins_run_timed(void);
|
void plugins_run_timed(void);
|
||||||
|
@ -60,6 +60,7 @@ python_plugin_create(const char * const filename)
|
|||||||
plugin->on_start_func = python_on_start_hook;
|
plugin->on_start_func = python_on_start_hook;
|
||||||
plugin->on_connect_func = python_on_connect_hook;
|
plugin->on_connect_func = python_on_connect_hook;
|
||||||
plugin->on_message_received_func = python_on_message_received_hook;
|
plugin->on_message_received_func = python_on_message_received_hook;
|
||||||
|
plugin->on_message_send_func = python_on_message_send_hook;
|
||||||
g_free(module_name);
|
g_free(module_name);
|
||||||
return plugin;
|
return plugin;
|
||||||
} else {
|
} else {
|
||||||
@ -150,6 +151,34 @@ python_on_message_received_hook(ProfPlugin *plugin, const char * const jid,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
python_on_message_send_hook(ProfPlugin *plugin, const char * const jid,
|
||||||
|
const char *message)
|
||||||
|
{
|
||||||
|
PyObject *p_args = Py_BuildValue("ss", jid, message);
|
||||||
|
PyObject *p_function;
|
||||||
|
|
||||||
|
PyObject *p_module = plugin->module;
|
||||||
|
if (PyObject_HasAttrString(p_module, "prof_on_message_send")) {
|
||||||
|
p_function = PyObject_GetAttrString(p_module, "prof_on_message_send");
|
||||||
|
python_check_error();
|
||||||
|
if (p_function && PyCallable_Check(p_function)) {
|
||||||
|
PyObject *result = PyObject_CallObject(p_function, p_args);
|
||||||
|
python_check_error();
|
||||||
|
Py_XDECREF(p_function);
|
||||||
|
if (result != Py_None) {
|
||||||
|
char *result_str = strdup(PyString_AsString(result));
|
||||||
|
Py_XDECREF(result);
|
||||||
|
return result_str;;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
python_check_error(void)
|
python_check_error(void)
|
||||||
{
|
{
|
||||||
|
@ -31,6 +31,7 @@ void python_init_hook(ProfPlugin *plugin, const char * const version, const char
|
|||||||
void python_on_start_hook(ProfPlugin *plugin);
|
void python_on_start_hook(ProfPlugin *plugin);
|
||||||
void python_on_connect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
|
void python_on_connect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
|
||||||
char * python_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
char * python_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||||
|
char * python_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||||
|
|
||||||
void python_check_error(void);
|
void python_check_error(void);
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ ruby_plugin_create(const char * const filename)
|
|||||||
plugin->on_start_func = ruby_on_start_hook;
|
plugin->on_start_func = ruby_on_start_hook;
|
||||||
plugin->on_connect_func = ruby_on_connect_hook;
|
plugin->on_connect_func = ruby_on_connect_hook;
|
||||||
plugin->on_message_received_func = ruby_on_message_received_hook;
|
plugin->on_message_received_func = ruby_on_message_received_hook;
|
||||||
|
plugin->on_message_send_func = ruby_on_message_send_hook;
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,6 +117,28 @@ ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
ruby_on_message_send_hook(ProfPlugin *plugin, const char * const jid,
|
||||||
|
const char *message)
|
||||||
|
{
|
||||||
|
VALUE v_jid = rb_str_new2(jid);
|
||||||
|
VALUE v_message = rb_str_new2(message);
|
||||||
|
|
||||||
|
VALUE module = (VALUE) plugin->module;
|
||||||
|
if (_method_exists(plugin, "prof_on_message_send")) {
|
||||||
|
VALUE result = rb_funcall(module, rb_intern("prof_on_message_send"), 2, v_jid, v_message);
|
||||||
|
if (TYPE(result) != T_NIL) {
|
||||||
|
char *result_str = STR2CSTR(result);
|
||||||
|
rb_gc_unregister_address(&result);
|
||||||
|
return result_str;
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ruby_check_error(void)
|
ruby_check_error(void)
|
||||||
{
|
{
|
||||||
|
@ -31,6 +31,7 @@ void ruby_init_hook(ProfPlugin *plugin, const char * const version, const char *
|
|||||||
void ruby_on_start_hook(ProfPlugin *plugin);
|
void ruby_on_start_hook(ProfPlugin *plugin);
|
||||||
void ruby_on_connect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
|
void ruby_on_connect_hook(ProfPlugin *plugin, const char * const account_name, const char * const fulljid);
|
||||||
char * ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
char * ruby_on_message_received_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||||
|
char * ruby_on_message_send_hook(ProfPlugin *plugin, const char * const jid, const char *message);
|
||||||
|
|
||||||
void ruby_check_error(void);
|
void ruby_check_error(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user