Supported user#id... and chat#id... from lua
This commit is contained in:
parent
7ce6dbbf0b
commit
d52183f8d5
12
lua-tg.c
12
lua-tg.c
@ -1141,8 +1141,16 @@ static int parse_lua_function (lua_State *L, struct lua_function *F) {
|
||||
ok = 0;
|
||||
break;
|
||||
}
|
||||
P = get_peer (s);
|
||||
if (!P || !(P->flags & FLAG_CREATED)) {
|
||||
if (sscanf (s, "user#id%lld", &num) == 1 && num > 0) {
|
||||
tgl_insert_empty_user (num);
|
||||
P = tgl_peer_get (TGL_MK_USER (num));
|
||||
} else if (sscanf (s, "chat#id%lld", &num) == 1 && num > 0) {
|
||||
tgl_insert_empty_chat (num);
|
||||
P = tgl_peer_get (TGL_MK_CHAT (num));
|
||||
} else {
|
||||
P = get_peer (s);
|
||||
}
|
||||
if (!P/* || !(P->flags & FLAG_CREATED)*/) {
|
||||
ok = 0;
|
||||
break;
|
||||
}
|
||||
|
17
structures.c
17
structures.c
@ -88,6 +88,7 @@ char *tgls_default_create_print_name (tgl_peer_id_t id, const char *a1, const ch
|
||||
char *s = buf;
|
||||
while (*s) {
|
||||
if (*s == ' ') { *s = '_'; }
|
||||
if (*s == '#') { *s = '@'; }
|
||||
s++;
|
||||
}
|
||||
s = buf;
|
||||
@ -1421,6 +1422,22 @@ void tglp_insert_chat (tgl_peer_t *P) {
|
||||
Peers[peer_num ++] = P;
|
||||
}
|
||||
|
||||
void tgl_insert_empty_user (int uid) {
|
||||
tgl_peer_id_t id = TGL_MK_USER (uid);
|
||||
if (tgl_peer_get (id)) { return; }
|
||||
tgl_peer_t *P = talloc0 (sizeof (*P));
|
||||
P->id = id;
|
||||
tglp_insert_user (P);
|
||||
}
|
||||
|
||||
void tgl_insert_empty_chat (int cid) {
|
||||
tgl_peer_id_t id = TGL_MK_CHAT (cid);
|
||||
if (tgl_peer_get (id)) { return; }
|
||||
tgl_peer_t *P = talloc0 (sizeof (*P));
|
||||
P->id = id;
|
||||
tglp_insert_chat (P);
|
||||
}
|
||||
|
||||
/* {{{ Free */
|
||||
void tgls_free_user (struct tgl_user *U) {
|
||||
if (U->first_name) { tfree_str (U->first_name); }
|
||||
|
Loading…
Reference in New Issue
Block a user