1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-22 13:13:03 +01:00

Added constants to the Python interface for calls to execute.

This commit is contained in:
jakob 2017-05-19 15:35:31 -04:00
parent 6d2b90ac9f
commit 5ed26eda9b
3 changed files with 18 additions and 3 deletions

View File

@ -52,7 +52,7 @@ Commands
========
.. function:: execute(command, class)
Execute the given command, where a class of 0 indicates a global command, 1 indicates a chat command, and 2 indicates a groupchat command.
Executes the given command. The API exports three constants for the class parameter; GLOBAL_COMMAND, CHAT_COMMAND, and GROUPCHAT_COMMAND.
:param command: The command to execute.
:type command: string

View File

@ -93,6 +93,10 @@ void api_send(const char *msg)
char *name = api_get_nick();
char timefrmt[TIME_STR_SIZE];
if (name == NULL)
return;
self_window = get_active_window();
get_time_str(timefrmt, sizeof(timefrmt));

View File

@ -23,6 +23,7 @@
#include <Python.h>
#include "api.h"
#include "execute.h"
extern Tox *user_tox;
@ -163,7 +164,7 @@ static PyObject *python_api_register(PyObject *self, PyObject *args)
return NULL;
if (!PyCallable_Check(callback)) {
PyErr_SetString(PyExc_TypeError, "Parameter must be callable");
PyErr_SetString(PyExc_TypeError, "Calback parameter must be callable");
return NULL;
}
@ -233,7 +234,17 @@ static struct PyModuleDef toxic_api_module = {
PyMODINIT_FUNC PyInit_toxic_api(void)
{
return PyModule_Create(&toxic_api_module);
PyObject *m = PyModule_Create(&toxic_api_module);
PyObject *global_command_const = Py_BuildValue("i", GLOBAL_COMMAND_MODE);
PyObject *chat_command_const = Py_BuildValue("i", CHAT_COMMAND_MODE);
PyObject *groupchat_command_const = Py_BuildValue("i", GROUPCHAT_COMMAND_MODE);
PyObject_SetAttrString(m, "GLOBAL_COMMAND", global_command_const);
PyObject_SetAttrString(m, "CHAT_COMMAND", chat_command_const);
PyObject_SetAttrString(m, "GROUPCHAT_COMMAND", groupchat_command_const);
Py_DECREF(global_command_const);
Py_DECREF(chat_command_const);
Py_DECREF(groupchat_command_const);
return m;
}
void terminate_python(void)