From e35946fde687c18f153cbd7d20f5a0dbe8c58afa Mon Sep 17 00:00:00 2001 From: Yago Date: Sun, 29 Nov 2015 12:43:23 +0100 Subject: [PATCH 1/3] Added channel_info in Lua functions --- README-LUA | 1 + lua-tg.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/README-LUA b/README-LUA index 3ef8165..b991e95 100644 --- a/README-LUA +++ b/README-LUA @@ -51,6 +51,7 @@ Function_list (arguments are listed aside from cb_function and cb_extra, : load_document_thumb(msg) chat_info (chat) + channel_info (channel) user_info (user) get_history (peer, limit) diff --git a/lua-tg.c b/lua-tg.c index 4746db0..643cbf3 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -683,6 +683,7 @@ enum lua_query_type { lq_load_video_thumb, lq_load_video, lq_chat_info, + lq_channel_info, lq_user_info, lq_history, lq_chat_add_user, @@ -1034,6 +1035,38 @@ void lua_secret_chat_cb (struct tgl_state *TLSR, void *cb_extra, int success, st free (cb); } +void lua_channel_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_channel *C) { + assert (TLSR == TLS); + struct lua_query_extra *cb = cb_extra; + lua_settop (luaState, 0); + //lua_checkstack (luaState, 20); + my_lua_checkstack (luaState, 20); + + lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func); + lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param); + + lua_pushnumber (luaState, success); + + if (success) { + push_peer (C->id, (void *)C); + } else { + lua_pushboolean (luaState, 0); + } + + assert (lua_gettop (luaState) == 4); + + int r = ps_lua_pcall (luaState, 3, 0, 0); + + luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func); + luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param); + + if (r) { + logprintf ("lua: %s\n", lua_tostring (luaState, -1)); + } + + free (cb); +} + void lua_user_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_user *C) { assert (TLSR == TLS); struct lua_query_extra *cb = cb_extra; @@ -1211,6 +1244,10 @@ void lua_do_all (void) { tgl_do_get_chat_info (TLS, lua_ptr[p + 1].peer_id, 0, lua_chat_cb, lua_ptr[p].ptr); p += 2; break; + case lq_channel_info: + tgl_do_get_channel_info (TLS, lua_ptr[p + 1].peer_id, 0, lua_channel_cb, lua_ptr[p].ptr); + p += 2; + break; case lq_user_info: tgl_do_get_user_info (TLS, lua_ptr[p + 1].peer_id, 0, lua_user_cb, lua_ptr[p].ptr); p += 2; @@ -1379,6 +1416,7 @@ struct lua_function functions[] = { {"fwd_msg", lq_fwd, { lfp_peer, lfp_msg, lfp_none }}, {"fwd_media", lq_fwd_media, { lfp_peer, lfp_msg, lfp_none }}, {"chat_info", lq_chat_info, { lfp_chat, lfp_none }}, + {"channel_info", lq_channel_info, { lfp_channel, lfp_none }}, {"user_info", lq_user_info, { lfp_user, lfp_none }}, {"get_history", lq_history, { lfp_peer, lfp_nonnegative_number, lfp_none }}, {"chat_add_user", lq_chat_add_user, { lfp_chat, lfp_user, lfp_none }}, From ea86db505dccee2f554ded4839be4ec7bfdfef40 Mon Sep 17 00:00:00 2001 From: Yago Date: Sun, 29 Nov 2015 14:25:48 +0100 Subject: [PATCH 2/3] channel_invite_user in lua --- lua-tg.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua-tg.c b/lua-tg.c index 643cbf3..d7db428 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -711,7 +711,8 @@ enum lua_query_type { lq_send_location, lq_extf, lq_import_chat_link, - lq_export_chat_link + lq_export_chat_link, + lq_channel_invite_user }; struct lua_query_extra { @@ -1340,6 +1341,10 @@ void lua_do_all (void) { tgl_do_send_location (TLS, lua_ptr[p + 1].peer_id, lua_ptr[p + 2].dnum, lua_ptr[p + 3].dnum, 0, lua_msg_cb, lua_ptr[p].ptr); p += 4; break; + case lq_channel_invite_user: + tgl_do_channel_invite_user (TLS, lua_ptr[p + 1].peer_id, lua_ptr[p + 2].peer_id, lua_empty_cb, lua_ptr[p].ptr); + p += 3; + break; /* lq_delete_msg, lq_restore_msg, @@ -1441,6 +1446,7 @@ struct lua_function functions[] = { {"ext_function", lq_extf, { lfp_string, lfp_none }}, {"import_chat_link", lq_import_chat_link, { lfp_string, lfp_none }}, {"export_chat_link", lq_export_chat_link, { lfp_chat, lfp_none }}, + {"channel_invite_user", lq_channel_invite_user, { lfp_channel, lfp_user, lfp_none }}, { 0, 0, { lfp_none}} }; From e0f5f163537591c5e4cd62580ef9b65343c5d20c Mon Sep 17 00:00:00 2001 From: Yago Date: Sun, 29 Nov 2015 14:37:05 +0100 Subject: [PATCH 3/3] Fixes chat_add_user and chat_del_user. 'p + 2' in stead of 'p + 1' --- lua-tg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua-tg.c b/lua-tg.c index d7db428..d6f64b1 100644 --- a/lua-tg.c +++ b/lua-tg.c @@ -1258,11 +1258,11 @@ void lua_do_all (void) { p += 3; break; case lq_chat_add_user: - tgl_do_add_user_to_chat (TLS, lua_ptr[p + 1].peer_id, lua_ptr[p + 1].peer_id, 10, lua_empty_cb, lua_ptr[p].ptr); + tgl_do_add_user_to_chat (TLS, lua_ptr[p + 1].peer_id, lua_ptr[p + 2].peer_id, 10, lua_empty_cb, lua_ptr[p].ptr); p += 3; break; case lq_chat_del_user: - tgl_do_del_user_from_chat (TLS, lua_ptr[p + 1].peer_id, lua_ptr[p + 1].peer_id, lua_empty_cb, lua_ptr[p].ptr); + tgl_do_del_user_from_chat (TLS, lua_ptr[p + 1].peer_id, lua_ptr[p + 2].peer_id, lua_empty_cb, lua_ptr[p].ptr); p += 3; break; case lq_add_contact: