From 509935a9aaa6b3d8f0ab1d0a325d33e8ab7cfffa Mon Sep 17 00:00:00 2001 From: zotan Date: Fri, 9 Feb 2018 22:15:27 +0100 Subject: [PATCH] Catch (some) APIErrors --- ReminderBot.cs | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/ReminderBot.cs b/ReminderBot.cs index 9013b90..802180a 100644 --- a/ReminderBot.cs +++ b/ReminderBot.cs @@ -10,6 +10,7 @@ using Telegram.Bot.Types; using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.ReplyMarkups; using Newtonsoft.Json; +using Telegram.Bot.Exceptions; namespace TelegramRemindMe { @@ -116,10 +117,16 @@ namespace TelegramRemindMe { case "Add a new task": currentChat.IsWorkingMessage = true; - currentChat.WorkingMsg = Bot.EditMessageTextAsync( - new ChatId(currentChat.ChatId), callbackQueryEventArgs.CallbackQuery.Message.MessageId, - "How should your new task be called?" - ).Result.MessageId; + //TODO: fix + try + { + currentChat.WorkingMsg = Bot.EditMessageTextAsync( + new ChatId(currentChat.ChatId), callbackQueryEventArgs.CallbackQuery.Message.MessageId, + "How should your new task be called?" + ).Result.MessageId; + } + catch (ApiRequestException) + {} currentChat.status = ChatStatusEnum.WaitingTaskTitle; break; case "Set a task as completed": @@ -134,9 +141,14 @@ namespace TelegramRemindMe sb.AppendLine("Send me the number of the task you want to complete."); currentChat.IsWorkingMessage = true; - currentChat.WorkingMsg = - Bot.EditMessageTextAsync(currentChat.ChatId, + try + { + currentChat.WorkingMsg = Bot.EditMessageTextAsync(currentChat.ChatId, callbackQueryEventArgs.CallbackQuery.Message.MessageId, sb.ToString()).Result.MessageId; + } + catch (ApiRequestException) + {} + currentChat.status = ChatStatusEnum.WaitingTaskComplete; break; case "Show all tasks": @@ -184,8 +196,12 @@ namespace TelegramRemindMe await Bot.SendChatActionAsync(chat.ChatId, ChatAction.Typing); //TODO: why is this firing when workingmsg already deleted? - if (chat.IsWorkingMessage) - await Bot.DeleteMessageAsync(chat.ChatId, chat.WorkingMsg); + try + { + if (chat.IsWorkingMessage) + await Bot.DeleteMessageAsync(chat.ChatId, chat.WorkingMsg); + } + catch (ApiRequestException){} chat.IsWorkingMessage = false; chat.status = ChatStatusEnum.Idle;