|
@@ -11,26 +11,8 @@ using Telegram.Bot.Types.Enums;
|
|
|
|
|
|
namespace MafiaTelegramBot.Controllers
|
|
|
{
|
|
|
- public static class MessageController //: ApiController
|
|
|
+ public static class MessageController
|
|
|
{
|
|
|
- /*
|
|
|
- [Route(@api/message/update)]
|
|
|
- public async Task<OkResult> UpdateCommand([FromBody]UpdateCommand update)
|
|
|
- {
|
|
|
- var commands = Bot.Commands;
|
|
|
- var message = update.Message;
|
|
|
- var client = await Bot.Get();
|
|
|
-
|
|
|
- foreach(var command in commands)
|
|
|
- {
|
|
|
- if (command.Contains(message.Text)) command.Execute(message, client);
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- return Ok();
|
|
|
- }
|
|
|
- */
|
|
|
-
|
|
|
public static async Task HandleUpdateAsync(ITelegramBotClient botClient, Update update,
|
|
|
CancellationToken cancellationToken)
|
|
|
{
|
|
@@ -38,8 +20,8 @@ namespace MafiaTelegramBot.Controllers
|
|
|
{
|
|
|
var handle = update.Type switch
|
|
|
{
|
|
|
- //TODO handle other update type if needed
|
|
|
- UpdateType.Message => update.Message.ReplyToMessage != null && update.Message.ReplyToMessage.Text != strings.start_message
|
|
|
+ UpdateType.Message => update.Message.ReplyToMessage != null &&
|
|
|
+ update.Message.ReplyToMessage.Text != strings.start_message
|
|
|
? Reply.Update(update)
|
|
|
: Command.Update(update),
|
|
|
UpdateType.CallbackQuery => Query.Update(update),
|
|
@@ -47,16 +29,6 @@ namespace MafiaTelegramBot.Controllers
|
|
|
};
|
|
|
await handle;
|
|
|
}
|
|
|
- catch (NullReferenceException)
|
|
|
- {
|
|
|
- var command = update.Type switch
|
|
|
- {
|
|
|
- UpdateType.Message => update.Message.Text,
|
|
|
- UpdateType.CallbackQuery => update.CallbackQuery.Data,
|
|
|
- _ => "unknown"
|
|
|
- };
|
|
|
- Console.WriteLine($"Command \"{command}\" not found");
|
|
|
- }
|
|
|
catch (Exception exception)
|
|
|
{
|
|
|
await HandleErrorAsync(botClient, exception, cancellationToken);
|
|
@@ -65,7 +37,7 @@ namespace MafiaTelegramBot.Controllers
|
|
|
|
|
|
private static Task UnknownUpdateHandlerAsync(Update update)
|
|
|
{
|
|
|
- Console.WriteLine($"Unknown update type: {update.Type}");
|
|
|
+ Console.WriteLine(update.Type);
|
|
|
return Task.CompletedTask;
|
|
|
}
|
|
|
|