WIP: implemented registration and EULA accept, WIP on auth issue

This commit is contained in:
2025-07-12 01:24:39 +03:00
parent ac39117cf4
commit 67a3457f2d
17 changed files with 569 additions and 87 deletions

View 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;
}
}