Skip to content

Commit

Permalink
support for custom keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
vvaltman committed Jun 17, 2015
1 parent b9447e6 commit b43ab0a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
1.3.3
* support for sending custom keyboard
1.3.2
* use TGL-2.0.2
* add block/unblock user methods
Expand Down
35 changes: 30 additions & 5 deletions interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
# include "json-tg.h"
#endif

#include "tgl/mtproto-common.h"
#include "auto/auto-store.h"
#include "auto/auto-fetch-ds.h"
#include "auto/auto-types.h"
#include "auto/auto-free-ds.h"

#define ALLOW_MULT 1
char *default_prompt = "> ";

Expand Down Expand Up @@ -127,14 +133,13 @@ extern int daemonize;
extern struct tgl_state *TLS;
int readline_deactivated;

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

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

void fail_interface (struct tgl_state *TLS, struct in_ev *ev, int error_code, const char *format, ...) __attribute__ (( format (printf, 4, 5)));

static void skip_wspc (void) {
while (*line_ptr && ((unsigned char)*line_ptr) <= ' ') {
line_ptr ++;
Expand Down Expand Up @@ -746,7 +751,27 @@ void do_msg (struct command *command, int arg_num, struct arg args[], struct in_
assert (arg_num == 2);
if (ev) { ev->refcnt ++; }
vlogprintf (E_DEBUG, "reply_id=%d, disable=%d\n", reply_id, disable_msg_preview);
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);
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);
}

void do_msg_kbd (struct command *command, int arg_num, struct arg args[], struct in_ev *ev) {
assert (arg_num == 3);
if (ev) { ev->refcnt ++; }

clear_packet ();
if (tglf_store_type (TLS, ARG2STR(1), TYPE_TO_PARAM (reply_markup)) < 0) {
fail_interface (TLS, ev, ENOSYS, "can not parse reply markup");
return;
}
in_ptr = packet_buffer;
in_end = packet_ptr;

struct tl_ds_reply_markup *DS_RM = fetch_ds_type_reply_markup (TYPE_TO_PARAM (reply_markup));
assert (DS_RM);

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);

free_ds_type_reply_markup (DS_RM, TYPE_TO_PARAM (reply_markup));
}

void do_reply (struct command *command, int arg_num, struct arg args[], struct in_ev *ev) {
Expand Down Expand Up @@ -1392,6 +1417,7 @@ struct command commands[MAX_COMMANDS_SIZE] = {
{"main_session", {ca_none}, do_main_session, "main_session\tSends updates to this connection (or terminal). Useful only with listening socket", NULL},
{"mark_read", {ca_peer, ca_none}, do_mark_read, "mark_read <peer>\tMarks messages with peer as read", NULL},
{"msg", {ca_peer, ca_msg_string_end, ca_none}, do_msg, "msg <peer> <text>\tSends text message to peer", NULL},
{"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},
{"quit", {ca_none}, do_quit, "quit\tQuits immediately", NULL},
{"rename_chat", {ca_chat, ca_string_end, ca_none}, do_rename_chat, "rename_chat <chat> <new name>\tRenames chat", NULL},
{"rename_contact", {ca_user, ca_string, ca_string, ca_none}, do_rename_contact, "rename_contact <user> <first name> <last name>\tRenames contact", NULL},
Expand Down Expand Up @@ -1837,7 +1863,6 @@ void print_fail (struct in_ev *ev) {
mprint_end (ev);
}

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

Expand Down Expand Up @@ -2299,7 +2324,7 @@ void interpreter_chat_mode (char *line) {
return;
}
if (strlen (line) > 0) {
tgl_do_send_message (TLS, chat_mode_id, line, strlen (line), 0, 0, 0);
tgl_do_send_message (TLS, chat_mode_id, line, strlen (line), 0, NULL, 0, 0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lua-tg.c
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@ void lua_do_all (void) {
tgl_do_get_dialog_list (TLS, 100, 0, lua_dialog_list_cb, lua_ptr[p ++]);
break;
case lq_msg:
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]);
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]);
free (lua_ptr[p + 2]);
p += 3;
break;
Expand Down
2 changes: 1 addition & 1 deletion python-tg.c
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ void py_do_all (void) {
}
flags |= TGL_SEND_MSG_FLAG_REPLY (reply_id);
}
tgl_do_send_message (TLS, PY_PEER_ID(peer), str, len, flags, py_msg_cb, cb_extra);
tgl_do_send_message (TLS, PY_PEER_ID(peer), str, len, flags, NULL, py_msg_cb, cb_extra);
} else
PyErr_Print();

Expand Down
2 changes: 1 addition & 1 deletion telegram.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
#define PROG_NAME "telegram-cli"
#endif

#define TELEGRAM_CLI_VERSION "1.3.2"
#define TELEGRAM_CLI_VERSION "1.3.3"
2 changes: 1 addition & 1 deletion tgl
Submodule tgl updated 5 files
+7 −0 auto-static-store.c
+1 −0 generate.c
+4 −4 queries.c
+2 −0 tgl-inner.h
+4 −1 tgl.h

0 comments on commit b43ab0a

Please sign in to comment.