Exemplo n.º 1
0
        public static async Task <ChannelInfo> 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 <TLChannel>()
                       .FirstOrDefault(c => c.title == ("WereWuff - The Game"));
            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);
        }
Exemplo n.º 2
0
        public async Task <UserSearchResult> GetUsers(TelegramClient client, List <string> chatsNames)
        {
            UserSearchResult searchResult = new UserSearchResult()
            {
                TlUsers = new List <TLUser>(), Users = new List <UserModel>()
            };

            try
            {
                List <TLChannel> channels = await GetChats(client, chatsNames);

                foreach (var channel in channels)
                {
                    var request = new TLRequestGetParticipants {
                        Channel = new TLInputChannel {
                            AccessHash = (long)channel.AccessHash,
                            ChannelId  = channel.Id
                        },
                        Filter = new TLChannelParticipantsRecent()
                    };

                    TLChannelParticipants found = await client.SendRequestAsync <TLChannelParticipants>(request);

                    foreach (var absUser in found.Users)
                    {
                        TLUser user = absUser as TLUser;

                        if (!user.Bot && !user.Deleted && !user.Self)
                        {
                            searchResult.TlUsers.Add(user);

                            var customeUser = _userService.CreateCustomUserModel(user);
                            searchResult.Users.Add(customeUser);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex);
            }

            return(searchResult);
        }
Exemplo n.º 3
0
        public async Task <TLChannelParticipants> GetChannelParticipants(int channelId, long channelHash, FilterEnum?filterEnum, int limit, int offset)
        {
            await client.ConnectAsync();

            TLAbsChannelParticipantsFilter filter;

            switch (filterEnum)
            {
            case FilterEnum.Admins:
                filter = new TLChannelParticipantsAdmins();
                break;

            case FilterEnum.Bots:
                filter = new TLChannelParticipantsBots();
                break;

            case FilterEnum.Kicked:
                filter = new TLChannelParticipantsKicked();
                break;

            case FilterEnum.Recent:
                filter = new TLChannelParticipantsRecent();
                break;

            default:
                filter = null;
                break;
            }

            TLRequestGetParticipants particpants = new TLRequestGetParticipants
            {
                channel = new TLInputChannel
                {
                    access_hash = channelHash,
                    channel_id  = channelId
                },
                filter = filter,
                limit  = limit,
                offset = offset
            };

            return(await client.SendRequestAsync <TLChannelParticipants>(particpants));
        }
Exemplo n.º 4
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);
        }