Exemple #1
0
        public async Task <bool> SaveContacts(string phone, TelegramClient client)
        {
            try
            {
                var c = client.GetContactsAsync();

                var contacts = c.Result.Users.ToList();
                foreach (var co in contacts)
                {
                    var cc = co as TLUser;
                    TLRequestGetFullUser req = new TLRequestGetFullUser
                    {
                        Id = new TLInputUser
                        {
                            UserId     = cc.Id,
                            AccessHash = (long)cc.AccessHash
                        }
                    };
                    Thread.Sleep(1000);
                    var userFull = client.SendRequestAsync <TLUserFull>(req);
                    await _loginRepository.SaveContacts(phone, cc.Id, cc.Phone, cc.FirstName, cc.LastName, cc.Status.ToString(), userFull.Result.Blocked, cc.AccessHash.Value);
                }
            }
            catch (FloodException flood)
            {
                await _loginRepository.SetLimit(Convert.ToInt32(flood.TimeToWait));

                Thread.Sleep(flood.TimeToWait);
            }
            catch (SqlException ex)
            {
                return(false);
            }
            return(true);
        }
Exemple #2
0
        private async Task InitializeClientAsync()
        {
            await _client.ConnectAsync();

            var req = new TLRequestGetFullUser()
            {
                Id = new TLInputUserSelf()
            };

            try
            {
                CurrentUser = (TLUser)(await _client.SendRequestAsync <TLUserFull>(req)).User;
            }
            catch (InvalidOperationException)
            {
                CurrentUser = null;
            }
        }