Ejemplo n.º 1
0
        public static async Task <ChannelInfo> GetInfoGroup(String channelName, TLSharp.Core.TelegramClient client)
        {
            ChannelInfo result = new ChannelInfo();
            TLChannel   channelInfo;

            if (client == null)
            {
                return(null);
            }
            var dialogs_temp = await client.GetUserDialogsAsync();

            TLDialogsSlice dialogs = dialogs_temp as TLDialogsSlice;

            TeleSharp.TL.Messages.TLChatFull res = new TeleSharp.TL.Messages.TLChatFull();
            try
            {
                channelInfo = (await client.SendRequestAsync <TeleSharp.TL.Contacts.TLResolvedPeer>(
                                   new TeleSharp.TL.Contacts.TLRequestResolveUsername
                {
                    Username = channelName
                }).ConfigureAwait(false)).Chats.Last() as TeleSharp.TL.TLChannel;

                TLRequestGetFullChannel req = new TLRequestGetFullChannel()
                {
                    Channel = new TLInputChannel()
                    {
                        AccessHash = channelInfo.AccessHash.Value, ChannelId = channelInfo.Id
                    }
                };

                res = await client.SendRequestAsync <TeleSharp.TL.Messages.TLChatFull>(req);
            }
            catch
            {
                return(null);
            }
            Int32 offset = 0;

            result.Channel  = channelInfo;
            result.ChatFull = res;
            while (offset < (res.FullChat as TLChannelFull).ParticipantsCount)
            {
                var pReq = new TLRequestGetParticipants()
                {
                    Channel = new TLInputChannel()
                    {
                        AccessHash = channelInfo.AccessHash.Value, ChannelId = channelInfo.Id
                    },
                    Filter = new TLChannelParticipantsRecent()
                    {
                    },
                    Limit  = 200,
                    Offset = offset
                };

                var pRes = await client.SendRequestAsync <TLChannelParticipants>(pReq);

                //TLChatParticipantAdmin

                for (Int32 i = 0; i < pRes.Participants.Count; i++)
                {
                    if (pRes.Participants[i] is TLChannelParticipantEditor || pRes.Participants[i] is TLChannelParticipantCreator ||
                        pRes.Participants[i] is TLChannelParticipantModerator)
                    {
                        result.Admins.Add(pRes.Users[i] as TLUser);
                    }
                }
                result.Users.AddRange(pRes.Users.Cast <TLUser>());
                offset += 200;
                await Task.Delay(500);
            }

            return(result);
        }