Exemple #1
0
        public static async Task <VkAddFriendsResultEnum> Add(this IVkFriendsApi src, ICapchaResolver resolver, int uid, string text = null)
        {
            var       tryAgainWithCapcha = false;
            string    sid            = null;
            string    img            = null;
            const int maxAttempt     = 5;
            var       currentAttempt = 0;

            while (currentAttempt < maxAttempt)
            {
                currentAttempt++;
                try
                {
                    if (tryAgainWithCapcha)
                    {
                        var capcha = await resolver.ResolveCapcha(img);

                        return(await src.Add(uid, text, sid, capcha));
                    }
                    else
                    {
                        return(await src.Add(uid, text));
                    }
                }
                catch (VkRequestCapchaNeededException ex)
                {
                    sid = ex.Error.CaptchaSid;
                    img = ex.Error.CaptchaImg;
                    tryAgainWithCapcha = true;
                }
            }
            return(VkAddFriendsResultEnum.Unknown);
        }
Exemple #2
0
        public static async Task <int?> Send(this IVkMessages src, ICapchaResolver resolver, string message, int?uid = null, int?chatId = null)
        {
            var       tryAgainWithCapcha = false;
            string    sid            = null;
            string    img            = null;
            const int maxAttempt     = 5;
            var       currentAttempt = 0;

            while (currentAttempt < maxAttempt)
            {
                currentAttempt++;
                try
                {
                    if (tryAgainWithCapcha)
                    {
                        var capcha = await resolver.ResolveCapcha(img);

                        await src.Send(message, uid, chatId, sid, capcha);
                    }
                    else
                    {
                        return(await src.Send(message, uid, chatId));
                    }
                }
                catch (VkRequestCapchaNeededException ex)
                {
                    sid = ex.Error.CaptchaSid;
                    img = ex.Error.CaptchaImg;
                    tryAgainWithCapcha = true;
                }
            }
            return(null);
        }