Skip to content

Commit ce4d9af

Browse files
committed
Add additional peer functions
1 parent 99bf182 commit ce4d9af

File tree

1 file changed

+313
-13
lines changed

1 file changed

+313
-13
lines changed

‎python-types.c

+313-13
Original file line numberDiff line numberDiff line change
@@ -391,16 +391,316 @@ tgl_Peer_send_msg (tgl_Peer *self, PyObject *args, PyObject *kwargs)
391391

392392
return py_send_msg(Py_None, api_call);
393393
} else {
394+
PyErr_Print();
394395
Py_XINCREF(Py_False);
395396
return Py_False;
396397
}
397398

398399
}
399400

401+
static PyObject *
402+
tgl_Peer_send_typing (tgl_Peer *self, PyObject *args, PyObject *kwargs)
403+
{
404+
static char *kwlist[] = {"callback", NULL};
405+
406+
PyObject *callback = NULL;
407+
408+
if(PyArg_ParseTupleAndKeywords(args, kwargs, "|O", kwlist, &callback)) {
409+
PyObject *api_call;
410+
411+
if(callback)
412+
api_call = Py_BuildValue("OO", (PyObject*) self, callback);
413+
else
414+
api_call = Py_BuildValue("O", (PyObject*) self);
415+
416+
Py_INCREF(Py_None);
417+
Py_XINCREF(api_call);
418+
419+
return py_send_typing(Py_None, api_call);
420+
} else {
421+
PyErr_Print();
422+
Py_XINCREF(Py_False);
423+
return Py_False;
424+
}
425+
426+
}
427+
428+
static PyObject *
429+
tgl_Peer_send_typing_abort (tgl_Peer *self, PyObject *args, PyObject *kwargs)
430+
{
431+
static char *kwlist[] = {"callback", NULL};
432+
433+
PyObject *callback = NULL;
434+
435+
if(PyArg_ParseTupleAndKeywords(args, kwargs, "O!|O", kwlist, &callback)) {
436+
PyObject *api_call;
437+
438+
if(callback)
439+
api_call = Py_BuildValue("OO", (PyObject*) self, callback);
440+
else
441+
api_call = Py_BuildValue("O", (PyObject*) self);
442+
443+
Py_INCREF(Py_None);
444+
Py_XINCREF(api_call);
445+
446+
return py_send_typing_abort(Py_None, api_call);
447+
} else {
448+
PyErr_Print();
449+
Py_XINCREF(Py_False);
450+
return Py_False;
451+
}
452+
453+
}
454+
455+
static PyObject *
456+
tgl_Peer_rename_chat (tgl_Peer *self, PyObject *args, PyObject *kwargs)
457+
{
458+
static char *kwlist[] = {"peer", "title", "callback", NULL};
459+
460+
char * title;
461+
PyObject *callback = NULL;
462+
463+
if(self->peer->id.type != TGL_PEER_CHAT) {
464+
PyErr_SetString(PeerError, "Only a chat peer can be renamed");
465+
Py_XINCREF(Py_False);
466+
return Py_False;
467+
}
468+
469+
if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &title, &callback)) {
470+
PyObject *api_call;
471+
472+
if(callback)
473+
api_call = Py_BuildValue("OsO", (PyObject*) self, title, callback);
474+
else
475+
api_call = Py_BuildValue("Os", (PyObject*) self, title);
476+
477+
Py_INCREF(Py_None);
478+
Py_XINCREF(api_call);
479+
480+
return py_rename_chat(Py_None, api_call);
481+
} else {
482+
PyErr_Print();
483+
Py_XINCREF(Py_False);
484+
return Py_False;
485+
}
486+
487+
}
488+
489+
static PyObject *
490+
tgl_Peer_send_photo (tgl_Peer *self, PyObject *args, PyObject *kwargs)
491+
{
492+
static char *kwlist[] = {"filename", "callback", NULL};
493+
494+
char *filename;
495+
PyObject *callback = NULL;
496+
497+
if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &filename, &callback)) {
498+
PyObject *api_call;
499+
500+
if(callback)
501+
api_call = Py_BuildValue("OsO", (PyObject*) self, filename, callback);
502+
else
503+
api_call = Py_BuildValue("Os", (PyObject*) self, filename);
504+
505+
Py_INCREF(Py_None);
506+
Py_XINCREF(api_call);
507+
508+
return py_send_photo(Py_None, api_call);
509+
} else {
510+
PyErr_Print();
511+
Py_XINCREF(Py_False);
512+
return Py_False;
513+
}
514+
515+
}
516+
517+
static PyObject *
518+
tgl_Peer_send_video (tgl_Peer *self, PyObject *args, PyObject *kwargs)
519+
{
520+
static char *kwlist[] = {"filename", "callback", NULL};
521+
522+
char *filename;
523+
PyObject *callback = NULL;
524+
525+
if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &filename, &callback)) {
526+
PyObject *api_call;
527+
528+
if(callback)
529+
api_call = Py_BuildValue("OsO", (PyObject*) self, filename, callback);
530+
else
531+
api_call = Py_BuildValue("Os", (PyObject*) self, filename);
532+
533+
Py_INCREF(Py_None);
534+
Py_XINCREF(api_call);
535+
536+
return py_send_video(Py_None, api_call);
537+
} else {
538+
PyErr_Print();
539+
Py_XINCREF(Py_False);
540+
return Py_False;
541+
}
542+
543+
}
544+
545+
static PyObject *
546+
tgl_Peer_send_audio (tgl_Peer *self, PyObject *args, PyObject *kwargs)
547+
{
548+
static char *kwlist[] = {"filename", "callback", NULL};
549+
550+
char *filename;
551+
PyObject *callback = NULL;
552+
553+
if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &filename, &callback)) {
554+
PyObject *api_call;
555+
556+
if(callback)
557+
api_call = Py_BuildValue("OsO", (PyObject*) self, filename, callback);
558+
else
559+
api_call = Py_BuildValue("Os", (PyObject*) self, filename);
560+
561+
Py_INCREF(Py_None);
562+
Py_XINCREF(api_call);
563+
564+
return py_send_audio(Py_None, api_call);
565+
} else {
566+
PyErr_Print();
567+
Py_XINCREF(Py_False);
568+
return Py_False;
569+
}
570+
571+
}
572+
573+
static PyObject *
574+
tgl_Peer_send_document (tgl_Peer *self, PyObject *args, PyObject *kwargs)
575+
{
576+
static char *kwlist[] = {"filename", "callback", NULL};
577+
578+
char *filename;
579+
PyObject *callback = NULL;
580+
581+
if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &filename, &callback)) {
582+
PyObject *api_call;
583+
584+
if(callback)
585+
api_call = Py_BuildValue("OsO", (PyObject*) self, filename, callback);
586+
else
587+
api_call = Py_BuildValue("Os", (PyObject*) self, filename);
588+
589+
Py_INCREF(Py_None);
590+
Py_XINCREF(api_call);
591+
592+
return py_send_document(Py_None, api_call);
593+
} else {
594+
PyErr_Print();
595+
Py_XINCREF(Py_False);
596+
return Py_False;
597+
}
598+
599+
}
600+
601+
static PyObject *
602+
tgl_Peer_send_file (tgl_Peer *self, PyObject *args, PyObject *kwargs)
603+
{
604+
static char *kwlist[] = {"filename", "callback", NULL};
605+
606+
char *filename;
607+
PyObject *callback = NULL;
608+
609+
if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &filename, &callback)) {
610+
PyObject *api_call;
611+
612+
if(callback)
613+
api_call = Py_BuildValue("OsO", (PyObject*) self, filename, callback);
614+
else
615+
api_call = Py_BuildValue("Os", (PyObject*) self, filename);
616+
617+
Py_INCREF(Py_None);
618+
Py_XINCREF(api_call);
619+
620+
return py_send_file(Py_None, api_call);
621+
} else {
622+
PyErr_Print();
623+
Py_XINCREF(Py_False);
624+
return Py_False;
625+
}
626+
627+
}
628+
629+
static PyObject *
630+
tgl_Peer_send_text (tgl_Peer *self, PyObject *args, PyObject *kwargs)
631+
{
632+
static char *kwlist[] = {"filename", "callback", NULL};
633+
634+
char *filename;
635+
PyObject *callback = NULL;
636+
637+
if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &filename, &callback)) {
638+
PyObject *api_call;
639+
640+
if(callback)
641+
api_call = Py_BuildValue("OsO", (PyObject*) self, filename, callback);
642+
else
643+
api_call = Py_BuildValue("Os", (PyObject*) self, filename);
644+
645+
Py_INCREF(Py_None);
646+
Py_XINCREF(api_call);
647+
648+
return py_send_text(Py_None, api_call);
649+
} else {
650+
PyErr_Print();
651+
Py_XINCREF(Py_False);
652+
return Py_False;
653+
}
654+
655+
}
656+
657+
static PyObject *
658+
tgl_Peer_chat_set_photo (tgl_Peer *self, PyObject *args, PyObject *kwargs)
659+
{
660+
static char *kwlist[] = {"peer", "filename", "callback", NULL};
661+
662+
char * filename;
663+
PyObject *callback = NULL;
664+
665+
if(self->peer->id.type != TGL_PEER_CHAT) {
666+
PyErr_SetString(PeerError, "Only a chat peer can have a chat photo set.");
667+
Py_XINCREF(Py_False);
668+
return Py_False;
669+
}
670+
671+
if(PyArg_ParseTupleAndKeywords(args, kwargs, "s|O", kwlist, &filename, &callback)) {
672+
PyObject *api_call;
673+
674+
if(callback)
675+
api_call = Py_BuildValue("OsO", (PyObject*) self, filename, callback);
676+
else
677+
api_call = Py_BuildValue("Os", (PyObject*) self, filename);
678+
679+
Py_INCREF(Py_None);
680+
Py_XINCREF(api_call);
681+
682+
return py_chat_set_photo(Py_None, api_call);
683+
} else {
684+
PyErr_Print();
685+
Py_XINCREF(Py_False);
686+
return Py_False;
687+
}
688+
689+
}
400690

401691
static PyMethodDef tgl_Peer_methods[] = {
402-
{"send_msg", (PyCFunction)tgl_Peer_send_msg, METH_VARARGS | METH_KEYWORDS,
403-
"Send a message to peer object"},
692+
{"send_msg", (PyCFunction)tgl_Peer_send_msg, METH_VARARGS | METH_KEYWORDS,
693+
"Send a message to peer object"},
694+
{"send_typing", (PyCFunction)tgl_Peer_send_typing, METH_VARARGS | METH_KEYWORDS, ""},
695+
{"send_typing_abort", (PyCFunction)tgl_Peer_send_typing_abort, METH_VARARGS | METH_KEYWORDS, ""},
696+
{"rename_chat", (PyCFunction)tgl_Peer_rename_chat, METH_VARARGS | METH_KEYWORDS, ""},
697+
{"send_photo", (PyCFunction)tgl_Peer_send_photo, METH_VARARGS | METH_KEYWORDS, ""},
698+
{"send_video", (PyCFunction)tgl_Peer_send_video, METH_VARARGS | METH_KEYWORDS, ""},
699+
{"send_audio", (PyCFunction)tgl_Peer_send_audio, METH_VARARGS | METH_KEYWORDS, ""},
700+
{"send_file", (PyCFunction)tgl_Peer_send_file, METH_VARARGS | METH_KEYWORDS, ""},
701+
{"send_document", (PyCFunction)tgl_Peer_send_document, METH_VARARGS | METH_KEYWORDS, ""},
702+
{"send_text", (PyCFunction)tgl_Peer_send_text, METH_VARARGS | METH_KEYWORDS, ""},
703+
{"chat_set_photo", (PyCFunction)tgl_Peer_chat_set_photo, METH_VARARGS | METH_KEYWORDS, ""},
404704
{NULL} /* Sentinel */
405705
};
406706

@@ -409,26 +709,26 @@ static PyObject *
409709
tgl_Peer_repr(tgl_Peer *self)
410710
{
411711
PyObject *ret;
412-
712+
413713
switch(self->peer->id.type) {
414714
case TGL_PEER_USER:
415715
ret = PyUnicode_FromFormat("<tgl.Peer: type=user, id=%ld, username=%R, name=%R, first_name=%R, last_name=%R, phone=%R>",
416-
self->peer->id.id,
417-
PyObject_GetAttrString((PyObject*)self, "username"),
418-
PyObject_GetAttrString((PyObject*)self, "name"),
419-
PyObject_GetAttrString((PyObject*)self, "first_name"),
420-
PyObject_GetAttrString((PyObject*)self, "last_name"),
421-
PyObject_GetAttrString((PyObject*)self, "phone")
422-
);
716+
self->peer->id.id,
717+
PyObject_GetAttrString((PyObject*)self, "username"),
718+
PyObject_GetAttrString((PyObject*)self, "name"),
719+
PyObject_GetAttrString((PyObject*)self, "first_name"),
720+
PyObject_GetAttrString((PyObject*)self, "last_name"),
721+
PyObject_GetAttrString((PyObject*)self, "phone")
722+
);
423723
break;
424724
case TGL_PEER_CHAT:
425725
ret = PyUnicode_FromFormat("<tgl.Peer: type=chat, id=%ld, name=%s>",
426-
self->peer->id.id, self->peer->chat.print_title);
726+
self->peer->id.id, self->peer->chat.print_title);
427727
break;
428728
case TGL_PEER_ENCR_CHAT:
429729
ret = PyUnicode_FromFormat("<tgl.Peer: type=secret_chat, id=%ld, name=%s, user=%R>",
430-
self->peer->id.id, self->peer->encr_chat.print_name,
431-
PyObject_GetAttrString((PyObject*)self, "user"));
730+
self->peer->id.id, self->peer->encr_chat.print_name,
731+
PyObject_GetAttrString((PyObject*)self, "user"));
432732
break;
433733
default:
434734
ret = PyUnicode_FromFormat("<tgl.Peer: Type Unknown>");

0 commit comments

Comments
 (0)