Skip to content

Commit b43ab0a

Browse files
author
vvaltman
committed
support for custom keyboard
1 parent b9447e6 commit b43ab0a

File tree

6 files changed

+36
-9
lines changed

6 files changed

+36
-9
lines changed

‎CHANGELOG

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
1.3.3
2+
* support for sending custom keyboard
13
1.3.2
24
* use TGL-2.0.2
35
* add block/unblock user methods

‎interface.c

+30-5
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@
8686
# include "json-tg.h"
8787
#endif
8888

89+
#include "tgl/mtproto-common.h"
90+
#include "auto/auto-store.h"
91+
#include "auto/auto-fetch-ds.h"
92+
#include "auto/auto-types.h"
93+
#include "auto/auto-free-ds.h"
94+
8995
#define ALLOW_MULT 1
9096
char *default_prompt = "> ";
9197

@@ -127,14 +133,13 @@ extern int daemonize;
127133
extern struct tgl_state *TLS;
128134
int readline_deactivated;
129135

136+
void fail_interface (struct tgl_state *TLS, struct in_ev *ev, int error_code, const char *format, ...) __attribute__ (( format (printf, 4, 5)));
130137
void event_incoming (struct bufferevent *bev, short what, void *_arg);
131138

132139
int is_same_word (const char *s, size_t l, const char *word) {
133140
return s && word && strlen (word) == l && !memcmp (s, word, l);
134141
}
135142

136-
void fail_interface (struct tgl_state *TLS, struct in_ev *ev, int error_code, const char *format, ...) __attribute__ (( format (printf, 4, 5)));
137-
138143
static void skip_wspc (void) {
139144
while (*line_ptr && ((unsigned char)*line_ptr) <= ' ') {
140145
line_ptr ++;
@@ -746,7 +751,27 @@ void do_msg (struct command *command, int arg_num, struct arg args[], struct in_
746751
assert (arg_num == 2);
747752
if (ev) { ev->refcnt ++; }
748753
vlogprintf (E_DEBUG, "reply_id=%d, disable=%d\n", reply_id, disable_msg_preview);
749-
tgl_do_send_message (TLS, args[0].P->id, ARG2STR(1), TGL_SEND_MSG_FLAG_REPLY(reply_id) | disable_msg_preview, print_msg_success_gw, ev);
754+
tgl_do_send_message (TLS, args[0].P->id, ARG2STR(1), TGL_SEND_MSG_FLAG_REPLY(reply_id) | disable_msg_preview, NULL, print_msg_success_gw, ev);
755+
}
756+
757+
void do_msg_kbd (struct command *command, int arg_num, struct arg args[], struct in_ev *ev) {
758+
assert (arg_num == 3);
759+
if (ev) { ev->refcnt ++; }
760+
761+
clear_packet ();
762+
if (tglf_store_type (TLS, ARG2STR(1), TYPE_TO_PARAM (reply_markup)) < 0) {
763+
fail_interface (TLS, ev, ENOSYS, "can not parse reply markup");
764+
return;
765+
}
766+
in_ptr = packet_buffer;
767+
in_end = packet_ptr;
768+
769+
struct tl_ds_reply_markup *DS_RM = fetch_ds_type_reply_markup (TYPE_TO_PARAM (reply_markup));
770+
assert (DS_RM);
771+
772+
tgl_do_send_message (TLS, args[0].P->id, ARG2STR(2), TGL_SEND_MSG_FLAG_REPLY(reply_id) | disable_msg_preview, DS_RM, print_msg_success_gw, ev);
773+
774+
free_ds_type_reply_markup (DS_RM, TYPE_TO_PARAM (reply_markup));
750775
}
751776

752777
void do_reply (struct command *command, int arg_num, struct arg args[], struct in_ev *ev) {
@@ -1392,6 +1417,7 @@ struct command commands[MAX_COMMANDS_SIZE] = {
13921417
{"main_session", {ca_none}, do_main_session, "main_session\tSends updates to this connection (or terminal). Useful only with listening socket", NULL},
13931418
{"mark_read", {ca_peer, ca_none}, do_mark_read, "mark_read <peer>\tMarks messages with peer as read", NULL},
13941419
{"msg", {ca_peer, ca_msg_string_end, ca_none}, do_msg, "msg <peer> <text>\tSends text message to peer", NULL},
1420+
{"msg_kbd", {ca_peer, ca_string, ca_msg_string_end, ca_none}, do_msg_kbd, "msg <peer> <kbd> <text>\tSends text message to peer with custom kbd", NULL},
13951421
{"quit", {ca_none}, do_quit, "quit\tQuits immediately", NULL},
13961422
{"rename_chat", {ca_chat, ca_string_end, ca_none}, do_rename_chat, "rename_chat <chat> <new name>\tRenames chat", NULL},
13971423
{"rename_contact", {ca_user, ca_string, ca_string, ca_none}, do_rename_contact, "rename_contact <user> <first name> <last name>\tRenames contact", NULL},
@@ -1837,7 +1863,6 @@ void print_fail (struct in_ev *ev) {
18371863
mprint_end (ev);
18381864
}
18391865

1840-
void fail_interface (struct tgl_state *TLS, struct in_ev *ev, int error_code, const char *format, ...) __attribute__ (( format (printf, 4, 5)));
18411866
void fail_interface (struct tgl_state *TLS, struct in_ev *ev, int error_code, const char *format, ...) {
18421867
static char error[1001];
18431868

@@ -2299,7 +2324,7 @@ void interpreter_chat_mode (char *line) {
22992324
return;
23002325
}
23012326
if (strlen (line) > 0) {
2302-
tgl_do_send_message (TLS, chat_mode_id, line, strlen (line), 0, 0, 0);
2327+
tgl_do_send_message (TLS, chat_mode_id, line, strlen (line), 0, NULL, 0, 0);
23032328
}
23042329
}
23052330

‎lua-tg.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ void lua_do_all (void) {
10261026
tgl_do_get_dialog_list (TLS, 100, 0, lua_dialog_list_cb, lua_ptr[p ++]);
10271027
break;
10281028
case lq_msg:
1029-
tgl_do_send_message (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], strlen (lua_ptr[p + 2]), 0, lua_msg_cb, lua_ptr[p]);
1029+
tgl_do_send_message (TLS, ((tgl_peer_t *)lua_ptr[p + 1])->id, lua_ptr[p + 2], strlen (lua_ptr[p + 2]), 0, NULL, lua_msg_cb, lua_ptr[p]);
10301030
free (lua_ptr[p + 2]);
10311031
p += 3;
10321032
break;

‎python-tg.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ void py_do_all (void) {
817817
}
818818
flags |= TGL_SEND_MSG_FLAG_REPLY (reply_id);
819819
}
820-
tgl_do_send_message (TLS, PY_PEER_ID(peer), str, len, flags, py_msg_cb, cb_extra);
820+
tgl_do_send_message (TLS, PY_PEER_ID(peer), str, len, flags, NULL, py_msg_cb, cb_extra);
821821
} else
822822
PyErr_Print();
823823

‎telegram.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121
#define PROG_NAME "telegram-cli"
2222
#endif
2323

24-
#define TELEGRAM_CLI_VERSION "1.3.2"
24+
#define TELEGRAM_CLI_VERSION "1.3.3"

0 commit comments

Comments
 (0)