public VkLikeService( IVkClient client, IJsonSerializer jsonSerializer, ILogger <VkLikeService> logger ) : base(client, jsonSerializer, logger) { }
public static InternalVkApiAuthorizationResponse AuthorizeByAccessToken(this IVkClient client, string accessToken, ulong appId) { return(client.Authorize(new InternalVkApiAuthorizationRequestParams { ApplicationId = appId, AccessToken = accessToken })); }
public BaseHttpClient( IVkClient client, IJsonSerializer jsonSerializer, ILogger <TClient> logger ) { _jsonSerializer = jsonSerializer; Logger = logger; _httpClient = client; }
public StatRequestExecutor(ApplicationSettings settings, IVkClient vkClient, ScreenNamesToVkApiObjectsCache screenNamesToVkApiObjectsCache, IStatsBuilder <StatsBuilderBuildArgs>[] statsBuilders, IUsernameProvider usernameProvider) { this.settings = settings; this.vkClient = vkClient; this.screenNamesToVkApiObjectsCache = screenNamesToVkApiObjectsCache; this.statsBuilders = statsBuilders; this.usernameProvider = usernameProvider; }
public static InternalVkApiAuthorizationResponse AuthorizeByLoginPassword(this IVkClient client, string login, string password, ulong appId) { return(client.Authorize(new InternalVkApiAuthorizationRequestParams { ApplicationId = appId, Login = login, Password = password })); }
public Crawler( IRepository<VkPost> postsRepository, IRepository<StatisticsEntity> statisticsRepository, IRepository<DbCollection> collectionsRepository, IDictionary<Type, IStatistics> statisticsContainer, IVkClient vkClient ) { XmlConfigurator.Configure(); _postsRepository = postsRepository; _statisticsRepository = statisticsRepository; _collectionsRepository = collectionsRepository; _collectionsRepository.SetTable("collections!"); _statsContainer = statisticsContainer; _vkClient = vkClient; }
private static void RunBot(VkApi vkApi, IVkClient vkClient) { var webClient = new WebClient { Encoding = Encoding.UTF8 }; var parameters = new VkParameters { { "group_id", "178216097" } }; dynamic responseOnLongPollApi = JObject.Parse(vkApi.Call("groups.getLongPollServer", parameters).RawJson); var key = responseOnLongPollApi.response.key.ToString(); var server = responseOnLongPollApi.response.server.ToString(); var ts = responseOnLongPollApi.response.ts.ToString(); var json = string.Empty; var url = string.Empty; while (true) { url = string.Format("{0}?act=a_check&key={1}&ts={2}&wait=1", server, key, json != string.Empty ? JObject.Parse(json)["ts"].ToString() : ts); json = webClient.DownloadString(url); var messages = JObject.Parse(json)["updates"].ToList(); foreach (var messageObj in messages) { if (messageObj["type"].ToString() != "message_new") { continue; } var inputMessageStr = messageObj["object"]["body"].ToString(); ConsoleLog.Info($"Input message: {inputMessageStr}"); var from = messageObj["object"]["user_id"].ToString(); Log.Info($"Input message: {inputMessageStr}"); var offset = 0; var batchSize = 1000; var maxCountMembersInGroup = 10000; //key - city id, value - count users in city var citiesDictionary = new Dictionary <string, int>(); var countUsersWithoutCities = 0; var urlBotMsg = $"https://api.vk.com/method/messages.send?v=5.41&access_token={Token}&user_id="; while (true) { if (vkClient.TryGetMembersCountFromGroup(inputMessageStr, out var membersCount)) { if (membersCount > maxCountMembersInGroup) { webClient.DownloadString(string.Format(urlBotMsg + "{0}&message={1}", from, $"Бот еще маленький. В группе {inputMessageStr} - {membersCount} человек. Бот умеет считать только до {maxCountMembersInGroup}")); break; } } else { webClient.DownloadString(string.Format(urlBotMsg + "{0}&message={1}", from, $"Неверный идентификатор группы: {inputMessageStr}")); break; } vkClient.TryGetMembersIdsFromGroup(inputMessageStr, offset, batchSize, out var membersIds); var cities = vkClient.GetUsersCities(membersIds.Select(i => i.ToString()).ToArray()); foreach (var city in cities) { if (string.IsNullOrEmpty(city)) { countUsersWithoutCities++; } else if (citiesDictionary.ContainsKey(city)) { citiesDictionary[city]++; } else { citiesDictionary.Add(city, 1); } } if (membersIds.Count() < batchSize) { var stringBuilder = new StringBuilder(); var i = 0; foreach (var cityInfo in citiesDictionary) { stringBuilder.AppendLine($"{cityInfo.Key} - {cityInfo.Value}"); i++; if (i == 20) { webClient.DownloadString(string.Format(urlBotMsg + "{0}&message={1}", from, stringBuilder)); i = 0; stringBuilder = new StringBuilder(); } } if (countUsersWithoutCities > 0) { stringBuilder.AppendLine($"Без указания города: {countUsersWithoutCities}"); } webClient.DownloadString(string.Format(urlBotMsg + "{0}&message={1}", from, stringBuilder)); //vkApi.Messages.Send(new MessagesSendParams //{ // Message = $"{stringBuilder}", // UserId = long.Parse(from), // RandomId = new Random().Next() //}); break; } offset = offset + membersIds.Count(); } Thread.Sleep(200); } } }
public ScreenNamesToVkApiObjectsCache(IVkClient vkClient) { this.vkClient = vkClient; }
public IdsToUsersCache(IVkClient vkClient) { this.vkClient = vkClient; }
public GetVkStatusAction(IVkClient vkClient, VkUser user) { _vkClient = vkClient; _user = user; }
public void OneTimeSetUp() { vkClient = A.Fake <IVkClient>(); usernameProvider = new UsernameProvider(new IdsToUsersCache(vkClient), new IdsToGroupsCache(vkClient)); }
public VkAuthenticatorFromSettings(ApplicationSettings appSettings, IVkClient vkClient) { this.appSettings = appSettings; this.vkClient = vkClient; }
public static InternalVkApiUser GetUserOrDie(this IVkClient client, long id) { return(client.GetUsers(new InternalVkApiUserGetRequestParams { Ids = new[] { id } }).Single()); }
public IdsToGroupsCache(IVkClient vkClient) { this.vkClient = vkClient; }