Уведомляем о проблемах. Но один раз, потом только после того, как проблема будет явно отмечена как решённая

This commit is contained in:
ftc
2024-01-27 16:04:11 +03:00
parent 070bc3fbf0
commit fe3051c73e
+32 -11
View File
@@ -17,11 +17,9 @@ namespace ZaoBot
class StatusMenuUserState : IUserState class StatusMenuUserState : IUserState
{ {
public const string CMD_BACK = "Назад"; public const string CMD_BACK = "Назад";
public const string CMD_CONFIRM_ITEM = "✅ ";
ITelegramBotClient botClient; ITelegramBotClient botClient;
private JsonDocument config;
HttpClient http = new HttpClient();
OpenHabClient openhab;
IServiceProvider services; IServiceProvider services;
StatusManager statusManager; StatusManager statusManager;
@@ -31,8 +29,6 @@ namespace ZaoBot
StatusManager statusManager) StatusManager statusManager)
{ {
this.botClient = botClient; this.botClient = botClient;
this.config = config.Data;
this.openhab = openhab;
this.services = services; this.services = services;
this.statusManager = statusManager; this.statusManager = statusManager;
} }
@@ -40,6 +36,7 @@ namespace ZaoBot
public async Task<IUserState> ProcessMessage(IUserState previous, Telegram.Bot.Types.Update e) public async Task<IUserState> ProcessMessage(IUserState previous, Telegram.Bot.Types.Update e)
{ {
var response = ""; var response = "";
List<List<KeyboardButton>> buttons = new List<List<KeyboardButton>>();
if (previous != this) if (previous != this)
{ {
response = "Возможные проблемы:\n"; response = "Возможные проблемы:\n";
@@ -47,6 +44,26 @@ namespace ZaoBot
{ {
response += item.label + ": " + item.status + "\n"; response += item.label + ": " + item.status + "\n";
} }
var confirmButtons = new List<KeyboardButton>();
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) else if (e.Message.Text == CMD_BACK)
{ {
@@ -58,12 +75,11 @@ namespace ZaoBot
{ {
response = "Я не понял"; response = "Я не понял";
} }
var replyKeyboardMarkup = new ReplyKeyboardMarkup( buttons.Add(new List<KeyboardButton>()
new KeyboardButton[][] {
{ CMD_BACK
new KeyboardButton[] { CMD_BACK }, });
} var replyKeyboardMarkup = new ReplyKeyboardMarkup(buttons);
);
await botClient.SendTextMessageAsync( await botClient.SendTextMessageAsync(
chatId: e.Message.Chat, chatId: e.Message.Chat,
@@ -72,5 +88,10 @@ namespace ZaoBot
); );
return this; return this;
} }
private string GetConfirmText(Problems.Item item)
{
return CMD_CONFIRM_ITEM + item.label;
}
} }
} }