public async override Task ExecuteAsync(CommandContext context) { if (context.IsCallback && context.Message != null) { await BotClient.EditMessageReplyMarkupAsync(context.Message.Chat, context.Message.MessageId, InlineKeyboardMarkup.Empty()); } CommandState newState = CommandState.MainMenu; string message = Localizer["BackMainMenu"]; var keyboard = CommandKeyboards.GetMainMenu(Localizer); if (context.State == CommandState.EditBookMenu) { context.SelectedBook = null; newState = CommandState.BookMenu; message = Localizer["BackBookMenu"]; keyboard = CommandKeyboards.GetBookMenu(Localizer); } else { context.SelectedBook = null; context.SelectedBookshelf = null; } context.ChangeState(newState); await BotClient.SendTextMessageAsync(context.Message.Chat, message, replyMarkup : keyboard); context.RedirectToCommand("/help"); }
public async override Task ExecuteAsync(CommandContext context) { EnterMessage = Localizer["RemoveBookEnter"]; NoExitstMessage = Localizer["RemoveBookError"]; ExistMessage = Localizer["RemoveBookSuccess"]; Message = ExistMessage; IReplyMarkup keyboard = new ReplyKeyboardRemove(); if (InputData(context, out Book book)) { if (book != null) { context.RemoveBook(book); context.CommandName = null; keyboard = CommandKeyboards.GetBookMenu(Localizer); } else { context.CommandName = Name; } } await BotClient.SendTextMessageAsync(context.Message.Chat, Message, replyMarkup : keyboard); }
public async override Task ExecuteAsync(CommandContext context) { EnterMessage = Localizer["AddBookEnter"]; NoExitstMessage = Localizer["AddBookSuccess"]; ExistMessage = Localizer["AddBookError"]; IReplyMarkup keyboard = new ReplyKeyboardRemove(); if (InputData(context, out Book book)) { if (book == null) { string title = context.Parameters ?? context.Data; var bookAccessor = new BookDAO(); if (context.PreviousCommand == Alias[0]) { book = await bookAccessor.GetBookAsync(title); } if (book == null) { book = new Book { Title = title }; if (context.PreviousCommand == Alias[0]) { await BotClient.SendTextMessageAsync(context.Message.Chat, Localizer["AddBookSearchError"]); } } else if (context.PreviousCommand == Alias[0]) { await BotClient.SendTextMessageAsync(context.Message.Chat, Localizer["AddBookSearchSuccess"]); } book.Bookshelf = context.SelectedBookshelf; context.AddBook(book); context.CommandName = null; keyboard = CommandKeyboards.GetBookMenu(Localizer); context.RedirectToCommand("/select", book.Title); } else { context.CommandName = Name; } } await BotClient.SendTextMessageAsync(context.Message.Chat, Message, replyMarkup : keyboard); }
public async override Task ExecuteAsync(CommandContext context) { if (context.IsCallback) { await ProcessCallback(context); return; } Bookshelf bookshelf = FindItem(context); IReplyMarkup keyboard = null; string message = Localizer["SelectBookshelfError"]; if (bookshelf != null) { message = string.Format(selectedMessage, bookshelf.Name, Localizer["SelectBookshelfSelected"]); context.SelectedBookshelf = bookshelf; context.ChangeState(CommandState.BookMenu); keyboard = CommandKeyboards.GetBookMenu(Localizer); } if (keyboard == null) { await BotClient.SendTextMessageAsync(context.Message.Chat, message, ParseMode.Html); } else { await BotClient.SendTextMessageAsync(context.Message.Chat, message, ParseMode.Html, replyMarkup : keyboard); keyboard = new InlineKeyboardMarkup( new[] { InlineKeyboardButton.WithCallbackData(Localizer["EditButton"], $"/change1 /select {bookshelf.Id}"), InlineKeyboardButton.WithCallbackData(Localizer["RemoveButton"], $"/change1 /select") } ); await BotClient.SendTextMessageAsync(context.Message.Chat, bookshelf.Name, replyMarkup : keyboard); } }