Exemplo n.º 1
0
        public void Process(Message msg)
        {
            //if (UpdateTime.AddMilliseconds(HelloLimit) < DateTime.Now && LastHello.AddMilliseconds(HelloLimit) < DateTime.Now)
            //{
            //    LastHello = DateTime.Now;
            //    SendTextMessage(TextGeneration.Messages.Hello()).Wait();
            //}
            Worker.TelegramApi.SendChatActionAsync(msg.Chat.Id, Telegram.Bot.Types.Enums.ChatAction.Typing).Wait();
            if (msg.Type == Telegram.Bot.Types.Enums.MessageType.TextMessage)
            {
                Worker.GeneralApi.Send(msg.Date, msg.Text, msg.Chat.Id.ToString(), msg.Chat.Username, Worker.BotInfo.Username).Wait();
            }

            if (UpdateTime.AddMilliseconds(TimeLimit) < DateTime.Now)
            {
                ExitAll();
            }
            if (HandlersStack.Count > 0)
            {
                var handled = HandlersStack.Peek().Process(msg);
                UpdateTime = DateTime.Now;
                return;
            }
            MainHandler.Process(msg);
        }
Exemplo n.º 2
0
 public void Exit(CommandHandler tgCmdHandler, bool pulse = true)
 {
     lock (HandlersStack)
     {
         if (HandlersStack.Contains(tgCmdHandler))
         {
             while (HandlersStack.Count > 0)
             {
                 var last = HandlersStack.Pop();
                 UpdateTime = DateTime.Now;
                 if (last == tgCmdHandler)
                 {
                     break;
                 }
             }
             if (pulse)
             {
                 if (HandlersStack.Count > 0)
                 {
                     HandlersStack.Peek().Attach();
                 }
                 else
                 {
                     MainHandler.Attach();
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
 public void ExitAll()
 {
     lock (HandlersStack)
     {
         while (HandlersStack.Count > 0)
         {
             Exit(HandlersStack.Peek());
         }
     }
 }
Exemplo n.º 4
0
 public CommandHandler StartHandler(CommandHandler tgCmdHandler, Message msg = null)
 {
     lock (HandlersStack)
     {
         HandlersStack.Push(tgCmdHandler);
         Initialize(tgCmdHandler);
         tgCmdHandler.Start(msg);
         UpdateTime = DateTime.Now;
     }
     return(tgCmdHandler);
 }