public async Task ExecuteRandomLike(int userId) { await using var scope = _transactionScopeFactory.CreateQuery(); var favouriteGroup = await scope .RawSql <FavouriteGroup>( $"select * from public.\"FavouriteGroup\" where \"{nameof(FavouriteGroup.UserId)}\" = {userId} order by random() limit 1") .Select(f => f.GroupId) .FirstOrDefaultAsync(); if (favouriteGroup != default) { using var user = _securityUserManager.SetUser(new SecurityUser { Id = userId }); var rnd = new Random(); var post = (await _vkClient.WallSearch(favouriteGroup, rnd.Next(1, 30), 1))?.Response?.Items ?.FirstOrDefault(); if (post != default && !(post.Likes?.UserLikes ?? true)) { await Task.Delay(300); await _vkLikeService.Like(new VkRepostViewModel(post.OwnerId, post.Id)); } _backgroundJobService.Schedule <IRandomLikeService>(x => x.ExecuteRandomLike(userId), TimeSpan.FromMilliseconds(rnd.Next(60 * 1000 * 3, 60 * 1000 * 60 * 5))); } }
public async Task <VkResponse <List <VkMessage> > > GetReposts(string id, int page, int take, string?search = null) { var data = await _wallService.WallSearch(id, page, take, search); var reposts = data.Response.Items .OrderByDescending(c => c.Date) .Where(c => c.CopyHistory != null && c.CopyHistory.Count > 0) .Select(c => c.CopyHistory.First()) .Distinct() .ToList(); var count = data.Response.Count; var result = reposts.Any() ? await _wallService.GetById(reposts .Select(c => new VkRepostViewModel(c.OwnerId, c.Id)) ) : new VkResponse <List <VkMessage> >(); result.Response ??= new VkResponse <List <VkMessage> > .VkResponseItems(); result.Response.Count = count; return(result); }