Catch (some) APIErrors

This commit is contained in:
zotan 2018-02-09 22:15:27 +01:00
parent 7b9efdf002
commit 509935a9aa
No known key found for this signature in database
GPG key ID: A8DA209231E36475

View file

@ -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;