Ejemplo n.º 1
0
        public static IReplyMarkup GetKeyboardByTelegramBotState(TelegramBotState state)
        {
            switch (state)
            {
            case TelegramBotState.DownloadMode:
                return(DownloadKeyboard());

            case TelegramBotState.DownloadQued:
                return(DownloadMessageKeyboard());

            case TelegramBotState.ConfigRouter:
                return(ConfigRouter());

            default:
                return(MainKeyboard());
            }
        }
Ejemplo n.º 2
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.");
        }
Ejemplo n.º 3
0
        private async Task ProcessUpdate(Update update)
        {
            Message message = update.Message;

            if (message == null)
            {
                message = update.CallbackQuery.Message;
            }

            if (message.Chat.Id == _ChatID)
            {
                await _telebot.SendChatActionAsync(message.Chat.Id, ChatAction.Typing, _ct);

                if (update.Type == UpdateType.MessageUpdate)
                {
                    string msg = string.Empty;
                    if (!string.IsNullOrEmpty(message.Text))
                    {
                        if (message.Text.Equals("\ud83d\udd5a Server starten"))
                        {
                            _serverAwake = await NetworkHelper.IsServerAwake();

                            msg = "Der Server ist bereits an.";
                            if (!_serverAwake)
                            {
                                await NetworkHelper.WakeTheServer();

                                ThreadPoolTimer.CreateTimer(CheckServerStateTimerElapsedHandler, new TimeSpan(0, 2, 0));
                                msg = "Der Server wird gestartet";
                            }
                        }
                        else if (message.Text.Equals("\ud83d\udd17 Download Modus"))
                        {
                            msg    = "Download Modus aktiv";
                            _state = TelegramBotState.DownloadMode;
                        }
                        else if (message.Text.Equals("\U0001f519 Download Modus beenden"))
                        {
                            msg    = "Download Modus beendet";
                            _state = TelegramBotState.MainMenu;
                        }
                    }
                    if (string.IsNullOrEmpty(msg))
                    {
                        if (_state >= TelegramBotState.DownloadMode && _state <= TelegramBotState.DownloadQued)
                        {
                            await _aria2.DownloadUri(message.Text, message.MessageId);

                            msg    = "Download eingereiht";
                            _state = TelegramBotState.DownloadQued;
                        }
                        else
                        {
                            msg = "Kommando nicht verstanden.";
                        }
                    }
                    await SendMessageAsync(msg).AsTask <int>();
                }
                else if (update.Type == UpdateType.CallbackQueryUpdate)
                {
                    await SendMessageAsync("Callback Stuff", message.MessageId);

                    //ToDo: Mit dem Download interagieren
                }
            }
        }