chore: cleanup
This commit is contained in:
parent
a526dbf6c6
commit
6e16c5831e
@ -12,9 +12,6 @@ public class EulaAgreementButtonCommand(PrepareUserState prepareUserState) : IAu
|
||||
{
|
||||
public async Task ExecuteAsync(Update update, GetUserResponse user, CancellationToken ct)
|
||||
{
|
||||
if (update.Type != UpdateType.Message || update.Message?.From == null)
|
||||
return;
|
||||
|
||||
await prepareUserState.AcceptEula(update, ct);
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using Telegram.Bot;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace JOBot.TClient.Commands;
|
||||
namespace JOBot.TClient.Commands.Commands;
|
||||
|
||||
public class InfoCommand(ITelegramBotClient bot) : ITelegramCommand
|
||||
{
|
@ -2,7 +2,7 @@ using JOBot.Proto;
|
||||
using JOBot.TClient.Services;
|
||||
using Telegram.Bot.Types;
|
||||
|
||||
namespace JOBot.TClient.Commands;
|
||||
namespace JOBot.TClient.Commands.Commands;
|
||||
|
||||
public class MenuCommand(MenuService menuService) : IAuthorizedTelegramCommand
|
||||
{
|
@ -1,9 +1,7 @@
|
||||
using JOBot.TClient.Commands.Buttons;
|
||||
using JOBot.TClient.Statements;
|
||||
using Telegram.Bot.Types;
|
||||
using Telegram.Bot.Types.Enums;
|
||||
|
||||
namespace JOBot.TClient.Commands;
|
||||
namespace JOBot.TClient.Commands.Commands;
|
||||
|
||||
public class StartCommand(PrepareUserState prepareUserState) : ITelegramCommand
|
||||
{
|
@ -8,6 +8,8 @@ public interface IAuthorizedTelegramCommand : ITelegramCommand
|
||||
{
|
||||
public Task ExecuteAsync(Update update, GetUserResponse user, CancellationToken ct);
|
||||
|
||||
/// <exception cref="UnauthorizedAccessException">Throws if you try to use ITelegramCommand.ExecuteAsync
|
||||
/// instead of IAuthorizedTelegramCommand.ExecuteAsync</exception>
|
||||
Task ITelegramCommand.ExecuteAsync(Update update, CancellationToken ct)
|
||||
{
|
||||
throw new UnauthorizedAccessException("You do not have permission to access this command.");
|
||||
|
@ -1,5 +1,6 @@
|
||||
using JOBot.TClient.Commands;
|
||||
using JOBot.TClient.Commands.Buttons;
|
||||
using JOBot.TClient.Commands.Commands;
|
||||
using JOBot.TClient.Infrastructure.Attributes.Authorization;
|
||||
using JOBot.TClient.Infrastructure.Extensions;
|
||||
using JOBot.TClient.Services;
|
||||
@ -42,9 +43,9 @@ public sealed class BotBackgroundService(
|
||||
[ButtonResource.EULAAgrement] = scope.ServiceProvider.GetRequiredService<EulaAgreementButtonCommand>(),
|
||||
};
|
||||
|
||||
if (update.Message?.Text is { } text && update.Message?.From != null)
|
||||
if (update.Message is { Text: { } text, From: not null })
|
||||
{
|
||||
var user = await userService.GetUser(update, ct); //Check user for existance
|
||||
var user = await userService.GetUser(update, ct); //Проверка существования пользователя
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
@ -56,15 +57,20 @@ public sealed class BotBackgroundService(
|
||||
{
|
||||
if (command is IAuthorizedTelegramCommand authorizedTelegramCommand)
|
||||
{
|
||||
var attribute = Attribute.GetCustomAttribute(command.GetType(), typeof(AcceptNotPreparedAttribute));
|
||||
var attribute = Attribute.GetCustomAttribute(
|
||||
command.GetType(),
|
||||
typeof(AcceptNotPreparedAttribute));
|
||||
if (!user.IsPrepared() && attribute is not AcceptNotPreparedAttribute)
|
||||
{
|
||||
await commands["/start"].ExecuteAsync(update, ct); //заставляем пользователя завершить регистрацию
|
||||
await commands["/start"].ExecuteAsync(update, ct);
|
||||
//заставляем пользователя завершить регистрацию
|
||||
return;
|
||||
}
|
||||
|
||||
await authorizedTelegramCommand.ExecuteAsync(update, user, ct);
|
||||
}
|
||||
else await command.ExecuteAsync(update, ct);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
using Grpc.Core;
|
||||
using Grpc.Net.Client;
|
||||
using JOBot.Proto;
|
||||
using JOBot.TClient.Commands;
|
||||
using JOBot.TClient.Commands.Buttons;
|
||||
using JOBot.TClient.Commands.Commands;
|
||||
using JOBot.TClient.Core.HostedServices;
|
||||
using JOBot.TClient.Services;
|
||||
using JOBot.TClient.Statements;
|
||||
|
Loading…
x
Reference in New Issue
Block a user