Skip to content

Commit 3f22df2

Browse files
author
vvaltman
committed
updated tgl. support for captions
1 parent 775f417 commit 3f22df2

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed

‎interface.c

+37-30
Original file line numberDiff line numberDiff line change
@@ -646,63 +646,63 @@ void do_dialog_list (int arg_num, struct arg args[], struct in_ev *ev) {
646646
}
647647

648648
void do_send_photo (int arg_num, struct arg args[], struct in_ev *ev) {
649-
assert (arg_num == 2);
649+
assert (arg_num >= 2);
650650
if (ev) { ev->refcnt ++; }
651-
tgl_do_send_document (TLS, -1, args[0].P->id, args[1].str, 0, print_msg_success_gw, ev);
651+
tgl_do_send_document (TLS, -1, args[0].P->id, args[1].str, 0, arg_num == 2 ? NULL : args[2].str, print_msg_success_gw, ev);
652652
}
653653

654654
void do_send_file (int arg_num, struct arg args[], struct in_ev *ev) {
655-
assert (arg_num == 2);
655+
assert (arg_num >= 2);
656656
if (ev) { ev->refcnt ++; }
657-
tgl_do_send_document (TLS, -2, args[0].P->id, args[1].str, 0, print_msg_success_gw, ev);
657+
tgl_do_send_document (TLS, -2, args[0].P->id, args[1].str, 0, arg_num == 2 ? NULL : args[2].str, print_msg_success_gw, ev);
658658
}
659659

660660
void do_send_audio (int arg_num, struct arg args[], struct in_ev *ev) {
661-
assert (arg_num == 2);
661+
assert (arg_num >= 2);
662662
if (ev) { ev->refcnt ++; }
663-
tgl_do_send_document (TLS, FLAG_DOCUMENT_AUDIO, args[0].P->id, args[1].str, 0, print_msg_success_gw, ev);
663+
tgl_do_send_document (TLS, FLAG_DOCUMENT_AUDIO, args[0].P->id, args[1].str, 0, arg_num == 2 ? NULL : args[2].str, print_msg_success_gw, ev);
664664
}
665665

666666
void do_send_video (int arg_num, struct arg args[], struct in_ev *ev) {
667-
assert (arg_num == 2);
667+
assert (arg_num >= 2);
668668
if (ev) { ev->refcnt ++; }
669-
tgl_do_send_document (TLS, FLAG_DOCUMENT_VIDEO, args[0].P->id, args[1].str, 0, print_msg_success_gw, ev);
669+
tgl_do_send_document (TLS, FLAG_DOCUMENT_VIDEO, args[0].P->id, args[1].str, 0, arg_num == 2 ? NULL : args[2].str, print_msg_success_gw, ev);
670670
}
671671

672672
void do_send_document (int arg_num, struct arg args[], struct in_ev *ev) {
673-
assert (arg_num == 2);
673+
assert (arg_num >= 2);
674674
if (ev) { ev->refcnt ++; }
675-
tgl_do_send_document (TLS, 0, args[0].P->id, args[1].str, 0, print_msg_success_gw, ev);
675+
tgl_do_send_document (TLS, 0, args[0].P->id, args[1].str, 0, arg_num == 2 ? NULL : args[2].str, print_msg_success_gw, ev);
676676
}
677677

678678
void do_reply_photo (int arg_num, struct arg args[], struct in_ev *ev) {
679-
assert (arg_num == 2);
679+
assert (arg_num >= 2);
680680
if (ev) { ev->refcnt ++; }
681-
tgl_do_reply_document (TLS, -1, args[0].num, args[2].str, print_msg_success_gw, ev);
681+
tgl_do_reply_document (TLS, -1, args[0].num, args[1].str, arg_num == 2 ? NULL : args[2].str, print_msg_success_gw, ev);
682682
}
683683

684684
void do_reply_file (int arg_num, struct arg args[], struct in_ev *ev) {
685-
assert (arg_num == 2);
685+
assert (arg_num >= 2);
686686
if (ev) { ev->refcnt ++; }
687-
tgl_do_reply_document (TLS, -2, args[0].num, args[1].str, print_msg_success_gw, ev);
687+
tgl_do_reply_document (TLS, -2, args[0].num, args[1].str, arg_num == 2 ? NULL : args[2].str, print_msg_success_gw, ev);
688688
}
689689

690690
void do_reply_audio (int arg_num, struct arg args[], struct in_ev *ev) {
691-
assert (arg_num == 2);
691+
assert (arg_num >= 2);
692692
if (ev) { ev->refcnt ++; }
693-
tgl_do_reply_document (TLS, FLAG_DOCUMENT_AUDIO, args[0].num, args[1].str, print_msg_success_gw, ev);
693+
tgl_do_reply_document (TLS, FLAG_DOCUMENT_AUDIO, args[0].num, args[1].str, arg_num == 2 ? NULL : args[2].str, print_msg_success_gw, ev);
694694
}
695695

696696
void do_reply_video (int arg_num, struct arg args[], struct in_ev *ev) {
697-
assert (arg_num == 2);
697+
assert (arg_num >= 2);
698698
if (ev) { ev->refcnt ++; }
699-
tgl_do_reply_document (TLS, FLAG_DOCUMENT_VIDEO, args[0].num, args[1].str, print_msg_success_gw, ev);
699+
tgl_do_reply_document (TLS, FLAG_DOCUMENT_VIDEO, args[0].num, args[1].str, arg_num == 2 ? NULL : args[2].str, print_msg_success_gw, ev);
700700
}
701701

702702
void do_reply_document (int arg_num, struct arg args[], struct in_ev *ev) {
703-
assert (arg_num == 2);
703+
assert (arg_num >= 2);
704704
if (ev) { ev->refcnt ++; }
705-
tgl_do_reply_document (TLS, 0, args[0].num, args[1].str, print_msg_success_gw, ev);
705+
tgl_do_reply_document (TLS, 0, args[0].num, args[1].str, arg_num == 2 ? NULL : args[2].str, print_msg_success_gw, ev);
706706
}
707707

708708
void do_send_text (int arg_num, struct arg args[], struct in_ev *ev) {
@@ -1285,28 +1285,28 @@ struct command commands[] = {
12851285
{"rename_chat", {ca_chat, ca_string_end, ca_none}, do_rename_chat, "rename_chat <chat> <new name>\tRenames chat"},
12861286
{"rename_contact", {ca_user, ca_string, ca_string, ca_none}, do_rename_contact, "rename_contact <user> <first name> <last name>\tRenames contact"},
12871287
{"reply", {ca_number, ca_string_end, ca_none}, do_reply, "msg <msg-id> <text>\tSends text reply to message"},
1288-
{"reply_audio", {ca_number, ca_file_name_end, ca_none}, do_send_audio, "reply_audio <msg-id> <file>\tSends audio to peer"},
1288+
{"reply_audio", {ca_number, ca_file_name, ca_none}, do_send_audio, "reply_audio <msg-id> <file>\tSends audio to peer"},
12891289
{"reply_contact", {ca_number, ca_string, ca_string, ca_string, ca_none}, do_reply_contact, "reply_contact <msg-id> <phone> <first-name> <last-name>\tSends contact (not necessary telegram user)"},
1290-
{"reply_document", {ca_number, ca_file_name_end, ca_none}, do_reply_document, "reply_document <msg-id> <file>\tSends document to peer"},
1291-
{"reply_file", {ca_number, ca_file_name_end, ca_none}, do_reply_file, "reply_file <msg-id> <file>\tSends document to peer"},
1290+
{"reply_document", {ca_number, ca_file_name, ca_none}, do_reply_document, "reply_document <msg-id> <file>\tSends document to peer"},
1291+
{"reply_file", {ca_number, ca_file_name, ca_none}, do_reply_file, "reply_file <msg-id> <file>\tSends document to peer"},
12921292
{"reply_location", {ca_number, ca_double, ca_double, ca_none}, do_reply_location, "reply_location <msg-id> <latitude> <longitude>\tSends geo location"},
1293-
{"reply_photo", {ca_number, ca_file_name_end, ca_none}, do_reply_photo, "reply_photo <msg-id> <file>\tSends photo to peer"},
1293+
{"reply_photo", {ca_number, ca_file_name, ca_string_end | ca_optional, ca_none}, do_reply_photo, "reply_photo <msg-id> <file> [caption]\tSends photo to peer"},
12941294
//{"reply_text", {ca_number, ca_file_name_end, ca_none}, do_reply_text, "reply_text <msg-id> <file>\tSends contents of text file as plain text message"},
1295-
{"reply_video", {ca_number, ca_file_name_end, ca_none}, do_reply_video, "reply_video <msg-id> <file>\tSends video to peer"},
1295+
{"reply_video", {ca_number, ca_file_name, ca_none}, do_reply_video, "reply_video <msg-id> <file>\tSends video to peer"},
12961296
// {"restore_msg", {ca_number, ca_none}, do_restore_msg, "restore_msg <msg-id>\tRestores message. Only available shortly (one hour?) after deletion"},
12971297
{"safe_quit", {ca_none}, do_safe_quit, "safe_quit\tWaits for all queries to end, then quits"},
12981298
{"search", {ca_peer | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_number | ca_optional, ca_string_end}, do_search, "search [peer] [limit] [from] [to] [offset] pattern\tSearch for pattern in messages from date from to date to (unixtime) in messages with peer (if peer not present, in all messages)"},
12991299
{"secret_chat_rekey", { ca_secret_chat, ca_none}, do_secret_chat_rekey, "generate new key for active secret chat"},
1300-
{"send_audio", {ca_peer, ca_file_name_end, ca_none}, do_send_audio, "send_audio <peer> <file>\tSends audio to peer"},
1300+
{"send_audio", {ca_peer, ca_file_name, ca_none}, do_send_audio, "send_audio <peer> <file>\tSends audio to peer"},
13011301
{"send_contact", {ca_peer, ca_string, ca_string, ca_string, ca_none}, do_send_contact, "send_contact <peer> <phone> <first-name> <last-name>\tSends contact (not necessary telegram user)"},
1302-
{"send_document", {ca_peer, ca_file_name_end, ca_none}, do_send_document, "send_document <peer> <file>\tSends document to peer"},
1303-
{"send_file", {ca_peer, ca_file_name_end, ca_none}, do_send_file, "send_file <peer> <file>\tSends document to peer"},
1302+
{"send_document", {ca_peer, ca_file_name, ca_none}, do_send_document, "send_document <peer> <file>\tSends document to peer"},
1303+
{"send_file", {ca_peer, ca_file_name, ca_none}, do_send_file, "send_file <peer> <file>\tSends document to peer"},
13041304
{"send_location", {ca_peer, ca_double, ca_double, ca_none}, do_send_location, "send_location <peer> <latitude> <longitude>\tSends geo location"},
1305-
{"send_photo", {ca_peer, ca_file_name_end, ca_none}, do_send_photo, "send_photo <peer> <file>\tSends photo to peer"},
1305+
{"send_photo", {ca_peer, ca_file_name, ca_string_end | ca_optional, ca_none}, do_send_photo, "send_photo <peer> <file> [caption]\tSends photo to peer"},
13061306
{"send_text", {ca_peer, ca_file_name_end, ca_none}, do_send_text, "send_text <peer> <file>\tSends contents of text file as plain text message"},
13071307
{"send_typing", {ca_peer, ca_none}, do_send_typing, "send_typing <peer>\tSends typing notification"},
13081308
{"send_typing_abort", {ca_peer, ca_none}, do_send_typing_abort, "send_typing <peer>\tSends typing notification abort"},
1309-
{"send_video", {ca_peer, ca_file_name_end, ca_none}, do_send_video, "send_video <peer> <file>\tSends video to peer"},
1309+
{"send_video", {ca_peer, ca_file_name, ca_string | ca_optional, ca_none}, do_send_video, "send_video <peer> <file> [caption]\tSends video to peer"},
13101310
{"set", {ca_string, ca_number, ca_none}, do_set, "set <param> <value>\tSets value of param. Currently available: log_level, debug_verbosity, alarm, msg_num"},
13111311
{"set_password", {ca_string | ca_optional, ca_none}, do_set_password, "set_password <hint>\tSets password"},
13121312
{"set_profile_name", {ca_string, ca_string, ca_none}, do_set_profile_name, "set_profile_name <first-name> <last-name>\tSets profile name."},
@@ -2676,6 +2676,9 @@ void print_media (struct in_ev *ev, struct tgl_message_media *M) {
26762676
} else {
26772677
mprintf (ev, "[photo]");
26782678
}
2679+
if (M->caption) {
2680+
mprintf (ev, " %s", M->caption);
2681+
}
26792682
return;
26802683
case tgl_message_media_document:
26812684
mprintf (ev, "[");
@@ -2722,6 +2725,10 @@ void print_media (struct in_ev *ev, struct tgl_message_media *M) {
27222725
}
27232726

27242727
mprintf (ev, "]");
2728+
2729+
if (M->caption) {
2730+
mprintf (ev, " %s", M->caption);
2731+
}
27252732

27262733
return;
27272734
case tgl_message_media_document_encr:

‎lua-tg.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -895,27 +895,27 @@ void lua_do_all (void) {
895895
p += 3;
896896
break;
897897
case lq_send_photo:
898-
tgl_do_send_document (TLS, -1, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], 0, lua_msg_cb, lua_ptr[p]);
898+
tgl_do_send_document (TLS, -1, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], 0, NULL, lua_msg_cb, lua_ptr[p]);
899899
free (lua_ptr[p + 2]);
900900
p += 3;
901901
break;
902902
case lq_send_video:
903-
tgl_do_send_document (TLS, FLAG_DOCUMENT_VIDEO, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], 0, lua_msg_cb, lua_ptr[p]);
903+
tgl_do_send_document (TLS, FLAG_DOCUMENT_VIDEO, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], 0, NULL, lua_msg_cb, lua_ptr[p]);
904904
free (lua_ptr[p + 2]);
905905
p += 3;
906906
break;
907907
case lq_send_audio:
908-
tgl_do_send_document (TLS, FLAG_DOCUMENT_AUDIO, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], 0, lua_msg_cb, lua_ptr[p]);
908+
tgl_do_send_document (TLS, FLAG_DOCUMENT_AUDIO, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], 0, NULL, lua_msg_cb, lua_ptr[p]);
909909
free (lua_ptr[p + 2]);
910910
p += 3;
911911
break;
912912
case lq_send_document:
913-
tgl_do_send_document (TLS, 0, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], 0, lua_msg_cb, lua_ptr[p]);
913+
tgl_do_send_document (TLS, 0, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], 0, NULL, lua_msg_cb, lua_ptr[p]);
914914
free (lua_ptr[p + 2]);
915915
p += 3;
916916
break;
917917
case lq_send_file:
918-
tgl_do_send_document (TLS, -2, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], 0, lua_msg_cb, lua_ptr[p]);
918+
tgl_do_send_document (TLS, -2, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], 0, NULL, lua_msg_cb, lua_ptr[p]);
919919
free (lua_ptr[p + 2]);
920920
p += 3;
921921
break;

‎tgl

0 commit comments

Comments
 (0)