Add additional peer functions

This commit is contained in:
Vincent Castellano 2015-05-21 23:27:28 -07:00
parent 99bf18283d
commit ce4d9aff00

View File

@ -391,16 +391,316 @@ tgl_Peer_send_msg (tgl_Peer *self, PyObject *args, PyObject *kwargs)
return py_send_msg(Py_None, api_call); return py_send_msg(Py_None, api_call);
} else { } else {
PyErr_Print();
Py_XINCREF(Py_False); Py_XINCREF(Py_False);
return Py_False; return Py_False;
} }
} }
static PyObject *
tgl_Peer_send_typing (tgl_Peer *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"callback", NULL};
PyObject *callback = NULL;
if(PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist, &callback)) {
PyObject *api_call;
if(callback)
api_call = Py_BuildValue("OO", (PyObject*) self, callback);
else
api_call = Py_BuildValue("O", (PyObject*) self);
Py_INCREF(Py_None);
Py_XINCREF(api_call);
return py_send_typing(Py_None, api_call);
} else {
PyErr_Print();
Py_XINCREF(Py_False);
return Py_False;
}
}
static PyObject *
tgl_Peer_send_typing_abort (tgl_Peer *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"callback", NULL};
PyObject *callback = NULL;
if(PyArg_ParseTupleAndKeywords(args, kwargs, "O!|O", kwlist, &callback)) {
PyObject *api_call;
if(callback)
api_call = Py_BuildValue("OO", (PyObject*) self, callback);
else
api_call = Py_BuildValue("O", (PyObject*) self);
Py_INCREF(Py_None);
Py_XINCREF(api_call);
return py_send_typing_abort(Py_None, api_call);
} else {
PyErr_Print();
Py_XINCREF(Py_False);
return Py_False;
}
}
static PyObject *
tgl_Peer_rename_chat (tgl_Peer *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"peer", "title", "callback", NULL};
char * title;
PyObject *callback = NULL;
if(self->peer->id.type != TGL_PEER_CHAT) {
PyErr_SetString(PeerError, "Only a chat peer can be renamed");
Py_XINCREF(Py_False);
return Py_False;
}
if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &title, &callback)) {
PyObject *api_call;
if(callback)
api_call = Py_BuildValue("OsO", (PyObject*) self, title, callback);
else
api_call = Py_BuildValue("Os", (PyObject*) self, title);
Py_INCREF(Py_None);
Py_XINCREF(api_call);
return py_rename_chat(Py_None, api_call);
} else {
PyErr_Print();
Py_XINCREF(Py_False);
return Py_False;
}
}
static PyObject *
tgl_Peer_send_photo (tgl_Peer *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"filename", "callback", NULL};
char *filename;
PyObject *callback = NULL;
if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &filename, &callback)) {
PyObject *api_call;
if(callback)
api_call = Py_BuildValue("OsO", (PyObject*) self, filename, callback);
else
api_call = Py_BuildValue("Os", (PyObject*) self, filename);
Py_INCREF(Py_None);
Py_XINCREF(api_call);
return py_send_photo(Py_None, api_call);
} else {
PyErr_Print();
Py_XINCREF(Py_False);
return Py_False;
}
}
static PyObject *
tgl_Peer_send_video (tgl_Peer *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"filename", "callback", NULL};
char *filename;
PyObject *callback = NULL;
if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &filename, &callback)) {
PyObject *api_call;
if(callback)
api_call = Py_BuildValue("OsO", (PyObject*) self, filename, callback);
else
api_call = Py_BuildValue("Os", (PyObject*) self, filename);
Py_INCREF(Py_None);
Py_XINCREF(api_call);
return py_send_video(Py_None, api_call);
} else {
PyErr_Print();
Py_XINCREF(Py_False);
return Py_False;
}
}
static PyObject *
tgl_Peer_send_audio (tgl_Peer *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"filename", "callback", NULL};
char *filename;
PyObject *callback = NULL;
if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &filename, &callback)) {
PyObject *api_call;
if(callback)
api_call = Py_BuildValue("OsO", (PyObject*) self, filename, callback);
else
api_call = Py_BuildValue("Os", (PyObject*) self, filename);
Py_INCREF(Py_None);
Py_XINCREF(api_call);
return py_send_audio(Py_None, api_call);
} else {
PyErr_Print();
Py_XINCREF(Py_False);
return Py_False;
}
}
static PyObject *
tgl_Peer_send_document (tgl_Peer *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"filename", "callback", NULL};
char *filename;
PyObject *callback = NULL;
if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &filename, &callback)) {
PyObject *api_call;
if(callback)
api_call = Py_BuildValue("OsO", (PyObject*) self, filename, callback);
else
api_call = Py_BuildValue("Os", (PyObject*) self, filename);
Py_INCREF(Py_None);
Py_XINCREF(api_call);
return py_send_document(Py_None, api_call);
} else {
PyErr_Print();
Py_XINCREF(Py_False);
return Py_False;
}
}
static PyObject *
tgl_Peer_send_file (tgl_Peer *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"filename", "callback", NULL};
char *filename;
PyObject *callback = NULL;
if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &filename, &callback)) {
PyObject *api_call;
if(callback)
api_call = Py_BuildValue("OsO", (PyObject*) self, filename, callback);
else
api_call = Py_BuildValue("Os", (PyObject*) self, filename);
Py_INCREF(Py_None);
Py_XINCREF(api_call);
return py_send_file(Py_None, api_call);
} else {
PyErr_Print();
Py_XINCREF(Py_False);
return Py_False;
}
}
static PyObject *
tgl_Peer_send_text (tgl_Peer *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"filename", "callback", NULL};
char *filename;
PyObject *callback = NULL;
if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &filename, &callback)) {
PyObject *api_call;
if(callback)
api_call = Py_BuildValue("OsO", (PyObject*) self, filename, callback);
else
api_call = Py_BuildValue("Os", (PyObject*) self, filename);
Py_INCREF(Py_None);
Py_XINCREF(api_call);
return py_send_text(Py_None, api_call);
} else {
PyErr_Print();
Py_XINCREF(Py_False);
return Py_False;
}
}
static PyObject *
tgl_Peer_chat_set_photo (tgl_Peer *self, PyObject *args, PyObject *kwargs)
{
static char *kwlist[] = {"peer", "filename", "callback", NULL};
char * filename;
PyObject *callback = NULL;
if(self->peer->id.type != TGL_PEER_CHAT) {
PyErr_SetString(PeerError, "Only a chat peer can have a chat photo set.");
Py_XINCREF(Py_False);
return Py_False;
}
if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &filename, &callback)) {
PyObject *api_call;
if(callback)
api_call = Py_BuildValue("OsO", (PyObject*) self, filename, callback);
else
api_call = Py_BuildValue("Os", (PyObject*) self, filename);
Py_INCREF(Py_None);
Py_XINCREF(api_call);
return py_chat_set_photo(Py_None, api_call);
} else {
PyErr_Print();
Py_XINCREF(Py_False);
return Py_False;
}
}
static PyMethodDef tgl_Peer_methods[] = { static PyMethodDef tgl_Peer_methods[] = {
{"send_msg", (PyCFunction)tgl_Peer_send_msg, METH_VARARGS | METH_KEYWORDS, {"send_msg", (PyCFunction)tgl_Peer_send_msg, METH_VARARGS | METH_KEYWORDS,
"Send a message to peer object"}, "Send a message to peer object"},
{"send_typing", (PyCFunction)tgl_Peer_send_typing, METH_VARARGS | METH_KEYWORDS, ""},
{"send_typing_abort", (PyCFunction)tgl_Peer_send_typing_abort, METH_VARARGS | METH_KEYWORDS, ""},
{"rename_chat", (PyCFunction)tgl_Peer_rename_chat, METH_VARARGS | METH_KEYWORDS, ""},
{"send_photo", (PyCFunction)tgl_Peer_send_photo, METH_VARARGS | METH_KEYWORDS, ""},
{"send_video", (PyCFunction)tgl_Peer_send_video, METH_VARARGS | METH_KEYWORDS, ""},
{"send_audio", (PyCFunction)tgl_Peer_send_audio, METH_VARARGS | METH_KEYWORDS, ""},
{"send_file", (PyCFunction)tgl_Peer_send_file, METH_VARARGS | METH_KEYWORDS, ""},
{"send_document", (PyCFunction)tgl_Peer_send_document, METH_VARARGS | METH_KEYWORDS, ""},
{"send_text", (PyCFunction)tgl_Peer_send_text, METH_VARARGS | METH_KEYWORDS, ""},
{"chat_set_photo", (PyCFunction)tgl_Peer_chat_set_photo, METH_VARARGS | METH_KEYWORDS, ""},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };