From 18b7b9120c9113d3cf5003d013c2648669d8e6e9 Mon Sep 17 00:00:00 2001 From: Slavasil Date: Sun, 20 Apr 2025 19:49:26 +0300 Subject: [PATCH] make return to main menu work --- SimpleTGBot/Interactions.cs | 14 +++++++++----- SimpleTGBot/TelegramBot.cs | 15 ++++++++++++--- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/SimpleTGBot/Interactions.cs b/SimpleTGBot/Interactions.cs index 103d5f0..bb36b21 100644 --- a/SimpleTGBot/Interactions.cs +++ b/SimpleTGBot/Interactions.cs @@ -9,17 +9,21 @@ internal static class Interactions public const string sendPictureOrQuitMessage = "Пришли мне картинку для демотиватора, чтобы продолжить. Чтобы отменить, напиши \"назад\" или \"\""; public const string sendTitleOrQuitMessage = "Пришли мне текст для демотиватора, чтобы продолжить. Чтобы отменить, нажми на кнопку в меню."; public const string awaitingTitleMessage = "Шикарная картинка. Давай сделаем из неё крутой интернет-мэм для скуфов. Какой текст ты бы хотел видеть на нём? Можно написать две строки, тогда первая строка будет заголовком, а вторая под ним."; - public const string showingResultMessage = "Вот такой демотиватор получился. Можно поменять цветовую схему, добавить водяной знак или оставить как есть."; + public const string showingResultMessage = "Вот такой демотиватор получился. Можно поменять цветовую схему, добавить водяной знак или оставить как есть (нажмите одну из кнопок)."; public const string awaitingSubtitleMessage = "Найс. Напиши текст, который будет под заголовком, или точку (.), чтобы не добавлять его."; - - public static readonly IReplyMarkup initialReplyMarkup = new ReplyKeyboardMarkup([[new KeyboardButton("▶️Начать")]]); - public static readonly IReplyMarkup backButtonReplyMarkup = new ReplyKeyboardMarkup(new KeyboardButton("↩️Назад")); - public static readonly IReplyMarkup quickActionReplyMarkup = new ReplyKeyboardRemove(); + public const string chooseActionMessage = "Нажмите на одну из кнопок."; static readonly string[] helloWords = ["прив","привет","▶️начать","ку","хай","приветик","превед","привки","хаюхай","здравствуй","здравствуйте","здорово","дарова","дороу","здарова","здорова"]; static readonly string[] cancelWords = ["↩️назад", "назад", "выйти", "отмена", "отменить", "отменяй", "галя", "галина", "стоп"]; static readonly string cancelButtonText = "↩️Назад"; + public static readonly string doneButtonText = "✅Готово"; + + public static readonly IReplyMarkup initialReplyMarkup = new ReplyKeyboardMarkup([[new KeyboardButton("▶️Начать")]]); + public static readonly IReplyMarkup backButtonReplyMarkup = new ReplyKeyboardMarkup(new KeyboardButton("↩️Назад")); + public static readonly IReplyMarkup quickActionReplyMarkup = new ReplyKeyboardRemove(); + public static readonly IReplyMarkup resultActionReplyMarkup = new ReplyKeyboardMarkup([new KeyboardButton(doneButtonText)]); + public static bool IsStartCommand(string message) { return message.Split(' ').FirstOrDefault() == "/start"; diff --git a/SimpleTGBot/TelegramBot.cs b/SimpleTGBot/TelegramBot.cs index 54d8536..49d4785 100644 --- a/SimpleTGBot/TelegramBot.cs +++ b/SimpleTGBot/TelegramBot.cs @@ -170,7 +170,16 @@ internal class TelegramBot bool replied = false; if (message.Text is { } messageText) { - + if (messageText == Interactions.doneButtonText) + { + replied = true; + dialogData.state = DialogState.AwaitingPicture; + await botClient.SendTextMessageAsync(message.Chat.Id, Interactions.awaitingPictureMessage, replyMarkup: Interactions.quickActionReplyMarkup); + } + } + if (!replied) + { + await botClient.SendTextMessageAsync(message.Chat.Id, Interactions.chooseActionMessage, replyMarkup: Interactions.resultActionReplyMarkup); } break; } @@ -228,7 +237,7 @@ internal class TelegramBot [new DemotivatorText() { Title = title, Subtitle = subtitle }], DemotivatorGen.DefaultStyle()); DialogFinishDemotivatorCreation(dialogData); - await botClient.SendPhotoAsync(message.Chat.Id, new InputFile(demotivator, "dem.png"), caption: Interactions.showingResultMessage, cancellationToken: cancellationToken); + await botClient.SendPhotoAsync(message.Chat.Id, new InputFile(demotivator, "dem.png"), caption: Interactions.showingResultMessage, replyMarkup: Interactions.resultActionReplyMarkup, cancellationToken: cancellationToken); demotivator.Dispose(); } else { @@ -250,7 +259,7 @@ internal class TelegramBot [new DemotivatorText() { Title = title, Subtitle = subtitle }], DemotivatorGen.DefaultStyle()); DialogFinishDemotivatorCreation(dialogData); - await botClient.SendPhotoAsync(message.Chat.Id, new InputFile(demotivator, "dem.png"), caption: Interactions.showingResultMessage, cancellationToken: cancellationToken); + await botClient.SendPhotoAsync(message.Chat.Id, new InputFile(demotivator, "dem.png"), caption: Interactions.showingResultMessage, replyMarkup: Interactions.resultActionReplyMarkup, cancellationToken: cancellationToken); demotivator.Dispose(); }