WIP: implemented registration and EULA accept, WIP on auth issue
This commit is contained in:
41
JOBot.TClient/Services/UserService.cs
Normal file
41
JOBot.TClient/Services/UserService.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Grpc.Core;
|
||||
using JOBot.Proto;
|
||||
using JOBot.TClient.Infrastructure.Exceptions;
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
using User = JOBot.Proto.User;
|
||||
|
||||
namespace JOBot.TClient.Services;
|
||||
|
||||
public class UserService(ITelegramBotClient bot, User.UserClient userClient)
|
||||
{
|
||||
/// <summary>
|
||||
/// Get user
|
||||
/// </summary>
|
||||
/// <param name="update">Telegram Update object</param>
|
||||
/// <param name="ct">Cancellation Token</param>
|
||||
/// <returns>RPC User Response or null if user not exists</returns>
|
||||
/// <exception cref="FallbackException">If something in server logic went wrong</exception>
|
||||
/// <exception cref="ArgumentNullException">If update.Message is null</exception>
|
||||
public async Task<GetUserResponse?> GetUser(Update update, CancellationToken ct = default)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(update.Message?.From);
|
||||
|
||||
GetUserResponse? user;
|
||||
try
|
||||
{
|
||||
user = await userClient.GetUserAsync(new GetUserRequest() //Получаем пользователя
|
||||
{
|
||||
UserId = update.Message.From.Id,
|
||||
});
|
||||
}
|
||||
catch (RpcException e) //Пользователь не найден?
|
||||
{
|
||||
if (e.StatusCode != StatusCode.NotFound)
|
||||
throw new FallbackException(TextResource.FallbackMessage, update.Message, bot);
|
||||
|
||||
return null;
|
||||
}
|
||||
return user;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user