Exemple #1
0
        private void BackgroundCheck()
        {
#if DEBUG
            logger.Warn("Background pinger is disabled in debug mode.");
#else
            Thread.Sleep(60000);
            while (true)
            {
                try
                {
                    foreach (BotConfig bot in coreConfig.Bots)
                    {
                        if (!PingedRecently(bot.Username) && IsPrimetime())
                        {
                            logger.Warn($"Бот {bot.Username} давно не пинговал, видимо, он умер.");
                            VK.Alert($"Бот {bot.Username} давно не пинговал, видимо, он умер.");
                        }
                    }
                }
                catch
                {
                }
                Thread.Sleep(60000);
                ReloadConfig();
            }
#endif
        }
Exemple #2
0
        static void ReOpener()
        {
            int i = 1;

            while (true)
            {
                Thread.Sleep(10000);
                if (died)
                {
                    if (!opening)
                    {
                        try {
                            Log.ApiError($"Trying to reconnect for the {i++}-th time");
                            VK.Alert("АХТУНГ, БАЛАНСЕР УПАЛ");
                            AllocSocket();
                            OpenSocket();
                        } catch (Exception ex) {
                            Log.Error("Some error occured. Message: " + ex.Message + "\nTrace: " + ex.StackTrace);
                        }
                    }
                    else
                    {
                        AllocSocket();
                        OpenSocket();
                    }
                }
            }
        }
Exemple #3
0
        public void Nanny()
        {
            Thread.Sleep(5000);
            if (ConfigObject.Bots.Any(bot => !bot.TMDisabled))
            {
                Balancer.Init();
            }
            Dictionary <string, DateTime> lastRestart = new Dictionary <string, DateTime>();
            TimeSpan restartInterval = new TimeSpan(0, 2, 0);

            while (!disposed)
            {
                try {
                    foreach (RunningBot bot in botProcs)
                    {
                        if (bot.IsRunning && bot.TheBot.WantToRestart())
                        {
                            DateTime now = DateTime.Now;
                            if (lastRestart.TryGetValue(bot.BotConfig.Username, out DateTime dt))
                            {
                                TimeSpan timeGone = now.Subtract(dt);
                                if (restartInterval.CompareTo(timeGone) > 0)
                                {
                                    mongoLog.ApiError($"Nanny is waiting {restartInterval.Subtract(timeGone).TotalSeconds} seconds");
                                    VK.Alert($"Nanny is waiting {restartInterval.Subtract(timeGone).TotalSeconds} seconds");
                                    Thread.Sleep(restartInterval.Subtract(timeGone));
                                }
                            }
                            mongoLog.ApiError($"Nanny is restarting bot {bot.BotConfig.Username}");
                            VK.Alert($"Nanny is restarting bot {bot.BotConfig.Username}");
                            RestartBot(bot.BotConfig.Username);
                            lastRestart[bot.BotConfig.Username] = DateTime.Now;
                            Thread.Sleep(100);
                        }
                    }
                } catch (Exception ex) {
                    mongoLog.Error($"Няне больно =(\n{ex.Message}{ex.StackTrace}");
                    VK.Alert($"Няне больно =(\n{ex.Message}{ex.StackTrace}");
                } finally {
                    Thread.Sleep(5000);
                }
            }
        }
Exemple #4
0
 private void BackgroundCheck()
 {
     Thread.Sleep(60000);
     while (!disposed)
     {
         try {
             foreach (BotConfig bot in coreConfig.Bots)
             {
                 if (!PingedRecently(bot.Username))
                 {
                     logger.Warn($"Бот {bot.Username} давно не пинговал, видимо, он умер.");
                     VK.Alert($"Бот {bot.Username} давно не пинговал, видимо, он умер.");
                 }
             }
         } catch {
         }
         Tasking.WaitForFalseOrTimeout(() => !disposed, 60000).Wait();
         ReloadConfig();
     }
 }
Exemple #5
0
 public void Crash(string data, params object[] formatParams)
 {
     VK.Alert($"Unhandled exception occured: {data}");
     logCollection.Insert(CreateRawLogMessage(LogLevel.Crash, data, formatParams));
 }
Exemple #6
0
 private bool Alert(string message)
 {
     return(VK.Alert($"[{bot.DisplayName}]: {message}"));
 }