Доработан обработчик команд. Добавлена публикация команд
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user