SwapDude/TelegramBot/BotHandler.cs
Lisoveliy aebe654c38
Some checks are pending
Deploy / update (push) Waiting to run
Build Project .NET / build (push) Waiting to run
chore: init commit from GitHub
2025-05-12 19:44:33 +03:00

61 lines
2.3 KiB
C#

using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using TelegramBot.Commands;
using TelegramBot.Commands.CommandMessages;
namespace TelegramBot;
public static class BotHandler
{
private static readonly LinkMessage LinkMessageProvider = new();
private static readonly StartCommandMessage StartCommandMessageProvider = new();
private static readonly ChangelogCommandMessage ChangelogCommandMessageProvider = new();
private static readonly ErrorMessage ErrorMessageProvider = new();
public static async Task HandleUpdateAsync(
ITelegramBotClient botClient,
Update update,
CancellationToken cancellationToken
)
{
switch (update.Type)
{
case UpdateType.Message:
switch (update.Message?.Text)
{
case StartCommandMessage.CommandName:
await StartCommandMessageProvider.InvokeFromMessage(botClient, update, cancellationToken);
break;
case ChangelogCommandMessage.CommandName:
await ChangelogCommandMessageProvider.InvokeFromMessage(botClient, update, cancellationToken);
break;
default:
Console.WriteLine(update.Message?.Text);
if (string.IsNullOrEmpty(update.Message?.Text))
{
await ErrorMessageProvider.InvokeFromMessage(botClient, update, cancellationToken);
break;
}
await LinkMessageProvider.InvokeFromMessage(botClient, update, cancellationToken);
break;
}
break;
case UpdateType.InlineQuery:
await LinkMessageProvider.InvokeFromInlineQuery(botClient, update, cancellationToken);
break;
}
}
public static Task HandleErrorAsync(
ITelegramBotClient botClient,
Exception exception,
CancellationToken cancellationToken
)
{
Console.WriteLine("Ошибка ядра:\n--------------------------");
Console.WriteLine(exception);
return Task.CompletedTask;
// throw exception;
}
}