From fe3051c73e59214c0c93b9454a0decc69f53d068 Mon Sep 17 00:00:00 2001 From: Denis Denisov Date: Sat, 27 Jan 2024 16:04:11 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B2=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB?= =?UTF-8?q?=D1=8F=D0=B5=D0=BC=20=D0=BE=20=D0=BF=D1=80=D0=BE=D0=B1=D0=BB?= =?UTF-8?q?=D0=B5=D0=BC=D0=B0=D1=85.=20=D0=9D=D0=BE=20=D0=BE=D0=B4=D0=B8?= =?UTF-8?q?=D0=BD=20=D1=80=D0=B0=D0=B7,=20=D0=BF=D0=BE=D1=82=D0=BE=D0=BC?= =?UTF-8?q?=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=BF=D0=BE=D1=81?= =?UTF-8?q?=D0=BB=D0=B5=20=D1=82=D0=BE=D0=B3=D0=BE,=20=D0=BA=D0=B0=D0=BA?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D0=B1=D0=BB=D0=B5=D0=BC=D0=B0=20=D0=B1?= =?UTF-8?q?=D1=83=D0=B4=D0=B5=D1=82=20=D1=8F=D0=B2=D0=BD=D0=BE=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BC=D0=B5=D1=87=D0=B5=D0=BD=D0=B0=20=D0=BA=D0=B0=D0=BA?= =?UTF-8?q?=20=D1=80=D0=B5=D1=88=D1=91=D0=BD=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- StatusMenuUserState.cs | 43 +++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/StatusMenuUserState.cs b/StatusMenuUserState.cs index 76df23c..7b89f5c 100644 --- a/StatusMenuUserState.cs +++ b/StatusMenuUserState.cs @@ -17,11 +17,9 @@ namespace ZaoBot class StatusMenuUserState : IUserState { public const string CMD_BACK = "Назад"; + public const string CMD_CONFIRM_ITEM = "✅ "; ITelegramBotClient botClient; - private JsonDocument config; - HttpClient http = new HttpClient(); - OpenHabClient openhab; IServiceProvider services; StatusManager statusManager; @@ -31,8 +29,6 @@ namespace ZaoBot StatusManager statusManager) { this.botClient = botClient; - this.config = config.Data; - this.openhab = openhab; this.services = services; this.statusManager = statusManager; } @@ -40,6 +36,7 @@ namespace ZaoBot public async Task ProcessMessage(IUserState previous, Telegram.Bot.Types.Update e) { var response = ""; + List> buttons = new List>(); if (previous != this) { response = "Возможные проблемы:\n"; @@ -47,6 +44,26 @@ namespace ZaoBot { response += item.label + ": " + item.status + "\n"; } + var confirmButtons = new List(); + foreach (var item in statusManager.StatusItems) + { + if (item.notified) + { + confirmButtons.Add(GetConfirmText(item)); + } + } + if (confirmButtons.Count > 0) buttons.Add(confirmButtons); + } + else if (e.Message.Text.StartsWith(CMD_CONFIRM_ITEM)) + { + foreach (var item in statusManager.StatusItems) + { + if (e.Message.Text == GetConfirmText(item)) + { + item.notified = false; + } + } + response = CMD_CONFIRM_ITEM; } else if (e.Message.Text == CMD_BACK) { @@ -58,12 +75,11 @@ namespace ZaoBot { response = "Я не понял"; } - var replyKeyboardMarkup = new ReplyKeyboardMarkup( - new KeyboardButton[][] - { - new KeyboardButton[] { CMD_BACK }, - } - ); + buttons.Add(new List() + { + CMD_BACK + }); + var replyKeyboardMarkup = new ReplyKeyboardMarkup(buttons); await botClient.SendTextMessageAsync( chatId: e.Message.Chat, @@ -72,5 +88,10 @@ namespace ZaoBot ); return this; } + + private string GetConfirmText(Problems.Item item) + { + return CMD_CONFIRM_ITEM + item.label; + } } }