fix!: prevent exceptions from being muted

happens by not awaiting tasks
This commit is contained in:
ZavaruKitsu
2022-10-08 20:00:21 +03:00
parent f41fdf90ed
commit f9d25dfb83
9 changed files with 61 additions and 55 deletions
+2 -2
View File
@@ -7,7 +7,7 @@ namespace TelegramBotBase.Base;
public static class Async
{
public delegate Task AsyncEventHandler<TEventArgs>(object sender, TEventArgs e) where TEventArgs : EventArgs;
public delegate Task AsyncEventHandler<in TEventArgs>(object sender, TEventArgs e) where TEventArgs : EventArgs;
public static IEnumerable<AsyncEventHandler<TEventArgs>> GetHandlers<TEventArgs>(
this AsyncEventHandler<TEventArgs> handler)
@@ -24,4 +24,4 @@ public static class Async
handler.GetHandlers()
.Select(handleAsync => handleAsync(sender, e)));
}
}
}
+6 -8
View File
@@ -41,7 +41,6 @@ public class MessageClient
ApiKey = apiKey;
TelegramClient = new TelegramBotClient(apiKey, proxy);
Prepare();
}
@@ -124,11 +123,9 @@ public class MessageClient
}
public Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
public async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update, CancellationToken cancellationToken)
{
OnMessageLoop(new UpdateResult(update, null));
return Task.CompletedTask;
await OnMessageLoop(new UpdateResult(update, null));
}
public Task HandleErrorAsync(ITelegramBotClient botClient, Exception exception,
@@ -161,6 +158,7 @@ public class MessageClient
/// This will set your bot commands to the given list.
/// </summary>
/// <param name="botcommands"></param>
/// <param name="languageCode"></param>
/// <returns></returns>
public async Task SetBotCommands(List<BotCommand> botcommands, BotCommandScope scope = null,
string languageCode = null)
@@ -186,10 +184,10 @@ public class MessageClient
remove => Events.RemoveHandler(EvOnMessageLoop, value);
}
public void OnMessageLoop(UpdateResult update)
public async Task OnMessageLoop(UpdateResult update)
{
(Events[EvOnMessageLoop] as Async.AsyncEventHandler<UpdateResult>)?.Invoke(this, update);
await (Events[EvOnMessageLoop] as Async.AsyncEventHandler<UpdateResult>)?.Invoke(this, update);
}
#endregion
}
}