From 87690a3630393e04d94cab346aa92a9b0fe70bf7 Mon Sep 17 00:00:00 2001 From: FlorianDahn Date: Tue, 22 Dec 2020 15:37:05 +0100 Subject: [PATCH] Update DeviceSession.cs Adding a feature for making future API calls. --- TelegramBotBase/Sessions/DeviceSession.cs | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/TelegramBotBase/Sessions/DeviceSession.cs b/TelegramBotBase/Sessions/DeviceSession.cs index 58ba599..bd08ab3 100644 --- a/TelegramBotBase/Sessions/DeviceSession.cs +++ b/TelegramBotBase/Sessions/DeviceSession.cs @@ -704,6 +704,8 @@ namespace TelegramBotBase.Sessions } } + #region "Users" + public virtual async Task RestrictUser(int userId, ChatPermissions permissions, DateTime until = default(DateTime)) { try @@ -753,7 +755,42 @@ namespace TelegramBotBase.Sessions } } + #endregion + /// + /// Gives access to the original TelegramClient without any Exception catchings. + /// + /// + /// + /// + public T RAW(Func call) + { + return call(this.Client.TelegramClient); + } + + /// + /// This will call a function on the TelegramClient and automatically Retry if an limit has been exceeded. + /// + /// + /// + /// + public async Task API(Func> call) + { + try + { + return await call(this.Client.TelegramClient); + } + catch(ApiRequestException ex) + { + await Task.Delay(ex.Parameters.RetryAfter); + + return await call(this.Client.TelegramClient); + } + } + + + + #region "Events" /// /// Eventhandler for sent messages @@ -796,5 +833,7 @@ namespace TelegramBotBase.Sessions { (this.__Events[__evMessageReceived] as EventHandler)?.Invoke(this, e); } + + #endregion } }