//TODO: нужно разделять id юзера и группы //TODO: выкладка на стену сообщества //TODO: английский алфавит //TODO: валидация static void Main(string[] args) { var ids = new List <string>(); while (true) { var id = Console.ReadLine(); if (string.IsNullOrWhiteSpace(id)) { break; } ids.Add(id); } var vkService = new VkService(); var statService = new StatService(); try { var dict = vkService.GetWallPosts(ids, 5); foreach (var item in dict) { Console.WriteLine($"{item.Key}, статистика для последних 5 постов: "); Console.WriteLine(statService.GetStat(item.Value)); } } catch (Exception e) { Console.WriteLine(e.Message); } }
void Start() { var config = ConfigHelper.GetConfig(); var controller = new VkController(VkService.GetInstance(config.Login, config.Pass, config.AppId, config.Phone, new Uri(config.WebDriver))); Task.Factory.StartNew(() => controller.StartLongPoolWatch()); }
public async Task <UserDto> GetUserViaExternalSocialNet(long externalUserId, string email, string externalToken, long expiresIn, SocialType socialType) { Logger.LogInformation($"{nameof(ExternalAuthService)}.{nameof(GetUserViaExternalSocialNet)}.Start Via email from mobile"); NormalizedSocialUserData socialUserData; switch (socialType) { case SocialType.Vk: socialUserData = await VkService.GetUserInfoAsync(externalUserId, email, externalToken, expiresIn); break; case SocialType.Facebook: case SocialType.Twiter: case SocialType.GooglePlus: case SocialType.Telegram: case SocialType.Badoo: case SocialType.Nothing: default: throw new Exception($"We do not support mobile logging via {socialType}."); } var result = await ExternalUserProcessing(socialUserData, socialType); Logger.LogInformation($"{nameof(ExternalAuthService)}.{nameof(GetUserViaExternalSocialNet)}.End Via email from mobile"); return(result); }
public async Task <UserDto> GetUserViaExternalSocialNet(string code, SocialType socialType, bool isTest = false) { Logger.LogInformation($"{nameof(ExternalAuthService)}.{nameof(GetUserViaExternalSocialNet)}.Start via code from web client"); NormalizedSocialUserData socialUserData; switch (socialType) { //socialUserData = await _fbService.GetUserInfoAsync(code); //break; case SocialType.Vk: socialUserData = await VkService.GetUserInfoAsync(code, isTest); break; case SocialType.Facebook: case SocialType.Twiter: case SocialType.GooglePlus: case SocialType.Telegram: case SocialType.Badoo: case SocialType.Nothing: default: throw new Exception($"We do not support logging via {socialType}."); } var result = await ExternalUserProcessing(socialUserData, socialType); Logger.LogInformation($"{nameof(ExternalAuthService)}.{nameof(GetUserViaExternalSocialNet)}.End via code from web client"); return(result); }
static void Main(string[] args) { DateTimeOffset date = DateTimeOffset.Now; string dateString = date.ToString("yyyy-MM-dd"); string fileName = $"program{date.Ticks}.png"; OvvaService ovva = new OvvaService(); var programs = ovva.GetProgramForChannelByDay(fileName, ConstantInfo.Lang, dateString, ConstantInfo.Channel); //foreach (var program in programs) //{ // var olol = new DateTime(program.BeginTime); // var olol1 = olol.ToString("t"); // program.Time = $"{new DateTime(program.BeginTime).ToString("t")} - {new DateTime(program.EndTime).ToString("t")}"; //} var costils = CostilParse(programs); string html = HtmlHelper.RenderHtml(costils, dateString); HtmlHelper.SaveHtmlToImage(html, fileName); VkService vk = new VkService(); vk.Authorize(ConstantInfo.AppId, ConstantInfo.Email, ConstantInfo.Password, Settings.All); var photos = vk.UploadImageInGroup((long)ConstantInfo.AlbumId, (long)ConstantInfo.GroupId, fileName); vk.WallPost("Hacaton Int20h", photos, (long)ConstantInfo.GroupId, true); }
static BotAPI() { vkService = new VkService(); gifService = new GifService(); Commands["call"] = async args => { var users = await vkService.GetGroupUsers(); await vkService.SendMessagesByIds(users, args[0]); }; Commands["ok"] = async args => { await vkService.SendMessageById(args[0], "Ok. Request is processing"); }; Commands["error"] = async args => { await vkService.SendMessageById(args[0], "Command not found. Send help"); }; Commands["anime"] = async args => { await vkService.SendMessageById(args[0], AnimeList.Urls[new Random().Next(0, AnimeList.Urls.Count)]); }; Commands["help"] = async args => { await vkService.SendMessageById(args[0], HelpText.Text); }; Commands["gg"] = async args => { string userId; string gifLink; if (args.Length > 1) { userId = args[1]; gifLink = gifService.GetGifByCategory(args[0]); } else { userId = args[0]; gifLink = gifService.GetRandomGif(); } if (gifLink == null) { await Commands["help"](new[] { userId }); } else { await vkService.SendGifById(userId, gifLink); } }; }
/// <summary> /// Start Message Processing /// </summary> public void ProcessMessages(VkService service, IList <IList <object> > messages) { var config = ConfigHelper.GetConfig(); int chatId = 5; //Chat ID if (config != null) { chatId = int.Parse(config.ChatId); } foreach (var update in messages) { if (!Convert.ToString(update[0]).Equals("4")) { continue; } if (!Convert.ToString(update[6]).Contains("/")) { continue; } var message = Convert.ToString(update[6]); try { if (config != null) { foreach (var assembly in config.Assemblies.Distinct()) { HttpClient client = new HttpClient(); var res = RunLogicAsync(client, new Parameter { AssemblyName = assembly, InvokeParameter = message }, config.ServiceUrl); var actualChatId = Convert.ToInt64(update[3]) - 2000000000; //3 for chat id if (actualChatId != chatId) { continue; } service.SendMessage(new MessagesSendParams { ChatId = chatId, Message = res }); } } } catch (Exception e) { ErrorSignal.FromCurrentContext().Raise(e); service.SendMessage(new MessagesSendParams { ChatId = chatId, Message = "down" }); } } }
private void LongPool_NewMessages(VkService owner, IList <IList <object> > messages) { NewMessages?.Invoke(owner, messages); try { ProcessMessages(owner, messages); } catch (Exception e) { ErrorSignal.FromCurrentContext().Raise(e); } }
public VkController(VkService api = null) { if (api == null) { var config = ConfigHelper.GetConfig(); Api = VkService.GetInstance(config.Login, config.Pass, config.AppId, config.Phone, new Uri(config.WebDriver)); } else { Api = api; } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Main form = new Main(); IMainService mainService = new MainService(); IMessageService messageService = new MessageService(); IVkService vkService = new VkService(); IInstagramService instagramService = new InstagramService(); MainPresenter presenter = new MainPresenter(form, instagramService, mainService, vkService, messageService); Application.Run(form); }
private async Task MainAsync() { var data = new DataManager(); data.LoadBotSettings("Settings.json"); var logger = new Logger(DataManager.BotSettings.LogLevel); data.Log += logger.Log; data.LoadGuildsSettings(); var client = new DiscordSocketClient(DataManager.BotSettings.DiscordSocketConfig); client.Log += logger.Log; var commandService = new CommandService(); commandService.Log += logger.Log; await commandService.AddModuleAsync <SettingsModule>(); await commandService.AddModuleAsync <NotifyModule>(); var vkService = new VkService(DataManager.BotSettings.VkAuthFilePath); vkService.Log += logger.Log; var notifyService = new NotifyService(client, vkService, data); notifyService.Log += logger.Log; var services = new ServiceCollection(); services.AddSingleton(data); services.AddSingleton(commandService); services.AddSingleton(vkService); services.AddSingleton(notifyService); var eventHandler = new DiscordEventHandler(client, commandService, services.BuildServiceProvider()); client.MessageReceived += eventHandler.HandleCommandAsync; client.GuildAvailable += eventHandler.GuildAvailable; client.GuildUpdated += eventHandler.GuildUpdated; client.Ready += eventHandler.ClientReady; await client.LoginAsync(TokenType.Bot, File.ReadAllText(DataManager.BotSettings.TokenFilePath)); await client.StartAsync(); await Task.Delay(-1); }
public void SendMessage([FromBody] string message) { try { var config = ConfigHelper.GetConfig(); if (config != null && message != null) { VkService.GetInstance(config.Login, config.Pass, config.AppId, config.Phone, new Uri(config.WebDriver)).SendMessage(new MessagesSendParams { ChatId = int.Parse(config.ChatId), Message = message }); } } catch (Exception e) { ErrorSignal.FromCurrentContext().Raise(e); } }
public void TestGetPrivateInfo() { #region Arrange var vkServiceToTest = new VkService(); var ids_path = "test_info.txt"; var client_id_expected = 9474548; var group_id_expected = 146932531; Type t = typeof(VkService); MethodInfo method = t.GetMethod("GetPrivateInfo", BindingFlags.Instance | BindingFlags.NonPublic); #endregion #region Act var ids_actual = (Dictionary <string, int>)method.Invoke(vkServiceToTest, new object[] { ids_path }); #endregion #region Assert Assert.AreEqual(client_id_expected, ids_actual["client_id"]); Assert.AreEqual(group_id_expected, ids_actual["group_id"]); #endregion }
public MemologyController(BaseDb baseDb, VkService vkService) { _dbContext = baseDb; _vkService = vkService; }
public CohortAnalysisController() { _dbContext = new BaseDb(); _vkService = new VkService(); }
public NotifyModule(NotifyService notify, VkService vk) { _notify = notify; _vk = vk; }
public override async void ExecuteAsync(Message message, TelegramBotClient client) { var chatId = message.Chat.Id; string response = VkService.ListSubscriptions(chatId); await client.SendTextMessageAsync(chatId, response); }
public LongPoolWatcher(VkService api) { _account = api; }
public SalesAnalysisController(VkService vkService) { _dbContext = new BaseDb(); _vkService = vkService; }
public void InitService() { _vk = new VkService("Configurations/Secrets/VkAuthParams.json"); }
public async Task <bool> AddUserSocialAsync(int userId, string code, SocialType socialType) { Logger.LogInformation($"{nameof(AccountService)}.{nameof(AddUserSocialAsync)}.Start"); NormalizedSocialUserData user; switch (socialType) { case SocialType.Facebook: user = await FbService.GetUserInfoAsync(code); break; case SocialType.Vk: user = await VkService.GetUserInfoAsync(code); break; case SocialType.Twiter: case SocialType.GooglePlus: case SocialType.Telegram: case SocialType.Badoo: case SocialType.Nothing: default: throw new Exception("We do not support this social network."); } var social = new SocialEntity { InternalId = userId, ExternalId = user.ExternalId, SocialType = socialType, Email = user.ExternalEmail, ExternalToken = user.ExternalToken, ExpiresIn = user.ExpiresIn }; if (!await Db.Users.AddUserSocialAsync(social)) { return(false); } var userInfo = await Db.UsersInfo.FindUserInfoAsync(userId, userId); if (userInfo.OriginalAvatarUrl.IsNullOrEmpty() || MediaConverter.IsStandardBackground(userInfo.OriginalAvatarUrl) && !user.OriginalPhotoUrl.IsNullOrEmpty()) { userInfo.OriginalAvatarUrl = await UploadAvatarUrlOrGetStandard(user.OriginalPhotoUrl); } var updateUser = new UpdateUserInfoDto { UserId = userInfo.UserId, FristName = userInfo.FirstName, LastName = userInfo.LastName, BirthDate = userInfo.BirthDate, SexType = userInfo.SexType, City = userInfo.City, Description = userInfo.Description }; try { await UpdateUserInfoAsync(updateUser); } catch (Exception e) { Logger.LogError(e, $"{nameof(AccountService)}.{nameof(AddUserSocialAsync)} Error"); } Logger.LogInformation($"{nameof(AccountService)}.{nameof(AddUserSocialAsync)}.End"); return(true); }
public VkController(VkService vkService, VkDatabaseService vkDatabaseService) { _vkService = vkService; _vkDatabaseService = vkDatabaseService; }