示例#1
0
        /// <summary>
        /// Loads the configuration from the specified file path.
        /// </summary>
        /// <returns></returns>
        public static BotSetup LoadConfig()
        {
            configPath = "TelegramBotConfig.json";
            BotSetup config = new BotSetup();

            if (System.IO.File.Exists(configPath))
            {
                string jsonconfig = System.IO.File.ReadAllText(configPath);

                try
                {
                    config = JsonConvert.DeserializeObject <BotSetup>(jsonconfig);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                return(config);
            }
            config          = new BotSetup();
            config.BotToken = "your token here";
            SaveConfig(config);
            return(null);
        }
示例#2
0
        /// <summary>
        /// Saves the config.
        /// </summary>
        /// <param name="config">Config.</param>
        public static void SaveConfig(BotSetup config)
        {
            string json = JsonConvert.SerializeObject(config, Formatting.Indented);

            System.IO.File.WriteAllText(configPath, json);
        }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Core.TelegramService"/> class.
 /// </summary>
 /// <param name="cfg">Cfg.</param>
 public TelegramService(BotSetup cfg)
 {
     Cfg = cfg;
     //Thread listener = new Thread(new ThreadStart(Start));
 }