Skip to content

Commit e35946f

Browse files
committed
Added channel_info in Lua functions
1 parent c61c8ba commit e35946f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

README-LUA

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Function_list (arguments are listed aside from cb_function and cb_extra, :
5151
load_document_thumb(msg)
5252

5353
chat_info (chat)
54+
channel_info (channel)
5455
user_info (user)
5556

5657
get_history (peer, limit)

lua-tg.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ enum lua_query_type {
683683
lq_load_video_thumb,
684684
lq_load_video,
685685
lq_chat_info,
686+
lq_channel_info,
686687
lq_user_info,
687688
lq_history,
688689
lq_chat_add_user,
@@ -1034,6 +1035,38 @@ void lua_secret_chat_cb (struct tgl_state *TLSR, void *cb_extra, int success, st
10341035
free (cb);
10351036
}
10361037

1038+
void lua_channel_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_channel *C) {
1039+
assert (TLSR == TLS);
1040+
struct lua_query_extra *cb = cb_extra;
1041+
lua_settop (luaState, 0);
1042+
//lua_checkstack (luaState, 20);
1043+
my_lua_checkstack (luaState, 20);
1044+
1045+
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->func);
1046+
lua_rawgeti (luaState, LUA_REGISTRYINDEX, cb->param);
1047+
1048+
lua_pushnumber (luaState, success);
1049+
1050+
if (success) {
1051+
push_peer (C->id, (void *)C);
1052+
} else {
1053+
lua_pushboolean (luaState, 0);
1054+
}
1055+
1056+
assert (lua_gettop (luaState) == 4);
1057+
1058+
int r = ps_lua_pcall (luaState, 3, 0, 0);
1059+
1060+
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->func);
1061+
luaL_unref (luaState, LUA_REGISTRYINDEX, cb->param);
1062+
1063+
if (r) {
1064+
logprintf ("lua: %s\n", lua_tostring (luaState, -1));
1065+
}
1066+
1067+
free (cb);
1068+
}
1069+
10371070
void lua_user_cb (struct tgl_state *TLSR, void *cb_extra, int success, struct tgl_user *C) {
10381071
assert (TLSR == TLS);
10391072
struct lua_query_extra *cb = cb_extra;
@@ -1211,6 +1244,10 @@ void lua_do_all (void) {
12111244
tgl_do_get_chat_info (TLS, lua_ptr[p + 1].peer_id, 0, lua_chat_cb, lua_ptr[p].ptr);
12121245
p += 2;
12131246
break;
1247+
case lq_channel_info:
1248+
tgl_do_get_channel_info (TLS, lua_ptr[p + 1].peer_id, 0, lua_channel_cb, lua_ptr[p].ptr);
1249+
p += 2;
1250+
break;
12141251
case lq_user_info:
12151252
tgl_do_get_user_info (TLS, lua_ptr[p + 1].peer_id, 0, lua_user_cb, lua_ptr[p].ptr);
12161253
p += 2;
@@ -1379,6 +1416,7 @@ struct lua_function functions[] = {
13791416
{"fwd_msg", lq_fwd, { lfp_peer, lfp_msg, lfp_none }},
13801417
{"fwd_media", lq_fwd_media, { lfp_peer, lfp_msg, lfp_none }},
13811418
{"chat_info", lq_chat_info, { lfp_chat, lfp_none }},
1419+
{"channel_info", lq_channel_info, { lfp_channel, lfp_none }},
13821420
{"user_info", lq_user_info, { lfp_user, lfp_none }},
13831421
{"get_history", lq_history, { lfp_peer, lfp_nonnegative_number, lfp_none }},
13841422
{"chat_add_user", lq_chat_add_user, { lfp_chat, lfp_user, lfp_none }},

0 commit comments

Comments
 (0)