Уведомляем о проблемах. Но один раз, потом только после того, как проблема будет явно отмечена как решённая
This commit is contained in:
+31
-10
@@ -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<IUserState> ProcessMessage(IUserState previous, Telegram.Bot.Types.Update e)
|
||||
{
|
||||
var response = "";
|
||||
List<List<KeyboardButton>> buttons = new List<List<KeyboardButton>>();
|
||||
if (previous != this)
|
||||
{
|
||||
response = "Возможные проблемы:\n";
|
||||
@@ -47,6 +44,26 @@ namespace ZaoBot
|
||||
{
|
||||
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)
|
||||
{
|
||||
@@ -58,12 +75,11 @@ namespace ZaoBot
|
||||
{
|
||||
response = "Я не понял";
|
||||
}
|
||||
var replyKeyboardMarkup = new ReplyKeyboardMarkup(
|
||||
new KeyboardButton[][]
|
||||
buttons.Add(new List<KeyboardButton>()
|
||||
{
|
||||
new KeyboardButton[] { CMD_BACK },
|
||||
}
|
||||
);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user