Got on_msg_receive working
This commit is contained in:
parent
a240097bbb
commit
3f2c13b93f
3
main.c
3
main.c
@ -604,6 +604,9 @@ void args_parse (int argc, char **argv) {
|
|||||||
#ifdef USE_LUA
|
#ifdef USE_LUA
|
||||||
"s:"
|
"s:"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef USE_PYTHON
|
||||||
|
"Z:"
|
||||||
|
#endif
|
||||||
|
|
||||||
)) != -1) {
|
)) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
|
@ -10,7 +10,7 @@ def on_our_id():
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def on_msg_receive(msg):
|
def on_msg_receive(msg):
|
||||||
return "Got msg!"
|
return "Got msg from " + msg["from"]["peer"]["first_name"]
|
||||||
|
|
||||||
def on_secret_chat_update(peer, types):
|
def on_secret_chat_update(peer, types):
|
||||||
return "on_secret_chat_update"
|
return "on_secret_chat_update"
|
13
python-tg.c
13
python-tg.c
@ -422,7 +422,7 @@ void py_new_msg (struct tgl_message *M) {
|
|||||||
|
|
||||||
msg = get_message (M);
|
msg = get_message (M);
|
||||||
|
|
||||||
arglist = Py_BuildValue("O", msg);
|
arglist = Py_BuildValue("(O)", msg);
|
||||||
result = PyEval_CallObject(_py_new_msg, arglist);
|
result = PyEval_CallObject(_py_new_msg, arglist);
|
||||||
Py_DECREF(arglist);
|
Py_DECREF(arglist);
|
||||||
|
|
||||||
@ -438,7 +438,7 @@ void py_secret_chat_update (struct tgl_secret_chat *C, unsigned flags) {
|
|||||||
peer = get_peer (C->id, (void *)C);
|
peer = get_peer (C->id, (void *)C);
|
||||||
types = get_update_types (flags);
|
types = get_update_types (flags);
|
||||||
|
|
||||||
arglist = Py_BuildValue("OO", peer, types);
|
arglist = Py_BuildValue("(OO)", peer, types);
|
||||||
result = PyEval_CallObject(_py_secret_chat_update, arglist);
|
result = PyEval_CallObject(_py_secret_chat_update, arglist);
|
||||||
Py_DECREF(arglist);
|
Py_DECREF(arglist);
|
||||||
|
|
||||||
@ -1462,11 +1462,8 @@ void py_chat_update (struct tgl_chat *C, unsigned flags) {
|
|||||||
//}
|
//}
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
static void my_python_register (PyObject *dict, const char *name, PyObject *f) {
|
#define my_python_register(dict, name, f) \
|
||||||
// Store callables for python functions
|
|
||||||
f = PyDict_GetItemString(dict, name);
|
f = PyDict_GetItemString(dict, name);
|
||||||
assert(PyCallable_Check(f)); // TODO handle this
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -1479,6 +1476,10 @@ void py_init (const char *file) {
|
|||||||
|
|
||||||
Py_Initialize();
|
Py_Initialize();
|
||||||
|
|
||||||
|
PyObject* sysPath = PySys_GetObject((char*)"path");
|
||||||
|
PyList_Append(sysPath, PyString_FromString("."));
|
||||||
|
|
||||||
|
|
||||||
pName = PyString_FromString(file);
|
pName = PyString_FromString(file);
|
||||||
pModule = PyImport_Import(pName);
|
pModule = PyImport_Import(pName);
|
||||||
pDict = PyModule_GetDict(pModule);
|
pDict = PyModule_GetDict(pModule);
|
||||||
|
Loading…
Reference in New Issue
Block a user