Пример #1
0
        public IEnumerable <TLAbsMessage> GetMessages(TLADialog dialog)
        {
            TLAbsInputPeer peer = CreatePeerFromDialog(dialog);

            int           iRead = 0;
            TLAbsMessages messages;

            while (iRead < dialog.Total)
            {
                messages = null;
                try
                {
                    messages = (TLAbsMessages)AsyncHelpers.RunSync <TLAbsMessages>(() => m_client.GetHistoryAsync(peer, iRead, 0, m_config.MessagesReadLimit));
                }
                catch (AggregateException e)
                {
                    if (e.InnerException.GetType() == typeof(FloodException))
                    {
                        FloodException f = (FloodException)e.InnerException;
                        Thread.Sleep((int)f.TimeToWait.TotalMilliseconds);
                    }
                    else
                    {
                        throw e;
                    }
                }

                if (messages != null)
                {
                    TLVector <TLAbsMessage> absMessages = null;

                    if (messages is TLMessagesSlice) // Need several loops to read all the messages
                    {
                        absMessages = ((TLMessagesSlice)messages).messages;
                    }

                    else if (messages is TLMessages) // All messges had been read at the first loop
                    {
                        absMessages = ((TLMessages)messages).messages;
                    }

                    else if (messages is TLChannelMessages) // Messages from Channel
                    {
                        absMessages = ((TLChannelMessages)messages).messages;
                    }

                    else
                    {
                        throw new TLCoreException("The message is not a TLMessagesSlice, a TLMessages or a TLChannelMessages");
                    }

                    foreach (TLAbsMessage message in absMessages.lists)
                    {
                        yield return(message);
                    }

                    iRead += m_config.MessagesReadLimit;
                }
            }
        }
        private static DateTime GetUntilWhenWeCanMakeRequests(FloodException eflood)
        {
            ;

            Thread.Sleep(1000);

            return(DateTime.Now + eflood.TimeToWait);
        }
Пример #3
0
        private void HandleRpcError(long messageReqMsgId, TRpcError error)
        {
            // rpc_error

            Log.Warn($"Recieve error from server: {error.ErrorMessage}");

            Exception exception;

            switch (error.ErrorMessage)
            {
            case var floodMessage when floodMessage.StartsWith("FLOOD_WAIT_"):
                var floodMessageTime = Regex.Match(floodMessage, @"\d+").Value;

                var seconds = int.Parse(floodMessageTime);
                exception = new FloodException(TimeSpan.FromSeconds(seconds));
                break;

            case var phoneMigrate when phoneMigrate.StartsWith("PHONE_MIGRATE_"):
                var phoneMigrateDcNumber = Regex.Match(phoneMigrate, @"\d+").Value;

                var phoneMigrateDcIdx = int.Parse(phoneMigrateDcNumber);
                exception = new PhoneMigrationException(phoneMigrateDcIdx);
                break;

            case var fileMigrate when fileMigrate.StartsWith("FILE_MIGRATE_"):
                var fileMigrateDcNumber = Regex.Match(fileMigrate, @"\d+").Value;

                var fileMigrateDcIdx = int.Parse(fileMigrateDcNumber);
                exception = new FileMigrationException(fileMigrateDcIdx);
                break;

            case var userMigrate when userMigrate.StartsWith("USER_MIGRATE_"):
                var userMigrateDcNumber = Regex.Match(userMigrate, @"\d+").Value;

                var userMigrateDcIdx = int.Parse(userMigrateDcNumber);
                exception = new UserMigrationException(userMigrateDcIdx);
                break;

            case "PHONE_CODE_INVALID":
                exception = new InvalidPhoneCodeException("The numeric code used to authenticate does not match the numeric code sent by SMS/Telegram");
                break;

            case "SESSION_PASSWORD_NEEDED":
                exception = new CloudPasswordNeededException("This Account has Cloud Password !");
                break;

            case "AUTH_RESTART":
                ResponseResultSetter.ReturnException(new AuthRestartException());
                return;

            default:
                exception = new InvalidOperationException(error.ErrorMessage);
                break;
            }

            ResponseResultSetter.ReturnException(messageReqMsgId, exception);
        }
Пример #4
0
        private void HandleRpcError(BinaryReader reader, ulong requestId)
        {
            // rpc_error
            var errorCode    = reader.ReadInt32();
            var errorMessage = Serializers.String.Read(reader);

            Log.Warn($"Recieve error from server: {errorMessage}");

            Exception exception;

            if (errorMessage.StartsWith("FLOOD_WAIT_"))
            {
                var resultString = Regex.Match(errorMessage, @"\d+").Value;
                var seconds      = int.Parse(resultString);
                exception = new FloodException(TimeSpan.FromSeconds(seconds));
            }
            else if (errorMessage.StartsWith("PHONE_MIGRATE_"))
            {
                var resultString = Regex.Match(errorMessage, @"\d+").Value;
                var dcIdx        = int.Parse(resultString);
                exception = new PhoneMigrationException(dcIdx);
            }
            else if (errorMessage.StartsWith("FILE_MIGRATE_"))
            {
                var resultString = Regex.Match(errorMessage, @"\d+").Value;
                var dcIdx        = int.Parse(resultString);
                exception = new FileMigrationException(dcIdx);
            }
            else if (errorMessage.StartsWith("USER_MIGRATE_"))
            {
                var resultString = Regex.Match(errorMessage, @"\d+").Value;
                var dcIdx        = int.Parse(resultString);
                exception = new UserMigrationException(dcIdx);
            }
            else if (errorMessage == "PHONE_CODE_INVALID")
            {
                exception = new InvalidPhoneCodeException("The numeric code used to authenticate does not match the numeric code sent by SMS/Telegram");
            }
            else if (errorMessage == "SESSION_PASSWORD_NEEDED")
            {
                exception = new CloudPasswordNeededException("This Account has Cloud Password !");
            }
            else
            {
                exception = new InvalidOperationException(errorMessage);
            }

            ResponseResultSetter.ReturnException(requestId, exception);
        }
Пример #5
0
        private void LoadGrid()
        {
            // Remove the text header of the first column and replace it by a "(Un)Select All" checkbox
            m_dgvDialogs.Columns["Selected"].HeaderCell = m_cbHeader;
            m_dgvDialogs.ClearSelection();

            m_dialogs.Clear();
            m_dialogs.AddRange(m_archiver.GetContacts());
            m_config.Contacts = m_dialogs.ToDictionary(d => d.Id, d => d.Title);
            m_dialogs.AddRange(m_archiver.GetUserDialogs());

            if (m_config.CountMessagesAtLaunch)
            {
                foreach (TLADialog dialog in m_dialogs)
                {
                    try
                    {
                        dialog.Total = m_archiver.GetTotalMessages(dialog);
                    }
                    catch (AggregateException e)
                    {
                        if (e.InnerException.GetType() == typeof(InvalidOperationException))
                        {
                            // CHANNEL_PRIVATE
                        }
                        else if (e.InnerException.GetType() == typeof(FloodException))
                        {
                            FloodException f = (FloodException)e.InnerException;
                            Thread.Sleep((int)f.TimeToWait.TotalMilliseconds);
                        }
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }
            }

            UpdateView();
        }
        public static async Task <bool> FixTheFactThatSomeGroupsDoesNotHaveOurModerationBot2(
            TelegramBotAbstract telegramBotAbstract)
        {
            const int      LIMIT = 20;
            var            i     = 0;
            TLAbsInputPeer u     =
                await UserbotPeer.GetPeerUserWithAccessHash("polinetwork3bot", telegramBotAbstract._userbotClient);

            if (u == null)
            {
                return(false);
            }

            id_of_chats_we_know_are_ok = new Dictionary <long, bool>();

            while (true)
            {
                TLAbsDialogs   x = null;
                FloodException floodException1 = null;
                try
                {
                    x = await telegramBotAbstract._userbotClient.GetUserDialogsAsync(limit : LIMIT, offsetId : i);
                }
                catch (FloodException floodException)
                {
                    floodException1 = floodException;
                }

                if (x == null && floodException1 != null)
                {
                    var untilWhen = GetUntilWhenWeCanMakeRequests(floodException1);
                    WaitUntil(untilWhen);

                    try
                    {
                        x = await telegramBotAbstract._userbotClient.GetUserDialogsAsync(limit : LIMIT, offsetId : i);
                    }
                    catch (Exception e7)
                    {
                        ;
                    }
                }

                if (x == null)
                {
                    return(i > 0);
                }

                if (x is TLDialogs x2)
                {
                    if (x2.Chats != null)
                    {
                        foreach (var x4 in x2.Chats)
                        {
                            var r1 = await FixTheFactThatSomeGroupsDoesNotHaveOurModerationBot3(x4, u,
                                                                                                telegramBotAbstract);

                            await NotifyUtil.NotifyIfFalseAsync(r1, 1.ToString(), telegramBotAbstract);
                        }
                    }
                }
                else if (x is TLDialogsSlice x3)
                {
                    if (x3.Chats != null)
                    {
                        foreach (var x4 in x3.Chats)
                        {
                            var r1 = await FixTheFactThatSomeGroupsDoesNotHaveOurModerationBot3(x4, u,
                                                                                                telegramBotAbstract);

                            await NotifyUtil.NotifyIfFalseAsync(r1, 2.ToString(), telegramBotAbstract);
                        }
                    }
                }
                else
                {
                    ;
                }

                i += LIMIT;
            }

            throw new NotImplementedException();
        }