1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'muc-hooks'

This commit is contained in:
James Booth 2016-04-15 22:58:32 +01:00
commit 6cc04bc3ba
6 changed files with 91 additions and 1 deletions

View File

@ -211,6 +211,42 @@ api_get_current_muc(void)
} }
} }
char *
api_get_current_nick(void)
{
ProfWin *current = wins_get_current();
if (current->type == WIN_MUC) {
ProfMucWin *mucwin = (ProfMucWin*)current;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
return muc_nick(mucwin->roomjid);
} else {
return NULL;
}
}
char**
api_get_current_occupants(void)
{
ProfWin *current = wins_get_current();
if (current->type == WIN_MUC) {
ProfMucWin *mucwin = (ProfMucWin*)current;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
GList *occupants_list = muc_roster(mucwin->roomjid);
char **result = malloc((g_list_length(occupants_list) + 1) * sizeof(char*));
GList *curr = occupants_list;
int i = 0;
while (curr) {
Occupant *occupant = curr->data;
result[i++] = strdup(occupant->nick);
curr = g_list_next(curr);
}
result[i] = NULL;
return result;
} else {
return NULL;
}
}
int int
api_current_win_is_console(void) api_current_win_is_console(void)
{ {

View File

@ -47,6 +47,8 @@ void api_send_line(char *line);
char * api_get_current_recipient(void); char * api_get_current_recipient(void);
char * api_get_current_muc(void); char * api_get_current_muc(void);
gboolean api_current_win_is_console(void); gboolean api_current_win_is_console(void);
char* api_get_current_nick(void);
char** api_get_current_occupants(void);
void api_register_command(const char *command_name, int min_args, int max_args, void api_register_command(const char *command_name, int min_args, int max_args,
const char **synopsis, const char *description, const char *arguments[][2], const char **examples, const char **synopsis, const char *description, const char *arguments[][2], const char **examples,

View File

@ -139,11 +139,23 @@ c_api_get_current_muc(void)
} }
static int static int
c_api_current_win_is_console() c_api_current_win_is_console(void)
{ {
return api_current_win_is_console(); return api_current_win_is_console();
} }
static char*
c_api_get_current_nick(void)
{
return api_get_current_nick();
}
static char**
c_api_get_current_occupants(void)
{
return api_get_current_occupants();
}
static void static void
c_api_log_debug(const char *message) c_api_log_debug(const char *message)
{ {
@ -289,6 +301,8 @@ c_api_init(void)
prof_get_current_recipient = c_api_get_current_recipient; prof_get_current_recipient = c_api_get_current_recipient;
prof_get_current_muc = c_api_get_current_muc; prof_get_current_muc = c_api_get_current_muc;
prof_current_win_is_console = c_api_current_win_is_console; prof_current_win_is_console = c_api_current_win_is_console;
prof_get_current_nick = c_api_get_current_nick;
prof_get_current_occupants = c_api_get_current_occupants;
prof_log_debug = c_api_log_debug; prof_log_debug = c_api_log_debug;
prof_log_info = c_api_log_info; prof_log_info = c_api_log_info;
prof_log_warning = c_api_log_warning; prof_log_warning = c_api_log_warning;

View File

@ -59,6 +59,8 @@ void (*prof_send_line)(char *line) = NULL;
char* (*prof_get_current_recipient)(void) = NULL; char* (*prof_get_current_recipient)(void) = NULL;
char* (*prof_get_current_muc)(void) = NULL; char* (*prof_get_current_muc)(void) = NULL;
int (*prof_current_win_is_console)(void) = NULL; int (*prof_current_win_is_console)(void) = NULL;
char* (*prof_get_current_nick)(void) = NULL;
char** (*prof_get_current_occupants)(void) = NULL;
void (*prof_log_debug)(const char *message) = NULL; void (*prof_log_debug)(const char *message) = NULL;
void (*prof_log_info)(const char *message) = NULL; void (*prof_log_info)(const char *message) = NULL;

View File

@ -59,6 +59,8 @@ void (*prof_send_line)(char *line);
char* (*prof_get_current_recipient)(void); char* (*prof_get_current_recipient)(void);
char* (*prof_get_current_muc)(void); char* (*prof_get_current_muc)(void);
int (*prof_current_win_is_console)(void); int (*prof_current_win_is_console)(void);
char* (*prof_get_current_nick)(void);
char** (*prof_get_current_occupants)(void);
void (*prof_log_debug)(const char *message); void (*prof_log_debug)(const char *message);
void (*prof_log_info)(const char *message); void (*prof_log_info)(const char *message);

View File

@ -316,6 +316,38 @@ python_api_get_current_muc(PyObject *self, PyObject *args)
} }
} }
static PyObject *
python_api_get_current_nick(PyObject *self, PyObject *args)
{
allow_python_threads();
char *nick = api_get_current_nick();
disable_python_threads();
if (nick) {
return Py_BuildValue("s", nick);
} else {
return Py_BuildValue("");
}
}
static PyObject*
python_api_get_current_occupants(PyObject *self, PyObject *args)
{
allow_python_threads();
char **occupants = api_get_current_occupants();
disable_python_threads();
PyObject *result = PyList_New(0);
if (occupants) {
int len = g_strv_length(occupants);
int i = 0;
for (i = 0; i < len; i++) {
PyList_Append(result, Py_BuildValue("s", occupants[i]));
}
return result;
} else {
return result;
}
}
static PyObject* static PyObject*
python_api_current_win_is_console(PyObject *self, PyObject *args) python_api_current_win_is_console(PyObject *self, PyObject *args)
{ {
@ -714,6 +746,8 @@ static PyMethodDef apiMethods[] = {
{ "notify", python_api_notify, METH_VARARGS, "Send desktop notification." }, { "notify", python_api_notify, METH_VARARGS, "Send desktop notification." },
{ "get_current_recipient", python_api_get_current_recipient, METH_VARARGS, "Return the jid of the recipient of the current window." }, { "get_current_recipient", python_api_get_current_recipient, METH_VARARGS, "Return the jid of the recipient of the current window." },
{ "get_current_muc", python_api_get_current_muc, METH_VARARGS, "Return the jid of the room of the current window." }, { "get_current_muc", python_api_get_current_muc, METH_VARARGS, "Return the jid of the room of the current window." },
{ "get_current_nick", python_api_get_current_nick, METH_VARARGS, "Return nickname in current room." },
{ "get_current_occupants", python_api_get_current_occupants, METH_VARARGS, "Return list of occupants in current room." },
{ "current_win_is_console", python_api_current_win_is_console, METH_VARARGS, "Returns whether the current window is the console." }, { "current_win_is_console", python_api_current_win_is_console, METH_VARARGS, "Returns whether the current window is the console." },
{ "log_debug", python_api_log_debug, METH_VARARGS, "Log a debug message" }, { "log_debug", python_api_log_debug, METH_VARARGS, "Log a debug message" },
{ "log_info", python_api_log_info, METH_VARARGS, "Log an info message" }, { "log_info", python_api_log_info, METH_VARARGS, "Log an info message" },