Доработан обработчик команд. Добавлена публикация команд
All checks were successful
CI / build-test (push) Successful in 31s
Release / pack-and-publish (release) Successful in 35s

This commit is contained in:
2025-12-07 10:09:59 +03:00
parent 8af03fa52b
commit edc718b1f9
9 changed files with 127 additions and 17 deletions

View File

@@ -69,16 +69,34 @@ public sealed class BotPagesApp
/// </summary>
public BotPagesApp MapCommand<TPage>(string commandTemplate) where TPage : Page
{
_commands.Map<TPage>(commandTemplate);
_commands.Map<TPage>(commandTemplate, false, null);
return this;
}
/// <summary>
/// Зарегистрировать команду, ведущую на страницу.
/// </summary>
public BotPagesApp MapCommand<TPage>(string commandTemplate, bool publish, string description) where TPage : Page
{
_commands.Map<TPage>(commandTemplate, publish, description);
return this;
}
/// <summary>
/// Зарегистрировать команду с кастомным обработчиком.
/// </summary>
public BotPagesApp MapCommand(string template, Func<PageContext, CancellationToken, Task> handler)
public BotPagesApp MapCommand(string template, CommandHandler handler)
{
_commands.Map(template, handler);
_commands.Map(template, handler, false, null);
return this;
}
/// <summary>
/// Зарегистрировать команду с кастомным обработчиком.
/// </summary>
public BotPagesApp MapCommand(string template, CommandHandler handler, bool publish, string description)
{
_commands.Map(template, handler, publish, description);
return this;
}
@@ -142,7 +160,6 @@ public sealed class BotPagesApp
{
if (_commands.TryDispatch(ctx, update.Text, ct, out var dispatched) && dispatched is not null)
{
_logger.Log(LogLevel.Info, $"Command '{update.Text}' dispatched.");
await dispatched;
return;
}
@@ -237,7 +254,7 @@ public sealed class BotPagesApp
{
foreach (var adapter in _adapterFactory.Adapters)
{
await adapter.Value.StartAdapterAsync(update => HandleUpdateAsync(update, cancellationToken), cancellationToken);
await adapter.Value.StartAdapterAsync(update => HandleUpdateAsync(update, cancellationToken), _commands.Commands, cancellationToken);
}
}
}