chore: init commit from GitHub
This commit is contained in:
61
TelegramBot/BotHandler.cs
Normal file
61
TelegramBot/BotHandler.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user