Example #1
0
        public string Solve(string url)
        {
            lock (Vk)
            {
                var userId = UsersSolvers.Current.GetRandUserId();
                Vk.Messages.Send(new MessagesSendParams()
                {
                    UserId  = userId,
                    Message = url
                });
                var startDate = DateTime.Now;
                while (true)
                {
                    if ((DateTime.Now - startDate).TotalMilliseconds > Settings.Current.Timeout)
                    {
                        return(string.Empty); //time is out
                    }
                    var dialogs = Vk.Messages.GetDialogs(new MessagesDialogsGetParams()
                    {
                        Unread = true,
                        Count  = 200,
                        Offset = 0
                    });

                    var response = dialogs.Messages.FirstOrDefault(x => x.UserId == userId);

                    if (response != null)
                    {
                        return(response.Body);
                    }

                    VkUtils.TechnicalSleepForVk();
                }
            }
        }
        public VkToSpotifyTests()
        {
            var initData = Utils.ReadFile(@$ "{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}{BasicInfo.Default_init_data}");

            var login    = initData.GetKey("VK.LOGIN");
            var password = initData.GetKey("VK.PASSWORD");

            _screenName = initData.GetKey("VK.SCREEN_NAME");

            Assert.IsNotNull(login);
            Assert.IsNotNull(password);
            Assert.IsNotNull(_screenName);

            _api = VkUtils.AuthorizeApi(login, password);

            Assert.IsNotNull(_api);
            Assert.IsTrue(_api.IsAuthorized);

            var clientId = initData.GetKey("SPOTIFY.CLIENT_ID");
            var secretId = initData.GetKey("SPOTIFY.SECRET_ID");

            Assert.IsNotNull(clientId);
            Assert.IsNotNull(secretId);

            var spotifyClient = SpotifyUtils.GetAuthorizedByIds(clientId, secretId);

            _searchEngine = new SpotifySearchEngine <Track>(spotifyClient);

            Assert.IsNotNull(_searchEngine);
        }
Example #3
0
 public void GetUserByScreenNameTest()
 {
     lock (_api)
     {
         var user = VkUtils.GetUserByScreenName(_screenName, _api);
         Assert.IsNotNull(user);
     }
 }
Example #4
0
        public override void Execute(VkApi vk, Message message, string sourceQuery)
        {
            var targetTag = GetTargetTag(sourceQuery);
            var tagAlbums = EroRepository.TagsAlbums[targetTag];
            var dialog    = DialogSettings.GetSession(vk, message);
            var result    = Utils.GetWhile(() => VkUtils.GetNextPictureAndMessageForDialog_Ad(vk, dialog, tagAlbums[Utils.GetNextRandom(0, tagAlbums.Count - 1)]), (res) => res.Key != null, 10);

            VkNet.VkUtils.SendImage(vk, message, result.Key, result.Value);
        }
Example #5
0
        public void GetAudioVkTest()
        {
            lock (_api)
            {
                var user       = VkUtils.GetUserByScreenName(_screenName, _api);
                var downloader = new VkMusicDownloadEngine(_api, 6000);
                var trackList  = downloader.DownloadTrackList(user);


                Assert.IsNotNull(trackList);
                Assert.AreNotEqual(0, trackList.Count());
            }
        }
Example #6
0
        public static void InitializeUsersIds(VkApi vk)
        {
            var hObject  = HierarchicalObject.FromFile(Constants.UsersToSendFilePath);
            var usersIds = new List <long>();

            for (int i = 0; hObject[i] is string; i++)
            {
                var userId = VkUtils.GetUserIdByUriName(vk, (string)hObject[i]);
                usersIds.Add(userId.Value);
            }

            Current = new UsersSolvers()
            {
                UsersIds = usersIds.ToArray()
            };
        }
Example #7
0
        public override void Execute(VkApi vk, Message message, string sourceQuery)
        {
            var query   = ExtractQuery(sourceQuery);
            var command = CommandUtils.AllCommands.FirstOrDefault(x => x.IsIt(query));

            if (command == null)
            {
                var dialog = DialogSettings.GetSession(vk, message);
                var result = Utils.GetWhile(() => VkUtils.GetNextPictureAndMessageForDialog_Ad(vk, dialog), (res) => res.Key != null, 10);
                VkNet.VkUtils.SendImage(vk, message, result.Key, result.Value);
            }
            else
            {
                command.Execute(vk, message, query);
            }
        }
        public void GetSongPairs()
        {
            lock (_searchEngine)
            {
                var user = VkUtils.GetUserByScreenName(_screenName, _api);
                Assert.IsNotNull(user);

                var downloader = new VkMusicDownloadEngine(_api, 6000);
                var trackList  = downloader.DownloadTrackList(user);

                Assert.IsNotNull(trackList);

                var tracksPairs = _searchEngine.FindTracksPairs(trackList);

                Assert.IsNotNull(tracksPairs);
            }
        }
Example #9
0
        /// <summary>
        ///     API Authorization
        /// </summary>
        public VkTests()
        {
            var initData = Utils.ReadFile(@$ "{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}{BasicInfo.Default_init_data}");

            var login    = initData.GetKey("VK.LOGIN");
            var password = initData.GetKey("VK.PASSWORD");

            _screenName = initData.GetKey("VK.SCREEN_NAME");

            Assert.IsNotNull(login);
            Assert.IsNotNull(password);
            Assert.IsNotNull(_screenName);

            _api = VkUtils.AuthorizeApi(login, password);

            Assert.IsNotNull(_api);
            Assert.IsTrue(_api.IsAuthorized);
        }
Example #10
0
 public static void AddVkTrackListDownloader(this IServiceCollection serviceCollection,
                                             IConfiguration configuration)
 {
     serviceCollection.AddSingleton <IMusicDownloadEngine <VkTrack, User> >(new VkMusicDownloadEngine(
                                                                                VkUtils.AuthorizeApi(configuration["VK:LOGIN"], configuration["VK:PASSWORD"]),
                                                                                uint.Parse(configuration["VK:MAX_REQUEST_LENGTH"])));
 }