Update DeviceSession.cs
Adding a feature for making future API calls.
This commit is contained in:
parent
975a942993
commit
87690a3630
@ -704,6 +704,8 @@ namespace TelegramBotBase.Sessions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#region "Users"
|
||||||
|
|
||||||
public virtual async Task RestrictUser(int userId, ChatPermissions permissions, DateTime until = default(DateTime))
|
public virtual async Task RestrictUser(int userId, ChatPermissions permissions, DateTime until = default(DateTime))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -753,7 +755,42 @@ namespace TelegramBotBase.Sessions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gives access to the original TelegramClient without any Exception catchings.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="call"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public T RAW<T>(Func<Telegram.Bot.TelegramBotClient, T> call)
|
||||||
|
{
|
||||||
|
return call(this.Client.TelegramClient);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This will call a function on the TelegramClient and automatically Retry if an limit has been exceeded.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="call"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public async Task<T> API<T>(Func<Telegram.Bot.TelegramBotClient, Task<T>> 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"
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Eventhandler for sent messages
|
/// Eventhandler for sent messages
|
||||||
@ -796,5 +833,7 @@ namespace TelegramBotBase.Sessions
|
|||||||
{
|
{
|
||||||
(this.__Events[__evMessageReceived] as EventHandler<MessageReceivedEventArgs>)?.Invoke(this, e);
|
(this.__Events[__evMessageReceived] as EventHandler<MessageReceivedEventArgs>)?.Invoke(this, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user