Пример #1
0
 /// <inheritdoc />
 public GetConversationsResult GetConversations(GetConversationsParams getConversationsParams)
 {
     return(_vk.Call <GetConversationsResult>("messages.getConversations",
                                              new VkParameters
     {
         { "filter", getConversationsParams.Filter },
         { "fields", getConversationsParams.Fields },
         { "offset", getConversationsParams.Offset },
         { "count", getConversationsParams.Count },
         { "extended", getConversationsParams.Extended },
         { "start_message_id", getConversationsParams.StartMessageId },
         { "group_id", getConversationsParams.GroupId }
     }));
 }
Пример #2
0
        public IEnumerable <long> GetDialogs(ulong offset = 0)
        {
            Debug.WriteLine($"{GetType()}.{nameof(GetDialogs)} started");
            var result  = new List <long>();
            var @params = new GetConversationsParams
            {
                Count  = 200,
                Offset = offset
            };
            var dialogs = _vkApi.Messages.GetConversations(@params);
            var total   = dialogs.Count;

            while (result.Count < total)
            {
                result.AddRange(dialogs.Items.Select(d => d.Conversation.Peer.Id).ToList());
                @params.Offset += 200;
                dialogs         = _vkApi.Messages.GetConversations(@params);
            }

            Debug.WriteLine($"{GetType()}.{nameof(GetDialogs)} completed");
            return(result);
        }
Пример #3
0
 /// <inheritdoc />
 public Task <GetConversationsResult> GetConversationsAsync(GetConversationsParams getConversationsParams)
 {
     return(TypeHelper.TryInvokeMethodAsync(() => GetConversations(getConversationsParams)));
 }
Пример #4
0
        public void Sender(object args)
        {
            SenderParams @params             = (SenderParams)args;
            int          sendedMessagesCount = 0;

            VkApi vk = new VkApi();

            vk.Authorize(new ApiAuthParams
            {
                AccessToken = @params.token
            }
                         );

            var getConvParams = new GetConversationsParams();
            List <Conversation> conversations = new List <Conversation>();

            Invoke(new Action(() => { statusLabel.Text = "Получение списка диалогов: 0"; }));

            if (@params.messagesCount <= 200)
            {
                getConvParams.Count = (ulong)@params.messagesCount;
                foreach (var conversation in vk.Messages.GetConversations(getConvParams).Items)
                {
                    conversations.Add(conversation.Conversation);
                }
                Invoke(new Action(() => { statusLabel.Text = $"Получение списка диалогов: {@params.messagesCount}"; }));
            }
            else
            {
                getConvParams.Count = 200;
                foreach (var conversation in vk.Messages.GetConversations(getConvParams).Items)
                {
                    conversations.Add(conversation.Conversation);
                }
                @params.messagesCount -= 200;
                getConvParams.Offset   = 200;

                while (@params.messagesCount >= 200)
                {
                    int last_count = conversations.Count;
                    foreach (var conversation in vk.Messages.GetConversations(getConvParams).Items)
                    {
                        conversations.Add(conversation.Conversation);
                    }
                    if (conversations.Count == last_count)
                    {
                        break;
                    }
                    @params.messagesCount -= 200;
                    getConvParams.Offset  += 200;
                    Invoke(new Action(() => { statusLabel.Text = $"Получение списка диалогов: {conversations.Count}"; }));
                }
                if (@params.messagesCount != 0)
                {
                    getConvParams.Count = (ulong)@params.messagesCount;
                    foreach (var conversation in vk.Messages.GetConversations(getConvParams).Items)
                    {
                        conversations.Add(conversation.Conversation);
                    }
                }
                Invoke(new Action(() => { statusLabel.Text = $"Получение списка диалогов: {conversations.Count}"; }));
            }

            List <UserList> users = new List <UserList>();

            if (@params.supportVaribles)
            {
                Invoke(new Action(() => { statusLabel.Text = $"Получение пользователей: 0 из {conversations.Count}"; }));

                List <long> user_ids = new List <long>();
                foreach (var conversation in conversations)
                {
                    user_ids.Add(conversation.Peer.Id);
                }

                while (true)
                {
                    if (user_ids.Count <= 1000)
                    {
                        var usersArray = vk.Users.Get(user_ids.ToArray());
                        foreach (var user in usersArray)
                        {
                            users.Add(new UserList((int)user.Id, user));
                            Invoke(new Action(() => { statusLabel.Text = $"Получение пользователей: {users.Count} из {conversations.Count}"; }));
                        }
                        break;
                    }
                    else
                    {
                        long[] cutArray = new long[1000];
                        Array.Copy(user_ids.ToArray(), cutArray, 1000);
                        var usersArray = vk.Users.Get(cutArray);
                        foreach (var user in usersArray)
                        {
                            user_ids.Remove(user.Id);
                            users.Add(new UserList((int)user.Id, user));
                            Invoke(new Action(() => { statusLabel.Text = $"Получение пользователей: {users.Count} из {conversations.Count}"; }));
                        }
                    }
                }
            }

            Invoke(new Action(() => { statusLabel.Text = $"Отправлено {sendedMessagesCount} из {conversations.Count}"; }));

            string url = @"https://api.vk.com/method/messages.send?message={0}&user_id={1}&attachment={2}&access_token={3}&random_id=0&v=5.100";

            int procent = 100 / conversations.Count;

            Invoke(new Action(() => { progressBar.Style = ProgressBarStyle.Continuous; }));
            foreach (var conversation in conversations)
            {
                HttpWebRequest client = (HttpWebRequest)WebRequest.Create(String.Format(url, @params.text, conversation.Peer.Id, @params.attachments, @params.token));
                if (@params.supportVaribles)
                {
                    foreach (var user in users)
                    {
                        if (user.id == conversation.Peer.Id)
                        {
                            string text = @params.text.Replace("{first_name}", user.user.FirstName);
                            text   = text.Replace("{last_name}", user.user.LastName);
                            client = (HttpWebRequest)WebRequest.Create(String.Format(url, text, conversation.Peer.Id, @params.attachments, @params.token));
                        }
                    }
                }
                client.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0";
                client.GetResponse();
                sendedMessagesCount += 1;
                Invoke(new Action(() => { statusLabel.Text = $"Отправлено {sendedMessagesCount} из {conversations.Count}"; }));
                client.Abort();
                if (progressBar.Value + procent > 100)
                {
                    Invoke(new Action(() => { progressBar.Value = 100; }));
                }
                else
                {
                    Invoke(new Action(() => { progressBar.Value += procent; }));
                }
            }
            MessageBox.Show("Рассылка завершена!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Invoke(new Action(() => { activateGUI(); }));
            Thread.CurrentThread.Abort();
        }
Пример #5
0
 public GetConversationsResult GetConversations(GetConversationsParams getConversationsParams)
 {
     throw new NotImplementedException();
 }
Пример #6
0
 public Task <GetConversationsResult> GetConversationsAsync(GetConversationsParams getConversationsParams)
 {
     throw new NotImplementedException();
 }