Exemplo n.º 1
0
 public RpcAria2Helper(TelegramBot telegramBot)
 {
     _telegramBot = telegramBot;
     _serverUri   = new Uri(telegramBot.Config.GetString("Aria2URL"));
     _Aria2Token  = telegramBot.Config.GetString("Aria2Secret");
     _log.TraceAsync("RPCAria2Helper initialisiert.");
 }
Exemplo n.º 2
0
        public async void Start()
        {
            Initialize();
            int offset = 0;

            await SendMessageAsync("Bot gestartet.");

            while (!_ct.IsCancellationRequested)
            {
                Update[] updates = await _telebot.GetUpdatesAsync(offset);

                if (updates.Any())
                {
                    await _log.TraceAsync("Update received.");

                    offset = updates.Max(u => u.Id) + 1;
                    foreach (Update update in updates)
                    {
                        await ProcessUpdate(update);
                    }
                }
            }
        }
Exemplo n.º 3
0
        private void Initialize()
        {
            LoggingConfiguration logConf = new LoggingConfiguration();

#if DEBUG
            logConf.AddTarget(LogLevel.Trace, LogLevel.Fatal, new StreamingFileTarget());
            logConf.AddTarget(LogLevel.Debug, LogLevel.Fatal, new DebugTarget());
#else
            logConf.AddTarget(LogLevel.Error, LogLevel.Fatal, new StreamingFileTarget());
#endif
            logConf.IsEnabled = true;
            LogManagerFactory.DefaultConfiguration = logConf;
            _log   = (ILoggerAsync)LogManagerFactory.DefaultLogManager.GetLogger <TelegramBot>();
            _ctSrc = new CancellationTokenSource();
            _ct    = _ctSrc.Token;
            _conf  = ResourceLoader.GetForViewIndependentUse("Config");
            _CheckServerStateTimer = ThreadPoolTimer.CreatePeriodicTimer(CheckServerStateTimerElapsedHandler, new TimeSpan(0, 5, 0));
            _telebot     = new TelegramBotClient(_conf.GetString("TelegramToken"));
            _ChatID      = Convert.ToInt64(_conf.GetString("TelegramChatID"));
            _aria2       = new Helpers.RpcAria2Helper(this);
            _serverAwake = false;
            _state       = TelegramBotState.None;
            _log.TraceAsync("Initialize abgeschlossen.");
        }