sochix / TLSharp

Telegram client library implemented in C#
1.01k stars 380 forks source link

TLSharp Get ALL Members. #933

Open kratossz opened 4 years ago

kratossz commented 4 years ago

Hi, i want to get all members in group but my code only attracts 1000 members.

`public static async Task GetChatInfo(string groupName) { if (! await AuthUser()) return null; var result = new ChannelInfo(); var dialogs = (TLDialogs)await client.GetUserDialogsAsync(); var main = dialogs.chats.lists.Where(c => c.GetType() == typeof(TLChannel)) .Cast() .FirstOrDefault(c => c.title == (groupName)); var req = new TLRequestGetFullChannel() { channel = new TLInputChannel() { access_hash = main.access_hash.Value, channel_id = main.id } };

        var res = await client.SendRequestAsync<TeleSharp.TL.Messages.TLChatFull>(req);

        //we have to do this in slices
        var offset = 0;
        result.Channel = main;
        result.ChatFull = res;
        while (offset < (res.full_chat as TLChannelFull).participants_count)
        {
            var pReq = new TLRequestGetParticipants()
            {
                channel = new TLInputChannel() { access_hash = main.access_hash.Value, channel_id = main.id },
                filter = new TLChannelParticipantsRecent() { },
                limit = 200,
                offset = offset
            };
            var pRes = await client.SendRequestAsync<TLChannelParticipants>(pReq);
            result.Users.AddRange(pRes.users.lists.Cast<TLUser>());
            offset += 200;
            await Task.Delay(500);
        }

        return result;
    }`