public void AddAudioToList(VkNet.Utils.VkCollection <VkNet.Model.Attachments.Audio> audios) { AudioList.Items.Clear(); foreach (var audio in audios) { AudioList.Items.Add($"{audio.Artist} - {audio.Title}"); } }
public MainWindow() { api = new VkApi(); InitializeComponent(); updatePbDelegate = new UpdateProgressBarDelegate(pbProgress.SetValue); TimeTo = DateTime.Now; tbDataTo.Text = TimeTo.Day + "." + TimeTo.Month + "." + TimeTo.Year; TimeTo2 = DateTime.Now; tbDataTo2.Text = TimeTo2.Day + "." + TimeTo2.Month + "." + TimeTo2.Year; try { LoadOptions(); UserPassword = pbPassword.Password; } catch { LoadCommplite = true; lErrors.Content = "Не удалось загрузить параметры. Будут использованы параметры по умолчанию."; } try { LoadMessage(); } catch { lErrors2.Document.Blocks.Clear(); lErrors2.Document.Blocks.Add(new Paragraph(new Run("Не удалось загрузить сохранённые сообщения. Возможно файл с сообщиниями не существует."))); //lErrors2.Content = "Не удалось загрузить сохранённые сообщения. Возможно файл с сообщиниями не существует."; } try { api.Authorize(new ApiAuthParams { ApplicationId = 5539924, Login = ULogin, Password = UserPassword, Settings = Settings.All }); uint countAlbums = (uint)api.Photo.GetAlbumsCount(groupId: groupId); AllAlbums = api.Photo.GetAlbums(new PhotoGetAlbumsParams { Count = countAlbums, OwnerId = -groupId }, skipAuthorization: true); for (int i = 0; i < countAlbums; i++) { cbAlbum.Items.Add("Альбом № " + (i + 1) + " имя: " + AllAlbums[i].Title + ". Количество фотографий: " + AllAlbums[i].Size); cbAlbum2.Items.Add("Альбом № " + (i + 1) + " имя: " + AllAlbums[i].Title + ". Количество фотографий: " + AllAlbums[i].Size); } cbAlbum.Items.Add("Все альбомы"); cbAlbum.SelectedIndex = cbAlbum.Items.Count - 1; cbAlbum2.SelectedIndex = 0; } catch (Exception) { lErrors.Content = "Не удалось загрузить альбомы. Возможно нет подключения к интернету."; } }
// Получаем список аудиозаписей пользователя private void GetAudio() { audios = api.Audio.Get(new AudioGetParams { Count = 100 }); int n = 0; foreach (var audio in audios) { checkedListBox1.Items.Add($" {n} > {audio.Artist} - {audio.Title}"); n += 1; } }
//возвращает List всех аудио public List <AudioUnit> GetAudiosList(long?Id) { VkNet.Utils.VkCollection <VkNet.Model.Attachments.Audio> audios = vk.Audio.Get( new AudioGetParams { OwnerId = Id }); List <AudioUnit> res = new List <AudioUnit>(); foreach (VkNet.Model.Attachments.Audio a in audios) { res.Add( new AudioUnit(a.Id, interMin(a.Duration), a.Artist, a.Title) ); } return(res); }
//возвращает List бесед /*public List<> getChats() * { * //https://vk.com/dev/messages.getConversations * MainWindow.vk1.vk.Messages.GetConversations( * new GetConversationsParams * { * * }); * * }*/ //возвращает List друзей public List <FriendUnit> GetFriendsList() { VkNet.Utils.VkCollection <User> friends = MainWindow.vk1.vk.Friends.Get( new FriendsGetParams { Fields = ProfileFields.FirstName }); List <FriendUnit> res = new List <FriendUnit>(); foreach (User f in friends) { res.Add( new FriendUnit(f.Id, f.FirstName + " " + f.LastName) ); } return(res); }
/// <summary> /// Каждый день проверяет, наступил ли у кого день рождения /// Если наступил - отправляет поздравительное сообщение /// </summary> public async void CheckBirthday(bool IsStarted) { while (IsStarted) { _friendList = GetFriendList(); Console.WriteLine(_friendList.Count + " друзей"); int greeted = 0; foreach (var friend in _friendList) { if (friend.BirthDate == DateTime.Now.ToShortDateString().Substring(0, 5)) { SendGreetings(friend); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Друг {0} поздравлен!\n", friend.FirstName); Console.ResetColor(); greeted++; } } if (greeted == 0) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Никто сегодня не празднует ДР :(\n"); Console.ResetColor(); } else { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Сегодня поздравили {0} человек(а)\n", greeted); Console.ResetColor(); } var Time = (DateTime.Now.AddDays(1).Date - DateTime.Now).TotalMilliseconds; Console.Write("Жду до следующего дня "); Console.ForegroundColor = ConsoleColor.Magenta; Console.Write(Math.Round((Time / (1000 * 60 * 60)), MidpointRounding.AwayFromZero)); Console.ResetColor(); Console.Write(" часов\n\n"); await Task.Run(() => Thread.Sleep(Convert.ToInt32(Time))); } }
public void AddAudioToList(VkNet.Utils.VkCollection <VkNet.Model.Attachments.Audio> audios) { MusicList.Items.Clear(); if (state == "SEARCH") { bool IncludeOwn = false; int startValue = 0; for (int i = 0; i < vkDatas.SearchAudios.Count; i++) { foreach (var ownaudio in vkDatas.Audio) { if (ownaudio.AccessKey == vkDatas.SearchAudios[i].AccessKey) { if (!IncludeOwn) { IncludeOwn = true; MusicList.Items.Add(" Ваши аудиозаписи:"); } MusicList.Items.Add(vkDatas.SearchAudios[i].Artist + " - " + vkDatas.SearchAudios[i].Title); startValue++; } } } if (startValue != 0) { MusicList.Items.Add(" Все аудиозаписи:"); } for (int j = startValue; j < vkDatas.SearchAudios.Count; j++) { MusicList.Items.Add(vkDatas.SearchAudios[j].Artist + " - " + vkDatas.SearchAudios[j].Title); } return; } foreach (var audio in audios) { Object title = new object(); title = $"{audio.Artist} - {audio.Title}"; MusicList.Items.Add(title); } }
public void RmlGetPop() { RmlReadGroups(@"Data/groups.dat"); foreach (var grinfo in str) { var info = grinfo.Split(' '); off = int.Parse(info[1]); id = info[0]; if (off < int.Parse(info[2])) { break; } club_curr++; } var grm_prm = new VkNet.Model.RequestParams.GroupsGetMembersParams(); grm_prm.Offset = off; grm_prm.GroupId = id; users = MainWindow.vkApi.Groups.GetMembers(grm_prm); //123 }
public static void deleteComments(int selectedIndex, VkNet.Utils.VkCollection <PhotoAlbum> AllAlbums, VkApi api, DateTime TimeFrom2, DateTime TimeTo2) { ulong offset = 0, count = 500; List <VkNet.Model.Attachments.Photo> AllPhoto = new List <VkNet.Model.Attachments.Photo>(); try { while (true) { var photos = api.Photo.Get(new PhotoGetParams { OwnerId = AllAlbums[selectedIndex].OwnerId, Extended = true, Count = count, Offset = offset, AlbumId = VkNet.Enums.SafetyEnums.PhotoAlbumType.Id(AllAlbums[selectedIndex].Id) }); for (int i = 0; i < photos.Count; i++) { AllPhoto.Add(photos[i]); } if (AllPhoto.Count == AllAlbums[selectedIndex].Size) { break; } else if (AllPhoto.Count > AllAlbums[selectedIndex].Size) { throw new OutOfBorderPhotoException(); } else { offset = offset + count; } } } catch (Exception ex) { throw new ErrorFindPhotoException(AllAlbums[selectedIndex].Title, "ErrorFindPhotoException. " + ex.ToString()); } for (int i = 0; i < AllPhoto.Count; i++) { if (AllPhoto[i].Comments.Count != 0) { count = 100; offset = 0; int delete_comment = 0; bool stop = true; try { while (true) { var Comments = api.Photo.GetComments(new PhotoGetCommentsParams { Sort = VkNet.Enums.SafetyEnums.CommentsSort.Desc, Count = count, Offset = offset, OwnerId = AllAlbums[selectedIndex].OwnerId, PhotoId = (ulong)AllPhoto[i].Id }); for (int j = 0; j < Comments.Count; j++) { if (Comments[j].Date >= TimeFrom2 && Comments[j].Date <= TimeTo2) { api.Photo.DeleteComment(commentId: Convert.ToUInt64(Comments[j].Id), ownerId: -167157478); delete_comment++; } else { if (Comments[j].Date < TimeFrom2) { stop = false; break; } } } if (!stop || Comments.Count == 0) { break; } else { offset = offset + count; } } } catch (Exception ex) { throw new ErrorFindCommentsException(i, AllAlbums[selectedIndex].Title, "ErrorFindCommentsException. " + ex.ToString()); } } } }
public static List <People> GetPeopleFromAlbum(int SelectedAlbum, VkNet.Utils.VkCollection <PhotoAlbum> AllAlbums, VkApi api, DateTime TimeFrom, DateTime TimeTo) { ulong offset = 0, count = 500; List <VkNet.Model.Attachments.Photo> AllPhoto = new List <VkNet.Model.Attachments.Photo>(); try { while (true) { var photos = api.Photo.Get(new PhotoGetParams { OwnerId = AllAlbums[SelectedAlbum].OwnerId, Extended = true, Count = count, Offset = offset, AlbumId = VkNet.Enums.SafetyEnums.PhotoAlbumType.Id(AllAlbums[SelectedAlbum].Id) }); for (int i = 0; i < photos.Count; i++) { AllPhoto.Add(photos[i]); } if (AllPhoto.Count == AllAlbums[SelectedAlbum].Size) { break; } else if (AllPhoto.Count > AllAlbums[SelectedAlbum].Size) { throw new OutOfBorderPhotoException(); } else { offset = offset + count; } } } catch { throw new ErrorFindPhotoException(AllAlbums[SelectedAlbum].Title); } List <List <VkNet.Model.Comment> > AllComents = new List <List <VkNet.Model.Comment> >(); for (int i = 0; i < AllPhoto.Count; i++) { AllComents.Add(new List <VkNet.Model.Comment>()); if (AllPhoto[i].Comments.Count != 0) { count = 100; offset = 0; bool stop = true; try { while (true) { var Comments = api.Photo.GetComments(new PhotoGetCommentsParams { Sort = VkNet.Enums.SafetyEnums.CommentsSort.Desc, Count = count, Offset = offset, OwnerId = AllAlbums[SelectedAlbum].OwnerId, PhotoId = (ulong)AllPhoto[i].Id }); for (int j = 0; j < Comments.Count; j++) { if (Comments[j].Date >= TimeFrom && Comments[j].Date <= TimeTo) { AllComents[i].Add(Comments[j]); } else { stop = false; break; } } if (AllComents[i].Count == AllPhoto[i].Comments.Count || !stop) { break; } else if (AllComents[i].Count > AllPhoto[i].Comments.Count) { throw new OutOfBorderCommentsException(); } else { offset = offset + count; } } } catch { throw new ErrorFindCommentsException(i, AllAlbums[SelectedAlbum].Title); } } } List <People> peoples = new List <People>(); for (int i = 0; i < AllComents.Count; i++) { for (int j = 0; j < AllComents[i].Count; j++) { People buff; if ((buff = peoples.Find(x => x.Id == AllComents[i][j].FromId)) != null) { buff.CommentsText[i].Add(AllComents[i][j].Text); buff.CommentsData[i].Add(AllComents[i][j].Date.Value); } else { peoples.Add(new People(AllComents.Count, "", AllComents[i][j].FromId)); peoples[peoples.Count - 1].CommentsText[i].Add(AllComents[i][j].Text); peoples[peoples.Count - 1].CommentsData[i].Add(AllComents[i][j].Date.Value); } } } return(peoples); }