Ejemplo n.º 1
0
        public BotAPI(Proxy proxy = null)
        {
            Configs  = BotManager.Core.Configs;
            Dialogs  = BotManager.Core.Dialogs;
            Commands = BotManager.Core.Commands;

            ContextController = new UserInputContextController();
            UiController      = BotManager.Core.Repository.CreateUiDispatcher(ContextController);
            UsersController   = BotManager.Core.Repository.CreateUserController();
            DataParser        = new DataParser();

            // start telegram api initializing
            HttpClient httpClient = null;

            try
            {
                BotManager.Core?.LogController?.LogSystem(new DebugMessage($"Start initializing Telegram Bot Api...\r\nUse proxy: {Configs.UseProxy}"));

                if (Configs.UseProxy)
                {
                    BotManager.Core?.LogController?.LogImportant(new DebugMessage($"Proxy enabled. Use proxy: <<xxx>>"));
                    // init httpClient
                    httpClient = new HttpClient();

                    BotManager.Core?.LogController?.LogImportant(new DebugMessage($"Proxy NOT IMPLEMENTED"));
                }

                Api                        = new TelegramBotClient(Configs.BotHash, httpClient);
                Api.OnMessage             += Api_OnMessage;
                Api.OnCallbackQuery       += Api_OnCallbackQuery;
                Api.OnInlineQuery         += Api_OnInlineQuery;
                Api.OnReceiveError        += Api_OnReceiveError;
                Api.OnReceiveGeneralError += Api_OnReceiveGeneralError;
                Api.OnUpdate              += Api_OnUpdate;

                // here we get some useful bot info and at the same time
                // checks if connection established or not.
                BotManager.Core?.LogController?.LogImportant(new DebugMessage($"Conect Api client with bot token: <<{Configs.BotHash}>> ..."));
                System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                sw.Start();

                BotInfo = Api.GetMeAsync().Result;
                BotName = BotInfo.Username;
                ContextController.SetIgnored(BotInfo.Id);

                sw.Stop();
                BotManager.Core?.LogController?
                .LogSucces(new DebugMessage($"Conection is cuccess (response time = {sw.Elapsed})\r\n--> Bot Api initialized and ready!"));
            }
            catch (Exception e)
            {
                BotManager.Core?.LogController?.LogCritical(new DebugMessage("Api initialization failed!", "BotApi()", e));
            }
            finally
            {
                httpClient?.Dispose();
            }
        }
Ejemplo n.º 2
0
 public UIDispatcher(UserInputContextController uicc)
 {
     // just setup references
     ContextController  = uicc;
     Configs            = BotManager.Core.Configs;
     Operations         = BotManager.Core.Operations;
     Dialogs            = BotManager.Core.Dialogs;
     CallbackDataParser = BotManager.Core.Repository.CreateCallbackParser();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Default constructor.
        /// Same thing as create new configs vith default values
        /// </summary>
        public EditorCore()
        {
            // set repository first
            Repository = new EditorRepository();

            Operations = new OperationsContainer();
            BotManager.SetCore(this);
            var rawConfigs = Config.RawData.Configs.GetDefaultConfigs();

            Configs = new BotConfigs(rawConfigs);
            Dialogs = new DialogsProvider(rawConfigs.Dialogs);
        }
Ejemplo n.º 4
0
        public EditorCore(BotConfigs configs, DialogsProvider dialogs)
        {
            if (configs == null)
            {
                throw new ArgumentNullException("configs");
            }

            Operations = new OperationsContainer();
            BotManager.SetCore(this);

            Configs = configs;
            Dialogs = dialogs;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Build serializeble configs from work data
        /// </summary>
        public Configs(BotConfigs configs, DialogsProvider dialogs)
        {
            BasicDelay = configs.BasicDelay;
            BotHash    = configs.BotHash;
            BotName    = configs.BotName;

            CustomValues   = new ConfigValuesContainer(configs.GetCustomValues(), CustomValuesSectionName);
            LanguageValues = new LangValuesContainer(configs.TextStrings);

            // fill proxies
            ProxyServers = new List <ProxyValue>();
            foreach (var prox in configs.Proxies)
            {
                ProxyServers.Add(new ProxyValue(prox));
            }

            Dialogs = new DialogsContainer(dialogs);
        }