Пример #1
0
        public TgSession(ITelegramBotClient telegramApi, AuthBase authHandler, TgSessionCmdHandler mainHandler)
        {
            TelegramApi = telegramApi;
            AuthHandler = authHandler;
            MainHandler = mainHandler;

            HandlersStack = new Stack <TgSessionCmdHandler>();

            Initialize(mainHandler);
        }
Пример #2
0
 public TgSessionCmdHandler StartHandler(TgSessionCmdHandler tgCmdHandler, Message msg = null)
 {
     lock (HandlersStack)
     {
         HandlersStack.Push(tgCmdHandler);
         Initialize(tgCmdHandler);
         if (msg != null)
         {
             tgCmdHandler.OnStart(msg);
         }
     }
     return(tgCmdHandler);
 }
Пример #3
0
 public void Exit(TgSessionCmdHandler tgCmdHandler)
 {
     lock (HandlersStack)
     {
         if (HandlersStack.Contains(tgCmdHandler))
         {
             while (HandlersStack.Count > 0)
             {
                 var last = HandlersStack.Pop();
                 if (last == tgCmdHandler)
                 {
                     break;
                 }
             }
         }
     }
 }
Пример #4
0
 protected void Initialize(TgSessionCmdHandler tgCmdHandler)
 {
     tgCmdHandler.Session     = this;
     tgCmdHandler.TelegramApi = TelegramApi;
     tgCmdHandler.Initialize();
 }