static async Task <int> Main(string[] args) { IApiInicializer initializer = new ApiFileInicializer("../../../files/ini.txt"); IMessageApi botApi = initializer.GetApi(); TokenBotAuthorizer tokenBotAuthorizer = new TokenBotAuthorizer("../../../files/remember.json", Globals.TokenAPI); //IAuthorizer authorizer = new DefaultAuthorizer(); Add authorization! //DictTagsService tagsService = new DictTagsService(); ApiFeedService apiFeedService = new ApiFeedService(Globals.FeedAPI, Globals.TagAPI, Globals.SpecialTagAPI, tokenBotAuthorizer); ApiUsersService apiUsersService = new ApiUsersService(Globals.UsersAPI, Globals.UsersRolesAPI, tokenBotAuthorizer); //IMessageConditionHandler commandConditionHandler = new CommandHandler(tagsService, botApi); PlainTextHandler emptyTextHandler = new PlainTextHandler(apiFeedService, botApi); AttachmentHandler attachmentHandler = new AttachmentHandler(botApi, apiUsersService); //WallPostEventsHandler wallPostEventsHandler = new WallPostEventsHandler(botApi, apiFeedService); WallPostEventsHandler wallPostEventsHandler = new WallPostEventsHandler(apiFeedService); ButtonHandler buttonHandler = new ButtonHandler(apiFeedService, apiUsersService, botApi); emptyTextHandler.AddTagToWallPost += wallPostEventsHandler.AddTagToPost; attachmentHandler.AddingPostEvent += wallPostEventsHandler.HandlePost; buttonHandler.AddingTagEvent += emptyTextHandler.AddingTag; buttonHandler.CancelTag += emptyTextHandler.StopAddingTag; buttonHandler.UserAddingTagToPost += emptyTextHandler.AddingTagToPost; buttonHandler.CancelUserAddingTagToPost += emptyTextHandler.StopAddingTagToPost; buttonHandler.AddingAdminEvent += emptyTextHandler.AddingAdmin; buttonHandler.CancelAdmin += emptyTextHandler.StopAddingAdmin; buttonHandler.RemovingAdmin += emptyTextHandler.RemovingAdmin; buttonHandler.CancelRemovingAdmin += emptyTextHandler.StopRemovingAdmin; buttonHandler.Cancel += wallPostEventsHandler.Cancel; buttonHandler.Send = wallPostEventsHandler; buttonHandler.AttachedTagsMessage += wallPostEventsHandler.AttachedTagsMessage; buttonHandler.AddingTagToPostEvent += wallPostEventsHandler.AddTagToPost; buttonHandler.DetachingTagEvent += wallPostEventsHandler.DetachTagFromPost; buttonHandler.GetUserNameEvent += botApi.GetUserName; while (true) { IEnumerable <Message> newMessages; try { newMessages = botApi.NewMessages(); } catch (TaskCanceledException e) { Console.WriteLine("timeout error caught!"); Console.WriteLine("new request"); newMessages = botApi.NewMessages(); } foreach (Message message in newMessages) { if (attachmentHandler.Condition(message)) { MessagesSendParams sendParams = await attachmentHandler.Reply(message); botApi.SendMessage(sendParams); } /*if (commandConditionHandler.Condition(message)) * { * botApi.SendMessage(commandConditionHandler.Reply(message)); * }*/ if (emptyTextHandler.Condition(message)) { MessagesSendParams sendParams = await emptyTextHandler.Reply(message); botApi.SendMessage(sendParams); } if (buttonHandler.Condition(message)) { MessagesSendParams sendParams = await buttonHandler.Reply(message); botApi.SendMessage(sendParams); } } } }
/*public WallPostEventsHandler(IMessageApi messageApi, ApiFeedService feedService) * { * _messageApi = messageApi; * _feedService = feedService; * }*/ public WallPostEventsHandler(ApiFeedService feedService) { _feedService = feedService; }
public PlainTextHandler(ApiFeedService feedService, IMessageApi messageApi) { _feedService = feedService; _messageApi = messageApi; }
public ButtonHandler(ApiFeedService feedService, ApiUsersService usersService, IMessageApi messageApi) { _feedService = feedService; _usersService = usersService; _messageApi = messageApi; }