Reply.cs 850 B

12345678910111213141516171819202122
  1. #nullable enable
  2. using System.Threading.Tasks;
  3. using Telegram.Bot.Types;
  4. using Telegram.Bot.Types.Enums;
  5. namespace MafiaTelegramBot.Models.Replies
  6. {
  7. public abstract class Reply : UpdateModel<string>
  8. {
  9. public static async Task<Message> Update(Update update)
  10. {
  11. var commands = Bot.Replies;
  12. var message = update.Message.ReplyToMessage.Text;
  13. var userId = update.Message.From.Id;
  14. var chatId = update.Message.Chat.Id;
  15. await Bot.Get().SendChatActionAsync(chatId, ChatAction.Typing);
  16. var command = FirstOrDefault(commands, message);
  17. if(command != null) return await ((Reply?) command.Clone(chatId, userId))!.Execute(update);
  18. return await Bot.SendWithMarkdown2(chatId, $"{strings.command_not_found} _*\\({message}\\)*_");
  19. }
  20. }
  21. }