Esempio n. 1
0
        static void Main(string[] args)
        {
            String apiKey = "APIKey";

            bot = new TelegramBotBase.BotBase <forms.Start>(apiKey);

            bot.Start();

            var timer = new Timer(5000);

            timer.Elapsed += Timer_Elapsed;
            timer.Start();

            Console.ReadLine();

            timer.Stop();
            bot.Stop();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            BotConfig = config.Config.load();

            if (BotConfig.ApiKey == null || BotConfig.ApiKey.Trim() == "")
            {
                Console.WriteLine("Config created...");
                Console.ReadLine();
                return;
            }

            var bot = new TelegramBotBase.BotBase <forms.StartForm>(BotConfig.ApiKey);

            bot.Start();

            Console.WriteLine("Bot started");

            Console.ReadLine();


            bot.Stop();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            //Serilog logger config
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .Enrich.FromLogContext()
                         .WriteTo.Console()
                         .WriteTo.File(new CompactJsonFormatter(), "./logs/msTgInterface/json/log.json", rollingInterval: RollingInterval.Day)
                         .WriteTo.File("./logs/msTgInterface/txt/log.txt", rollingInterval: RollingInterval.Day)
                         .CreateLogger();

            //Microsoft.Logging for VkNet config and setup
            using var loggerFactory = LoggerFactory.Create(builder => {
                builder
                .ClearProviders()
                .AddFilter("Microsoft", LogLevel.Warning)
                .AddFilter("System", LogLevel.Warning)
                .SetMinimumLevel(LogLevel.Debug)
                .AddSerilog(dispose: true);
            });

            VkApisManager.logger = loggerFactory.CreateLogger <VkNet.VkApi>();

            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("appsettings.json");

            var configuration = builder.Build();

            var modelScoutAPIOptions = new ModelScoutAPIOptions();

            configuration.GetSection(ModelScoutAPIOptions.ModelScout)
            .Bind(modelScoutAPIOptions);

            var apiKey = configuration.GetSection("TgInterface")
                         .GetSection("ApiKey")
                         .Value;

            var bot = new TelegramBotBase.BotBase <Forms.StartForm>(apiKey);

            ModelScoutAPIPooler.DefaultOptions = modelScoutAPIOptions;
            VkApisManager.modelScoutAPIOptions = modelScoutAPIOptions;

            bot.StateMachine = new TelegramBotBase.States.JSONStateMachine(
                AppContext.BaseDirectory + "config\\states.json");

            bot.SetSetting(TelegramBotBase.Enums.eSettings.LogAllMessages, true);
            bot.Message += (s, en) => {
                using (LogContext.PushProperty("message", en.Message)) {
                    Log.Information(
                        "New msg from @{Username}({ChatId}) \"{Text}\" {RawData}",
                        en.Message.Message.From.Username,
                        en.DeviceId,
                        en.Message.MessageText,
                        en.Message.RawData ?? "");
                }
            };

            bot.Start();
            Log.Information("Bot started");

            Console.ReadLine();

            bot.Stop();
            Log.Information("Bot stopped");
        }